Search in sources :

Example 1 with InstanceRelationship

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

the class AbstractInstances method updateInstanceRelationships.

private CompletableFuture<List<Response>> updateInstanceRelationships(Instance instance, CollectionResourceRepository relatedInstancesClient, Response result) {
    JsonObject json = result.getJson();
    List<JsonObject> relationsList = JsonArrayHelper.toList(json.getJsonArray("instanceRelationships"));
    Map<String, InstanceRelationship> existingRelationships = new HashMap();
    relationsList.stream().map(InstanceRelationship::new).forEachOrdered(relObj -> existingRelationships.put(relObj.id, relObj));
    Map<String, InstanceRelationship> updatingRelationships = new HashMap();
    if (instance.getParentInstances() != null) {
        instance.getParentInstances().forEach(parent -> {
            String id = (parent.id == null ? UUID.randomUUID().toString() : parent.id);
            updatingRelationships.put(id, new InstanceRelationship(id, parent.superInstanceId, instance.getId(), parent.instanceRelationshipTypeId));
        });
    }
    if (instance.getChildInstances() != null) {
        instance.getChildInstances().forEach(child -> {
            String id = (child.id == null ? UUID.randomUUID().toString() : child.id);
            updatingRelationships.put(id, new InstanceRelationship(id, instance.getId(), child.subInstanceId, child.instanceRelationshipTypeId));
        });
    }
    List<CompletableFuture<Response>> allFutures = update(relatedInstancesClient, existingRelationships, updatingRelationships);
    return allResultsOf(allFutures);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) HashMap(java.util.HashMap) JsonObject(io.vertx.core.json.JsonObject) InstanceRelationship(org.folio.inventory.domain.instances.InstanceRelationship)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)1 HashMap (java.util.HashMap)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 InstanceRelationship (org.folio.inventory.domain.instances.InstanceRelationship)1