Search in sources :

Example 6 with Entity

use of com.developmentontheedge.be5.metadata.model.Entity in project be5 by DevelopmentOnTheEdge.

the class YamlDeserializer method reloadEntity.

public Entity reloadEntity(final Entity oldEntity) throws ReadException {
    this.fileSystem = new ProjectFileSystem(oldEntity.getProject());
    this.setProject(oldEntity.getProject());
    final Entity entity = this.readEntity(oldEntity.getModule(), oldEntity.getName());
    if (oldEntity.getPrototype() != null) {
        @SuppressWarnings("unchecked") final BeModelCollection<BeModelElement> prototype = (BeModelCollection<BeModelElement>) oldEntity.getPrototype();
        entity.merge(prototype, true, true);
    }
    EntitiesFactory.addToModule(entity, oldEntity.getModule());
    return entity;
}
Also used : ProjectFileSystem(com.developmentontheedge.be5.metadata.serialization.ProjectFileSystem) Entity(com.developmentontheedge.be5.metadata.model.Entity) BeModelElement(com.developmentontheedge.be5.metadata.model.base.BeModelElement) BeModelCollection(com.developmentontheedge.be5.metadata.model.base.BeModelCollection)

Example 7 with Entity

use of com.developmentontheedge.be5.metadata.model.Entity in project be5 by DevelopmentOnTheEdge.

the class YamlDeserializer method readCustomizations.

/**
 * Used with customizations (module), entity, query, operation and static page.
 */
@SuppressWarnings("unchecked")
private void readCustomizations(final Map<String, Object> serialized, final BeVectorCollection<?> target, boolean replace) {
    if (project == null)
        throw new IllegalStateException();
    final Map<String, Object> serializedCustomizations = (Map<String, Object>) serialized.get("customizations");
    if (serializedCustomizations == null || serializedCustomizations.isEmpty())
        return;
    final BeVectorCollection<PageCustomization> customizations = replace ? new PageCustomizations(target) : target.getOrCreateCollection(PageCustomization.CUSTOMIZATIONS_COLLECTION, PageCustomization.class);
    try {
        for (final String name : serializedCustomizations.keySet()) {
            final Map<String, Object> content = (Map<String, Object>) serializedCustomizations.get(name);
            final List<String> splitted = StreamEx.split(name, "\\.").toList();
            final String type;
            final String domain;
            if (splitted.size() == 1) {
                type = "";
                domain = splitted.get(0);
            } else {
                type = splitted.get(splitted.size() - 1);
                splitted.remove(splitted.size() - 1);
                domain = String.join(".", splitted);
            }
            final PageCustomization customization = new PageCustomization(type, domain, customizations);
            customization.setCode((String) content.get(TAG_CODE));
            customization.setOriginModuleName(project.getProjectOrigin());
            DataElementUtils.saveQuiet(customization);
        }
    } catch (Exception e) {
        loadContext.addWarning(new ReadException(e, target, project.getLocation()));
    }
    if (replace)
        DataElementUtils.save(customizations);
}
Also used : ReadException(com.developmentontheedge.be5.metadata.exception.ReadException) PageCustomizations(com.developmentontheedge.be5.metadata.model.PageCustomizations) PageCustomization(com.developmentontheedge.be5.metadata.model.PageCustomization) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ReadException(com.developmentontheedge.be5.metadata.exception.ReadException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MarkedYAMLException(org.yaml.snakeyaml.error.MarkedYAMLException) YAMLException(org.yaml.snakeyaml.error.YAMLException)

Example 8 with Entity

use of com.developmentontheedge.be5.metadata.model.Entity in project be5 by DevelopmentOnTheEdge.

the class MassChangeTest method testMassChange.

@Test
public void testMassChange() {
    Project project = new Project("test");
    Entity entity = new Entity("entity", project.getApplication(), EntityType.TABLE);
    DataElementUtils.save(entity);
    Query queryToChange = new Query("queryToChange", entity);
    DataElementUtils.save(queryToChange);
    Query query = new Query("query", entity);
    DataElementUtils.save(query);
    MassChange mc = new MassChange("Query[name*=\"Change\"]", project.getApplication().getMassChangeCollection(), Collections.singletonMap("type", QueryType.D2));
    assertEquals("type", mc.getPropertiesString());
    assertEquals("Query[name*=Change]", mc.getSelectorString());
    DataElementUtils.save(mc);
    assertEquals(QueryType.D1, queryToChange.getType());
    assertEquals(QueryType.D1, query.getType());
    LoadContext context = new LoadContext();
    project.applyMassChanges(context);
    context.check();
    assertEquals(QueryType.D2, entity.getQueries().get("queryToChange").getType());
    assertEquals(QueryType.D1, entity.getQueries().get("query").getType());
}
Also used : LoadContext(com.developmentontheedge.be5.metadata.serialization.LoadContext) Test(org.junit.Test)

Example 9 with Entity

use of com.developmentontheedge.be5.metadata.model.Entity in project be5 by DevelopmentOnTheEdge.

the class ReadModelFromXmlTest method testWriteReadQueryOperation.

@Test
public void testWriteReadQueryOperation() throws Exception {
    final Project project = new Project("TestProject");
    final Module module = project.getApplication();
    DataElementUtils.saveQuiet(module);
    final Entity table = new Entity("table", module, EntityType.TABLE);
    DataElementUtils.saveQuiet(table);
    final Operation op = Operation.createOperation("op", Operation.OPERATION_TYPE_JAVA, table);
    DataElementUtils.saveQuiet(op);
    final Query query = new Query("q", table);
    DataElementUtils.saveQuiet(query);
    query.getOperationNames().add("op");
    final Path tempFolder = Files.createTempDirectory("be4-temp");
    Serialization.save(project, tempFolder);
    final Project readProject = Serialization.load(tempFolder);
    final Entity readEntity = readProject.getApplication().getEntity("table");
    assertEquals("op", readEntity.getQueries().get("q").getOperationNames().getValuesArray()[0]);
    FileUtils.deleteRecursively(tempFolder);
}
Also used : Path(java.nio.file.Path) Project(com.developmentontheedge.be5.metadata.model.Project) Entity(com.developmentontheedge.be5.metadata.model.Entity) Query(com.developmentontheedge.be5.metadata.model.Query) Operation(com.developmentontheedge.be5.metadata.model.Operation) Module(com.developmentontheedge.be5.metadata.model.Module) Test(org.junit.Test)

Example 10 with Entity

use of com.developmentontheedge.be5.metadata.model.Entity in project be5 by DevelopmentOnTheEdge.

the class ReadModelFromXmlTest method testWriteReadLocalizations.

@Test
public void testWriteReadLocalizations() throws Exception {
    final Project project = new Project("test");
    final Localizations localizations = project.getApplication().getLocalizations();
    localizations.addLocalization("en", "entity", Arrays.asList("topic"), "hello", "Hello!");
    localizations.addLocalization("de", "entity", Arrays.asList("topic", "topic2"), "hello", "Guten Tag!");
    localizations.addLocalization("it", "entity", Arrays.asList("topic2"), "hello", "Buon giorno!");
    final Path tempFolder = Files.createTempDirectory("be4-temp");
    Serialization.save(project, tempFolder);
    final Project project2 = Serialization.load(tempFolder);
    final Localizations localizations2 = project2.getApplication().getLocalizations();
    assertEquals("Hello!", localizations2.get("en").get("entity").elements().iterator().next().getValue());
    assertEquals("Guten Tag!", localizations2.get("de").get("entity").elements().iterator().next().getValue());
    assertEquals("Buon giorno!", localizations2.get("it").get("entity").elements().iterator().next().getValue());
    FileUtils.deleteRecursively(tempFolder);
}
Also used : Path(java.nio.file.Path) Project(com.developmentontheedge.be5.metadata.model.Project) Localizations(com.developmentontheedge.be5.metadata.model.Localizations) Test(org.junit.Test)

Aggregations

Entity (com.developmentontheedge.be5.metadata.model.Entity)36 Query (com.developmentontheedge.be5.metadata.model.Query)19 Module (com.developmentontheedge.be5.metadata.model.Module)16 Project (com.developmentontheedge.be5.metadata.model.Project)16 Test (org.junit.Test)11 Path (java.nio.file.Path)9 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 ColumnDef (com.developmentontheedge.be5.metadata.model.ColumnDef)7 Operation (com.developmentontheedge.be5.metadata.model.Operation)7 TableDef (com.developmentontheedge.be5.metadata.model.TableDef)7 Meta (com.developmentontheedge.be5.api.services.Meta)4 ReadException (com.developmentontheedge.be5.metadata.exception.ReadException)4 BeModelElement (com.developmentontheedge.be5.metadata.model.base.BeModelElement)4 Map (java.util.Map)4 ProjectElementException (com.developmentontheedge.be5.metadata.exception.ProjectElementException)3 DdlElement (com.developmentontheedge.be5.metadata.model.DdlElement)3 Localizations (com.developmentontheedge.be5.metadata.model.Localizations)3 LinkedHashMap (java.util.LinkedHashMap)3 Be5Exception (com.developmentontheedge.be5.api.exceptions.Be5Exception)2