Search in sources :

Example 11 with DisplayType

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

the class I18nGettextParser method sysDefined.

// 系统定义的
static void sysDefined(JSONObject into) {
    into.put("_", "中文");
    for (DisplayType o : DisplayType.values()) into.put(o.getDisplayName(), o.getDisplayName());
    for (ActionType o : ActionType.values()) into.put(o.getDisplayName(), o.getDisplayName());
    for (ApprovalState s : ApprovalState.values()) into.put(s.getName(), s.getName());
    for (Entity entity : Application.getPersistManagerFactory().getMetadataFactory().getEntities()) {
        if (!EasyMetaFactory.valueOf(entity).isBuiltin())
            continue;
        sysDefinedMeta(entity, into);
        for (Field field : entity.getFields()) {
            if (!EasyMetaFactory.valueOf(field).isBuiltin())
                continue;
            sysDefinedMeta(field, into);
        }
    }
    into.put("__", "__");
}
Also used : Entity(cn.devezhao.persist4j.Entity) Field(cn.devezhao.persist4j.Field) ActionType(com.rebuild.core.service.trigger.ActionType) DisplayType(com.rebuild.core.metadata.easymeta.DisplayType) ApprovalState(com.rebuild.core.service.approval.ApprovalState)

Example 12 with DisplayType

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

the class DynamicMetadataFactory method appendConfig4Db.

/**
 * 从数据库读取配置
 *
 * @param config
 */
private void appendConfig4Db(Document config) {
    final Element rootElement = config.getRootElement();
    Object[][] customEntities = Application.createQueryNoFilter("select typeCode,entityName,physicalName,entityLabel,entityId,comments,icon,nameField,masterEntity,extConfig from MetaEntity").array();
    for (Object[] c : customEntities) {
        String name = (String) c[1];
        Element entity = rootElement.addElement("entity");
        entity.addAttribute("type-code", c[0].toString()).addAttribute("name", name).addAttribute("physical-name", (String) c[2]).addAttribute("description", (String) c[3]).addAttribute("parent", "false").addAttribute("name-field", StringUtils.defaultIfBlank((String) c[7], EntityHelper.CreatedOn)).addAttribute("main", (String) c[8]).addAttribute("creatable", "true").addAttribute("updatable", "true").addAttribute("queryable", "true").addAttribute("deletable", "true");
        // 实体扩展配置
        JSONObject extraAttrs;
        if (StringUtils.isBlank((String) c[9])) {
            extraAttrs = new JSONObject();
        } else {
            extraAttrs = JSON.parseObject((String) c[9]);
        }
        extraAttrs.put("metaId", c[4]);
        extraAttrs.put("comments", c[5]);
        extraAttrs.put("icon", c[6]);
        entity.addAttribute("extra-attrs", extraAttrs.toJSONString());
    }
    Set<String> cascadingFieldsChild = new HashSet<>();
    Object[][] customFields = Application.createQueryNoFilter("select belongEntity,fieldName,physicalName,fieldLabel,displayType,nullable,creatable,updatable," + "maxLength,defaultValue,refEntity,cascade,fieldId,comments,extConfig,repeatable,queryable from MetaField").array();
    for (Object[] c : customFields) {
        final String entityName = (String) c[0];
        final String fieldName = (String) c[1];
        Element entityElement = (Element) rootElement.selectSingleNode("entity[@name='" + entityName + "']");
        if (entityElement == null) {
            log.warn("No entity `{}` found for field `{}`", entityName, fieldName);
            continue;
        }
        Element field = entityElement.addElement("field");
        field.addAttribute("name", fieldName).addAttribute("physical-name", (String) c[2]).addAttribute("description", (String) c[3]).addAttribute("max-length", String.valueOf(c[8])).addAttribute("default-value", (String) c[9]).addAttribute("nullable", String.valueOf(c[5])).addAttribute("creatable", String.valueOf(c[6])).addAttribute("updatable", String.valueOf(c[7])).addAttribute("repeatable", String.valueOf(c[15])).addAttribute("queryable", String.valueOf(c[16]));
        DisplayType dt;
        try {
            dt = DisplayType.valueOf((String) c[4]);
        } catch (IllegalArgumentException noenum) {
            c[4] = "TEXT";
            dt = DisplayType.valueOf((String) c[4]);
            log.warn(noenum.getLocalizedMessage());
        }
        field.addAttribute("type", dt.getFieldType().getName());
        if (fieldName.equals(EntityHelper.AutoId)) {
            field.addAttribute("auto-value", "true");
        }
        if (dt == DisplayType.DECIMAL) {
            field.addAttribute("decimal-scale", "8");
        }
        if (dt == DisplayType.ANYREFERENCE || dt == DisplayType.N2NREFERENCE || dt == DisplayType.REFERENCE || dt == DisplayType.PICKLIST || dt == DisplayType.CLASSIFICATION) {
            field.addAttribute("ref-entity", (String) c[10]).addAttribute("cascade", (String) c[11]);
        }
        if (dt == DisplayType.ID) {
            field.addAttribute("queryable", "false");
        } else // bugfix
        if (dt == DisplayType.BARCODE) {
            field.addAttribute("queryable", "true");
        }
        // 字段扩展配置
        JSONObject extraAttrs;
        if (JSONUtils.wellFormat((String) c[14])) {
            extraAttrs = JSON.parseObject((String) c[14]);
        } else {
            extraAttrs = new JSONObject();
        }
        extraAttrs.put("metaId", c[12]);
        extraAttrs.put("comments", c[13]);
        extraAttrs.put("displayType", dt.name());
        String cascadingField = extraAttrs.getString(EasyFieldConfigProps.REFERENCE_CASCADINGFIELD);
        if (StringUtils.isNotBlank(cascadingField) && dt == DisplayType.REFERENCE) {
            extraAttrs.put("_cascadingFieldParent", cascadingField);
            String[] fs = cascadingField.split(SPLITER_RE);
            cascadingFieldsChild.add(entityName + SPLITER + fs[0] + SPLITER + fieldName + SPLITER + fs[1]);
        }
        field.addAttribute("extra-attrs", extraAttrs.toJSONString());
    }
    // 处理父级级联的父子级关系
    for (String child : cascadingFieldsChild) {
        String[] fs = child.split(SPLITER_RE);
        Element fieldElement = (Element) rootElement.selectSingleNode(String.format("entity[@name='%s']/field[@name='%s']", fs[0], fs[1]));
        if (fieldElement == null) {
            log.warn("No field found: {}.{}", fs[0], fs[1]);
            continue;
        }
        JSONObject extraAttrs = JSON.parseObject(fieldElement.valueOf("@extra-attrs"));
        extraAttrs.put("_cascadingFieldChild", fs[2] + SPLITER + fs[3]);
        fieldElement.addAttribute("extra-attrs", extraAttrs.toJSONString());
    }
    if (log.isDebugEnabled())
        XmlHelper.dump(rootElement);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) DisplayType(com.rebuild.core.metadata.easymeta.DisplayType) Element(org.dom4j.Element) JSONObject(com.alibaba.fastjson.JSONObject) HashSet(java.util.HashSet)

Example 13 with DisplayType

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

the class MetaSchemaGenerator method performField.

private JSON performField(Field field) {
    final JSONObject schemaField = new JSONObject(true);
    final EasyField easyField = EasyMetaFactory.valueOf(field);
    final DisplayType dt = easyField.getDisplayType();
    schemaField.put("field", easyField.getName());
    schemaField.put("fieldLabel", easyField.getLabel());
    schemaField.put("displayType", dt.name());
    if (easyField.getComments() != null) {
        schemaField.put("comments", easyField.getComments());
    }
    schemaField.put("nullable", field.isNullable());
    schemaField.put("updatable", field.isUpdatable());
    schemaField.put("repeatable", field.isRepeatable());
    schemaField.put("queryable", field.isQueryable());
    Object defaultVal = field.getDefaultValue();
    if (defaultVal != null && StringUtils.isNotBlank((String) defaultVal)) {
        schemaField.put("defaultValue", defaultVal);
    }
    if (dt == DisplayType.REFERENCE || dt == DisplayType.N2NREFERENCE) {
        schemaField.put("refEntity", field.getReferenceEntity().getName());
    } else if (dt == DisplayType.PICKLIST || dt == DisplayType.MULTISELECT) {
        schemaField.put("items", performPickList(field));
    }
    JSONObject extConfig = easyField.getExtraAttrs(true);
    if (!extConfig.isEmpty()) {
        schemaField.put("extConfig", extConfig);
    }
    return schemaField;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) DisplayType(com.rebuild.core.metadata.easymeta.DisplayType) JSONObject(com.alibaba.fastjson.JSONObject) EasyField(com.rebuild.core.metadata.easymeta.EasyField)

Example 14 with DisplayType

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

the class EasyMetaFactory method valueOf.

/**
 * @param field
 * @return
 */
public static EasyField valueOf(Field field) {
    String displayType = field.getExtraAttrs() == null ? null : field.getExtraAttrs().getString("displayType");
    DisplayType dt = displayType == null ? convertBuiltinFieldType(field) : DisplayType.valueOf(displayType);
    if (dt == null) {
        throw new RebuildException("Unsupported field type : " + field);
    }
    try {
        Constructor<?> c = ReflectionUtils.accessibleConstructor(dt.getEasyClass(), Field.class, DisplayType.class);
        return (EasyField) c.newInstance(field, dt);
    } catch (Exception ex) {
        throw new RebuildException(ex);
    }
}
Also used : DisplayType(com.rebuild.core.metadata.easymeta.DisplayType) RebuildException(com.rebuild.core.RebuildException) RebuildException(com.rebuild.core.RebuildException) MetadataException(cn.devezhao.persist4j.metadata.MetadataException)

Example 15 with DisplayType

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

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