Search in sources :

Example 1 with FlowPropertyDescriptor

use of org.openlca.core.model.descriptors.FlowPropertyDescriptor in project olca-modules by GreenDelta.

the class DisplayValues method referenceUnit.

/**
 * Returns the name of the reference unit of the given flow.
 */
public static String referenceUnit(FlowDescriptor flow, EntityCache cache) {
    FlowPropertyDescriptor descriptor = cache.get(FlowPropertyDescriptor.class, flow.refFlowPropertyId);
    if (descriptor == null) {
        log.warn("no reference flow property for flow {}", flow);
        return "";
    }
    try {
        FlowProperty property = cache.get(FlowProperty.class, descriptor.id);
        Unit refUnit = property.unitGroup.referenceUnit;
        return refUnit.name;
    } catch (Exception e) {
        log.error("failed to get reference unit for flow " + flow.id, e);
        return "";
    }
}
Also used : FlowPropertyDescriptor(org.openlca.core.model.descriptors.FlowPropertyDescriptor) Unit(org.openlca.core.model.Unit) FlowProperty(org.openlca.core.model.FlowProperty)

Example 2 with FlowPropertyDescriptor

use of org.openlca.core.model.descriptors.FlowPropertyDescriptor 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

FlowPropertyDescriptor (org.openlca.core.model.descriptors.FlowPropertyDescriptor)2 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 FlowProperty (org.openlca.core.model.FlowProperty)1 FlowType (org.openlca.core.model.FlowType)1 Unit (org.openlca.core.model.Unit)1 FlowDescriptor (org.openlca.core.model.descriptors.FlowDescriptor)1 UnitDescriptor (org.openlca.core.model.descriptors.UnitDescriptor)1 FlowRef (org.openlca.io.maps.FlowRef)1