use of com.developmentontheedge.be5.metadata.model.Operation in project be5 by DevelopmentOnTheEdge.
the class DocumentGeneratorImpl method routeAndRun.
@Override
public Object routeAndRun(Query query, Map<String, String> parameters, int sortColumn, boolean sortDesc) {
switch(query.getType()) {
case STATIC:
if (ActionUtils.isStaticPage(query)) {
return getStatic(query);
} else {
throw Be5Exception.internalInQuery(new IllegalStateException("Unsupported static request"), query);
}
case D1:
case D1_UNKNOWN:
return getTable(query, parameters, sortColumn, sortDesc);
case D2:
case CONTAINER:
case CUSTOM:
case JAVASCRIPT:
throw Be5Exception.internal("Not support operation type: " + query.getType());
case GROOVY:
try {
Class aClass = groovyRegister.getClass(query.getEntity() + query.getName(), query.getQuery(), query.getFileName());
if (aClass != null) {
TableBuilder tableBuilder = (TableBuilder) aClass.newInstance();
tableBuilder.initialize(query, parameters);
injector.injectAnnotatedFields(tableBuilder);
return getTable(query, parameters, tableBuilder.getTableModel());
} else {
throw Be5Exception.internal("Class " + query.getQuery() + " is null.");
}
} catch (NoClassDefFoundError | IllegalAccessException | InstantiationException e) {
throw new UnsupportedOperationException("Groovy feature has been excluded", e);
}
default:
throw Be5Exception.internal("Unknown action type '" + query.getType() + "'");
}
}
use of com.developmentontheedge.be5.metadata.model.Operation in project be5 by DevelopmentOnTheEdge.
the class DocumentGeneratorImpl method getQueryOperations.
private List<Operation> getQueryOperations(Query query) {
List<Operation> queryOperations = new ArrayList<>();
OperationSet operationNames = query.getOperationNames();
for (String operationName : operationNames.getFinalValues()) {
Operation op = query.getEntity().getOperations().get(operationName);
if (op != null)
queryOperations.add(op);
}
return queryOperations;
}
use of com.developmentontheedge.be5.metadata.model.Operation in project be5 by DevelopmentOnTheEdge.
the class OperationModelBase method execute.
@Override
public Operation execute() {
Operation operation = operationExecutor.create(getOperationInfo(), getOperationContext());
operation.setResult(OperationResult.execute());
operationExecutor.execute(operation, (Map<String, Object>) presetValues);
if (operation.getStatus() == OperationStatus.ERROR) {
throw (RuntimeException) operation.getResult().getDetails();
}
return operation;
}
use of com.developmentontheedge.be5.metadata.model.Operation in project be5 by DevelopmentOnTheEdge.
the class ReadModelFromXmlTest method testWriteReadCustomizedModule.
@Test
public void testWriteReadCustomizedModule() throws Exception {
final Project project = new Project("TestProject");
final Module module = new Module("testmodule", project.getModules());
DataElementUtils.saveQuiet(module);
final Entity table = new Entity("customizedtable", module, EntityType.TABLE);
DataElementUtils.saveQuiet(table);
final Operation op1 = Operation.createOperation("normop", Operation.OPERATION_TYPE_JAVA, table);
assertFalse(module.isCustomized());
DataElementUtils.saveQuiet(op1);
final Operation op2 = Operation.createOperation("custop", Operation.OPERATION_TYPE_JAVA, table);
op2.setOriginModuleName(Project.APPLICATION);
DataElementUtils.saveQuiet(op2);
final Query q1 = new Query("normq", table);
DataElementUtils.saveQuiet(q1);
final Query q2 = new Query("custq", table);
q2.setOriginModuleName(Project.APPLICATION);
DataElementUtils.saveQuiet(q2);
assertTrue(module.isCustomized());
final Path tempFolder = Files.createTempDirectory("be4-temp");
Serialization.save(project, tempFolder);
final Project project2 = Serialization.load(tempFolder);
final Module readModule = project2.getModule("testmodule");
assertNotNull(readModule);
assertTrue(readModule.isCustomized());
final Entity readTable = readModule.getEntity("customizedtable");
assertNotNull(readTable);
assertTrue(readTable.isCustomized());
assertEquals(1, readTable.getOperations().getSize());
assertNotNull(readTable.getOperations().get("custop"));
assertEquals(1, readTable.getQueries().getSize());
assertNotNull(readTable.getQueries().get("custq"));
FileUtils.deleteRecursively(tempFolder);
}
use of com.developmentontheedge.be5.metadata.model.Operation in project be5 by DevelopmentOnTheEdge.
the class ReadModelFromXmlTest method testWriteReadOperationExtender.
@Test
public void testWriteReadOperationExtender() 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 OperationExtender ex1 = new OperationExtender(op, module.getName());
DataElementUtils.saveQuiet(ex1);
ex1.setClassName("test.class.name");
ex1.setInvokeOrder(1);
final JavaScriptOperationExtender ex2 = new JavaScriptOperationExtender(op, module.getName());
DataElementUtils.saveQuiet(ex2);
ex2.setFileName("MyExtender.js");
ex2.setCode("Hello world!");
final Path tempFolder = Files.createTempDirectory("be4-temp");
Serialization.save(project, tempFolder);
final Project readProject = Serialization.load(tempFolder);
final Entity readEntity = readProject.getApplication().getEntity("table");
final BeModelCollection<OperationExtender> extenders = readEntity.getOperations().get("op").getExtenders();
assertEquals(2, extenders.getSize());
final OperationExtender readEx1 = extenders.get("application - 0001");
assertEquals("test.class.name", readEx1.getClassName());
assertEquals(1, readEx1.getInvokeOrder());
final JavaScriptOperationExtender readEx2 = (JavaScriptOperationExtender) extenders.get("application - 0002");
assertEquals(0, readEx2.getInvokeOrder());
assertEquals("MyExtender.js", readEx2.getFileName());
assertEquals("Hello world!", readEx2.getCode());
FileUtils.deleteRecursively(tempFolder);
}
Aggregations