use of com.developmentontheedge.be5.operation.Operation in project be5 by DevelopmentOnTheEdge.
the class DateTimeTest method testOperation.
@Test
public void testOperation() {
Operation operation = createOperation("dateTime", "All records", "Insert", "0");
ImmutableMap<String, Object> values = ImmutableMap.of("activeFrom", "1901-02-03");
Either<Object, OperationResult> generate = generateOperation(operation, values);
Object parameters = generate.getFirst();
assertEquals("{" + "'values':{'activeFrom':'1901-02-03'}," + "'meta':{'/activeFrom':{'displayName':'activeFrom','type':'Date'}}," + "'order':['/activeFrom']" + "}", oneQuotes(JsonFactory.bean(parameters)));
OperationResult result = executeOperation(operation, values).getSecond();
assertEquals(OperationResult.redirect("table/dateTime/All records"), result);
}
use of com.developmentontheedge.be5.operation.Operation 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.operation.Operation 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.operation.Operation in project be5 by DevelopmentOnTheEdge.
the class YamlDeserializer method readCustomizations.
/**
* Used with customizations (module), entity, query, operation and static page.
*/
@SuppressWarnings("unchecked")
private void readCustomizations(final Map<String, Object> serialized, final BeVectorCollection<?> target, boolean replace) {
if (project == null)
throw new IllegalStateException();
final Map<String, Object> serializedCustomizations = (Map<String, Object>) serialized.get("customizations");
if (serializedCustomizations == null || serializedCustomizations.isEmpty())
return;
final BeVectorCollection<PageCustomization> customizations = replace ? new PageCustomizations(target) : target.getOrCreateCollection(PageCustomization.CUSTOMIZATIONS_COLLECTION, PageCustomization.class);
try {
for (final String name : serializedCustomizations.keySet()) {
final Map<String, Object> content = (Map<String, Object>) serializedCustomizations.get(name);
final List<String> splitted = StreamEx.split(name, "\\.").toList();
final String type;
final String domain;
if (splitted.size() == 1) {
type = "";
domain = splitted.get(0);
} else {
type = splitted.get(splitted.size() - 1);
splitted.remove(splitted.size() - 1);
domain = String.join(".", splitted);
}
final PageCustomization customization = new PageCustomization(type, domain, customizations);
customization.setCode((String) content.get(TAG_CODE));
customization.setOriginModuleName(project.getProjectOrigin());
DataElementUtils.saveQuiet(customization);
}
} catch (Exception e) {
loadContext.addWarning(new ReadException(e, target, project.getLocation()));
}
if (replace)
DataElementUtils.save(customizations);
}
use of com.developmentontheedge.be5.operation.Operation in project be5 by DevelopmentOnTheEdge.
the class ReadModelFromXmlTest method testWriteReadQueryOperation.
@Test
public void testWriteReadQueryOperation() throws Exception {
final Project project = new Project("TestProject");
final Module module = project.getApplication();
DataElementUtils.saveQuiet(module);
final Entity table = new Entity("table", module, EntityType.TABLE);
DataElementUtils.saveQuiet(table);
final Operation op = Operation.createOperation("op", Operation.OPERATION_TYPE_JAVA, table);
DataElementUtils.saveQuiet(op);
final Query query = new Query("q", table);
DataElementUtils.saveQuiet(query);
query.getOperationNames().add("op");
final Path tempFolder = Files.createTempDirectory("be4-temp");
Serialization.save(project, tempFolder);
final Project readProject = Serialization.load(tempFolder);
final Entity readEntity = readProject.getApplication().getEntity("table");
assertEquals("op", readEntity.getQueries().get("q").getOperationNames().getValuesArray()[0]);
FileUtils.deleteRecursively(tempFolder);
}
Aggregations