Search in sources :

Example 16 with DisplayType

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

the class BatchUpdateController method buildField.

/**
 * @param field
 * @return
 */
public static JSONObject buildField(EasyField field) {
    JSONObject map = (JSONObject) field.toJSON();
    // 字段选项
    DisplayType dt = field.getDisplayType();
    if (dt == DisplayType.PICKLIST) {
        map.put("options", PickListManager.instance.getPickList(field.getRawMeta()));
    } else if (dt == DisplayType.STATE) {
        map.put("options", StateManager.instance.getStateOptions(field.getRawMeta()));
    } else if (dt == DisplayType.MULTISELECT) {
        map.put("options", MultiSelectManager.instance.getSelectList(field.getRawMeta()));
    } else if (dt == DisplayType.BOOL) {
        JSONArray options = new JSONArray();
        options.add(JSONUtils.toJSONObject(new String[] { "id", "text" }, new Object[] { true, Language.L("是") }));
        options.add(JSONUtils.toJSONObject(new String[] { "id", "text" }, new Object[] { false, Language.L("否") }));
        map.put("options", options);
    } else if (dt == DisplayType.NUMBER) {
        map.put(EasyFieldConfigProps.NUMBER_NOTNEGATIVE, field.getExtraAttr(EasyFieldConfigProps.NUMBER_FORMAT));
    } else if (dt == DisplayType.DECIMAL) {
        map.put(EasyFieldConfigProps.DECIMAL_FORMAT, field.getExtraAttr(EasyFieldConfigProps.DECIMAL_FORMAT));
    }
    return map;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) DisplayType(com.rebuild.core.metadata.easymeta.DisplayType) JSONArray(com.alibaba.fastjson.JSONArray)

Example 17 with DisplayType

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

the class PicklistDataController method fetchPicklist.

// for PickList/MultiSelect/State
@GetMapping({ "picklist", "field-options" })
public JSON fetchPicklist(HttpServletRequest request) {
    String entity = getParameterNotNull(request, "entity");
    String field = getParameterNotNull(request, "field");
    Field fieldMeta = getRealField(entity, field);
    DisplayType dt = EasyMetaFactory.getDisplayType(fieldMeta);
    JSON options;
    if (dt == DisplayType.STATE) {
        options = StateManager.instance.getStateOptions(fieldMeta);
    } else if (dt == DisplayType.MULTISELECT) {
        options = MultiSelectManager.instance.getSelectList(fieldMeta);
    } else {
        options = PickListManager.instance.getPickList(fieldMeta);
    }
    return options;
}
Also used : Field(cn.devezhao.persist4j.Field) DisplayType(com.rebuild.core.metadata.easymeta.DisplayType) JSON(com.alibaba.fastjson.JSON) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 18 with DisplayType

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

the class TestSupport method addTestEntities.

/**
 * 添加测试用实体
 *
 * @param dropExists
 * @return
 * @throws Exception
 */
@SuppressWarnings("SameParameterValue")
protected static boolean addTestEntities(boolean dropExists) throws Exception {
    boolean changed = false;
    if (dropExists) {
        if (MetadataHelper.containsEntity(TestAllFields)) {
            LOG.warn("Dropping test entity : " + TestAllFields);
            new Entity2Schema(UserService.ADMIN_USER).dropEntity(MetadataHelper.getEntity(TestAllFields), true);
        }
        if (MetadataHelper.containsEntity(SalesOrder)) {
            LOG.warn("Dropping test entity : " + SalesOrder);
            new Entity2Schema(UserService.ADMIN_USER).dropEntity(MetadataHelper.getEntity(SalesOrder), true);
        }
        if (MetadataHelper.containsEntity(Account)) {
            LOG.warn("Dropping test entity : " + Account);
            new Entity2Schema(UserService.ADMIN_USER).dropEntity(MetadataHelper.getEntity(Account), true);
        }
    }
    if (!MetadataHelper.containsEntity(TestAllFields)) {
        Entity2Schema entity2Schema = new Entity2Schema(UserService.ADMIN_USER);
        String entityName = entity2Schema.createEntity(TestAllFields.toUpperCase(), null, null, true);
        Entity testEntity = MetadataHelper.getEntity(entityName);
        for (DisplayType dt : DisplayType.values()) {
            if (dt == DisplayType.ID || dt == DisplayType.ANYREFERENCE) {
                continue;
            }
            String fieldName = dt.name().toUpperCase();
            if (BlockList.isBlock(fieldName))
                fieldName += "1";
            if (dt == DisplayType.REFERENCE || dt == DisplayType.N2NREFERENCE) {
                new Field2Schema(UserService.ADMIN_USER).createField(testEntity, fieldName, dt, null, entityName, null);
            } else if (dt == DisplayType.CLASSIFICATION) {
                JSON extra = JSON.parseObject("{classification:'018-0000000000000001'}");
                new Field2Schema(UserService.ADMIN_USER).createField(testEntity, fieldName, dt, null, entityName, extra);
            } else if (dt == DisplayType.STATE) {
                JSON extra = JSON.parseObject("{stateClass:'com.rebuild.core.support.state.HowtoState'}");
                new Field2Schema(UserService.ADMIN_USER).createField(testEntity, fieldName, dt, null, entityName, extra);
            } else {
                new Field2Schema(UserService.ADMIN_USER).createField(testEntity, fieldName, dt, null, null, null);
            }
        }
        changed = true;
    }
    if (!MetadataHelper.containsEntity(Account)) {
        String metaschema = FileUtils.readFileToString(ResourceUtils.getFile("classpath:schema-Account999.json"));
        MetaschemaImporter importer = new MetaschemaImporter(JSON.parseObject(metaschema));
        TaskExecutors.run((HeavyTask<?>) importer.setUser(UserService.ADMIN_USER));
        changed = true;
    }
    if (!MetadataHelper.containsEntity(SalesOrder)) {
        String metaschema = FileUtils.readFileToString(ResourceUtils.getFile("classpath:schema-SalesOrder999.json"));
        MetaschemaImporter importer = new MetaschemaImporter(JSON.parseObject(metaschema));
        TaskExecutors.run((HeavyTask<?>) importer.setUser(UserService.ADMIN_USER));
        changed = true;
    }
    return changed;
}
Also used : Entity(cn.devezhao.persist4j.Entity) Entity2Schema(com.rebuild.core.metadata.impl.Entity2Schema) DisplayType(com.rebuild.core.metadata.easymeta.DisplayType) Field2Schema(com.rebuild.core.metadata.impl.Field2Schema) JSON(com.alibaba.fastjson.JSON) MetaschemaImporter(com.rebuild.core.rbstore.MetaschemaImporter)

Example 19 with DisplayType

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

Example 20 with DisplayType

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

the class GroupAggregationController method getTargetFields.

@RequestMapping("group-aggregation-fields")
public JSON getTargetFields(@EntityParam(name = "target") Entity targetEntity) {
    // 目标-分组字段
    List<String[]> targetGroupFields = new ArrayList<>();
    // 目标字段
    List<String[]> targetFields = new ArrayList<>();
    for (Field field : MetadataSorter.sortFields(targetEntity)) {
        EasyField easyField = EasyMetaFactory.valueOf(field);
        String[] build = buildIfGroupField(easyField);
        if (build != null)
            targetGroupFields.add(build);
        DisplayType dt = easyField.getDisplayType();
        if (dt == DisplayType.NUMBER || dt == DisplayType.DECIMAL) {
            targetFields.add(buildField(field));
        }
    }
    return JSONUtils.toJSONObject(new String[] { "targetGroupFields", "targetFields" }, new Object[] { targetGroupFields, targetFields });
}
Also used : FieldAggregationController.isAllowSourceField(com.rebuild.web.robot.trigger.FieldAggregationController.isAllowSourceField) Field(cn.devezhao.persist4j.Field) FieldAggregationController.buildField(com.rebuild.web.robot.trigger.FieldAggregationController.buildField) EasyField(com.rebuild.core.metadata.easymeta.EasyField) DisplayType(com.rebuild.core.metadata.easymeta.DisplayType) ArrayList(java.util.ArrayList) EasyField(com.rebuild.core.metadata.easymeta.EasyField) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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