-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MODLD-593 (Spike): Retaining admin metadata
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
src/main/java/org/folio/linked/data/service/resource/ResourceEdgeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.folio.linked.data.service.resource; | ||
|
||
import org.folio.linked.data.model.entity.Resource; | ||
|
||
public interface ResourceEdgeService { | ||
void copyOutgoingEdges(Resource from, Resource to); | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/org/folio/linked/data/service/resource/impl/ResourceEdgeServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.folio.linked.data.service.resource.impl; | ||
|
||
import org.folio.ld.dictionary.PredicateDictionary; | ||
import org.folio.ld.dictionary.ResourceTypeDictionary; | ||
import org.folio.linked.data.model.entity.Resource; | ||
import org.folio.linked.data.model.entity.ResourceEdge; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Predicate; | ||
|
||
@Service | ||
public class ResourceEdgeServiceImpl { | ||
|
||
// If there are more conditions like this, move them to an inner class or enum | ||
private static final Predicate<ResourceEdge> IS_ADMIN_METADATA = edge -> edge.getPredicate().getUri() | ||
.equals(PredicateDictionary.ADMIN_METADATA.getUri()); | ||
private static final Predicate<ResourceEdge> SOME_OTHER_CONDITION = edge -> true; // Dummy condition | ||
|
||
private Map<ResourceTypeDictionary, Predicate<ResourceEdge>> rules; | ||
|
||
public ResourceEdgeServiceImpl() { | ||
initializeRules(); | ||
} | ||
|
||
public void copyOutgoingEdges(Resource from, Resource to) { | ||
this.rules.entrySet() | ||
.stream() | ||
.filter(entry -> from.isOfType(entry.getKey())) | ||
.filter(entry -> to.isOfType(entry.getKey())) | ||
.map(Map.Entry::getValue) | ||
.flatMap(condition -> from.getOutgoingEdges().stream().filter(condition)) | ||
.map(edge -> new ResourceEdge(to, edge.getTarget(), edge.getPredicate())) | ||
.forEach(to::addOutgoingEdge); | ||
} | ||
|
||
private void initializeRules() { | ||
this.rules = Map.of( | ||
ResourceTypeDictionary.WORK, IS_ADMIN_METADATA.or(SOME_OTHER_CONDITION), // Chain more conditions here | ||
ResourceTypeDictionary.INSTANCE, IS_ADMIN_METADATA // Chain more conditions here | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters