Search in sources :

Example 1 with DisplayType

use of com.rebuild.core.metadata.easymeta.DisplayType in project rebuild by getrebuild.

the class FormsBuilder method buildModelElements.

/**
 * 构建表单元素
 *
 * @param elements
 * @param entity
 * @param data
 * @param user
 * @param useAdvControl
 */
protected void buildModelElements(JSONArray elements, Entity entity, Record data, ID user, boolean useAdvControl) {
    final User formUser = Application.getUserStore().getUser(user);
    final Date now = CalendarUtils.now();
    // Check and clean
    for (Iterator<Object> iter = elements.iterator(); iter.hasNext(); ) {
        JSONObject el = (JSONObject) iter.next();
        String fieldName = el.getString("field");
        if (DIVIDER_LINE.equalsIgnoreCase(fieldName)) {
            continue;
        }
        // 已删除字段
        if (!MetadataHelper.checkAndWarnField(entity, fieldName)) {
            iter.remove();
            continue;
        }
        // v2.2 高级控制
        Object displayOnCreate = el.remove("displayOnCreate");
        Object displayOnUpdate = el.remove("displayOnUpdate");
        Object requiredOnCreate = el.remove("requiredOnCreate");
        Object requiredOnUpdate = el.remove("requiredOnUpdate");
        if (useAdvControl) {
            // 显示
            if (displayOnCreate != null && !(Boolean) displayOnCreate && data == null) {
                iter.remove();
                continue;
            }
            if (displayOnUpdate != null && !(Boolean) displayOnUpdate && data != null) {
                iter.remove();
                continue;
            }
            // 必填
            if (requiredOnCreate != null && (Boolean) requiredOnCreate && data == null) {
                el.put("nullable", false);
            }
            if (requiredOnUpdate != null && (Boolean) requiredOnUpdate && data != null) {
                el.put("nullable", false);
            }
        }
        // 自动只读的
        final boolean roViaAuto = el.getBooleanValue("readonly");
        final Field fieldMeta = entity.getField(fieldName);
        final EasyField easyField = EasyMetaFactory.valueOf(fieldMeta);
        final DisplayType dt = easyField.getDisplayType();
        el.put("label", easyField.getLabel());
        el.put("type", dt.name());
        el.put("readonly", (data != null && !fieldMeta.isUpdatable()) || roViaAuto);
        // 优先使用指定值
        final Boolean nullable = el.getBoolean("nullable");
        if (nullable != null) {
            el.put("nullable", nullable);
        } else {
            el.put("nullable", fieldMeta.isNullable());
        }
        // 字段扩展配置 FieldExtConfigProps
        JSONObject fieldExtAttrs = easyField.getExtraAttrs(true);
        el.putAll(fieldExtAttrs);
        if (dt == DisplayType.PICKLIST) {
            JSONArray options = PickListManager.instance.getPickList(fieldMeta);
            el.put("options", options);
        } else if (dt == DisplayType.STATE) {
            JSONArray options = StateManager.instance.getStateOptions(fieldMeta);
            el.put("options", options);
            el.remove(EasyFieldConfigProps.STATE_CLASS);
        } else if (dt == DisplayType.MULTISELECT) {
            JSONArray options = MultiSelectManager.instance.getSelectList(fieldMeta);
            el.put("options", options);
        } else if (dt == DisplayType.DATETIME) {
            String format = StringUtils.defaultIfBlank(easyField.getExtraAttr(EasyFieldConfigProps.DATETIME_FORMAT), easyField.getDisplayType().getDefaultFormat());
            el.put(EasyFieldConfigProps.DATETIME_FORMAT, format);
        } else if (dt == DisplayType.DATE) {
            String format = StringUtils.defaultIfBlank(easyField.getExtraAttr(EasyFieldConfigProps.DATE_FORMAT), easyField.getDisplayType().getDefaultFormat());
            el.put(EasyFieldConfigProps.DATE_FORMAT, format);
        } else if (dt == DisplayType.TIME) {
            String format = StringUtils.defaultIfBlank(easyField.getExtraAttr(EasyFieldConfigProps.TIME_FORMAT), easyField.getDisplayType().getDefaultFormat());
            el.put(EasyFieldConfigProps.TIME_FORMAT, format);
        } else if (dt == DisplayType.CLASSIFICATION) {
            el.put("openLevel", ClassificationManager.instance.getOpenLevel(fieldMeta));
        }
        // 编辑/视图
        if (data != null) {
            Object value = wrapFieldValue(data, easyField, user);
            if (value != null) {
                el.put("value", value);
            }
        } else // 新建记录
        {
            if (!fieldMeta.isCreatable()) {
                el.put("readonly", true);
                switch(fieldName) {
                    case EntityHelper.CreatedOn:
                    case EntityHelper.ModifiedOn:
                        el.put("value", CalendarUtils.getUTCDateTimeFormat().format(now));
                        break;
                    case EntityHelper.CreatedBy:
                    case EntityHelper.ModifiedBy:
                    case EntityHelper.OwningUser:
                        el.put("value", FieldValueHelper.wrapMixValue(formUser.getId(), formUser.getFullName()));
                        break;
                    case EntityHelper.OwningDept:
                        Department dept = formUser.getOwningDept();
                        Assert.notNull(dept, "Department of user is unset : " + formUser.getId());
                        el.put("value", FieldValueHelper.wrapMixValue((ID) dept.getIdentity(), dept.getName()));
                        break;
                    case EntityHelper.ApprovalId:
                        el.put("value", FieldValueHelper.wrapMixValue(null, Language.L("未提交")));
                        break;
                    case EntityHelper.ApprovalState:
                        el.put("value", ApprovalState.DRAFT.getState());
                        break;
                    default:
                        break;
                }
            }
            // 默认值
            if (el.get("value") == null) {
                if (dt == DisplayType.SERIES) {
                    el.put("value", Language.L("自动值"));
                } else {
                    Object defaultValue = easyField.exprDefaultValue();
                    if (defaultValue != null) {
                        el.put("value", easyField.wrapValue(defaultValue));
                    }
                }
            }
            // 触发器自动值
            if (roViaAuto && el.get("value") == null) {
                if (dt == DisplayType.EMAIL || dt == DisplayType.PHONE || dt == DisplayType.URL || dt == DisplayType.DATE || dt == DisplayType.DATETIME || dt == DisplayType.NUMBER || dt == DisplayType.DECIMAL || dt == DisplayType.SERIES || dt == DisplayType.TEXT || dt == DisplayType.NTEXT) {
                    el.put("value", Language.L("自动值"));
                }
            }
        }
    // end 新建记录
    }
// end for
}
Also used : User(com.rebuild.core.privileges.bizz.User) DisplayType(com.rebuild.core.metadata.easymeta.DisplayType) JSONArray(com.alibaba.fastjson.JSONArray) EasyField(com.rebuild.core.metadata.easymeta.EasyField) EasyField(com.rebuild.core.metadata.easymeta.EasyField) Field(cn.devezhao.persist4j.Field) Department(com.rebuild.core.privileges.bizz.Department) JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject) ID(cn.devezhao.persist4j.engine.ID)

Example 2 with DisplayType

use of com.rebuild.core.metadata.easymeta.DisplayType in project rebuild by getrebuild.

the class Dimension method getSqlName.

@Override
public String getSqlName() {
    DisplayType dt = EasyMetaFactory.getDisplayType(getField());
    if (dt == DisplayType.DATE || dt == DisplayType.DATETIME) {
        switch(getFormatCalc()) {
            case Y:
                return String.format("DATE_FORMAT(%s,'%s')", super.getSqlName(), "%Y");
            case Q:
                return MessageFormat.format("CONCAT(YEAR({0}),'' Q'',QUARTER({0}))", super.getSqlName());
            case M:
                return String.format("DATE_FORMAT(%s,'%s')", super.getSqlName(), "%Y-%m");
            case H:
                return String.format("DATE_FORMAT(%s,'%s')", super.getSqlName(), "%Y-%m-%d %HH");
            default:
                return String.format("DATE_FORMAT(%s,'%s')", super.getSqlName(), "%Y-%m-%d");
        }
    } else if (dt == DisplayType.TIME) {
        if (getFormatCalc() == FormatCalc.H) {
            return String.format("DATE_FORMAT(%s,'%s')", super.getSqlName(), "%H");
        } else {
            return String.format("DATE_FORMAT(%s,'%s')", super.getSqlName(), "%H:%i");
        }
    } else if (dt == DisplayType.CLASSIFICATION && getFormatCalc() != null && getFormatCalc().name().startsWith("L")) {
        int useLevel = ClassificationManager.instance.getOpenLevel(getField()) + 1;
        int selectLevel = Integer.parseInt(getFormatCalc().name().substring(1));
        // Last
        if (selectLevel >= useLevel || selectLevel == 4) {
            return super.getSqlName();
        }
        StringBuilder sqlName = new StringBuilder(super.getSqlName());
        for (int i = 0; i < useLevel - selectLevel; i++) {
            sqlName.append(".parent");
        }
        return sqlName.toString();
    } else {
        return super.getSqlName();
    }
}
Also used : DisplayType(com.rebuild.core.metadata.easymeta.DisplayType)

Example 3 with DisplayType

use of com.rebuild.core.metadata.easymeta.DisplayType in project rebuild by getrebuild.

the class ChartData method wrapAxisValue.

/**
 * 获取纬度标签
 *
 * @param dimension
 * @param value
 * @return
 */
protected String wrapAxisValue(Dimension dimension, Object value) {
    if (value == null) {
        return ChartsHelper.VALUE_NONE;
    }
    EasyField axisField = EasyMetaFactory.valueOf(dimension.getField());
    DisplayType axisType = axisField.getDisplayType();
    String label;
    if (axisType == DisplayType.REFERENCE || axisType == DisplayType.CLASSIFICATION || axisType == DisplayType.BOOL || axisType == DisplayType.PICKLIST || axisType == DisplayType.STATE) {
        label = (String) FieldValueHelper.wrapFieldValue(value, axisField, true);
    } else {
        label = value.toString();
    }
    return label;
}
Also used : DisplayType(com.rebuild.core.metadata.easymeta.DisplayType) EasyField(com.rebuild.core.metadata.easymeta.EasyField)

Example 4 with DisplayType

use of com.rebuild.core.metadata.easymeta.DisplayType in project rebuild by getrebuild.

the class MetaschemaImporter method performField.

private Field performField(JSONObject schemaField, Entity belong) {
    String fieldName = schemaField.getString("field");
    String fieldLabel = schemaField.getString("fieldLabel");
    String displayType = schemaField.getString("displayType");
    JSON extConfig = schemaField.getJSONObject("extConfig");
    DisplayType dt = DisplayType.valueOf(displayType);
    if (dt == DisplayType.ID || MetadataHelper.isCommonsField(fieldName)) {
        return null;
    }
    Field unsafeField = new Field2Schema(this.getUser()).createUnsafeField(belong, fieldName, fieldLabel, dt, schemaField.getBooleanValue("nullable"), true, schemaField.getBooleanValue("updatable"), !schemaField.containsKey("repeatable") || schemaField.getBooleanValue("repeatable"), !schemaField.containsKey("queryable") || schemaField.getBooleanValue("queryable"), schemaField.getString("comments"), schemaField.getString("refEntity"), null, extConfig, schemaField.getString("defaultValue"));
    if (DisplayType.PICKLIST == dt || DisplayType.MULTISELECT == dt) {
        picklistHolders.put(unsafeField, performPickList(schemaField.getJSONArray("items")));
    }
    return unsafeField;
}
Also used : Field(cn.devezhao.persist4j.Field) DisplayType(com.rebuild.core.metadata.easymeta.DisplayType) Field2Schema(com.rebuild.core.metadata.impl.Field2Schema) JSON(com.alibaba.fastjson.JSON)

Example 5 with DisplayType

use of com.rebuild.core.metadata.easymeta.DisplayType in project rebuild by getrebuild.

the class ReferenceSearchController method resultSearch.

private List<Object> resultSearch(String sqlWhere, Entity entity, int maxResults) {
    Field nameField = entity.getNameField();
    String sql = MessageFormat.format("select {0},{1} from {2} where {3}", entity.getPrimaryField().getName(), nameField.getName(), entity.getName(), sqlWhere);
    if (!sqlWhere.contains(" order by ")) {
        DisplayType dt = EasyMetaFactory.getDisplayType(nameField);
        if (dt != DisplayType.ID) {
            sql += " order by " + nameField.getName();
        } else if (entity.containsField(EntityHelper.ModifiedOn)) {
            sql += " order by modifiedOn desc";
        }
    }
    Object[][] array = QueryHelper.createQuery(sql, entity).setLimit(maxResults).array();
    List<Object> result = new ArrayList<>();
    for (Object[] o : array) {
        ID recordId = (ID) o[0];
        if (MetadataHelper.isBizzEntity(entity) && (!UserHelper.isActive(recordId) || recordId.equals(UserService.SYSTEM_USER))) {
            continue;
        }
        String label = (String) FieldValueHelper.wrapFieldValue(o[1], nameField, true);
        if (StringUtils.isBlank(label)) {
            label = FieldValueHelper.NO_LABEL_PREFIX + recordId.toLiteral().toUpperCase();
        }
        result.add(FieldValueHelper.wrapMixValue(recordId, label));
    }
    return result;
}
Also used : Field(cn.devezhao.persist4j.Field) DisplayType(com.rebuild.core.metadata.easymeta.DisplayType) ID(cn.devezhao.persist4j.engine.ID)

Aggregations

DisplayType (com.rebuild.core.metadata.easymeta.DisplayType)25 Field (cn.devezhao.persist4j.Field)13 JSONObject (com.alibaba.fastjson.JSONObject)11 EasyField (com.rebuild.core.metadata.easymeta.EasyField)10 Entity (cn.devezhao.persist4j.Entity)7 JSONArray (com.alibaba.fastjson.JSONArray)5 ID (cn.devezhao.persist4j.engine.ID)4 JSON (com.alibaba.fastjson.JSON)4 Field2Schema (com.rebuild.core.metadata.impl.Field2Schema)3 ArrayList (java.util.ArrayList)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Record (cn.devezhao.persist4j.Record)2 Department (com.rebuild.core.privileges.bizz.Department)2 StandardRecord (cn.devezhao.persist4j.engine.StandardRecord)1 MetadataException (cn.devezhao.persist4j.metadata.MetadataException)1 MissingMetaExcetion (cn.devezhao.persist4j.metadata.MissingMetaExcetion)1 RebuildException (com.rebuild.core.RebuildException)1 EasyDateTime (com.rebuild.core.metadata.easymeta.EasyDateTime)1 EasyEntity (com.rebuild.core.metadata.easymeta.EasyEntity)1 Entity2Schema (com.rebuild.core.metadata.impl.Entity2Schema)1