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;
}
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;
}
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);
}
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);
}
}
}
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;
}
Aggregations