Search in sources :

Example 6 with Meta

use of com.developmentontheedge.be5.api.services.Meta in project be5 by DevelopmentOnTheEdge.

the class DatabaseModel method getEntity.

@Override
public EntityModel getEntity(String entityName) {
    Objects.requireNonNull(entityName);
    Entity entity = meta.getEntity(entityName);
    if (entity == null)
        throw Be5Exception.unknownEntity(entityName);
    return new EntityModelBase(sqlService, dpsHelper, validator, operationHelper, operationExecutor, meta, entity);
}
Also used : Entity(com.developmentontheedge.be5.metadata.model.Entity)

Example 7 with Meta

use of com.developmentontheedge.be5.api.services.Meta in project be5 by DevelopmentOnTheEdge.

the class ProjectFileSystemTest method testPathsMap.

@Test
public void testPathsMap() throws IOException {
    Project prj = new Project("test");
    Path root = tmp.newFolder().toPath();
    prj.setLocation(root);
    ProjectFileSystem pfs = new ProjectFileSystem(prj);
    Map<Path, Boolean> map = EntryStream.of(pfs.getPaths()).mapKeys(root::relativize).toSortedMap();
    assertTrue(StreamEx.of("", "src", "src/js/extenders", "src/js/forms", "src/js/operations", "src/js/queries", "src/l10n", "src/meta/data", "src/meta/entities").map(Paths::get).noneMatch(map::get));
    assertTrue(StreamEx.of("src/ftl", "src/include", "src/meta/modules", "src/groovy/operations", "src/pages").map(Paths::get).allMatch(map::get));
}
Also used : Path(java.nio.file.Path) Project(com.developmentontheedge.be5.metadata.model.Project) Paths(java.nio.file.Paths) Test(org.junit.Test)

Example 8 with Meta

use of com.developmentontheedge.be5.api.services.Meta in project be5 by DevelopmentOnTheEdge.

the class EntityModels method createEntities.

// private String artifactIdToPackage(String path)
// {
// StringBuilder s = new StringBuilder();
// boolean toUpperCase = false;
// path = path.toLowerCase();
// for (int i = 0; i < path.length(); i++)
// {
// if(path.charAt(i) == '-')
// {
// toUpperCase = true;
// continue;
// }
// if(toUpperCase){
// s.append(Character.toUpperCase(path.charAt(i)));
// toUpperCase = false;
// }else{
// s.append(path.charAt(i));
// }
// }
// 
// return s.toString();
// }
private void createEntities(String generatedSourcesPath, String packageName, Configuration cfg) throws IOException {
    Template entityTpl = cfg.getTemplate("entity.ftl");
    Meta meta = injector.getMeta();
    List<Entity> entities = meta.getOrderedEntities("ru");
    for (Entity entity : entities) {
        if (entity.getName().startsWith("_"))
            continue;
        String entityClassName = Strings.capitalize(entity.getName());
        Map<String, Object> input = new HashMap<>();
        input.put("entityClassName", entityClassName);
        input.put("packageName", packageName);
        Map<String, ColumnDef> columns = meta.getColumns(entity);
        List<ColumnsInfo> columnsInfos = new ArrayList<>();
        for (ColumnDef columnDef : columns.values()) {
            columnsInfos.add(new ColumnsInfo(columnDef.getName(), meta.getColumnType(columnDef).getSimpleName()));
        }
        input.put("columns", columnsInfos);
        Utils.createFile(generatedSourcesPath, packageName, entityClassName + ".java", entityTpl, input);
        entityCount++;
    }
}
Also used : Meta(com.developmentontheedge.be5.api.services.Meta) Entity(com.developmentontheedge.be5.metadata.model.Entity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ColumnDef(com.developmentontheedge.be5.metadata.model.ColumnDef) Template(freemarker.template.Template)

Example 9 with Meta

use of com.developmentontheedge.be5.api.services.Meta in project be5 by DevelopmentOnTheEdge.

the class EntityModels method createService.

private void createService(String generatedSourcesPath, String packageName, String serviceClassName, Configuration cfg) throws IOException {
    Template serviceTpl = cfg.getTemplate("service.ftl");
    Meta meta = injector.getMeta();
    List<Entity> entities = meta.getOrderedEntities("ru");
    Map<String, Object> input = new HashMap<>();
    input.put("serviceClassName", serviceClassName);
    input.put("packageName", packageName);
    List<String> entityNames = new ArrayList<>();
    for (Entity entity : entities) {
        if (entity.getName().startsWith("_"))
            continue;
        entityNames.add(entity.getName());
    }
    input.put("entityNames", entityNames);
    Utils.createFile(generatedSourcesPath, packageName, serviceClassName + ".java", serviceTpl, input);
}
Also used : Meta(com.developmentontheedge.be5.api.services.Meta) Entity(com.developmentontheedge.be5.metadata.model.Entity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Template(freemarker.template.Template)

Example 10 with Meta

use of com.developmentontheedge.be5.api.services.Meta in project be5 by DevelopmentOnTheEdge.

the class Menu method generateEntityOperations.

private List<OperationNode> generateEntityOperations(Entity entity, Meta meta, UserAwareMeta userAwareMeta, List<String> roles, boolean withIds) {
    List<OperationNode> operations = new ArrayList<>();
    Query allRecords = entity.getQueries().get(DatabaseConstants.ALL_RECORDS_VIEW);
    String insertOperationName = INSERT_OPERATION;
    if (allRecords != null && allRecords.getOperationNames().getFinalValues().contains(insertOperationName)) {
        Operation insertOperation = entity.getOperations().get(insertOperationName);
        if (insertOperation != null && meta.isAvailableFor(insertOperation, roles)) {
            String title = userAwareMeta.getLocalizedOperationTitle(entity.getName(), insertOperationName);
            Action action = ActionUtils.toAction(DatabaseConstants.ALL_RECORDS_VIEW, insertOperation);
            OperationId id = withIds ? new OperationId(entity.getName(), insertOperationName) : null;
            OperationNode operation = new OperationNode(id, title, action);
            operations.add(operation);
        }
    }
    return operations;
}
Also used : Action(com.developmentontheedge.be5.model.Action) Query(com.developmentontheedge.be5.metadata.model.Query) ArrayList(java.util.ArrayList) Operation(com.developmentontheedge.be5.metadata.model.Operation)

Aggregations

Entity (com.developmentontheedge.be5.metadata.model.Entity)4 ArrayList (java.util.ArrayList)4 Meta (com.developmentontheedge.be5.api.services.Meta)3 Query (com.developmentontheedge.be5.metadata.model.Query)3 Template (freemarker.template.Template)3 Test (org.junit.Test)3 Action (com.developmentontheedge.be5.model.Action)2 HashMap (java.util.HashMap)2 ColumnDef (com.developmentontheedge.be5.metadata.model.ColumnDef)1 Operation (com.developmentontheedge.be5.metadata.model.Operation)1 Project (com.developmentontheedge.be5.metadata.model.Project)1 ErrorModel (com.developmentontheedge.be5.model.jsonapi.ErrorModel)1 JsonApiModel (com.developmentontheedge.be5.model.jsonapi.JsonApiModel)1 ResourceData (com.developmentontheedge.be5.model.jsonapi.ResourceData)1 Operation (com.developmentontheedge.be5.operation.Operation)1 OperationResult (com.developmentontheedge.be5.operation.OperationResult)1 Be5ProjectTest (com.developmentontheedge.be5.test.Be5ProjectTest)1 SqlMockOperationTest (com.developmentontheedge.be5.test.SqlMockOperationTest)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1