Search in sources :

Example 1 with Entity

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

Example 2 with Entity

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

the class DataElementUtils method moveToApplication.

/**
 * Moves the model element to the application if the element is an entity item.
 *
 * @param modelElement
 */
public static void moveToApplication(final BeModelElement modelElement) {
    if (modelElement instanceof BeElementWithOriginModule) {
        BeElementWithOriginModule r = (BeElementWithOriginModule) modelElement;
        r.setOriginModuleName(r.getProject().getProjectOrigin());
    }
}
Also used : BeElementWithOriginModule(com.developmentontheedge.be5.metadata.model.base.BeElementWithOriginModule)

Example 3 with Entity

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

the class Entity method getErrors.

@Override
public List<ProjectElementException> getErrors() {
    final List<ProjectElementException> errors = new ArrayList<>();
    if (getName().length() > Constants.MAX_ID_LENGTH) {
        errors.add(new ProjectElementException(getCompletePath(), "name", "Entity name is too long."));
    }
    for (final Module module : getProject().getModulesAndApplication()) {
        final Module thisModule = getModule();
        if (module == thisModule)
            break;
        final Entity duplicate = module.getEntity(getName());
        if (duplicate != null) {
            errors.add(new ProjectElementException(getCompletePath(), "name", "Entity with name '" + getName() + "' already exists."));
            break;
        }
    }
    final TableDef tableDef = findTableDefinition();
    if (tableDef != null) {
        errors.addAll(tableDef.getErrors());
    }
    for (final Query query : getQueries()) {
        errors.addAll(query.getErrors());
    }
    for (final Operation operation : getOperations()) {
        errors.addAll(operation.getErrors());
    }
    return errors;
}
Also used : ProjectElementException(com.developmentontheedge.be5.metadata.exception.ProjectElementException) ArrayList(java.util.ArrayList)

Example 4 with Entity

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

the class YamlDeserializer method readQuery.

public static Query readQuery(final LoadContext loadContext, final String queryName, final Map<String, Object> content, final Entity entity) {
    YamlDeserializer yamlDeserializer = new YamlDeserializer(loadContext);
    yamlDeserializer.setProject(entity.getProject());
    EntityDeserializer entityDeserializer = yamlDeserializer.new EntityDeserializer();
    try {
        return entityDeserializer.readQuery(queryName, content, entity);
    } catch (ReadException e) {
        Query query = new Query(queryName, entity);
        loadContext.addWarning(e.attachElement(query));
        return query;
    }
}
Also used : ReadException(com.developmentontheedge.be5.metadata.exception.ReadException) Query(com.developmentontheedge.be5.metadata.model.Query)

Example 5 with Entity

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

the class YamlDeserializer method readEntity.

public static Entity readEntity(final LoadContext loadContext, final String entityName, final Map<String, Object> content, final Module module) {
    YamlDeserializer yamlDeserializer = new YamlDeserializer(loadContext);
    yamlDeserializer.setProject(module.getProject());
    EntityDeserializer entityDeserializer = yamlDeserializer.new EntityDeserializer();
    try {
        return entityDeserializer.readEntity(entityName, content, module);
    } catch (ReadException e) {
        Entity entity = new Entity(entityName, module, EntityType.TABLE);
        loadContext.addWarning(e.attachElement(entity));
        return entity;
    }
}
Also used : ReadException(com.developmentontheedge.be5.metadata.exception.ReadException) Entity(com.developmentontheedge.be5.metadata.model.Entity)

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