Search in sources :

Example 6 with Action

use of com.developmentontheedge.be5.model.Action in project be5 by DevelopmentOnTheEdge.

the class Menu method collectEntityContent.

private void collectEntityContent(Entity entity, String language, Meta meta, UserAwareMeta userAwareMeta, List<String> roles, boolean withIds, List<RootNode> out) {
    List<Query> permittedQueries = meta.getQueries(entity, roles);
    if (permittedQueries.isEmpty()) {
        return;
    }
    String title = meta.getTitle(entity, language);
    List<OperationNode> operations = generateEntityOperations(entity, meta, userAwareMeta, roles, withIds);
    if (operations.isEmpty()) {
        operations = null;
    }
    if (canBeMovedToRoot(permittedQueries, title, language, meta)) {
        // Query in the root, contains an action.
        Id id = null;
        Action action = ActionUtils.toAction(permittedQueries.get(0));
        boolean isDefault = permittedQueries.get(0).isDefaultView();
        if (withIds) {
            String queryTitle = getTitleOfRootQuery(permittedQueries, title, language, meta);
            id = new Id(entity.getName(), queryTitle);
        }
        out.add(RootNode.action(id, title, isDefault, action, operations));
    } else {
        // No query in the root, just inner queries.
        List<QueryNode> children = generateEntityQueries(permittedQueries, language, meta, withIds);
        Id id = new Id(entity.getName(), null);
        out.add(RootNode.container(id, title, children, operations));
    }
}
Also used : Action(com.developmentontheedge.be5.model.Action) Query(com.developmentontheedge.be5.metadata.model.Query)

Example 7 with Action

use of com.developmentontheedge.be5.model.Action 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 8 with Action

use of com.developmentontheedge.be5.model.Action 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 9 with Action

use of com.developmentontheedge.be5.model.Action in project be5 by DevelopmentOnTheEdge.

the class OperationExecutorImpl method create.

@Override
public Operation create(OperationInfo operationInfo, OperationContext operationContext) {
    Operation operation;
    switch(operationInfo.getType()) {
        case OPERATION_TYPE_GROOVY:
            try {
                Class aClass = groovyOperationLoader.get(operationInfo);
                if (aClass != null) {
                    operation = (Operation) aClass.newInstance();
                } else {
                    throw Be5Exception.internalInOperation(new Error("Class " + operationInfo.getCode() + " is null."), operationInfo.getModel());
                }
            } catch (NoClassDefFoundError | IllegalAccessException | InstantiationException e) {
                throw new UnsupportedOperationException("Groovy feature has been excluded", e);
            } catch (Throwable e) {
                throw Be5Exception.internalInOperation(e, operationInfo.getModel());
            }
            break;
        case OPERATION_TYPE_JAVA:
            try {
                operation = (Operation) Class.forName(operationInfo.getCode()).newInstance();
                break;
            } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
                throw Be5Exception.internalInOperation(new RuntimeException("It is possible to use the 'file:' instead of the 'code:' " + "in the yaml file. \n\t" + e.getMessage(), e), operationInfo.getModel());
            }
        case OPERATION_TYPE_JAVAFUNCTION:
        case OPERATION_TYPE_SQL:
        case OPERATION_TYPE_JAVASCRIPT:
        case OPERATION_TYPE_JSSERVER:
        case OPERATION_TYPE_DOTNET:
        case OPERATION_TYPE_JAVADOTNET:
            throw Be5Exception.internal("Not support operation type: " + operationInfo.getType());
        default:
            throw Be5Exception.internal("Unknown action type '" + operationInfo.getType() + "'");
    }
    operation.initialize(operationInfo, operationContext, OperationResult.create());
    injector.injectAnnotatedFields(operation);
    return operation;
}
Also used : Operation(com.developmentontheedge.be5.metadata.model.Operation) TransactionalOperation(com.developmentontheedge.be5.operation.TransactionalOperation) Operation(com.developmentontheedge.be5.operation.Operation)

Example 10 with Action

use of com.developmentontheedge.be5.model.Action in project be5 by DevelopmentOnTheEdge.

the class Menu method generateEntityOperations.

private List<OperationNode> generateEntityOperations(Entity entity, Meta meta, UserAwareMeta userAwareMeta, List<String> roles, boolean withIds) {
    List<OperationNode> operations = new ArrayList<>();
    Query allRecords = entity.getQueries().get(DatabaseConstants.ALL_RECORDS_VIEW);
    String insertOperationName = INSERT_OPERATION;
    if (allRecords != null && allRecords.getOperationNames().getFinalValues().contains(insertOperationName)) {
        Operation insertOperation = entity.getOperations().get(insertOperationName);
        if (insertOperation != null && meta.isAvailableFor(insertOperation, roles)) {
            String title = userAwareMeta.getLocalizedOperationTitle(entity.getName(), insertOperationName);
            Action action = ActionUtils.toAction(DatabaseConstants.ALL_RECORDS_VIEW, insertOperation);
            OperationId id = withIds ? new OperationId(entity.getName(), insertOperationName) : null;
            OperationNode operation = new OperationNode(id, title, action);
            operations.add(operation);
        }
    }
    return operations;
}
Also used : Action(com.developmentontheedge.be5.model.Action) Query(com.developmentontheedge.be5.metadata.model.Query) ArrayList(java.util.ArrayList) Operation(com.developmentontheedge.be5.metadata.model.Operation)

Aggregations

Action (com.developmentontheedge.be5.model.Action)10 Be5ProjectTest (com.developmentontheedge.be5.test.Be5ProjectTest)7 Test (org.junit.Test)7 Response (com.developmentontheedge.be5.api.Response)4 Operation (com.developmentontheedge.be5.metadata.model.Operation)2 Query (com.developmentontheedge.be5.metadata.model.Query)2 UserAwareMeta (com.developmentontheedge.be5.api.helpers.UserAwareMeta)1 TableOperationPresentation (com.developmentontheedge.be5.model.TableOperationPresentation)1 Operation (com.developmentontheedge.be5.operation.Operation)1 TransactionalOperation (com.developmentontheedge.be5.operation.TransactionalOperation)1 TableBuilder (com.developmentontheedge.be5.query.TableBuilder)1 ArrayList (java.util.ArrayList)1