Search in sources :

Example 1 with ChildInstance

use of org.folio.ChildInstance in project mod-inventory by folio-org.

the class InstanceUtil method mergeFieldsWhichAreNotControlled.

/**
 * Merges fields from Instances which are NOT controlled by the underlying SRS MARC
 * @param existing - Instance in DB
 * @param mapped - Instance after mapping
 * @return - result Instance
 */
public static Instance mergeFieldsWhichAreNotControlled(Instance existing, org.folio.Instance mapped) {
    mapped.setId(existing.getId());
    List<ParentInstance> parentInstances = constructParentInstancesList(existing);
    List<ChildInstance> childInstances = constructChildInstancesList(existing);
    // Fields which are not affects by default mapping.
    org.folio.Instance tmp = new org.folio.Instance().withId(existing.getId()).withVersion(Integer.parseInt(existing.getVersion())).withDiscoverySuppress(existing.getDiscoverySuppress()).withStaffSuppress(existing.getStaffSuppress()).withPreviouslyHeld(existing.getPreviouslyHeld()).withCatalogedDate(existing.getCatalogedDate()).withStatusId(existing.getStatusId()).withStatisticalCodeIds(existing.getStatisticalCodeIds()).withNatureOfContentTermIds(existing.getNatureOfContentTermIds()).withTags(new Tags().withTagList(existing.getTags())).withParentInstances(parentInstances).withChildInstances(childInstances);
    JsonObject existingInstanceAsJson = JsonObject.mapFrom(tmp);
    JsonObject mappedInstanceAsJson = JsonObject.mapFrom(mapped);
    JsonObject mergedInstanceAsJson = InstanceUtil.mergeInstances(existingInstanceAsJson, mappedInstanceAsJson);
    return Instance.fromJson(mergedInstanceAsJson);
}
Also used : ParentInstance(org.folio.ParentInstance) ParentInstance(org.folio.ParentInstance) ChildInstance(org.folio.ChildInstance) Instance(org.folio.inventory.domain.instances.Instance) JsonObject(io.vertx.core.json.JsonObject) ChildInstance(org.folio.ChildInstance) Tags(org.folio.Tags)

Example 2 with ChildInstance

use of org.folio.ChildInstance 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

ChildInstance (org.folio.ChildInstance)2 JsonObject (io.vertx.core.json.JsonObject)1 ArrayList (java.util.ArrayList)1 ParentInstance (org.folio.ParentInstance)1 Tags (org.folio.Tags)1 Instance (org.folio.inventory.domain.instances.Instance)1 InstanceRelationshipToChild (org.folio.inventory.domain.instances.InstanceRelationshipToChild)1