use of org.openlca.ecospold.ISource in project olca-modules by GreenDelta.
the class DBSearch method findSource.
public Source findSource(ISource source) {
try {
log.trace("Search for source {} in database", source.getTitle());
String jpql = "select s from Source s where s.name = :name";
Map<String, Object> args = new HashMap<>();
int year = source.getYear() != null ? source.getYear().getYear() : 0;
args.put("name", source.getFirstAuthor() + " " + year);
Source candidate = Query.on(database).getFirst(Source.class, jpql, args);
if (candidate == null)
return null;
if (Objects.equals(candidate.textReference, source.getTitle()))
return candidate;
return null;
} catch (Exception e) {
log.error("Failed to search for Source", e);
return null;
}
}
use of org.openlca.ecospold.ISource in project olca-modules by GreenDelta.
the class EcoSpold01Import method sources.
private void sources(DataSet ds) {
for (ISource eSource : ds.getSources()) {
String id = ES1KeyGen.forSource(eSource);
Source oSource = db.findSource(eSource, id);
if (oSource != null) {
log.skipped(oSource);
continue;
}
oSource = new Source();
oSource.refId = id;
Mapper.mapSource(eSource, oSource);
db.put(oSource, id);
log.imported(oSource);
}
}
use of org.openlca.ecospold.ISource in project olca-modules by GreenDelta.
the class EcoSpold01Import method mapSources.
private void mapSources(ProcessDocumentation doc, DataSet dataSet) {
Map<Integer, Source> sources = new HashMap<>();
for (ISource source : dataSet.getSources()) {
Source s = db.findSource(source, ES1KeyGen.forSource(source));
if (s != null) {
sources.put(source.getNumber(), s);
doc.sources.add(s);
}
}
if (dataSet.getDataGeneratorAndPublication() != null && dataSet.getDataGeneratorAndPublication().getReferenceToPublishedSource() != null)
doc.publication = sources.get(dataSet.getDataGeneratorAndPublication().getReferenceToPublishedSource());
}
use of org.openlca.ecospold.ISource in project olca-modules by GreenDelta.
the class ActorSourceMapper method map.
int map(Source inSource, DataSet dataset) {
if (inSource == null)
return -1;
int id = (int) inSource.id;
for (ISource s : dataset.getSources()) {
if (s.getNumber() == id)
return id;
}
ISource source = factory.createSource();
source.setNumber(id);
source.setFirstAuthor(inSource.name);
source.setText(inSource.description);
source.setTitle(inSource.textReference);
source.setYear(Util.toXml(inSource.year));
source.setPlaceOfPublications("unknown");
source.setSourceType(0);
dataset.getSources().add(source);
createDefaults(source);
return id;
}
use of org.openlca.ecospold.ISource in project olca-modules by GreenDelta.
the class StructureDefaults method defSource.
private static ISource defSource(DataSet dataSet, IEcoSpoldFactory factory) {
for (ISource source : dataSet.getSources()) {
if (source.getNumber() == 1)
return source;
}
ISource source = factory.createSource();
source.setNumber(1);
source.setFirstAuthor("default");
source.setYear(Util.toXml(new Short((short) 9999)));
source.setTitle("Created for EcoSpold 1 compatibility");
source.setPlaceOfPublications("none");
source.setSourceType(0);
dataSet.getSources().add(source);
return source;
}