Search in sources :

Example 11 with Entity

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

the class SelectorTest method testMatch.

@Test
public void testMatch() throws ParseException {
    Project project = new Project("test");
    Module app = project.getApplication();
    Module mod = new Module("mod", project.getModules());
    DataElementUtils.save(mod);
    Entity appTable = new Entity("appTable", app, EntityType.TABLE);
    DataElementUtils.save(appTable);
    DataElementUtils.save(new Query("All records", appTable));
    Entity appDict = new Entity("appDict", app, EntityType.DICTIONARY);
    DataElementUtils.save(appDict);
    Query dictRecords = new Query("All records", appDict);
    dictRecords.setInvisible(true);
    DataElementUtils.save(dictRecords);
    Entity modTable = new Entity("modTable", mod, EntityType.DICTIONARY);
    DataElementUtils.save(modTable);
    DataElementUtils.save(new Query("All records", modTable));
    SelectorRule rule1 = UnionSelectorRule.create("Query[invisible=true]");
    assertEquals("Query[invisible=true]", rule1.toString());
    checkRule(rule1, "test/application/Entities/appDict/Queries/All records", project);
    SelectorRule rule2 = UnionSelectorRule.create(".table Query[name=\"All records\"]");
    assertEquals(".table Query[name=\"All records\"]", rule2.toString());
    checkRule(rule2, "test/application/Entities/appTable/Queries/All records", project);
    SelectorRule rule3 = UnionSelectorRule.create("Module#mod Query[name=\"All records\"]");
    assertEquals("Module#mod Query[name=\"All records\"]", rule3.toString());
    checkRule(rule3, "test/Modules/mod/Entities/modTable/Queries/All records", project);
    SelectorRule rule4 = UnionSelectorRule.create("Entity:not(.dictionary)");
    assertEquals("Entity:not(.dictionary)", rule4.toString());
    checkRule(rule4, "test/application/Entities/appTable", project);
}
Also used : Project(com.developmentontheedge.be5.metadata.model.Project) Entity(com.developmentontheedge.be5.metadata.model.Entity) Query(com.developmentontheedge.be5.metadata.model.Query) Module(com.developmentontheedge.be5.metadata.model.Module) Test(org.junit.Test)

Example 12 with Entity

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

the class AppDb method execute.

private void execute(final Module module) throws ProjectElementException {
    boolean started = false;
    for (Entity entity : module.getOrCreateEntityCollection().getAvailableElements()) {
        DdlElement scheme = entity.getScheme();
        if (scheme instanceof TableDef) {
            if (scheme.withoutDbScheme()) {
                if (!started) {
                    logger.setOperationName("[A] " + module.getCompletePath());
                    started = true;
                }
                processDdl(scheme);
                createdTables++;
            } else {
                logger.setOperationName("Skip table with schema: " + scheme.getEntityName());
            }
        }
    }
    // Define views after tables as there might be dependencies
    for (Entity entity : module.getOrCreateEntityCollection().getAvailableElements()) {
        DdlElement scheme = entity.getScheme();
        if (scheme instanceof ViewDef) {
            if (scheme.withoutDbScheme()) {
                if (!started) {
                    logger.setOperationName("[A] " + module.getCompletePath());
                    started = true;
                }
                processDdl(scheme);
                createdViews++;
            } else {
                logger.setOperationName("Skip table with schema: " + scheme.getEntityName());
            }
        }
    }
}
Also used : Entity(com.developmentontheedge.be5.metadata.model.Entity) DdlElement(com.developmentontheedge.be5.metadata.model.DdlElement) ViewDef(com.developmentontheedge.be5.metadata.model.ViewDef) TableDef(com.developmentontheedge.be5.metadata.model.TableDef)

Example 13 with Entity

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

the class AppValidate method checkDdl.

private void checkDdl() throws MojoFailureException {
    if (ddlPath != null) {
        Entity entity = be5Project.getEntity(ddlPath);
        if (entity == null) {
            throw new MojoFailureException("Invalid entity: " + ddlPath);
        }
        DdlElement scheme = entity.getScheme();
        if (scheme == null) {
            throw new MojoFailureException("Entity has no scheme: " + ddlPath);
        }
        getLog().info("DDL: " + scheme.getDdl().replaceAll("\n", System.lineSeparator()));
    }
}
Also used : Entity(com.developmentontheedge.be5.metadata.model.Entity) MojoFailureException(org.apache.maven.plugin.MojoFailureException) DdlElement(com.developmentontheedge.be5.metadata.model.DdlElement)

Example 14 with Entity

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

the class AppValidate method saveProject.

// private List<ProjectElementException> validateDeps( List<Project> moduleProjects )
// {
// List<ProjectElementException> moduleErrors = new ArrayList<>();
// Map<String, String> entityToModule = new HashMap<>();
// for(Project prj : moduleProjects)
// {
// for(Entity entity : prj.getApplication().getEntities())
// entityToModule.put( entity.getName(), prj.getName() );
// }
// for(Project prj : moduleProjects)
// {
// for(Entity entity : prj.getApplication().getEntities())
// {
// for(TableReference ref : entity.getAllReferences())
// {
// String moduleTo = entityToModule.get( ref.getTableTo() );
// if(moduleTo != null && prj.getModule( moduleTo ) == null)
// {
// moduleErrors.add( new ProjectElementException( ref, "Reference to entity '" + ref.getTableTo()
// + "' which is defined in module '" + moduleTo + "' which is not specified in dependencies of module '"
// + prj.getName() + "'" ) );
// }
// }
// }
// }
// return moduleErrors;
// }
private void saveProject() throws MojoFailureException {
    if (saveProject) {
        try {
            getLog().info("Saving...");
            Serialization.save(be5Project, be5Project.getLocation());
        } catch (ProjectSaveException e) {
            throw new MojoFailureException("Can not save project.", e);
        }
    }
}
Also used : MojoFailureException(org.apache.maven.plugin.MojoFailureException) ProjectSaveException(com.developmentontheedge.be5.metadata.exception.ProjectSaveException)

Example 15 with Entity

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

the class TestUtils method setUp.

@Before
public void setUp() throws Exception {
    tpmProjectPath = tmp.newFolder().toPath();
    project = ProjectTestUtils.getProject("test");
    Entity entity = ProjectTestUtils.createEntity(project, "entity", "ID");
    ProjectTestUtils.createScheme(entity);
    ProjectTestUtils.createScript(project, "delete from entity;\nINSERT INTO entity (name) VALUES ('foo')");
    ProjectTestUtils.createH2Profile(project, "profileTestMavenPlugin");
    Query query = ProjectTestUtils.createQuery(entity, "All records", Arrays.asList('@' + SpecialRoleGroup.ALL_ROLES_EXCEPT_GUEST_GROUP, "-User"));
    query.getOperationNames().setValues(Collections.singleton("op"));
    ProjectTestUtils.createOperation(entity);
    Path modulePath = tmp.newFolder().toPath();
    Project moduleProject = createModule(project, "testModule", modulePath);
    Serialization.save(project, tpmProjectPath);
    ArrayList<URL> urls = new ArrayList<>();
    urls.add(modulePath.resolve("project.yaml").toUri().toURL());
    urls.add(tpmProjectPath.resolve("project.yaml").toUri().toURL());
    ModuleLoader2.loadAllProjects(urls);
    LoadContext ctx = new LoadContext();
    ModuleLoader2.mergeAllModules(project, Collections.singletonList(moduleProject), ctx);
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) LoadContext(com.developmentontheedge.be5.metadata.serialization.LoadContext) URL(java.net.URL) Before(org.junit.Before)

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