Search in sources :

Example 21 with Operation

use of com.developmentontheedge.be5.operation.Operation in project be5 by DevelopmentOnTheEdge.

the class OperationModelBase method generate.

@Override
public Object generate() {
    Operation operation = operationExecutor.create(getOperationInfo(), getOperationContext());
    operation.setResult(OperationResult.generate());
    return operationExecutor.generate(operation, (Map<String, Object>) presetValues);
}
Also used : Operation(com.developmentontheedge.be5.operation.Operation)

Example 22 with Operation

use of com.developmentontheedge.be5.operation.Operation in project be5 by DevelopmentOnTheEdge.

the class DocumentGeneratorImpl method getDocument.

@Override
public JsonApiModel getDocument(Query query, Map<String, String> parameters, int sortColumn, boolean sortDesc) {
    Object data = routeAndRun(query, parameters, sortColumn, sortDesc);
    HashUrl url = new HashUrl(TABLE_ACTION, query.getEntity().getName(), query.getName()).named(parameters);
    List<ResourceData> included = new ArrayList<>();
    String topForm = (String) ParseRequestUtils.getValuesFromJson(query.getLayout()).get(TOP_FORM);
    if (topForm != null) {
        com.developmentontheedge.be5.operation.Operation operation = operationExecutor.create(query.getEntity().getName(), query.getName(), topForm, new String[] {}, parameters);
        Either<FormPresentation, OperationResult> dataTopForm = generateForm(operation, Collections.emptyMap());
        included.add(new ResourceData(TOP_FORM, dataTopForm.isFirst() ? FORM_ACTION : OPERATION_RESULT, dataTopForm.get(), Collections.singletonMap(SELF_LINK, operation.getUrl().toString())));
    }
    return JsonApiModel.data(new ResourceData(TABLE_ACTION, data, Collections.singletonMap(SELF_LINK, url.toString())), included.toArray(new ResourceData[0]), null);
}
Also used : ResourceData(com.developmentontheedge.be5.model.jsonapi.ResourceData) FormPresentation(com.developmentontheedge.be5.model.FormPresentation) ArrayList(java.util.ArrayList) HashUrl(com.developmentontheedge.be5.util.HashUrl) OperationResult(com.developmentontheedge.be5.operation.OperationResult)

Example 23 with Operation

use of com.developmentontheedge.be5.operation.Operation in project be5 by DevelopmentOnTheEdge.

the class ProjectGenerator method createLoginAndLogoutOperations.

private void createLoginAndLogoutOperations(final Project project) {
    final Entity logoutEntity = new Entity("_logout_", project.getApplication(), EntityType.TABLE);
    logoutEntity.setDisplayName("Logout");
    logoutEntity.setOrder("99");
    logoutEntity.setPrimaryKey("dummy");
    logoutEntity.getIcon().setSource(Icon.SOURCE_BE);
    logoutEntity.getIcon().setName("logout.gif");
    final Query logout = new Query("Logout", logoutEntity);
    logout.setType(QueryType.STATIC);
    logout.getRoles().add('@' + SpecialRoleGroup.ALL_ROLES_EXCEPT_GUEST_GROUP);
    logout.setQuery("logout");
    DataElementUtils.saveQuiet(logout);
    EntitiesFactory.addToModule(logoutEntity, project.getApplication());
    Module beModule = project.getModule(SYSTEM_MODULE);
    Entity usersEntity = new Entity("users", beModule, EntityType.TABLE);
    usersEntity.setOrder("90");
    usersEntity.getIcon().setSource("be:people.gif");
    DataElementUtils.saveQuiet(usersEntity);
    Query loginQuery = new Query("Login", usersEntity);
    loginQuery.setType(QueryType.STATIC);
    loginQuery.setQuery("login");
    loginQuery.getRoles().add("Guest");
    DataElementUtils.saveQuiet(loginQuery);
// Query forgotPassword = new Query("Forgot Password?", usersEntity);
// forgotPassword.getRoles().add( "Guest" );
// forgotPassword.setParametrizingOperationName( "Send password" );
// DataElementUtils.saveQuiet( forgotPassword );
// Operation sendPassword = Operation.createOperation( "Send password", Operation.OPERATION_TYPE_JAVA, usersEntity );
// sendPassword.setCode( SendPassword.class.getName() );
// DataElementUtils.saveQuiet( sendPassword );
}
Also used : Entity(com.developmentontheedge.be5.metadata.model.Entity) Query(com.developmentontheedge.be5.metadata.model.Query) Module(com.developmentontheedge.be5.metadata.model.Module)

Example 24 with Operation

use of com.developmentontheedge.be5.operation.Operation in project be5 by DevelopmentOnTheEdge.

the class StandardOperationsTest method insertOperationInitValues.

@Test
public void insertOperationInitValues() {
    Operation operation = createOperation("testtableAdmin", "All records", "Insert", "");
    assertEquals(OperationStatus.CREATE, operation.getStatus());
    Object first = generateOperation(operation, "{}").getFirst();
    assertEquals(OperationStatus.GENERATE, operation.getStatus());
    assertEquals("{'name':'','value':''}", oneQuotes(JsonFactory.bean(first).getJsonObject("values").toString()));
}
Also used : Operation(com.developmentontheedge.be5.operation.Operation) Test(org.junit.Test) SqlMockOperationTest(com.developmentontheedge.be5.test.SqlMockOperationTest)

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