use of org.folio.inventory.domain.instances.InstanceRelationshipToParent in project mod-inventory by folio-org.
the class InstanceUtil method constructParentInstancesList.
private static List<ParentInstance> constructParentInstancesList(Instance existing) {
List<ParentInstance> parentInstances = new ArrayList<>();
for (InstanceRelationshipToParent parent : existing.getParentInstances()) {
ParentInstance parentInstance = new ParentInstance().withId(parent.getId()).withSuperInstanceId(parent.getSuperInstanceId()).withInstanceRelationshipTypeId(parent.getInstanceRelationshipTypeId());
parentInstances.add(parentInstance);
}
return parentInstances;
}
use of org.folio.inventory.domain.instances.InstanceRelationshipToParent in project mod-inventory by folio-org.
the class InstanceUtilTest method shouldMergeInstances.
@Test
public void shouldMergeInstances() {
Set<AlternativeTitle> alternativeTitles = new HashSet<>();
alternativeTitles.add(new AlternativeTitle().withAlternativeTitle("alt1").withAlternativeTitleTypeId("30773a27-b485-4dab-aeb6-b8c04fa3cb19"));
List<Contributor> contributors = new ArrayList<>();
contributors.add(new Contributor().withName("contributor1").withContributorNameTypeId("30773a27-b485-4dab-aeb6-b8c04fa3cb19").withContributorTypeId("30773a27-b485-4dab-aeb6-b8c04fa3cb19").withContributorTypeText("text").withPrimary(true));
Instance mapped = new Instance().withId("30773a27-b485-4dab-aeb6-b8c04fa3cb17").withHrid("in000000001").withModeOfIssuanceId("30773a27-b485-4dab-aeb6-b8c04fa3cb18").withAlternativeTitles(alternativeTitles).withContributors(contributors);
List<String> statisticalCodeIds = new ArrayList<>();
statisticalCodeIds.add("30773a27-b485-4dab-aeb6-b8c04fa3cb19");
statisticalCodeIds.add("30773a27-b485-4dab-aeb6-b8c04fa3cb18");
List<String> natureOfContentTermIds = new ArrayList<>();
statisticalCodeIds.add("30773a27-b485-4dab-aeb6-b8c04fa3cb21");
statisticalCodeIds.add("30773a27-b485-4dab-aeb6-b8c04fa3cb22");
List<InstanceRelationshipToParent> parents = new ArrayList<>();
parents.add(new InstanceRelationshipToParent("30773a27-b485-4dab-aeb6-b8c04fa3cb19", "30773a27-b485-4dab-aeb6-b8c04fa3cb23", "30773a27-b485-4dab-aeb6-b8c04fa3cb24"));
List<InstanceRelationshipToChild> children = new ArrayList<>();
children.add(new InstanceRelationshipToChild("30773a27-b485-4dab-aeb6-b8c04fa3cb19", "30773a27-b485-4dab-aeb6-b8c04fa3cb23", "30773a27-b485-4dab-aeb6-b8c04fa3cb24"));
List<String> tagList = new ArrayList<>();
tagList.add("Tag1");
tagList.add("Tag2");
org.folio.inventory.domain.instances.Instance existing = new org.folio.inventory.domain.instances.Instance("30773a27-b485-4dab-aeb6-b8c04fa3cb17", "7", "in000000001", "source", "title", "30773a27-b485-4dab-aeb6-b8c04fa3cb19");
existing.setStatisticalCodeIds(statisticalCodeIds);
existing.setDiscoverySuppress(true);
existing.setStaffSuppress(true);
existing.setPreviouslyHeld(true);
existing.setCatalogedDate("");
existing.setStatusId("30773a27-b485-4dab-aeb6-b8c04fa3cb26");
existing.setNatureOfContentTermIds(natureOfContentTermIds);
existing.setParentInstances(parents);
existing.setChildInstances(children);
existing.setTags(tagList);
org.folio.inventory.domain.instances.Instance instance = InstanceUtil.mergeFieldsWhichAreNotControlled(existing, mapped);
assertEquals("30773a27-b485-4dab-aeb6-b8c04fa3cb17", instance.getId());
assertEquals("in000000001", instance.getHrid());
assertEquals("30773a27-b485-4dab-aeb6-b8c04fa3cb18", instance.getModeOfIssuanceId());
assertEquals(contributors.get(0).getName(), instance.getContributors().get(0).name);
assertEquals(statisticalCodeIds, instance.getStatisticalCodeIds());
assertTrue(instance.getDiscoverySuppress());
assertTrue(instance.getStaffSuppress());
assertTrue(instance.getPreviouslyHeld());
assertEquals("", instance.getCatalogedDate());
assertEquals("30773a27-b485-4dab-aeb6-b8c04fa3cb26", instance.getStatusId());
assertEquals(natureOfContentTermIds, instance.getNatureOfContentTermIds());
assertNotNull(instance.getTags());
assertEquals(tagList, instance.getTags());
assertEquals("30773a27-b485-4dab-aeb6-b8c04fa3cb19", instance.getParentInstances().get(0).getId());
assertEquals("30773a27-b485-4dab-aeb6-b8c04fa3cb19", instance.getChildInstances().get(0).getId());
}
use of org.folio.inventory.domain.instances.InstanceRelationshipToParent in project mod-inventory by folio-org.
the class AbstractInstances method toRepresentation.
/**
* Populates multiple Instances representation (downwards)
*
* @param instancesResponse Set of Instances to transform to representations
* @param context
* @return Result set as JSON object
*/
protected JsonObject toRepresentation(InstancesResponse instancesResponse, WebContext context) {
JsonObject representation = new JsonObject();
JsonArray results = new JsonArray();
MultipleRecords<Instance> wrappedInstances = instancesResponse.getSuccess().getResult();
List<Instance> instances = wrappedInstances.records;
instances.forEach(instance -> {
List<InstanceRelationshipToParent> parentInstances = instancesResponse.getParentInstanceMap().get(instance.getId());
List<InstanceRelationshipToChild> childInstances = instancesResponse.getChildInstanceMap().get(instance.getId());
List<PrecedingSucceedingTitle> precedingTitles = instancesResponse.getPrecedingTitlesMap().get(instance.getId());
List<PrecedingSucceedingTitle> succeedingTitles = instancesResponse.getSucceedingTitlesMap().get(instance.getId());
results.add(instance.setParentInstances(parentInstances).setChildInstances(childInstances).setPrecedingTitles(precedingTitles).setSucceedingTitles(succeedingTitles).getJsonForResponse(context));
});
representation.put("instances", results).put("totalRecords", wrappedInstances.totalRecords);
return representation;
}
use of org.folio.inventory.domain.instances.InstanceRelationshipToParent in project mod-inventory by folio-org.
the class Instances method withInstanceRelationships.
private CompletableFuture<Instance> withInstanceRelationships(Instance instance, Response result) {
List<InstanceRelationshipToParent> parentInstanceList = new ArrayList<>();
List<InstanceRelationshipToChild> childInstanceList = new ArrayList<>();
if (result.getStatusCode() == 200) {
JsonObject json = result.getJson();
List<JsonObject> relationsList = JsonArrayHelper.toList(json.getJsonArray("instanceRelationships"));
relationsList.forEach(rel -> {
if (rel.getString(InstanceRelationship.SUPER_INSTANCE_ID_KEY).equals(instance.getId())) {
childInstanceList.add(new InstanceRelationshipToChild(rel));
} else if (rel.getString(InstanceRelationship.SUB_INSTANCE_ID_KEY).equals(instance.getId())) {
parentInstanceList.add(new InstanceRelationshipToParent(rel));
}
});
instance.getParentInstances().addAll(parentInstanceList);
instance.getChildInstances().addAll(childInstanceList);
}
return completedFuture(instance);
}
use of org.folio.inventory.domain.instances.InstanceRelationshipToParent in project mod-inventory by folio-org.
the class Instances method withInstancesRelationships.
private CompletableFuture<InstancesResponse> withInstancesRelationships(InstancesResponse instancesResponse, List<JsonObject> relationsList) {
Map<String, List<InstanceRelationshipToParent>> parentInstanceMap = new HashMap<>();
Map<String, List<InstanceRelationshipToChild>> childInstanceMap = new HashMap<>();
relationsList.forEach(rel -> {
addToList(childInstanceMap, rel.getString("superInstanceId"), new InstanceRelationshipToChild(rel));
addToList(parentInstanceMap, rel.getString("subInstanceId"), new InstanceRelationshipToParent(rel));
});
instancesResponse.setChildInstanceMap(childInstanceMap);
instancesResponse.setParentInstanceMap(parentInstanceMap);
return CompletableFuture.completedFuture(instancesResponse);
}
Aggregations