Search in sources :

Example 1 with Ref

use of org.openlca.ilcd.commons.Ref in project olca-modules by GreenDelta.

the class RefTree method fetchChilds.

private static List<Node> fetchChilds(Object obj) {
    if (obj == null)
        return Collections.emptyList();
    List<Node> nodes = new ArrayList<>();
    try {
        for (Field field : obj.getClass().getDeclaredFields()) {
            if (!follow(field.getType()))
                continue;
            field.setAccessible(true);
            Object val = field.get(obj);
            if (val == null)
                continue;
            if (val instanceof Ref) {
                addNode(field, (Ref) val, nodes);
                continue;
            }
            if (val instanceof Collection) {
                Collection<?> c = (Collection<?>) val;
                followCollection(field, c, nodes);
                continue;
            }
            if (val instanceof Map) {
                Map<?, ?> m = (Map<?, ?>) val;
                followCollection(field, m.values(), nodes);
                continue;
            }
            if (Object[].class.isAssignableFrom(val.getClass())) {
                Object[] array = (Object[]) val;
                followCollection(field, Arrays.asList(array), nodes);
                continue;
            }
            collectChilds(field, val, nodes);
        }
    } catch (Exception e) {
        Logger log = LoggerFactory.getLogger(RefTree.class);
        log.error("failed to create RefTree", e);
    }
    return nodes;
}
Also used : ArrayList(java.util.ArrayList) Logger(org.slf4j.Logger) Field(java.lang.reflect.Field) Ref(org.openlca.ilcd.commons.Ref) Collection(java.util.Collection) Map(java.util.Map)

Example 2 with Ref

use of org.openlca.ilcd.commons.Ref in project olca-modules by GreenDelta.

the class Refs method ilcd.

/**
 * Returns the data set reference of the ILCD format.
 */
public static Ref ilcd() {
    Ref ref = new Ref();
    ref.type = DataSetType.SOURCE;
    ref.uri = "../sources/a97a0155-0234-4b87-b4ce-a45da52f2a40_01.01.000.xml";
    ref.uuid = "a97a0155-0234-4b87-b4ce-a45da52f2a40";
    ref.version = "01.01.000";
    LangString.set(ref.name, "ILCD format", "en");
    return ref;
}
Also used : Ref(org.openlca.ilcd.commons.Ref)

Example 3 with Ref

use of org.openlca.ilcd.commons.Ref in project olca-modules by GreenDelta.

the class FlowPropertyBagTest method testGetUnitGroupReference.

@Test
public void testGetUnitGroupReference() {
    Ref ref = bag.getUnitGroupReference();
    assertEquals("93a60a57-a3c8-11da-a746-0800200c9a66", ref.uuid);
}
Also used : Ref(org.openlca.ilcd.commons.Ref) Test(org.junit.Test)

Example 4 with Ref

use of org.openlca.ilcd.commons.Ref in project olca-modules by GreenDelta.

the class DependencyTraversal method forEach.

public void forEach(Consumer<IDataSet> fn) {
    if (fn == null)
        return;
    var visited = new HashSet<Ref>();
    var deque = new ArrayDeque<Ref>();
    deque.add(start);
    visited.add(start);
    while (!deque.isEmpty()) {
        Ref next = deque.poll();
        try {
            var dataSet = store.get(next.getDataSetClass(), next.uuid);
            if (dataSet == null) {
                log.warn("could not get data set for {}", next);
                continue;
            }
            fn.accept(dataSet);
            for (Ref dep : RefTree.create(dataSet).getRefs()) {
                if (visited.contains(dep))
                    continue;
                visited.add(dep);
                if (filter != null && !filter.test(dep))
                    continue;
                deque.add(dep);
            }
        } catch (Exception e) {
            log.error("failed to get dependencies for {}", next, e);
        }
    }
}
Also used : Ref(org.openlca.ilcd.commons.Ref) ArrayDeque(java.util.ArrayDeque) HashSet(java.util.HashSet)

Example 5 with Ref

use of org.openlca.ilcd.commons.Ref in project olca-modules by GreenDelta.

the class DataSetRef method makeRef.

public static Ref makeRef(RootEntity model, ExportConfig config) {
    if (model == null) {
        return new Ref();
    }
    Ref ref = new Ref();
    ref.version = "01.00.000";
    ref.uuid = model.refId;
    setUriAndType(model, ref);
    if (model.name != null) {
        LangString.set(ref.name, model.name, config.lang);
    }
    return ref;
}
Also used : Ref(org.openlca.ilcd.commons.Ref)

Aggregations

Ref (org.openlca.ilcd.commons.Ref)17 Test (org.junit.Test)3 InputStream (java.io.InputStream)2 ProcessSampleTest (org.openlca.ilcd.io.ProcessSampleTest)2 Process (org.openlca.ilcd.processes.Process)2 Field (java.lang.reflect.Field)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 CategoryDao (org.openlca.core.database.CategoryDao)1 FlowProperty (org.openlca.core.model.FlowProperty)1 Source (org.openlca.core.model.Source)1 Classification (org.openlca.ilcd.commons.Classification)1 QuantitativeReference (org.openlca.ilcd.flowproperties.QuantitativeReference)1 ComplianceDeclaration (org.openlca.ilcd.processes.ComplianceDeclaration)1 ComplianceList (org.openlca.ilcd.processes.ComplianceList)1 DataEntry (org.openlca.ilcd.processes.DataEntry)1