Search in sources :

Example 46 with Entity

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

the class AppValidate method checkQuery.

private void checkQuery() throws MojoFailureException {
    if (queryPath == null)
        return;
    int pos = queryPath.indexOf('.');
    if (pos <= 0) {
        throw new MojoFailureException("Invalid query path supplied: " + queryPath);
    }
    String entityName = queryPath.substring(0, pos);
    String queryName = queryPath.substring(pos + 1);
    Entity entity = be5Project.getEntity(entityName);
    if (entity == null) {
        throw new MojoFailureException("Invalid entity: " + entityName);
    }
    Query query = entity.getQueries().get(queryName);
    if (query == null) {
        try {
            queryName = new String(queryName.getBytes("CP866"), "CP1251");
            query = entity.getQueries().get(queryName);
        } catch (UnsupportedEncodingException e) {
            throw new MojoFailureException("Can not load query, path=" + queryPath, e);
        }
    }
    if (query == null) {
        throw new MojoFailureException("Invalid query: " + queryName);
    }
    getLog().info("Query: " + query.getQueryCompiled().getResult().replaceAll("\n", System.lineSeparator()));
}
Also used : Entity(com.developmentontheedge.be5.metadata.model.Entity) Query(com.developmentontheedge.be5.metadata.model.Query) MojoFailureException(org.apache.maven.plugin.MojoFailureException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 47 with Entity

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

the class DpsHelper method checkDpsColumns.

public void checkDpsColumns(BeModelElement modelElements, DynamicPropertySet dps) {
    StringBuilder errorMsg = new StringBuilder();
    Map<String, ColumnDef> columns = meta.getColumns(getEntity(modelElements));
    for (ColumnDef column : columns.values()) {
        if (!column.isCanBeNull() && !column.isAutoIncrement() && column.getDefaultValue() == null && !dps.hasProperty(column.getName())) {
            errorMsg.append("Dps not contain notNull column '").append(column.getName()).append("'\n");
        }
    }
    for (DynamicProperty property : dps) {
        if (!columns.keySet().contains(property.getName())) {
            errorMsg.append("Entity not contain column '").append(property.getName()).append("'\n");
        }
    }
    if (!errorMsg.toString().isEmpty()) {
        throw Be5Exception.internal("Dps columns errors for modelElements '" + modelElements.getName() + "'\n" + errorMsg);
    }
}
Also used : DynamicProperty(com.developmentontheedge.beans.DynamicProperty) ColumnDef(com.developmentontheedge.be5.metadata.model.ColumnDef)

Example 48 with Entity

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

the class DpsHelper method addDpForColumnsWithoutTags.

public <T extends DynamicPropertySet> T addDpForColumnsWithoutTags(T dps, BeModelElement modelElements, Collection<String> columnNames) {
    Map<String, ColumnDef> columns = meta.getColumns(getEntity(modelElements));
    for (String propertyName : columnNames) {
        ColumnDef columnDef = columns.get(propertyName);
        if (columnDef != null) {
            DynamicProperty dynamicProperty = getDynamicPropertyWithoutTags(columnDef, modelElements);
            dps.add(dynamicProperty);
        } else {
            throw Be5Exception.internal("Entity '" + modelElements.getName() + "' not contain column " + propertyName);
        }
    }
    return dps;
}
Also used : DynamicProperty(com.developmentontheedge.beans.DynamicProperty) ColumnDef(com.developmentontheedge.be5.metadata.model.ColumnDef)

Example 49 with Entity

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

the class GroovyOperationLoader method initOperationMap.

void initOperationMap() {
    Map<String, com.developmentontheedge.be5.metadata.model.Operation> newOperationMap = new HashMap<>();
    List<Entity> entities = meta.getOrderedEntities("ru");
    for (Entity entity : entities) {
        List<String> operationNames = meta.getOperationNames(entity);
        for (String operationName : operationNames) {
            com.developmentontheedge.be5.metadata.model.Operation operation = meta.getOperationIgnoringRoles(entity, operationName);
            if (operation.getType().equals(OPERATION_TYPE_GROOVY)) {
                GroovyOperation groovyOperation = (GroovyOperation) operation;
                String fileName = groovyOperation.getFileName().replace("/", ".");
                newOperationMap.put(fileName, operation);
            }
        }
    }
    groovyOperationsMap = newOperationMap;
}
Also used : Entity(com.developmentontheedge.be5.metadata.model.Entity) Operation(com.developmentontheedge.be5.metadata.model.Operation) HashMap(java.util.HashMap) Operation(com.developmentontheedge.be5.metadata.model.Operation) GroovyOperation(com.developmentontheedge.be5.metadata.model.GroovyOperation) GroovyOperation(com.developmentontheedge.be5.metadata.model.GroovyOperation)

Example 50 with Entity

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

the class MetaImpl method createQueryFromSql.

@Override
public Query createQueryFromSql(String sql) {
    Entity e = new Entity("be5DynamicQueries", getProject().getApplication(), EntityType.TABLE);
    e.setBesql(true);
    DataElementUtils.save(e);
    Query query = new Query("query", e);
    DataElementUtils.save(query);
    query.setQuery(sql);
    return query;
}
Also used : Entity(com.developmentontheedge.be5.metadata.model.Entity) Query(com.developmentontheedge.be5.metadata.model.Query)

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