use of org.folio.inventory.domain.instances.titles.PrecedingSucceedingTitle in project mod-inventory by folio-org.
the class PrecedingSucceedingTitlesHelper method prepareSucceedingTitles.
private void prepareSucceedingTitles(Instance instance, List<PrecedingSucceedingTitle> preparedTitles) {
if (instance.getSucceedingTitles() != null) {
for (PrecedingSucceedingTitle child : instance.getSucceedingTitles()) {
PrecedingSucceedingTitle precedingSucceedingTitle = new PrecedingSucceedingTitle(UUID.randomUUID().toString(), instance.getId(), child.succeedingInstanceId, child.title, child.hrid, child.identifiers);
preparedTitles.add(precedingSucceedingTitle);
}
}
}
use of org.folio.inventory.domain.instances.titles.PrecedingSucceedingTitle 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.titles.PrecedingSucceedingTitle in project mod-inventory by folio-org.
the class Instances method withPrecedingSucceedingTitles.
private CompletableFuture<Instance> withPrecedingSucceedingTitles(RoutingContext routingContext, WebContext context, Instance instance, Response result) {
if (result.getStatusCode() == 200) {
JsonObject json = result.getJson();
List<JsonObject> relationsList = JsonArrayHelper.toList(json.getJsonArray("precedingSucceedingTitles"));
List<CompletableFuture<PrecedingSucceedingTitle>> precedingTitleCompletableFutures = relationsList.stream().filter(rel -> isPrecedingTitle(instance, rel)).map(rel -> getPrecedingSucceedingTitle(routingContext, context, rel, PrecedingSucceedingTitle.PRECEDING_INSTANCE_ID_KEY)).collect(Collectors.toList());
List<CompletableFuture<PrecedingSucceedingTitle>> succeedingTitleCompletableFutures = relationsList.stream().filter(rel -> isSucceedingTitle(instance, rel)).map(rel -> getPrecedingSucceedingTitle(routingContext, context, rel, PrecedingSucceedingTitle.SUCCEEDING_INSTANCE_ID_KEY)).collect(Collectors.toList());
return completedFuture(instance).thenCompose(r -> withPrecedingTitles(instance, precedingTitleCompletableFutures)).thenCompose(r -> withSucceedingTitles(instance, succeedingTitleCompletableFutures));
}
return completedFuture(null);
}
use of org.folio.inventory.domain.instances.titles.PrecedingSucceedingTitle in project mod-inventory by folio-org.
the class AbstractInstances method updatePrecedingTitles.
private void updatePrecedingTitles(Instance instance, Map<String, PrecedingSucceedingTitle> updatingPrecedingSucceedingTitles) {
if (instance.getPrecedingTitles() != null) {
instance.getPrecedingTitles().forEach(parent -> {
String id = (parent.id == null ? UUID.randomUUID().toString() : parent.id);
PrecedingSucceedingTitle precedingSucceedingTitle = new PrecedingSucceedingTitle(id, parent.precedingInstanceId, instance.getId(), parent.title, parent.hrid, parent.identifiers);
updatingPrecedingSucceedingTitles.put(id, precedingSucceedingTitle);
});
}
}
use of org.folio.inventory.domain.instances.titles.PrecedingSucceedingTitle in project mod-inventory by folio-org.
the class AbstractInstances method updatePrecedingSucceedingTitles.
private CompletableFuture<List<Response>> updatePrecedingSucceedingTitles(Instance instance, CollectionResourceRepository precedingSucceedingTitlesClient, Response result) {
JsonObject json = result.getJson();
List<JsonObject> relationsList = JsonArrayHelper.toList(json.getJsonArray("precedingSucceedingTitles"));
Map<String, PrecedingSucceedingTitle> existingPrecedingSucceedingTitles = getExistedPrecedingSucceedingTitles(relationsList);
Map<String, PrecedingSucceedingTitle> updatingPrecedingSucceedingTitles = getUpdatingPrecedingSucceedingTitles(instance);
List<CompletableFuture<Response>> allFutures = update(precedingSucceedingTitlesClient, existingPrecedingSucceedingTitles, updatingPrecedingSucceedingTitles);
return allResultsOf(allFutures);
}
Aggregations