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