use of org.folio.ParentInstance 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);
}
use of org.folio.ParentInstance in project mod-inventory by folio-org.
the class InstanceUtil method constructParentInstancesList.
private static List<ParentInstance> constructParentInstancesList(Instance existing) {
List<ParentInstance> parentInstances = new ArrayList<>();
for (InstanceRelationshipToParent parent : existing.getParentInstances()) {
ParentInstance parentInstance = new ParentInstance().withId(parent.getId()).withSuperInstanceId(parent.getSuperInstanceId()).withInstanceRelationshipTypeId(parent.getInstanceRelationshipTypeId());
parentInstances.add(parentInstance);
}
return parentInstances;
}
Aggregations