use of org.openlca.core.model.ProcessLink in project olca-modules by GreenDelta.
the class ProductSystemWriter method exchangeIDs.
/**
* Creates a map exchangeID -> internalID of the exchanges used in the
* product system links.
*/
private TLongLongHashMap exchangeIDs(ProductSystem system) {
var map = new TLongLongHashMap();
if (system.referenceExchange != null) {
map.put(system.referenceExchange.id, -1);
}
for (ProcessLink link : system.processLinks) {
map.put(link.exchangeId, -1L);
}
try {
String sql = "select id, internal_id from tbl_exchanges";
NativeSql.on(exp.db).query(sql, r -> {
long id = r.getLong(1);
long internal = r.getLong(2);
if (map.containsKey(id)) {
map.put(id, internal);
}
return true;
});
} catch (Exception e) {
Logger log = LoggerFactory.getLogger(getClass());
log.error("Failed to query exchange IDs", e);
}
return map;
}
use of org.openlca.core.model.ProcessLink in project olca-app by GreenDelta.
the class GraphEditor method createNecessaryLinks.
public void createNecessaryLinks(ProcessNode node) {
MutableProcessLinkSearchMap linkSearch = node.parent().linkSearch;
ProductSystemNode sysNode = node.parent();
long id = node.process.id;
for (ProcessLink pLink : linkSearch.getLinks(id)) {
boolean isProvider = pLink.providerId == id;
long otherID = isProvider ? pLink.processId : pLink.providerId;
ProcessNode otherNode = model.getProcessNode(otherID);
if (otherNode == null)
continue;
ProcessNode outNode = null;
ProcessNode inNode = null;
FlowType type = sysNode.flows.type(pLink.flowId);
if (type == FlowType.PRODUCT_FLOW) {
outNode = isProvider ? node : otherNode;
inNode = isProvider ? otherNode : node;
} else if (type == FlowType.WASTE_FLOW) {
outNode = isProvider ? otherNode : node;
inNode = isProvider ? node : otherNode;
}
if (outNode == null)
continue;
if (!outNode.isExpandedRight() && !inNode.isExpandedLeft())
continue;
Link link = new Link();
link.outputNode = outNode;
link.inputNode = inNode;
link.processLink = pLink;
link.link();
}
}
use of org.openlca.core.model.ProcessLink in project olca-app by GreenDelta.
the class ReconnectLinkCommand method execute.
@Override
public void execute() {
ProductSystemNode systemNode = sourceNode.parent();
oldLink.unlink();
systemNode.getProductSystem().processLinks.remove(oldLink.processLink);
systemNode.linkSearch.remove(oldLink.processLink);
var processLink = new ProcessLink();
processLink.providerId = sourceNode.process.id;
processLink.setProviderType(sourceNode.process.type);
processLink.flowId = oldLink.processLink.flowId;
processLink.processId = targetNode.parent().process.id;
processLink.exchangeId = targetNode.exchange.id;
systemNode.getProductSystem().processLinks.add(processLink);
systemNode.linkSearch.put(processLink);
link = new Link();
link.outputNode = sourceNode;
link.inputNode = targetNode.parent();
link.processLink = processLink;
link.link();
systemNode.editor.setDirty();
}
use of org.openlca.core.model.ProcessLink in project olca-app by GreenDelta.
the class TreeLayout method build.
private void build(ProductSystem productSystem, Node[] nodes) {
List<Node> children = new ArrayList<>();
for (Node node : nodes) {
long processId = node.processId;
for (ProcessLink link : linkSearch.getLinks(processId)) {
if (link.processId != processId)
continue;
long providerId = link.providerId;
if (containing.get(providerId) != null)
continue;
Node child = new Node();
child.processId = providerId;
node.leftChildren.add(child);
containing.put(child.processId, 1);
children.add(child);
}
}
if (children.size() > 0)
build(productSystem, children.toArray(new Node[children.size()]));
children.clear();
for (Node node : nodes) {
long processId = node.processId;
for (ProcessLink link : linkSearch.getLinks(processId)) {
if (link.providerId != processId)
continue;
long recipientId = link.processId;
if (containing.get(recipientId) != null)
continue;
Node child = new Node();
child.processId = recipientId;
node.rightChildren.add(child);
containing.put(child.processId, 1);
children.add(child);
}
}
if (children.size() > 0)
build(productSystem, children.toArray(new Node[children.size()]));
}
use of org.openlca.core.model.ProcessLink in project olca-app by GreenDelta.
the class LinkUpdate method linkOf.
private ProcessLink linkOf(ProcessDescriptor process, long exchangeId) {
if (keepExisting) {
var old = oldLinks.get(exchangeId);
if (old != null)
return old;
}
var exchange = exchanges.get(exchangeId);
if (exchange == null)
return null;
var providers = providerIndex.get(exchange.flowId);
if (providers == null)
return null;
long providerId = 0;
ProcessDescriptor provider = null;
for (var it = providers.iterator(); it.hasNext(); ) {
long candidateId = it.next();
// only link default providers
if (providerLinking == ProviderLinking.ONLY_DEFAULTS) {
if (candidateId == exchange.defaultProviderId) {
providerId = candidateId;
break;
}
continue;
}
// set the candidate as provider if there is nothing better
var candidate = processes.get(candidateId);
if (candidate == null)
continue;
if (isBetterProvider(process, provider, candidate, exchange)) {
provider = candidate;
providerId = candidateId;
}
}
if (providerId == 0)
return null;
var link = new ProcessLink();
link.providerId = providerId;
link.exchangeId = exchangeId;
link.processId = process.id;
link.providerType = ProcessLink.ProviderType.PROCESS;
link.flowId = exchange.flowId;
return link;
}
Aggregations