Search in sources :

Example 26 with Entity

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

the class Be5QueryExecutor method resolveTypeOfRefColumn.

private void resolveTypeOfRefColumn(AstStart ast) {
    ast.tree().select(AstBeParameterTag.class).forEach(tag -> {
        if (tag.getRefColumn() != null) {
            String[] split = tag.getRefColumn().split("\\.");
            String table, column;
            if (split.length == 2) {
                table = split[0];
                column = split[1];
            } else if (split.length == 3) {
                table = split[0] + "." + split[1];
                column = split[2];
            } else {
                return;
            }
            Entity entity = meta.getEntity(table);
            if (entity != null) {
                tag.setType(meta.getColumnType(entity, column).getName());
            }
        }
    });
}
Also used : Entity(com.developmentontheedge.be5.metadata.model.Entity) AstBeParameterTag(com.developmentontheedge.sql.model.AstBeParameterTag)

Example 27 with Entity

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

the class QueryBuilder method select.

private void select(String sql, Request req, Injector injector) {
    DocumentGenerator documentGenerator = injector.get(DocumentGenerator.class);
    String userQBuilderQueryName = UserInfoHolder.getUserName() + "Query";
    Map<String, String> parametersMap = req.getValuesFromJsonAsStrings(RestApiConstants.VALUES);
    Entity entity = new Entity(entityName, injector.getProject().getApplication(), EntityType.TABLE);
    DataElementUtils.save(entity);
    Query query = new Query(userQBuilderQueryName, entity);
    query.setType(QueryType.D1_UNKNOWN);
    if (sql != null) {
        query.setQuery(sql);
    }
    DataElementUtils.save(query);
    try {
        resourceDataList.add(new ResourceData("finalSql", FrontendConstants.STATIC_ACTION, new StaticPagePresentation("Final sql", new Be5QueryExecutor(query, parametersMap, injector).getFinalSql()), null));
    } catch (Be5Exception e) {
        errorModelList.add(new ErrorModel(e));
    }
    try {
        JsonApiModel document = documentGenerator.getDocument(query, parametersMap);
        // todo refactor documentGenerator
        document.getData().setId("result");
        resourceDataList.add(document.getData());
        resourceDataList.addAll(Arrays.asList(document.getIncluded()));
    } catch (Be5Exception e) {
        errorModelList.add(new ErrorModel(e));
    }
    entity.getOrigin().remove(entityName);
}
Also used : Be5Exception(com.developmentontheedge.be5.api.exceptions.Be5Exception) Entity(com.developmentontheedge.be5.metadata.model.Entity) ResourceData(com.developmentontheedge.be5.model.jsonapi.ResourceData) StaticPagePresentation(com.developmentontheedge.be5.model.StaticPagePresentation) Query(com.developmentontheedge.be5.metadata.model.Query) SqlQuery(com.developmentontheedge.sql.model.SqlQuery) DocumentGenerator(com.developmentontheedge.be5.query.DocumentGenerator) ErrorModel(com.developmentontheedge.be5.model.jsonapi.ErrorModel) Be5QueryExecutor(com.developmentontheedge.be5.query.impl.model.Be5QueryExecutor) JsonApiModel(com.developmentontheedge.be5.model.jsonapi.JsonApiModel)

Example 28 with Entity

use of com.developmentontheedge.be5.metadata.model.Entity 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 29 with Entity

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

the class DataElementUtils method moveBackToItsModule.

/**
 * Moves the model element back to the its module if the element is an entity item.
 *
 * @param modelElement
 */
public static void moveBackToItsModule(final BeModelElement modelElement) {
    if (modelElement instanceof BeElementWithOriginModule) {
        BeElementWithOriginModule r = (BeElementWithOriginModule) modelElement;
        r.setOriginModuleName(r.getModule().getName());
    }
}
Also used : BeElementWithOriginModule(com.developmentontheedge.be5.metadata.model.base.BeElementWithOriginModule)

Example 30 with Entity

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

the class Serialization method reloadEntity.

public static Entity reloadEntity(final Entity oldEntity) throws ReadException {
    checkProject(oldEntity.getProject());
    turnOffAutomaticSerialization();
    try {
        return new YamlDeserializer(new LoadContext()).reloadEntity(oldEntity);
    } finally {
        turnOnAutomaticSerialization();
    }
}
Also used : YamlDeserializer(com.developmentontheedge.be5.metadata.serialization.yaml.YamlDeserializer)

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