Search in sources :

Example 21 with Query

use of com.developmentontheedge.be5.metadata.model.Query 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 22 with Query

use of com.developmentontheedge.be5.metadata.model.Query 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 23 with Query

use of com.developmentontheedge.be5.metadata.model.Query 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)

Example 24 with Query

use of com.developmentontheedge.be5.metadata.model.Query 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 25 with Query

use of com.developmentontheedge.be5.metadata.model.Query 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)

Aggregations

Query (com.developmentontheedge.be5.metadata.model.Query)29 Entity (com.developmentontheedge.be5.metadata.model.Entity)16 ArrayList (java.util.ArrayList)15 Test (org.junit.Test)15 Project (com.developmentontheedge.be5.metadata.model.Project)12 Module (com.developmentontheedge.be5.metadata.model.Module)8 Path (java.nio.file.Path)8 Operation (com.developmentontheedge.be5.metadata.model.Operation)6 HashMap (java.util.HashMap)6 Be5Exception (com.developmentontheedge.be5.api.exceptions.Be5Exception)4 ProjectElementException (com.developmentontheedge.be5.metadata.exception.ProjectElementException)4 Be5ProjectTest (com.developmentontheedge.be5.test.Be5ProjectTest)4 Map (java.util.Map)4 UserAwareMeta (com.developmentontheedge.be5.api.helpers.UserAwareMeta)3 ReadException (com.developmentontheedge.be5.metadata.exception.ReadException)3 DataElementPath (com.developmentontheedge.be5.metadata.model.base.DataElementPath)3 LoadContext (com.developmentontheedge.be5.metadata.serialization.LoadContext)3 LinkedHashMap (java.util.LinkedHashMap)3 BeModelElement (com.developmentontheedge.be5.metadata.model.base.BeModelElement)2 Action (com.developmentontheedge.be5.model.Action)2