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;
}
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;
}
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;
}
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 });
}
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 });
}
Aggregations