Search in sources :

Example 11 with Operation

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() + "'");
    }
}
Also used : TableBuilder(com.developmentontheedge.be5.query.TableBuilder)

Example 12 with Operation

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;
}
Also used : ArrayList(java.util.ArrayList) Operation(com.developmentontheedge.be5.metadata.model.Operation) OperationSet(com.developmentontheedge.be5.metadata.model.OperationSet)

Example 13 with Operation

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;
}
Also used : Operation(com.developmentontheedge.be5.operation.Operation)

Example 14 with 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);
}
Also used : Path(java.nio.file.Path) Project(com.developmentontheedge.be5.metadata.model.Project) Entity(com.developmentontheedge.be5.metadata.model.Entity) Query(com.developmentontheedge.be5.metadata.model.Query) Operation(com.developmentontheedge.be5.metadata.model.Operation) Module(com.developmentontheedge.be5.metadata.model.Module) Test(org.junit.Test)

Example 15 with Operation

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);
}
Also used : Path(java.nio.file.Path) Project(com.developmentontheedge.be5.metadata.model.Project) Entity(com.developmentontheedge.be5.metadata.model.Entity) JavaScriptOperationExtender(com.developmentontheedge.be5.metadata.model.JavaScriptOperationExtender) OperationExtender(com.developmentontheedge.be5.metadata.model.OperationExtender) JavaScriptOperationExtender(com.developmentontheedge.be5.metadata.model.JavaScriptOperationExtender) Operation(com.developmentontheedge.be5.metadata.model.Operation) Module(com.developmentontheedge.be5.metadata.model.Module) Test(org.junit.Test)

Aggregations

Operation (com.developmentontheedge.be5.metadata.model.Operation)9 Entity (com.developmentontheedge.be5.metadata.model.Entity)6 Operation (com.developmentontheedge.be5.operation.Operation)6 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Module (com.developmentontheedge.be5.metadata.model.Module)5 Query (com.developmentontheedge.be5.metadata.model.Query)5 Project (com.developmentontheedge.be5.metadata.model.Project)4 OperationResult (com.developmentontheedge.be5.operation.OperationResult)4 Path (java.nio.file.Path)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 ReadException (com.developmentontheedge.be5.metadata.exception.ReadException)2 BeModelElement (com.developmentontheedge.be5.metadata.model.base.BeModelElement)2 Action (com.developmentontheedge.be5.model.Action)2 FormPresentation (com.developmentontheedge.be5.model.FormPresentation)2 TableOperationPresentation (com.developmentontheedge.be5.model.TableOperationPresentation)2 ResourceData (com.developmentontheedge.be5.model.jsonapi.ResourceData)2 SqlMockOperationTest (com.developmentontheedge.be5.test.SqlMockOperationTest)2 HashUrl (com.developmentontheedge.be5.util.HashUrl)2