Search in sources :

Example 1 with Project

use of org.openlca.core.model.Project 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;
}
Also used : ImpactCategory(org.openlca.core.model.ImpactCategory) Category(org.openlca.core.model.Category) UnitGroup(org.openlca.core.model.UnitGroup) ImpactCategoryWriter(org.openlca.proto.io.output.ImpactCategoryWriter) ProductSystem(org.openlca.core.model.ProductSystem) Process(org.openlca.core.model.Process) UnitGroupWriter(org.openlca.proto.io.output.UnitGroupWriter) ImpactMethod(org.openlca.core.model.ImpactMethod) ProductSystemWriter(org.openlca.proto.io.output.ProductSystemWriter) Source(org.openlca.core.model.Source) CurrencyWriter(org.openlca.proto.io.output.CurrencyWriter) FlowPropertyWriter(org.openlca.proto.io.output.FlowPropertyWriter) Actor(org.openlca.core.model.Actor) Currency(org.openlca.core.model.Currency) CategoryWriter(org.openlca.proto.io.output.CategoryWriter) ImpactCategoryWriter(org.openlca.proto.io.output.ImpactCategoryWriter) FlowProperty(org.openlca.core.model.FlowProperty) FlowWriter(org.openlca.proto.io.output.FlowWriter) ImpactCategory(org.openlca.core.model.ImpactCategory) SourceWriter(org.openlca.proto.io.output.SourceWriter) Flow(org.openlca.core.model.Flow) LocationWriter(org.openlca.proto.io.output.LocationWriter) Project(org.openlca.core.model.Project) DQSystemWriter(org.openlca.proto.io.output.DQSystemWriter) ParameterWriter(org.openlca.proto.io.output.ParameterWriter) DQSystem(org.openlca.core.model.DQSystem) ActorWriter(org.openlca.proto.io.output.ActorWriter) ImpactMethodWriter(org.openlca.proto.io.output.ImpactMethodWriter) ProjectWriter(org.openlca.proto.io.output.ProjectWriter) Parameter(org.openlca.core.model.Parameter) SocialIndicator(org.openlca.core.model.SocialIndicator) ProcessWriter(org.openlca.proto.io.output.ProcessWriter) Location(org.openlca.core.model.Location) SocialIndicatorWriter(org.openlca.proto.io.output.SocialIndicatorWriter)

Example 2 with Project

use of org.openlca.core.model.Project in project olca-modules by GreenDelta.

the class ProjectImport method of.

@Override
public ImportStatus<Project> of(String id) {
    var project = imp.get(Project.class, id);
    // check if we are in update mode
    var update = false;
    if (project != null) {
        update = imp.shouldUpdate(project);
        if (!update) {
            return ImportStatus.skipped(project);
        }
    }
    // resolve the proto object
    var proto = imp.reader.getProject(id);
    if (proto == null)
        return project != null ? ImportStatus.skipped(project) : ImportStatus.error("Could not resolve Project " + id);
    var wrap = ProtoWrap.of(proto);
    if (update) {
        if (imp.skipUpdate(project, wrap))
            return ImportStatus.skipped(project);
    }
    // map the data
    if (project == null) {
        project = new Project();
        project.refId = id;
    }
    wrap.mapTo(project, imp);
    map(proto, project);
    // insert or update it
    var dao = new ProjectDao(imp.db);
    project = update ? dao.update(project) : dao.insert(project);
    imp.putHandled(project);
    return update ? ImportStatus.updated(project) : ImportStatus.created(project);
}
Also used : Project(org.openlca.core.model.Project) ProtoProject(org.openlca.proto.ProtoProject) ProjectDao(org.openlca.core.database.ProjectDao)

Example 3 with Project

use of org.openlca.core.model.Project in project olca-modules by GreenDelta.

the class ParameterReferencesTest method createProject.

private Project createProject(ParameterRedef... redefs) {
    Project p = new Project();
    p.refId = UUID.randomUUID().toString();
    ProjectVariant v = new ProjectVariant();
    p.variants.add(v);
    v.parameterRedefs.addAll(Arrays.asList(redefs));
    return p;
}
Also used : Project(org.openlca.core.model.Project) ProjectVariant(org.openlca.core.model.ProjectVariant)

Example 4 with Project

use of org.openlca.core.model.Project in project olca-modules by GreenDelta.

the class ParametersTest method testFindRedefOwners.

@Test
public void testFindRedefOwners() {
    // create a process with a local parameter
    var process = TestProcess.refProduct("prod", 1, "kg").param("param", 42).get();
    var param = process.parameters.get(0);
    // create project and product system
    var project = new Project();
    project.variants.add(new ProjectVariant());
    db.insert(project);
    var system = new ProductSystem();
    system.parameterSets.add(new ParameterRedefSet());
    db.insert(system);
    // should not find something
    var owners = Parameters.findRedefOwners(param, process, db);
    assertTrue(owners.isEmpty());
    // add parameter redefs
    var redef = new ParameterRedef();
    redef.name = param.name;
    redef.contextId = process.id;
    redef.contextType = ModelType.PROCESS;
    redef.value = 24;
    project.variants.get(0).parameterRedefs.add(redef.copy());
    project = db.update(project);
    system.parameterSets.get(0).parameters.add(redef.copy());
    system = db.update(system);
    // should find something
    owners = Parameters.findRedefOwners(param, process, db);
    assertEquals(2, owners.size());
    assertTrue(owners.contains(Descriptor.of(system)));
    assertTrue(owners.contains(Descriptor.of(project)));
    db.clear();
}
Also used : Project(org.openlca.core.model.Project) ProjectVariant(org.openlca.core.model.ProjectVariant) ProductSystem(org.openlca.core.model.ProductSystem) ParameterRedef(org.openlca.core.model.ParameterRedef) ParameterRedefSet(org.openlca.core.model.ParameterRedefSet) Test(org.junit.Test)

Example 5 with Project

use of org.openlca.core.model.Project in project olca-modules by GreenDelta.

the class ProjectImport method map.

@Override
Project map(JsonObject json, long id) {
    if (json == null)
        return null;
    Project p = new Project();
    In.mapAtts(json, p, id, conf);
    mapAtts(json, p);
    mapVariants(json, p);
    return conf.db.put(p);
}
Also used : Project(org.openlca.core.model.Project)

Aggregations

Project (org.openlca.core.model.Project)14 ProjectVariant (org.openlca.core.model.ProjectVariant)8 Test (org.junit.Test)5 ParameterRedef (org.openlca.core.model.ParameterRedef)4 Parameter (org.openlca.core.model.Parameter)3 Process (org.openlca.core.model.Process)3 ArrayList (java.util.ArrayList)2 ProductSystem (org.openlca.core.model.ProductSystem)2 HashSet (java.util.HashSet)1 List (java.util.List)1 Objects (java.util.Objects)1 SortedSet (java.util.SortedSet)1 TreeSet (java.util.TreeSet)1 UUID (java.util.UUID)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Action (org.eclipse.jface.action.Action)1 ITableLabelProvider (org.eclipse.jface.viewers.ITableLabelProvider)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 SWT (org.eclipse.swt.SWT)1 Image (org.eclipse.swt.graphics.Image)1