use of org.openlca.core.model.Source in project olca-modules by GreenDelta.
the class SourceSheet method write.
private void write() {
Excel.trackSize(sheet, 0, 5);
writeHeader();
var sources = new SourceDao(config.database).getAll();
sources.sort(new EntitySorter());
for (Source source : sources) {
row++;
write(source);
}
Excel.autoSize(sheet, 0, 5);
}
use of org.openlca.core.model.Source in project olca-modules by GreenDelta.
the class SourceTest method testSource.
@Test
public void testSource() {
SourceDao dao = new SourceDao(Tests.getDb());
Source source = createModel(dao);
doExport(source, dao);
doImport(dao, source);
dao.delete(source);
}
use of org.openlca.core.model.Source in project olca-modules by GreenDelta.
the class SourceTest method createModel.
private Source createModel(SourceDao dao) {
Source source = new Source();
source.name = "Source";
source.refId = UUID.randomUUID().toString();
dao.insert(source);
return source;
}
use of org.openlca.core.model.Source in project olca-modules by GreenDelta.
the class SourceImport method of.
@Override
public ImportStatus<Source> of(String id) {
var source = imp.get(Source.class, id);
// check if we are in update mode
var update = false;
if (source != null) {
update = imp.shouldUpdate(source);
if (!update) {
return ImportStatus.skipped(source);
}
}
// resolve the proto object
var proto = imp.reader.getSource(id);
if (proto == null)
return source != null ? ImportStatus.skipped(source) : ImportStatus.error("Could not resolve Source " + id);
var wrap = ProtoWrap.of(proto);
if (update) {
if (imp.skipUpdate(source, wrap))
return ImportStatus.skipped(source);
}
// map the data
if (source == null) {
source = new Source();
}
wrap.mapTo(source, imp);
map(proto, source);
// insert or update it
var dao = new SourceDao(imp.db);
source = update ? dao.update(source) : dao.insert(source);
imp.putHandled(source);
return update ? ImportStatus.updated(source) : ImportStatus.created(source);
}
use of org.openlca.core.model.Source in project olca-app by GreenDelta.
the class ImageSection method update.
void update() {
for (Control c : controls) {
c.dispose();
}
controls.clear();
ProcessDocumentation doc = editor.getModel().documentation;
if (doc == null)
return;
List<File> files = new ArrayList<>();
for (Source s : doc.sources) {
if (!isImage(s.externalFile))
continue;
File dir = new FileStore(Database.get()).getFolder(s);
File file = new File(dir, s.externalFile);
if (!file.exists())
continue;
files.add(file);
}
if (files.isEmpty())
return;
if (comp == null) {
comp = UI.formSection(body, tk, "Attached images");
}
files.forEach(this::createControls);
comp.pack();
Composite container = comp;
while (container != null) {
container = container.getParent();
if (container instanceof ScrolledForm) {
((ScrolledForm) container).reflow(true);
break;
}
}
}
Aggregations