Search in sources :

Example 6 with Operation

use of com.developmentontheedge.be5.metadata.model.Operation in project be5 by DevelopmentOnTheEdge.

the class OperationExecutorImpl method create.

@Override
public Operation create(String entityName, String queryName, String operationName, String[] selectedRows, Map<String, String> operationParams) {
    OperationInfo operationInfo = userAwareMeta.getOperation(entityName, operationName);
    OperationContext operationContext = new OperationContext(selectedRows, queryName, operationParams);
    return create(operationInfo, operationContext);
}
Also used : OperationInfo(com.developmentontheedge.be5.operation.OperationInfo) OperationContext(com.developmentontheedge.be5.operation.OperationContext)

Example 7 with Operation

use of com.developmentontheedge.be5.metadata.model.Operation in project be5 by DevelopmentOnTheEdge.

the class Project method getContext.

/**
 * Creates and returns FreeMarker context for given element
 * @param element to create context for (can be null)
 * @return
 */
public Map<String, Object> getContext(TemplateElement element) {
    Map<String, Object> context = new HashMap<>();
    BeModelElement parent = element;
    while (parent != null) {
        if (parent instanceof PageCustomization) {
            context.put("customization", parent);
        } else if (parent instanceof Query) {
            context.put("query", parent);
        } else if (parent instanceof Operation) {
            context.put("operation", parent);
        } else if (parent instanceof Entity) {
            context.put("entity", parent);
        } else if (parent instanceof Module) {
            context.put("module", parent);
        }
        parent = parent.getOrigin();
    }
    for (String name : getPropertyNames()) {
        context.put(name, getProperty(name));
    }
    BeConnectionProfile profile = getConnectionProfile();
    if (profile != null) {
        for (String name : profile.getPropertyNames()) {
            context.put(name, profile.getProperty(name));
        }
    }
    return context;
}
Also used : BeModelElement(com.developmentontheedge.be5.metadata.model.base.BeModelElement) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with Operation

use of com.developmentontheedge.be5.metadata.model.Operation in project be5 by DevelopmentOnTheEdge.

the class Form method generate.

@Override
public void generate(Request req, Response res, Injector injector) {
    OperationExecutor operationExecutor = injector.get(OperationExecutor.class);
    DocumentGenerator documentGenerator = injector.get(DocumentGenerator.class);
    String entityName = req.getNonEmpty(RestApiConstants.ENTITY);
    String queryName = req.getNonEmpty(RestApiConstants.QUERY);
    String operationName = req.getNonEmpty(RestApiConstants.OPERATION);
    String[] selectedRows = ParseRequestUtils.selectedRows(nullToEmpty(req.get(RestApiConstants.SELECTED_ROWS)));
    Map<String, String> operationParams = req.getValuesFromJsonAsStrings(RestApiConstants.OPERATION_PARAMS);
    Map<String, Object> values = req.getValuesFromJson(RestApiConstants.VALUES);
    Operation operation;
    try {
        operation = operationExecutor.create(entityName, queryName, operationName, selectedRows, operationParams);
    } catch (Be5Exception e) {
        HashUrl url = new HashUrl(FORM_ACTION, entityName, queryName, operationName).named(operationParams);
        res.sendErrorAsJson(new ErrorModel(e, "", Collections.singletonMap(SELF_LINK, url.toString())), req.getDefaultMeta());
        return;
    }
    Either<FormPresentation, OperationResult> data;
    try {
        switch(req.getRequestUri()) {
            case "":
                data = documentGenerator.generateForm(operation, values);
                break;
            case "apply":
                data = documentGenerator.executeForm(operation, values);
                break;
            default:
                res.sendUnknownActionError();
                return;
        }
    } catch (Be5Exception e) {
        res.sendErrorAsJson(documentGenerator.getErrorModel(e, operation.getUrl()), req.getDefaultMeta());
        return;
    }
    res.sendAsJson(new ResourceData(data.isFirst() ? FORM_ACTION : OPERATION_RESULT, data.get(), Collections.singletonMap(SELF_LINK, operation.getUrl().toString())), req.getDefaultMeta());
}
Also used : Be5Exception(com.developmentontheedge.be5.api.exceptions.Be5Exception) ResourceData(com.developmentontheedge.be5.model.jsonapi.ResourceData) HashUrl(com.developmentontheedge.be5.util.HashUrl) OperationResult(com.developmentontheedge.be5.operation.OperationResult) Operation(com.developmentontheedge.be5.operation.Operation) DocumentGenerator(com.developmentontheedge.be5.query.DocumentGenerator) FormPresentation(com.developmentontheedge.be5.model.FormPresentation) OperationExecutor(com.developmentontheedge.be5.api.services.OperationExecutor) ErrorModel(com.developmentontheedge.be5.model.jsonapi.ErrorModel)

Example 9 with Operation

use of com.developmentontheedge.be5.metadata.model.Operation in project be5 by DevelopmentOnTheEdge.

the class DocumentGeneratorImpl method presentOperation.

private TableOperationPresentation presentOperation(Query query, Operation operation) {
    String visibleWhen = Operations.determineWhenVisible(operation);
    String title = userAwareMeta.getLocalizedOperationTitle(query.getEntity().getName(), operation.getName());
    // boolean requiresConfirmation = operation.isConfirm();
    boolean isClientSide = Operations.isClientSide(operation);
    Action action = null;
    if (isClientSide) {
        action = Action.call(Operations.asClientSide(operation).toHashUrl());
    }
    return new TableOperationPresentation(operation.getName(), title, visibleWhen, false, isClientSide, action);
}
Also used : Action(com.developmentontheedge.be5.model.Action) TableOperationPresentation(com.developmentontheedge.be5.model.TableOperationPresentation)

Example 10 with Operation

use of com.developmentontheedge.be5.metadata.model.Operation in project be5 by DevelopmentOnTheEdge.

the class DocumentGeneratorImpl method collectOperations.

private List<TableOperationPresentation> collectOperations(Query query) {
    List<TableOperationPresentation> operations = new ArrayList<>();
    List<String> userRoles = UserInfoHolder.getCurrentRoles();
    for (Operation operation : getQueryOperations(query)) {
        if (Operations.isAllowed(operation, userRoles)) {
            operations.add(presentOperation(query, operation));
        }
    }
    operations.sort(Comparator.comparing(TableOperationPresentation::getTitle));
    return operations;
}
Also used : TableOperationPresentation(com.developmentontheedge.be5.model.TableOperationPresentation) ArrayList(java.util.ArrayList) Operation(com.developmentontheedge.be5.metadata.model.Operation)

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