Search in sources :

Example 1 with EasyField

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

the class DataListManager method formatField.

/**
 * @param field
 * @param parent
 * @return
 */
public Map<String, Object> formatField(Field field, Field parent) {
    String parentField = parent == null ? "" : (parent.getName() + ".");
    String parentLabel = parent == null ? "" : (EasyMetaFactory.getLabel(parent) + ".");
    EasyField easyField = EasyMetaFactory.valueOf(field);
    return JSONUtils.toJSONObject(new String[] { "field", "label", "type" }, new Object[] { parentField + easyField.getName(), parentLabel + easyField.getLabel(), easyField.getDisplayType(false) });
}
Also used : EasyField(com.rebuild.core.metadata.easymeta.EasyField)

Example 2 with EasyField

use of com.rebuild.core.metadata.easymeta.EasyField 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 3 with EasyField

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

the class EntityRecordCreator method verify.

@Override
public void verify(Record record) {
    // 自动只读字段忽略非空检查
    final Set<String> autoReadonlyFields = EasyMetaFactory.getAutoReadonlyFields(entity.getName());
    // 非空
    List<String> notNulls = new ArrayList<>();
    // 格式
    List<String> notWells = new ArrayList<>();
    // 新建
    if (record.getPrimary() == null) {
        for (Field field : entity.getFields()) {
            if (MetadataHelper.isCommonsField(field))
                continue;
            EasyField easyField = EasyMetaFactory.valueOf(field);
            if (easyField.getDisplayType() == DisplayType.SERIES || easyField.getDisplayType() == DisplayType.BARCODE) {
                continue;
            }
            Object hasVal = record.getObjectValue(field.getName());
            boolean canNull = field.isNullable() || autoReadonlyFields.contains(field.getName());
            if (NullValue.isNull(hasVal)) {
                if (!canNull) {
                    notNulls.add(easyField.getLabel());
                }
            } else {
                if (field.isCreatable()) {
                    if (!matchsPattern(easyField, hasVal)) {
                        notWells.add(easyField.getLabel());
                    }
                } else {
                    if (!isForceCreateable(field)) {
                        log.warn("Remove non-creatable field : " + field);
                        record.removeValue(field.getName());
                    }
                }
            }
        }
    } else // 更新
    {
        for (String fieldName : record.getAvailableFields()) {
            Field field = entity.getField(fieldName);
            if (MetadataHelper.isCommonsField(field))
                continue;
            Object hasVal = record.getObjectValue(field.getName());
            boolean canNull = field.isNullable() || autoReadonlyFields.contains(field.getName());
            EasyField easyField = EasyMetaFactory.valueOf(field);
            if (NullValue.isNull(hasVal)) {
                if (!canNull) {
                    notNulls.add(easyField.getLabel());
                }
            } else {
                if (field.isUpdatable()) {
                    if (!matchsPattern(easyField, hasVal)) {
                        notWells.add(easyField.getLabel());
                    }
                } else {
                    log.warn("Remove non-updatable field : " + field);
                    record.removeValue(fieldName);
                }
            }
        }
    }
    if (!notNulls.isEmpty()) {
        throw new DataSpecificationException(Language.L("%s 不允许为空", StringUtils.join(notNulls, " / ")));
    }
    if (!notWells.isEmpty()) {
        throw new DataSpecificationException(Language.L("%s 格式不正确", StringUtils.join(notWells, " / ")));
    }
}
Also used : Field(cn.devezhao.persist4j.Field) EasyField(com.rebuild.core.metadata.easymeta.EasyField) ArrayList(java.util.ArrayList) JSONObject(com.alibaba.fastjson.JSONObject) DataSpecificationException(com.rebuild.core.service.DataSpecificationException) EasyField(com.rebuild.core.metadata.easymeta.EasyField)

Example 4 with EasyField

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

the class GeneralEntityService method appendDefaultValue.

/**
 * 补充默认值
 *
 * @param recordOfNew
 */
private void appendDefaultValue(Record recordOfNew) {
    Assert.isNull(recordOfNew.getPrimary(), "Must be new record");
    Entity entity = recordOfNew.getEntity();
    if (MetadataHelper.isBizzEntity(entity) || !MetadataHelper.hasPrivilegesField(entity)) {
        return;
    }
    for (Field field : entity.getFields()) {
        if (MetadataHelper.isCommonsField(field) || recordOfNew.hasValue(field.getName(), true)) {
            continue;
        }
        EasyField easyField = EasyMetaFactory.valueOf(field);
        if (easyField.getDisplayType() == DisplayType.SERIES)
            continue;
        Object defaultValue = easyField.exprDefaultValue();
        if (defaultValue != null) {
            recordOfNew.setObjectValue(field.getName(), defaultValue);
        }
    }
}
Also used : EasyField(com.rebuild.core.metadata.easymeta.EasyField) EasyField(com.rebuild.core.metadata.easymeta.EasyField)

Example 5 with EasyField

use of com.rebuild.core.metadata.easymeta.EasyField 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)

Aggregations

EasyField (com.rebuild.core.metadata.easymeta.EasyField)27 Field (cn.devezhao.persist4j.Field)16 JSONObject (com.alibaba.fastjson.JSONObject)15 DisplayType (com.rebuild.core.metadata.easymeta.DisplayType)11 Entity (cn.devezhao.persist4j.Entity)10 ArrayList (java.util.ArrayList)7 JSONArray (com.alibaba.fastjson.JSONArray)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Record (cn.devezhao.persist4j.Record)4 ID (cn.devezhao.persist4j.engine.ID)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 MissingMetaExcetion (cn.devezhao.persist4j.metadata.MissingMetaExcetion)2 FieldAggregationController.buildField (com.rebuild.web.robot.trigger.FieldAggregationController.buildField)2 FieldAggregationController.isAllowSourceField (com.rebuild.web.robot.trigger.FieldAggregationController.isAllowSourceField)2 FieldType (cn.devezhao.persist4j.dialect.FieldType)1 Type (cn.devezhao.persist4j.dialect.Type)1 StandardRecord (cn.devezhao.persist4j.engine.StandardRecord)1 JSON (com.alibaba.fastjson.JSON)1 LayoutConfigService (com.rebuild.core.configuration.general.LayoutConfigService)1