Search in sources :

Example 16 with ModelType

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

the class ZipStoreTest method testWriteModels.

@Test
public void testWriteModels() {
    Map<ModelType, String> entries = writeModels();
    with(zip -> {
        for (ModelType type : entries.keySet()) {
            var refId = entries.get(type);
            var json = zip.get(type, refId);
            Assert.assertNotNull(json);
        }
    });
}
Also used : ModelType(org.openlca.core.model.ModelType) Test(org.junit.Test)

Example 17 with ModelType

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

the class ZipStoreTest method testReadModels.

@Test
public void testReadModels() {
    Map<ModelType, String> entries = writeModels();
    with(zip -> {
        for (ModelType type : entries.keySet()) {
            String id = entries.get(type);
            JsonObject obj = zip.get(type, id);
            String name = obj.get("name").getAsString();
            Assert.assertEquals(type.name(), name);
        }
    });
}
Also used : ModelType(org.openlca.core.model.ModelType) JsonObject(com.google.gson.JsonObject) Test(org.junit.Test)

Example 18 with ModelType

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

the class CategoryDao method getTable.

private String getTable(ModelType modelType) {
    if (tables == null) {
        tables = new HashMap<>();
        for (ModelType type : ModelType.values()) {
            if (type.getModelClass() == null || !RefEntity.class.isAssignableFrom(type.getModelClass()))
                continue;
            String table = Daos.refDao(db, type).getEntityTable();
            tables.put(type, table);
        }
    }
    return tables.get(modelType);
}
Also used : ModelType(org.openlca.core.model.ModelType)

Example 19 with ModelType

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

the class References method of.

public static <D extends RootDescriptor> List<Reference> of(IDatabase db, Collection<D> owners) {
    ModelType type = null;
    var ids = new HashSet<Long>();
    for (var d : owners) {
        if (d == null || d.id == 0)
            continue;
        if (type == null) {
            type = d.type;
        } else if (type != d.type) {
            throw new IllegalArgumentException("Mixed descriptor " + "types are not allowed in reference search");
        }
        ids.add(d.id);
    }
    return type == null || ids.isEmpty() ? Collections.emptyList() : of(db, type, ids);
}
Also used : ModelType(org.openlca.core.model.ModelType) HashSet(java.util.HashSet)

Example 20 with ModelType

use of org.openlca.core.model.ModelType in project olca-app by GreenDelta.

the class Widgets method dropComponent.

public static TextDropComponent dropComponent(Composite parent, String label, String property, ModelEditor<?> editor, FormToolkit toolkit) {
    ModelType modelType = getModelType(editor.getModel(), property);
    toolkit.createLabel(parent, label, SWT.NONE);
    TextDropComponent text = new TextDropComponent(parent, toolkit, modelType);
    UI.gridData(text, true, false);
    editor.getBinding().onModel(editor::getModel, property, text);
    new CommentControl(parent, toolkit, property, editor.getComments());
    return text;
}
Also used : CommentControl(org.openlca.app.editors.comments.CommentControl) ModelType(org.openlca.core.model.ModelType) TextDropComponent(org.openlca.app.components.TextDropComponent)

Aggregations

ModelType (org.openlca.core.model.ModelType)21 JsonObject (com.google.gson.JsonObject)4 Test (org.junit.Test)4 HashSet (java.util.HashSet)3 Category (org.openlca.core.model.Category)3 JsonArray (com.google.gson.JsonArray)2 File (java.io.File)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2 JsonElement (com.google.gson.JsonElement)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 StandardCopyOption (java.nio.file.StandardCopyOption)1 ArrayList (java.util.ArrayList)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 TextDropComponent (org.openlca.app.components.TextDropComponent)1 CommentControl (org.openlca.app.editors.comments.CommentControl)1 Tests (org.openlca.core.Tests)1