Search in sources :

Example 1 with Project

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

the class ProjectTest method testGetQuery.

@Test
public void testGetQuery() {
    Project project = projectProvider.getProject();
    assertEquals("SELECT\n" + "  t.name AS \"Name\",\n" + "  t.value AS \"Value\"\n" + "FROM\n" + "  testtable t", project.getEntity("testtable").getQueries().get("All records").getQuery());
}
Also used : Project(com.developmentontheedge.be5.metadata.model.Project) Test(org.junit.Test) Be5ProjectTest(com.developmentontheedge.be5.test.Be5ProjectTest)

Example 2 with Project

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

the class ProjectGenerator method addModules.

private void addModules(final Project project) {
    final String[] modules;
    {
        final List<String> ms = Lists.newArrayList(parameters.getModules());
        ms.remove(SYSTEM_MODULE);
        ms.add(0, SYSTEM_MODULE);
        modules = Iterables.toArray(ms, String.class);
    }
    for (final String module : modules) {
        final Module newModule = new Module(module, project.getModules());
        DataElementUtils.saveQuiet(newModule);
    }
}
Also used : List(java.util.List) Module(com.developmentontheedge.be5.metadata.model.Module)

Example 3 with Project

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

the class ProjectGenerator method setLanguages.

private void setLanguages(final Project project) {
    for (final String language : parameters.getLanguages()) {
        final Localizations localizations = project.getApplication().getLocalizations();
        final LanguageLocalizations languageLocalizations = new LanguageLocalizations(language, localizations);
        DataElementUtils.saveQuiet(languageLocalizations);
    }
}
Also used : LanguageLocalizations(com.developmentontheedge.be5.metadata.model.LanguageLocalizations) LanguageLocalizations(com.developmentontheedge.be5.metadata.model.LanguageLocalizations) Localizations(com.developmentontheedge.be5.metadata.model.Localizations)

Example 4 with Project

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

the class ProjectGenerator method addIncludes.

public static void addIncludes(final Project project) {
    final StringBuilder sb = new StringBuilder();
    for (final Module module : project.getModules()) {
        final FreemarkerCatalog collection = module.getMacroCollection();
        if (collection == null)
            continue;
        final FreemarkerScript script = collection.optScript(FreemarkerCatalog.MAIN_MACRO_LIBRARY);
        if (script == null)
            continue;
        sb.append("<#include \"../../Modules/" + module.getName() + "/Macros/common\"/>\n");
    }
    final String includes = sb.toString();
    if (!includes.isEmpty()) {
        final FreemarkerScript script = new FreemarkerScript(FreemarkerCatalog.MAIN_MACRO_LIBRARY, project.getMacroCollection());
        script.setSource(includes);
        DataElementUtils.saveQuiet(script);
    }
}
Also used : FreemarkerCatalog(com.developmentontheedge.be5.metadata.model.FreemarkerCatalog) FreemarkerScript(com.developmentontheedge.be5.metadata.model.FreemarkerScript) Module(com.developmentontheedge.be5.metadata.model.Module)

Example 5 with Project

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

the class MassChange method apply.

public List<BeModelElement> apply(LoadContext loadContext, Project project) {
    List<BeModelElement> elements = SelectorUtils.select(project, getRule());
    List<BeModelElement> changedElements = new ArrayList<>();
    for (BeModelElement element : elements) {
        if (element instanceof Query) {
            Query oldQuery = (Query) element;
            Query newQuery = YamlDeserializer.readQuery(loadContext, oldQuery.getName(), data, oldQuery.getEntity());
            DataElementUtils.saveQuiet(newQuery);
            newQuery.merge(oldQuery, false, true);
            newQuery.setOriginModuleName(oldQuery.getOriginModuleName());
        } else if (element instanceof Operation) {
            Operation oldOperation = (Operation) element;
            Map<String, Object> realData = data;
            // Set type, because it cannot be inherited yet
            if (!data.containsKey("type") && !Operation.OPERATION_TYPE_JAVA.equals(oldOperation.getType())) {
                realData = new HashMap<>(data);
                realData.put("type", oldOperation.getType());
            }
            Operation newOperation = YamlDeserializer.readOperation(loadContext, oldOperation.getName(), realData, oldOperation.getEntity());
            DataElementUtils.saveQuiet(newOperation);
            newOperation.merge(oldOperation, false, true);
            newOperation.setOriginModuleName(oldOperation.getOriginModuleName());
        } else if (element instanceof Entity) {
            Entity oldEntity = (Entity) element;
            Map<String, Object> realData = data;
            // Set type, because it cannot be inherited yet
            if (!data.containsKey("type")) {
                realData = new HashMap<>(data);
                realData.put("type", oldEntity.getType().getSqlName());
            }
            Entity newEntity = YamlDeserializer.readEntity(loadContext, oldEntity.getName(), realData, oldEntity.getModule());
            for (EntityItem q : newEntity.getQueries()) q.setOriginModuleName(oldEntity.getModule().getName());
            for (EntityItem o : newEntity.getOperations()) o.setOriginModuleName(oldEntity.getModule().getName());
            DataElementUtils.saveQuiet(newEntity);
            newEntity.merge(oldEntity, false, true);
        } else {
            loadContext.addWarning(new ReadException(element, null, "Mass change is not supported for type " + element.getClass().getSimpleName()));
            continue;
        }
        changedElements.add(element);
    }
    return changedElements;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ReadException(com.developmentontheedge.be5.metadata.exception.ReadException) BeModelElement(com.developmentontheedge.be5.metadata.model.base.BeModelElement) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

Project (com.developmentontheedge.be5.metadata.model.Project)40 Module (com.developmentontheedge.be5.metadata.model.Module)19 Test (org.junit.Test)19 Entity (com.developmentontheedge.be5.metadata.model.Entity)14 Path (java.nio.file.Path)13 Query (com.developmentontheedge.be5.metadata.model.Query)12 LoadContext (com.developmentontheedge.be5.metadata.serialization.LoadContext)7 ArrayList (java.util.ArrayList)7 ProjectLoadException (com.developmentontheedge.be5.metadata.exception.ProjectLoadException)6 FreemarkerScript (com.developmentontheedge.be5.metadata.model.FreemarkerScript)5 URL (java.net.URL)5 Map (java.util.Map)5 ReadException (com.developmentontheedge.be5.metadata.exception.ReadException)4 BeConnectionProfile (com.developmentontheedge.be5.metadata.model.BeConnectionProfile)4 Operation (com.developmentontheedge.be5.metadata.model.Operation)4 IOException (java.io.IOException)4 MojoFailureException (org.apache.maven.plugin.MojoFailureException)4 WriteException (com.developmentontheedge.be5.metadata.exception.WriteException)3 FreemarkerCatalog (com.developmentontheedge.be5.metadata.model.FreemarkerCatalog)3 Localizations (com.developmentontheedge.be5.metadata.model.Localizations)3