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);
}
Aggregations