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("__", "__");
}
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);
}
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;
}
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);
}
}
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 });
}
}
Aggregations