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;
}
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());
}
}
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;
}
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;
}
}
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;
}
}
Aggregations