Search in sources :

Example 1 with UnitDescriptor

use of org.openlca.core.model.descriptors.UnitDescriptor in project olca-app by GreenDelta.

the class JsonRefCollector method buildFlows.

private List<FlowRef> buildFlows(ZipFile zip) {
    List<FlowRef> flowRefs = new ArrayList<>();
    for (ZipEntry e : flowEntries) {
        JsonObject obj = unpack(e, zip);
        if (obj == null)
            continue;
        String id = Json.getString(obj, "@id");
        if (id == null)
            continue;
        FlowRef ref = new FlowRef();
        ref.flow = new FlowDescriptor();
        ref.flow.refId = id;
        ref.flow.name = Json.getString(obj, "name");
        ref.flow.flowType = Json.getEnum(obj, "flowType", FlowType.class);
        // the category
        String catID = Json.getRefId(obj, "category");
        ref.flowCategory = categoryPaths.get(catID);
        // find the reference flow property
        String propID = null;
        JsonArray props = Json.getArray(obj, "flowProperties");
        if (props != null) {
            for (JsonElement elem : props) {
                if (!elem.isJsonObject())
                    continue;
                JsonObject prop = elem.getAsJsonObject();
                boolean isRef = Json.getBool(prop, "referenceFlowProperty", false);
                if (!isRef)
                    continue;
                propID = Json.getRefId(prop, "flowProperty");
                break;
            }
        }
        if (propID != null) {
            ref.property = new FlowPropertyDescriptor();
            ref.property.refId = propID;
            ref.property.name = propertyNames.get(propID);
            String unitID = propertyUnits.get(propID);
            if (unitID != null) {
                ref.unit = new UnitDescriptor();
                ref.unit.refId = unitID;
                ref.unit.name = unitNames.get(unitID);
            }
        }
        flowRefs.add(ref);
    }
    return flowRefs;
}
Also used : FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) FlowPropertyDescriptor(org.openlca.core.model.descriptors.FlowPropertyDescriptor) JsonArray(com.google.gson.JsonArray) FlowRef(org.openlca.io.maps.FlowRef) JsonElement(com.google.gson.JsonElement) UnitDescriptor(org.openlca.core.model.descriptors.UnitDescriptor) FlowType(org.openlca.core.model.FlowType)

Aggregations

JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 ArrayList (java.util.ArrayList)1 ZipEntry (java.util.zip.ZipEntry)1 FlowType (org.openlca.core.model.FlowType)1 FlowDescriptor (org.openlca.core.model.descriptors.FlowDescriptor)1 FlowPropertyDescriptor (org.openlca.core.model.descriptors.FlowPropertyDescriptor)1 UnitDescriptor (org.openlca.core.model.descriptors.UnitDescriptor)1 FlowRef (org.openlca.io.maps.FlowRef)1