Search in sources :

Example 11 with DynamicProperty

use of com.developmentontheedge.beans.DynamicProperty in project be5 by DevelopmentOnTheEdge.

the class Be5QueryExecutor method applySort.

private void applySort(DebugQueryLogger dql, AstStart ast) {
    if (sortColumn >= 0) {
        try {
            DynamicProperty[] schema = getSchema(new Formatter().format(ast, context, parserContext));
            int sortCol = getQuerySortingColumn(schema);
            if (sortCol > 0) {
                AstSelect sel = (AstSelect) ast.getQuery().jjtGetChild(ast.getQuery().jjtGetNumChildren() - 1);
                AstOrderBy orderBy = sel.getOrderBy();
                if (orderBy == null) {
                    orderBy = new AstOrderBy();
                    sel.addChild(orderBy);
                    AstLimit astLimit = sel.children().select(AstLimit.class).findFirst().orElse(null);
                    if (astLimit != null) {
                        sel.removeChild(astLimit);
                        sel.addChild(astLimit);
                    }
                }
                AstOrderingElement oe = new AstOrderingElement(AstNumericConstant.of(sortCol));
                if (sortDesc) {
                    oe.setDirectionToken(new Token(0, "DESC"));
                }
                orderBy.addChild(oe);
                orderBy.moveToFront(oe);
            }
            dql.log("With sort", ast);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Also used : AstSelect(com.developmentontheedge.sql.model.AstSelect) AstOrderBy(com.developmentontheedge.sql.model.AstOrderBy) AstLimit(com.developmentontheedge.sql.model.AstLimit) DynamicProperty(com.developmentontheedge.beans.DynamicProperty) AstOrderingElement(com.developmentontheedge.sql.model.AstOrderingElement) SQLException(java.sql.SQLException) Formatter(com.developmentontheedge.sql.format.Formatter) Token(com.developmentontheedge.sql.model.Token)

Example 12 with DynamicProperty

use of com.developmentontheedge.beans.DynamicProperty in project be5 by DevelopmentOnTheEdge.

the class BeConnectionProfile method getProperties.

public DynamicPropertySet getProperties() {
    return new AbstractDynamicPropertySet() {

        private static final long serialVersionUID = 1L;

        @Override
        public int size() {
            return properties.size();
        }

        @Override
        public boolean replaceWith(String name, DynamicProperty prop) {
            if (!properties.containsKey(name))
                return false;
            properties.put(name, (String) prop.getValue());
            return true;
        }

        @Override
        public void renameProperty(String from, String to) {
            String value = properties.get(from);
            properties.remove(from);
            properties.put(to, value);
        }

        @Override
        public Object remove(String name) {
            return properties.remove(name);
        }

        @Override
        public Iterator<DynamicProperty> propertyIterator() {
            return StreamEx.ofKeys(properties).map(this::findProperty).iterator();
        }

        @Override
        public Iterator<String> nameIterator() {
            return properties.keySet().iterator();
        }

        @Override
        public boolean moveTo(String name, int index) {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean contains(DynamicProperty property) {
            return properties.containsKey(property.getName());
        }

        @Override
        public Map<String, Object> asMap() {
            return new LinkedHashMap<>(properties);
        }

        @Override
        public boolean addBefore(String propName, DynamicProperty property) {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean addAfter(String propName, DynamicProperty property) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void add(DynamicProperty property) {
            properties.put(property.getName(), (String) property.getValue());
        }

        @Override
        protected DynamicProperty findProperty(String name) {
            String value = properties.get(name);
            return value == null ? null : new DynamicProperty(name, String.class, value);
        }
    };
}
Also used : AbstractDynamicPropertySet(com.developmentontheedge.beans.AbstractDynamicPropertySet) DynamicProperty(com.developmentontheedge.beans.DynamicProperty) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with DynamicProperty

use of com.developmentontheedge.beans.DynamicProperty in project be5 by DevelopmentOnTheEdge.

the class Login method getParameters.

@Override
public Object getParameters(Map<String, Object> presetValues) throws Exception {
    dpsHelper.addDpForColumns(dps, getInfo().getEntity(), Arrays.asList("user_name", "user_pass"), presetValues);
    DynamicProperty user_pass = dps.getProperty("user_pass");
    user_pass.setAttribute(CAN_BE_NULL, false);
    user_pass.setAttribute(PASSWORD_FIELD, true);
    return dps;
}
Also used : DynamicProperty(com.developmentontheedge.beans.DynamicProperty)

Example 14 with DynamicProperty

use of com.developmentontheedge.beans.DynamicProperty in project be5 by DevelopmentOnTheEdge.

the class DpsHelper method setOperationParams.

public <T extends DynamicPropertySet> T setOperationParams(T dps, Map<String, String> operationParams) {
    Map<String, ?> params = ParseRequestUtils.getOperationParamsWithoutFilter(operationParams);
    for (Map.Entry<String, ?> entry : params.entrySet()) {
        DynamicProperty property = dps.getProperty(entry.getKey());
        if (property != null) {
            property.setValue(entry.getValue());
            property.setReadOnly(true);
        }
    }
    return dps;
}
Also used : DynamicProperty(com.developmentontheedge.beans.DynamicProperty) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 15 with DynamicProperty

use of com.developmentontheedge.beans.DynamicProperty in project be5 by DevelopmentOnTheEdge.

the class DpsHelper method getDynamicPropertyWithoutTags.

public DynamicProperty getDynamicPropertyWithoutTags(ColumnDef columnDef, BeModelElement modelElements) {
    DynamicProperty dp = new DynamicProperty(columnDef.getName(), meta.getColumnType(columnDef));
    if (modelElements.getClass() == Query.class) {
        dp.setDisplayName(userAwareMeta.getColumnTitle(columnDef.getEntity().getName(), modelElements.getName(), columnDef.getName()));
    } else if (modelElements.getClass() == Entity.class) {
        dp.setDisplayName(userAwareMeta.getColumnTitle(columnDef.getEntity().getName(), columnDef.getName()));
    } else if (modelElements.getClass() == JavaOperation.class || modelElements.getClass() == GroovyOperation.class) {
        dp.setDisplayName(userAwareMeta.getLocalizedOperationField(columnDef.getEntity().getName(), modelElements.getName(), columnDef.getName()));
    }
    if (columnDef.getDefaultValue() != null) {
        dp.setValue(meta.getColumnDefaultValue(columnDef));
    }
    if (columnDef.isCanBeNull() || (columnDef.getTypeString().equals(SqlColumnType.TYPE_BOOL) && columnDef.getDefaultValue() != null)) {
        dp.setCanBeNull(true);
    }
    if (SqlColumnType.TYPE_VARCHAR.equals(columnDef.getType().getTypeName()) || SqlColumnType.TYPE_CHAR.equals(columnDef.getType().getTypeName())) {
        dp.setAttribute(BeanInfoConstants.COLUMN_SIZE_ATTR, columnDef.getType().getSize());
    }
    if (SqlColumnType.TYPE_DECIMAL.equals(columnDef.getType().getTypeName())) {
        int size = columnDef.getType().getSize();
        dp.setAttribute(BeanInfoConstants.VALIDATION_RULES, Arrays.asList(getRange(size, false), step(getPrecision(columnDef.getType().getPrecision()))));
    }
    if (SqlColumnType.TYPE_CURRENCY.equals(columnDef.getType().getTypeName())) {
        dp.setAttribute(BeanInfoConstants.VALIDATION_RULES, Arrays.asList(getRange(columnDef.getType().getSize(), false), step(0.01)));
    }
    if (SqlColumnType.TYPE_INT.equals(columnDef.getType().getTypeName()) || SqlColumnType.TYPE_UINT.equals(columnDef.getType().getTypeName())) {
        boolean unsigned = SqlColumnType.TYPE_UINT.equals(columnDef.getType().getTypeName());
        dp.setAttribute(BeanInfoConstants.VALIDATION_RULES, Arrays.asList(range(unsigned ? 0 : Integer.MIN_VALUE, Integer.MAX_VALUE), step(1)));
    }
    if (SqlColumnType.TYPE_BIGINT.equals(columnDef.getType().getTypeName()) || SqlColumnType.TYPE_UBIGINT.equals(columnDef.getType().getTypeName())) {
        boolean unsigned = SqlColumnType.TYPE_UBIGINT.equals(columnDef.getType().getTypeName());
        dp.setAttribute(BeanInfoConstants.VALIDATION_RULES, Arrays.asList(range(unsigned ? 0 : Long.MIN_VALUE, Long.MAX_VALUE), step(1)));
    }
    if (columnDef.getName().endsWith(HIDDEN_COLUMN_PREFIX))
        dp.setHidden(true);
    return dp;
}
Also used : Entity(com.developmentontheedge.be5.metadata.model.Entity) DynamicProperty(com.developmentontheedge.beans.DynamicProperty) GroovyOperation(com.developmentontheedge.be5.metadata.model.GroovyOperation) JavaOperation(com.developmentontheedge.be5.metadata.model.JavaOperation)

Aggregations

DynamicProperty (com.developmentontheedge.beans.DynamicProperty)27 DynamicPropertySet (com.developmentontheedge.beans.DynamicPropertySet)7 ColumnDef (com.developmentontheedge.be5.metadata.model.ColumnDef)6 Map (java.util.Map)6 HashMap (java.util.HashMap)5 DynamicPropertySetSupport (com.developmentontheedge.beans.DynamicPropertySetSupport)4 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 LinkedHashMap (java.util.LinkedHashMap)3 Be5Exception (com.developmentontheedge.be5.api.exceptions.Be5Exception)2 Formatter (com.developmentontheedge.sql.format.Formatter)2 List (java.util.List)2 TreeMap (java.util.TreeMap)2 SEARCH_PARAM (com.developmentontheedge.be5.api.FrontendConstants.SEARCH_PARAM)1 SEARCH_PRESETS_PARAM (com.developmentontheedge.be5.api.FrontendConstants.SEARCH_PRESETS_PARAM)1 Entity (com.developmentontheedge.be5.metadata.model.Entity)1 GroovyOperation (com.developmentontheedge.be5.metadata.model.GroovyOperation)1 JavaOperation (com.developmentontheedge.be5.metadata.model.JavaOperation)1 Query (com.developmentontheedge.be5.metadata.model.Query)1 JsonApiModel (com.developmentontheedge.be5.model.jsonapi.JsonApiModel)1