use of org.openlca.core.model.Source in project olca-modules by GreenDelta.
the class DocImportMapper method mapPublicationSource.
private void mapPublicationSource(AdminInfo adminInfo) {
DataGenerator gen = adminInfo.dataGenerator;
if (gen == null || gen.publishedSourceId == null)
return;
SourceDao dao = new SourceDao(database);
Source source = dao.getForRefId(gen.publishedSourceId);
if (source == null) {
source = new Source();
source.refId = gen.publishedSourceId;
StringBuilder title = new StringBuilder();
StringBuilder shortTitle = new StringBuilder();
if (gen.publishedSourceFirstAuthor != null) {
title.append(gen.publishedSourceFirstAuthor);
shortTitle.append(gen.publishedSourceFirstAuthor);
}
if (gen.publishedSourceYear != null) {
title.append(gen.publishedSourceYear);
shortTitle.append(gen.publishedSourceYear);
}
source.textReference = title.toString();
source.name = shortTitle.toString();
source = dao.insert(source);
}
doc.publication = source;
}
use of org.openlca.core.model.Source in project olca-modules by GreenDelta.
the class SourceImport method createNew.
private Source createNew() {
source = new Source();
String[] path = Categories.getPath(ilcdSource.getValue());
source.category = new CategoryDao(config.db()).sync(ModelType.SOURCE, path);
setDescriptionAttributes();
importExternalFile();
return config.insert(source);
}
use of org.openlca.core.model.Source in project olca-modules by GreenDelta.
the class DataUtil method toDataSet.
static ProtoDataSet.Builder toDataSet(IDatabase db, RefEntity e) {
var ds = ProtoDataSet.newBuilder();
var conf = WriterConfig.of(db);
if (e instanceof Actor)
return ds.setActor(new ActorWriter(conf).write((Actor) e));
if (e instanceof Category)
return ds.setCategory(new CategoryWriter(conf).write((Category) e));
if (e instanceof Currency)
return ds.setCurrency(new CurrencyWriter(conf).write((Currency) e));
if (e instanceof DQSystem)
return ds.setDqSystem(new DQSystemWriter(conf).write((DQSystem) e));
if (e instanceof Flow)
return ds.setFlow(new FlowWriter(conf).write((Flow) e));
if (e instanceof FlowProperty)
return ds.setFlowProperty(new FlowPropertyWriter(conf).write((FlowProperty) e));
if (e instanceof ImpactCategory)
return ds.setImpactCategory(new ImpactCategoryWriter(conf).write((ImpactCategory) e));
if (e instanceof ImpactMethod)
return ds.setImpactMethod(new ImpactMethodWriter(conf).write((ImpactMethod) e));
if (e instanceof Location)
return ds.setLocation(new LocationWriter(conf).write((Location) e));
if (e instanceof Parameter)
return ds.setParameter(new ParameterWriter(conf).write((Parameter) e));
if (e instanceof Process)
return ds.setProcess(new ProcessWriter(conf).write((Process) e));
if (e instanceof ProductSystem)
return ds.setProductSystem(new ProductSystemWriter(conf).write((ProductSystem) e));
if (e instanceof Project)
return ds.setProject(new ProjectWriter(conf).write((Project) e));
if (e instanceof SocialIndicator)
return ds.setSocialIndicator(new SocialIndicatorWriter(conf).write((SocialIndicator) e));
if (e instanceof Source)
return ds.setSource(new SourceWriter(conf).write((Source) e));
if (e instanceof UnitGroup)
return ds.setUnitGroup(new UnitGroupWriter(conf).write((UnitGroup) e));
return ds;
}
use of org.openlca.core.model.Source in project olca-modules by GreenDelta.
the class SourceTest method doImport.
private void doImport(SourceDao dao, Source source) {
with(zip -> {
JsonImport jImport = new JsonImport(zip, Tests.getDb());
jImport.run();
});
Assert.assertTrue(dao.contains(source.refId));
Source clone = dao.getForRefId(source.refId);
Assert.assertEquals(source.name, clone.name);
}
use of org.openlca.core.model.Source in project olca-modules by GreenDelta.
the class ProcessDocReader method addSources.
private void addSources(ProcessDocumentation doc) {
JsonElement sources = json.get("sources");
if (sources == null || !sources.isJsonArray())
return;
for (JsonElement e : sources.getAsJsonArray()) {
if (!e.isJsonObject())
return;
String refId = Json.getString(e.getAsJsonObject(), "@id");
Source source = SourceImport.run(refId, conf);
if (source != null)
doc.sources.add(source);
}
}
Aggregations