use of org.openlca.core.model.descriptors.ParameterDescriptor in project olca-modules by GreenDelta.
the class ParameterReferenceSearch method findParameterReferences.
private List<Reference> findParameterReferences(Set<Long> ids) {
List<String> formulaQueries = Search.createQueries("SELECT id, lower(formula) FROM tbl_parameters", "WHERE id IN", ids);
Map<Long, Set<String>> variables = getVariablesUsedInFormulas(formulaQueries);
Set<String> names = new HashSet<>();
for (Long key : variables.keySet()) names.addAll(variables.get(key));
List<Reference> results = new ArrayList<>();
List<ParameterDescriptor> descriptors = new ParameterDao(database).getDescriptors(names.toArray(new String[names.size()]), ParameterScope.GLOBAL);
results.addAll(toReferences(descriptors, false, variables));
Set<String> found = new HashSet<>();
for (ParameterDescriptor d : descriptors) found.add(d.name.toLowerCase());
for (String name : names) if (!found.contains(name)) {
List<Reference> refs = createMissingReferences(name, variables);
results.addAll(refs);
}
return results;
}
use of org.openlca.core.model.descriptors.ParameterDescriptor in project olca-modules by GreenDelta.
the class BaseParametrizedReferenceSearch method findParameterRedefs.
protected List<Reference> findParameterRedefs(Set<Long> ids, Map<Long, Long> idToOwnerId, Class<? extends AbstractEntity> nestedOwnerType, String nestedProperty) {
Map<Long, Set<String>> names = new HashMap<>();
List<String> queries = Search.createQueries("SELECT f_owner, lower(name) FROM tbl_parameter_redefs WHERE context_type IS NULL", "AND f_owner IN", ids);
collect(queries, names, null);
Set<String> allNames = merge(names);
List<ParameterDescriptor> descriptors = new ParameterDao(database).getDescriptors(allNames.toArray(new String[allNames.size()]), ParameterScope.GLOBAL);
List<Reference> references = toReferences(descriptors, false, names, idToOwnerId, nestedOwnerType, nestedProperty);
references.addAll(createMissingParameterRedefReferences(names, descriptors, idToOwnerId, nestedProperty, nestedOwnerType));
return references;
}
use of org.openlca.core.model.descriptors.ParameterDescriptor in project olca-modules by GreenDelta.
the class BaseParametrizedReferenceSearch method toReferences.
private List<Reference> toReferences(List<ParameterDescriptor> descriptors, boolean optional, Map<Long, Set<String>> names, Map<Long, Long> ownerIds, Class<? extends AbstractEntity> nestedType, String nestedProperty) {
Map<Long, Set<Long>> descriptorToOwnerIds = new HashMap<>();
for (ParameterDescriptor d : descriptors) {
for (long ownerId : names.keySet()) {
if (!names.get(ownerId).contains(d.name.toLowerCase()))
continue;
put(d.id, ownerId, descriptorToOwnerIds);
}
}
List<Reference> references = new ArrayList<>();
for (ParameterDescriptor descriptor : descriptors) {
Set<Long> set = descriptorToOwnerIds.get(descriptor.id);
if (set == null)
continue;
for (long ownerId : set) {
Class<? extends AbstractEntity> type = (Class<? extends AbstractEntity>) descriptor.type.getModelClass();
long id = descriptor.id;
long nestedOwnerId = 0;
if (ownerIds != null) {
nestedOwnerId = ownerId;
ownerId = ownerIds.get(ownerId);
}
Reference reference = new Reference(descriptor.name, type, id, this.type, ownerId, nestedProperty, nestedType, nestedOwnerId, optional);
references.add(reference);
}
}
return references;
}
use of org.openlca.core.model.descriptors.ParameterDescriptor in project olca-modules by GreenDelta.
the class BaseParametrizedReferenceSearch method findParameters.
protected List<Reference> findParameters(Set<Long> ids, Map<Long, Set<String>> formulas) {
Map<Long, Set<String>> names = new HashMap<>();
List<String> queries = Search.createQueries("SELECT f_owner, lower(name), is_input_param, lower(formula) FROM tbl_parameters", "WHERE f_owner IN", ids);
collect(queries, names, formulas);
Map<Long, Set<String>> undeclared = findUndeclaredParameters(names, formulas);
Set<String> allUndeclared = merge(undeclared);
List<ParameterDescriptor> descriptors = new ParameterDao(database).getDescriptors(allUndeclared.toArray(new String[allUndeclared.size()]), ParameterScope.GLOBAL);
List<Reference> results = toReferences(descriptors, false, undeclared);
Set<String> found = new HashSet<>();
for (ParameterDescriptor d : descriptors) {
found.add(d.name.toLowerCase());
}
for (String name : allUndeclared) {
if (found.contains(name))
continue;
results.addAll(createMissingParameterReferences(name, undeclared));
}
return results;
}
Aggregations