Search in sources :

Example 1 with InstanceRelationshipToChild

use of org.folio.inventory.domain.instances.InstanceRelationshipToChild 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());
}
Also used : Instance(org.folio.Instance) ArrayList(java.util.ArrayList) Contributor(org.folio.Contributor) InstanceRelationshipToChild(org.folio.inventory.domain.instances.InstanceRelationshipToChild) AlternativeTitle(org.folio.AlternativeTitle) InstanceRelationshipToParent(org.folio.inventory.domain.instances.InstanceRelationshipToParent) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with InstanceRelationshipToChild

use of org.folio.inventory.domain.instances.InstanceRelationshipToChild 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;
}
Also used : JsonArray(io.vertx.core.json.JsonArray) Instance(org.folio.inventory.domain.instances.Instance) PrecedingSucceedingTitle(org.folio.inventory.domain.instances.titles.PrecedingSucceedingTitle) JsonObject(io.vertx.core.json.JsonObject) InstanceRelationshipToChild(org.folio.inventory.domain.instances.InstanceRelationshipToChild) InstanceRelationshipToParent(org.folio.inventory.domain.instances.InstanceRelationshipToParent)

Example 3 with InstanceRelationshipToChild

use of org.folio.inventory.domain.instances.InstanceRelationshipToChild 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);
}
Also used : ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) InstanceRelationshipToChild(org.folio.inventory.domain.instances.InstanceRelationshipToChild) InstanceRelationshipToParent(org.folio.inventory.domain.instances.InstanceRelationshipToParent)

Example 4 with InstanceRelationshipToChild

use of org.folio.inventory.domain.instances.InstanceRelationshipToChild 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);
}
Also used : HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList) InstanceRelationshipToChild(org.folio.inventory.domain.instances.InstanceRelationshipToChild) InstanceRelationshipToParent(org.folio.inventory.domain.instances.InstanceRelationshipToParent)

Example 5 with InstanceRelationshipToChild

use of org.folio.inventory.domain.instances.InstanceRelationshipToChild in project mod-inventory by folio-org.

the class InstanceUtil method constructChildInstancesList.

private static List<ChildInstance> constructChildInstancesList(Instance existing) {
    List<ChildInstance> childInstances = new ArrayList<>();
    for (InstanceRelationshipToChild child : existing.getChildInstances()) {
        ChildInstance childInstance = new ChildInstance().withId(child.getId()).withSubInstanceId(child.getSubInstanceId()).withInstanceRelationshipTypeId(child.getInstanceRelationshipTypeId());
        childInstances.add(childInstance);
    }
    return childInstances;
}
Also used : ArrayList(java.util.ArrayList) ChildInstance(org.folio.ChildInstance) InstanceRelationshipToChild(org.folio.inventory.domain.instances.InstanceRelationshipToChild)

Aggregations

InstanceRelationshipToChild (org.folio.inventory.domain.instances.InstanceRelationshipToChild)5 ArrayList (java.util.ArrayList)4 InstanceRelationshipToParent (org.folio.inventory.domain.instances.InstanceRelationshipToParent)4 JsonObject (io.vertx.core.json.JsonObject)2 JsonArray (io.vertx.core.json.JsonArray)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 AlternativeTitle (org.folio.AlternativeTitle)1 ChildInstance (org.folio.ChildInstance)1 Contributor (org.folio.Contributor)1 Instance (org.folio.Instance)1 Instance (org.folio.inventory.domain.instances.Instance)1 PrecedingSucceedingTitle (org.folio.inventory.domain.instances.titles.PrecedingSucceedingTitle)1 Test (org.junit.Test)1