Search in sources :

Example 1 with BeModelElement

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

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

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

the class YamlDeserializer method reloadEntity.

public Entity reloadEntity(final Entity oldEntity) throws ReadException {
    this.fileSystem = new ProjectFileSystem(oldEntity.getProject());
    this.setProject(oldEntity.getProject());
    final Entity entity = this.readEntity(oldEntity.getModule(), oldEntity.getName());
    if (oldEntity.getPrototype() != null) {
        @SuppressWarnings("unchecked") final BeModelCollection<BeModelElement> prototype = (BeModelCollection<BeModelElement>) oldEntity.getPrototype();
        entity.merge(prototype, true, true);
    }
    EntitiesFactory.addToModule(entity, oldEntity.getModule());
    return entity;
}
Also used : ProjectFileSystem(com.developmentontheedge.be5.metadata.serialization.ProjectFileSystem) Entity(com.developmentontheedge.be5.metadata.model.Entity) BeModelElement(com.developmentontheedge.be5.metadata.model.base.BeModelElement) BeModelCollection(com.developmentontheedge.be5.metadata.model.base.BeModelCollection)

Example 4 with BeModelElement

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

the class VariableSelector method getTags.

@Override
public String[] getTags() {
    Project project = ((BeModelElement) getBean()).getProject();
    Map<String, String> variableNames = project.getVariables();
    String[] result = new String[variableNames.size() + 1];
    result[0] = "(none)";
    int i = 1;
    for (Entry<String, String> entry : variableNames.entrySet()) {
        result[i++] = entry.getKey() + " (" + entry.getValue() + ")";
    }
    return result;
}
Also used : Project(com.developmentontheedge.be5.metadata.model.Project) BeModelElement(com.developmentontheedge.be5.metadata.model.base.BeModelElement)

Example 5 with BeModelElement

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

the class MetaImpl method getColumns.

@Override
@SuppressWarnings(value = "unchecked")
public Map<String, ColumnDef> getColumns(Entity entity) {
    BeModelElement scheme = entity.getAvailableElement("Scheme");
    if (scheme == null)
        return new HashMap<>();
    BeCaseInsensitiveCollection<ColumnDef> columns = (BeCaseInsensitiveCollection<ColumnDef>) ((TableDef) scheme).get("Columns");
    return StreamSupport.stream(columns.spliterator(), false).collect(Utils.toLinkedMap(ColumnDef::getName, Function.identity()));
}
Also used : BeCaseInsensitiveCollection(com.developmentontheedge.be5.metadata.model.base.BeCaseInsensitiveCollection) BeModelElement(com.developmentontheedge.be5.metadata.model.base.BeModelElement) ColumnDef(com.developmentontheedge.be5.metadata.model.ColumnDef)

Aggregations

BeModelElement (com.developmentontheedge.be5.metadata.model.base.BeModelElement)9 ColumnDef (com.developmentontheedge.be5.metadata.model.ColumnDef)8 DynamicProperty (com.developmentontheedge.beans.DynamicProperty)7 BeModelCollection (com.developmentontheedge.be5.metadata.model.base.BeModelCollection)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 ReadException (com.developmentontheedge.be5.metadata.exception.ReadException)2 Entity (com.developmentontheedge.be5.metadata.model.Entity)2 Project (com.developmentontheedge.be5.metadata.model.Project)2 BeElementWithOriginModule (com.developmentontheedge.be5.metadata.model.base.BeElementWithOriginModule)2 Timestamp (java.sql.Timestamp)2 Date (java.util.Date)2 Map (java.util.Map)2 ProjectElementException (com.developmentontheedge.be5.metadata.exception.ProjectElementException)1 WriteException (com.developmentontheedge.be5.metadata.exception.WriteException)1 GroovyOperation (com.developmentontheedge.be5.metadata.model.GroovyOperation)1 JavaOperation (com.developmentontheedge.be5.metadata.model.JavaOperation)1 BeCaseInsensitiveCollection (com.developmentontheedge.be5.metadata.model.base.BeCaseInsensitiveCollection)1 Field (com.developmentontheedge.be5.metadata.serialization.Field)1