use of org.openlca.io.maps.FlowRef in project olca-app by GreenDelta.
the class Sync method packageSync.
/**
* Synchronizes the given (external) flow references which are the target or
* source flow definitions of a mapping with the (internal) flow references
* provided by the given data package (which can be an ILCD or JSON-LD package).
* The sync.-state of the flow references of the mapping is mutated so that it
* can be displayed in the mapping tool.
*/
static void packageSync(IProvider pack, Stream<FlowRef> mappingRefs) {
if (mappingRefs == null || pack == null)
return;
Map<String, FlowRef> packRefs = pack.getFlowRefs().stream().collect(Collectors.toMap(ref -> ref.flow.refId, ref -> ref));
mappingRefs.forEach(mapRef -> {
if (Sync.isInvalidFlowRef(mapRef))
return;
// we update the status in the following sync. steps
mapRef.status = null;
// check the flow
String flowID = mapRef.flow.refId;
FlowRef packRef = packRefs.get(flowID);
if (packRef == null) {
mapRef.status = MappingStatus.error("there is no flow with id=" + flowID + " in the data package");
return;
}
// the IDs are equal, the flow properties should have the same name
if (mapRef.property == null) {
mapRef.property = packRef.property;
} else {
if (packRef.property == null) {
mapRef.status = MappingStatus.error("the flow in the data package" + " has no corresponding flow property");
return;
}
Descriptor packProp = packRef.property;
Descriptor mapProp = mapRef.property;
if (Strings.nullOrEqual(packProp.refId, mapProp.refId) && packProp.name != null && mapProp.name != null && !Strings.nullOrEqual(packProp.name, mapProp.name)) {
mapRef.status = MappingStatus.error("the flow property in the data " + "package has the same ID but a different name: " + packProp.name + " != " + mapProp.name);
return;
}
}
// when the IDs are equal, the names must be equal too
if (mapRef.unit == null) {
mapRef.unit = packRef.unit;
} else if (packRef.unit != null) {
// mapping packages not always contain their reference units
// if (packRef.unit == null) {
// mapRef.status = Status.error("the flow in the data package"
// + " has no corresponding unit");
// return;
// }
Descriptor packUnit = packRef.unit;
Descriptor mapUnit = mapRef.unit;
if (Strings.nullOrEqual(packUnit.refId, mapUnit.refId) && packUnit.name != null && mapUnit.name != null && !Strings.nullOrEqual(packUnit.name, mapUnit.name)) {
mapRef.status = MappingStatus.error("the flow unit in the data " + "package has the same ID but a different name: " + packUnit.name + " != " + mapUnit.name);
return;
}
}
Sync.checkFlowName(mapRef, packRef.flow.name);
Sync.checkFlowCategory(mapRef, packRef.flowCategory);
Sync.checkFlowType(mapRef, packRef.flow.flowType);
Sync.checkFlowLocation(mapRef, packRef.flowLocation);
if (mapRef.status == null) {
mapRef.status = MappingStatus.ok("flow in sync with data package");
}
});
}
Aggregations