Search in sources :

Example 16 with EasyField

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

the class ChartDesignController method putFields.

private void putFields(List<String[]> dest, Entity entity, Field parent) {
    for (Field field : MetadataSorter.sortFields(entity)) {
        EasyField easyField = EasyMetaFactory.valueOf(field);
        DisplayType dt = easyField.getDisplayType();
        if (dt == DisplayType.IMAGE || dt == DisplayType.FILE || dt == DisplayType.AVATAR || dt == DisplayType.BARCODE || dt == DisplayType.NTEXT || dt == DisplayType.ANYREFERENCE || dt == DisplayType.N2NREFERENCE || dt == DisplayType.MULTISELECT || dt == DisplayType.LOCATION || dt == DisplayType.SIGN) {
            continue;
        }
        String type = "text";
        if (dt == DisplayType.DATE || dt == DisplayType.DATETIME) {
            type = "date";
        } else if (dt == DisplayType.TIME) {
            type = "time";
        } else if (dt == DisplayType.NUMBER || dt == DisplayType.DECIMAL) {
            type = "num";
        } else if (dt == DisplayType.CLASSIFICATION) {
            type = "clazz";
        }
        dest.add(new String[] { (parent == null ? "" : (parent.getName() + ".")) + easyField.getName(), (parent == null ? "" : (EasyMetaFactory.getLabel(parent) + ".")) + easyField.getLabel(), type });
    }
}
Also used : EasyField(com.rebuild.core.metadata.easymeta.EasyField) Field(cn.devezhao.persist4j.Field) DisplayType(com.rebuild.core.metadata.easymeta.DisplayType) EasyField(com.rebuild.core.metadata.easymeta.EasyField)

Example 17 with EasyField

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

the class FormDesignController method sets.

@RequestMapping({ "form-update" })
public void sets(@PathVariable String entity, HttpServletRequest request, HttpServletResponse response) {
    JSON formJson = ServletUtils.getRequestJson(request);
    // 修改字段名称
    Map<String, String> newLabels = new HashMap<>();
    JSONArray config = ((JSONObject) formJson).getJSONArray("config");
    for (Object o : config) {
        JSONObject item = (JSONObject) o;
        String newLabel = item.getString("__newLabel");
        if (StringUtils.isNotBlank(newLabel)) {
            newLabels.put(item.getString("field"), newLabel);
        }
        item.remove("__newLabel");
    }
    ((JSONObject) formJson).put("config", config);
    Record record = EntityHelper.parse((JSONObject) formJson, getRequestUser(request));
    if (record.getPrimary() == null) {
        record.setString("shareTo", FormsManager.SHARE_ALL);
    }
    Application.getBean(LayoutConfigService.class).createOrUpdate(record);
    if (!newLabels.isEmpty()) {
        List<Record> willUpdate = new ArrayList<>();
        Entity entityMeta = MetadataHelper.getEntity(entity);
        for (Map.Entry<String, String> e : newLabels.entrySet()) {
            Field fieldMeta = entityMeta.getField(e.getKey());
            EasyField fieldEasy = EasyMetaFactory.valueOf(fieldMeta);
            if (fieldEasy.isBuiltin() || fieldEasy.getMetaId() == null) {
                continue;
            }
            Record fieldRecord = EntityHelper.forUpdate(fieldEasy.getMetaId(), UserService.SYSTEM_USER, false);
            fieldRecord.setString("fieldLabel", e.getValue());
            willUpdate.add(fieldRecord);
        }
        if (!willUpdate.isEmpty()) {
            Application.getCommonsService().createOrUpdate(willUpdate.toArray(new Record[0]), false);
            MetadataHelper.getMetadataFactory().refresh();
        }
    }
    writeSuccess(response);
}
Also used : Entity(cn.devezhao.persist4j.Entity) LayoutConfigService(com.rebuild.core.configuration.general.LayoutConfigService) HashMap(java.util.HashMap) JSONArray(com.alibaba.fastjson.JSONArray) ArrayList(java.util.ArrayList) JSON(com.alibaba.fastjson.JSON) EasyField(com.rebuild.core.metadata.easymeta.EasyField) EasyField(com.rebuild.core.metadata.easymeta.EasyField) Field(cn.devezhao.persist4j.Field) JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject) Record(cn.devezhao.persist4j.Record) HashMap(java.util.HashMap) Map(java.util.Map) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with EasyField

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

the class TransformConfigController method buildEntity.

private JSONObject buildEntity(Entity entity, boolean isSource) {
    JSONObject entityData = JSONUtils.toJSONObject(new String[] { "entity", "label" }, new Object[] { entity.getName(), EasyMetaFactory.getLabel(entity) });
    JSONArray fields = new JSONArray();
    if (isSource) {
        fields.add(EasyMetaFactory.toJSON(entity.getPrimaryField()));
    }
    for (Field field : MetadataSorter.sortFields(entity)) {
        if (!isSource && !field.isCreatable())
            continue;
        EasyField easyField = EasyMetaFactory.valueOf(field);
        if (easyField.getDisplayType() == DisplayType.BARCODE)
            continue;
        fields.add(easyField.toJSON());
    }
    // 二级字段(父级)
    if (isSource && entity.getMainEntity() != null) {
        Field dtmField = MetadataHelper.getDetailToMainField(entity);
        String namePrefix = dtmField.getName() + ".";
        String labelPrefix = EasyMetaFactory.getLabel(dtmField) + ".";
        for (Field field : MetadataSorter.sortFields(dtmField.getReferenceEntity())) {
            if (!field.isQueryable() || MetadataHelper.isCommonsField(field))
                continue;
            EasyField easyField = EasyMetaFactory.valueOf(field);
            if (easyField.getDisplayType() == DisplayType.BARCODE)
                continue;
            JSONObject o = (JSONObject) easyField.toJSON();
            o.put("name", namePrefix + o.getString("name"));
            o.put("label", labelPrefix + o.getString("label"));
            fields.add(o);
        }
    }
    entityData.put("fields", fields);
    return entityData;
}
Also used : Field(cn.devezhao.persist4j.Field) EasyField(com.rebuild.core.metadata.easymeta.EasyField) JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) EasyField(com.rebuild.core.metadata.easymeta.EasyField)

Example 19 with EasyField

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

the class FieldAggregationController method isAllowSourceField.

/**
 * 允许作为源字段
 *
 * @param field
 * @return
 */
protected static boolean isAllowSourceField(Field field) {
    String fieldName = field.getName();
    if (MetadataHelper.isApprovalField(fieldName))
        return false;
    EasyField easyField = EasyMetaFactory.valueOf(field);
    return easyField.isQueryable() && easyField.getDisplayType() != DisplayType.BARCODE;
}
Also used : EasyField(com.rebuild.core.metadata.easymeta.EasyField)

Example 20 with EasyField

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

the class FieldWritebackController method getTargetFields.

@RequestMapping("field-writeback-fields")
public JSON getTargetFields(@EntityParam(name = "source") Entity sourceEntity, HttpServletRequest request) {
    String target = getParameter(request, "target");
    Entity targetEntity = StringUtils.isBlank(target) ? null : MetadataHelper.getEntity(target);
    JSONArray sourceFields = new JSONArray();
    JSONArray targetFields = new JSONArray();
    // 源字段
    // 本实体
    sourceFields.add(EasyMetaFactory.toJSON(sourceEntity.getPrimaryField()));
    for (Field field : MetadataSorter.sortFields(sourceEntity)) {
        EasyField easyField = EasyMetaFactory.valueOf(field);
        if (easyField.getDisplayType() == DisplayType.BARCODE)
            continue;
        sourceFields.add(easyField.toJSON());
    }
    // 关联实体的
    for (Field fieldRef : MetadataSorter.sortFields(sourceEntity, DisplayType.REFERENCE)) {
        // FIXME 是否过滤系统级引用实体 ???
        if (MetadataHelper.isCommonsField(fieldRef))
            continue;
        Entity refEntity = fieldRef.getReferenceEntity();
        if (refEntity.getEntityCode() == EntityHelper.RobotApprovalConfig)
            continue;
        String fieldRefName = fieldRef.getName() + ".";
        String fieldRefLabel = EasyMetaFactory.getLabel(fieldRef) + ".";
        for (Field field : MetadataSorter.sortFields(refEntity)) {
            EasyField easyField = EasyMetaFactory.valueOf(field);
            if (easyField.getDisplayType() == DisplayType.BARCODE)
                continue;
            JSONObject subField = (JSONObject) easyField.toJSON();
            subField.put("name", fieldRefName + subField.getString("name"));
            subField.put("label", fieldRefLabel + subField.getString("label"));
            sourceFields.add(subField);
        }
    }
    if (targetEntity != null) {
        for (Field field : MetadataSorter.sortFields(targetEntity)) {
            EasyField easyField = EasyMetaFactory.valueOf(field);
            DisplayType dt = easyField.getDisplayType();
            if (dt == DisplayType.SERIES || dt == DisplayType.BARCODE || dt == DisplayType.ANYREFERENCE || easyField.isBuiltin()) {
                continue;
            }
            targetFields.add(BatchUpdateController.buildField(easyField));
        }
    }
    // 审批流程启用
    boolean hadApproval = targetEntity != null && RobotApprovalManager.instance.hadApproval(targetEntity, null) != null;
    return JSONUtils.toJSONObject(new String[] { "source", "target", "hadApproval" }, new Object[] { sourceFields, targetFields, hadApproval });
}
Also used : Entity(cn.devezhao.persist4j.Entity) EasyField(com.rebuild.core.metadata.easymeta.EasyField) Field(cn.devezhao.persist4j.Field) JSONObject(com.alibaba.fastjson.JSONObject) DisplayType(com.rebuild.core.metadata.easymeta.DisplayType) JSONArray(com.alibaba.fastjson.JSONArray) EasyField(com.rebuild.core.metadata.easymeta.EasyField) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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