use of com.rebuild.core.metadata.easymeta.EasyField in project rebuild by getrebuild.
the class DataListManager method formatField.
/**
* @param field
* @param parent
* @return
*/
public Map<String, Object> formatField(Field field, Field parent) {
String parentField = parent == null ? "" : (parent.getName() + ".");
String parentLabel = parent == null ? "" : (EasyMetaFactory.getLabel(parent) + ".");
EasyField easyField = EasyMetaFactory.valueOf(field);
return JSONUtils.toJSONObject(new String[] { "field", "label", "type" }, new Object[] { parentField + easyField.getName(), parentLabel + easyField.getLabel(), easyField.getDisplayType(false) });
}
use of com.rebuild.core.metadata.easymeta.EasyField in project rebuild by getrebuild.
the class FormsBuilder method buildModelElements.
/**
* 构建表单元素
*
* @param elements
* @param entity
* @param data
* @param user
* @param useAdvControl
*/
protected void buildModelElements(JSONArray elements, Entity entity, Record data, ID user, boolean useAdvControl) {
final User formUser = Application.getUserStore().getUser(user);
final Date now = CalendarUtils.now();
// Check and clean
for (Iterator<Object> iter = elements.iterator(); iter.hasNext(); ) {
JSONObject el = (JSONObject) iter.next();
String fieldName = el.getString("field");
if (DIVIDER_LINE.equalsIgnoreCase(fieldName)) {
continue;
}
// 已删除字段
if (!MetadataHelper.checkAndWarnField(entity, fieldName)) {
iter.remove();
continue;
}
// v2.2 高级控制
Object displayOnCreate = el.remove("displayOnCreate");
Object displayOnUpdate = el.remove("displayOnUpdate");
Object requiredOnCreate = el.remove("requiredOnCreate");
Object requiredOnUpdate = el.remove("requiredOnUpdate");
if (useAdvControl) {
// 显示
if (displayOnCreate != null && !(Boolean) displayOnCreate && data == null) {
iter.remove();
continue;
}
if (displayOnUpdate != null && !(Boolean) displayOnUpdate && data != null) {
iter.remove();
continue;
}
// 必填
if (requiredOnCreate != null && (Boolean) requiredOnCreate && data == null) {
el.put("nullable", false);
}
if (requiredOnUpdate != null && (Boolean) requiredOnUpdate && data != null) {
el.put("nullable", false);
}
}
// 自动只读的
final boolean roViaAuto = el.getBooleanValue("readonly");
final Field fieldMeta = entity.getField(fieldName);
final EasyField easyField = EasyMetaFactory.valueOf(fieldMeta);
final DisplayType dt = easyField.getDisplayType();
el.put("label", easyField.getLabel());
el.put("type", dt.name());
el.put("readonly", (data != null && !fieldMeta.isUpdatable()) || roViaAuto);
// 优先使用指定值
final Boolean nullable = el.getBoolean("nullable");
if (nullable != null) {
el.put("nullable", nullable);
} else {
el.put("nullable", fieldMeta.isNullable());
}
// 字段扩展配置 FieldExtConfigProps
JSONObject fieldExtAttrs = easyField.getExtraAttrs(true);
el.putAll(fieldExtAttrs);
if (dt == DisplayType.PICKLIST) {
JSONArray options = PickListManager.instance.getPickList(fieldMeta);
el.put("options", options);
} else if (dt == DisplayType.STATE) {
JSONArray options = StateManager.instance.getStateOptions(fieldMeta);
el.put("options", options);
el.remove(EasyFieldConfigProps.STATE_CLASS);
} else if (dt == DisplayType.MULTISELECT) {
JSONArray options = MultiSelectManager.instance.getSelectList(fieldMeta);
el.put("options", options);
} else if (dt == DisplayType.DATETIME) {
String format = StringUtils.defaultIfBlank(easyField.getExtraAttr(EasyFieldConfigProps.DATETIME_FORMAT), easyField.getDisplayType().getDefaultFormat());
el.put(EasyFieldConfigProps.DATETIME_FORMAT, format);
} else if (dt == DisplayType.DATE) {
String format = StringUtils.defaultIfBlank(easyField.getExtraAttr(EasyFieldConfigProps.DATE_FORMAT), easyField.getDisplayType().getDefaultFormat());
el.put(EasyFieldConfigProps.DATE_FORMAT, format);
} else if (dt == DisplayType.TIME) {
String format = StringUtils.defaultIfBlank(easyField.getExtraAttr(EasyFieldConfigProps.TIME_FORMAT), easyField.getDisplayType().getDefaultFormat());
el.put(EasyFieldConfigProps.TIME_FORMAT, format);
} else if (dt == DisplayType.CLASSIFICATION) {
el.put("openLevel", ClassificationManager.instance.getOpenLevel(fieldMeta));
}
// 编辑/视图
if (data != null) {
Object value = wrapFieldValue(data, easyField, user);
if (value != null) {
el.put("value", value);
}
} else // 新建记录
{
if (!fieldMeta.isCreatable()) {
el.put("readonly", true);
switch(fieldName) {
case EntityHelper.CreatedOn:
case EntityHelper.ModifiedOn:
el.put("value", CalendarUtils.getUTCDateTimeFormat().format(now));
break;
case EntityHelper.CreatedBy:
case EntityHelper.ModifiedBy:
case EntityHelper.OwningUser:
el.put("value", FieldValueHelper.wrapMixValue(formUser.getId(), formUser.getFullName()));
break;
case EntityHelper.OwningDept:
Department dept = formUser.getOwningDept();
Assert.notNull(dept, "Department of user is unset : " + formUser.getId());
el.put("value", FieldValueHelper.wrapMixValue((ID) dept.getIdentity(), dept.getName()));
break;
case EntityHelper.ApprovalId:
el.put("value", FieldValueHelper.wrapMixValue(null, Language.L("未提交")));
break;
case EntityHelper.ApprovalState:
el.put("value", ApprovalState.DRAFT.getState());
break;
default:
break;
}
}
// 默认值
if (el.get("value") == null) {
if (dt == DisplayType.SERIES) {
el.put("value", Language.L("自动值"));
} else {
Object defaultValue = easyField.exprDefaultValue();
if (defaultValue != null) {
el.put("value", easyField.wrapValue(defaultValue));
}
}
}
// 触发器自动值
if (roViaAuto && el.get("value") == null) {
if (dt == DisplayType.EMAIL || dt == DisplayType.PHONE || dt == DisplayType.URL || dt == DisplayType.DATE || dt == DisplayType.DATETIME || dt == DisplayType.NUMBER || dt == DisplayType.DECIMAL || dt == DisplayType.SERIES || dt == DisplayType.TEXT || dt == DisplayType.NTEXT) {
el.put("value", Language.L("自动值"));
}
}
}
// end 新建记录
}
// end for
}
use of com.rebuild.core.metadata.easymeta.EasyField in project rebuild by getrebuild.
the class EntityRecordCreator method verify.
@Override
public void verify(Record record) {
// 自动只读字段忽略非空检查
final Set<String> autoReadonlyFields = EasyMetaFactory.getAutoReadonlyFields(entity.getName());
// 非空
List<String> notNulls = new ArrayList<>();
// 格式
List<String> notWells = new ArrayList<>();
// 新建
if (record.getPrimary() == null) {
for (Field field : entity.getFields()) {
if (MetadataHelper.isCommonsField(field))
continue;
EasyField easyField = EasyMetaFactory.valueOf(field);
if (easyField.getDisplayType() == DisplayType.SERIES || easyField.getDisplayType() == DisplayType.BARCODE) {
continue;
}
Object hasVal = record.getObjectValue(field.getName());
boolean canNull = field.isNullable() || autoReadonlyFields.contains(field.getName());
if (NullValue.isNull(hasVal)) {
if (!canNull) {
notNulls.add(easyField.getLabel());
}
} else {
if (field.isCreatable()) {
if (!matchsPattern(easyField, hasVal)) {
notWells.add(easyField.getLabel());
}
} else {
if (!isForceCreateable(field)) {
log.warn("Remove non-creatable field : " + field);
record.removeValue(field.getName());
}
}
}
}
} else // 更新
{
for (String fieldName : record.getAvailableFields()) {
Field field = entity.getField(fieldName);
if (MetadataHelper.isCommonsField(field))
continue;
Object hasVal = record.getObjectValue(field.getName());
boolean canNull = field.isNullable() || autoReadonlyFields.contains(field.getName());
EasyField easyField = EasyMetaFactory.valueOf(field);
if (NullValue.isNull(hasVal)) {
if (!canNull) {
notNulls.add(easyField.getLabel());
}
} else {
if (field.isUpdatable()) {
if (!matchsPattern(easyField, hasVal)) {
notWells.add(easyField.getLabel());
}
} else {
log.warn("Remove non-updatable field : " + field);
record.removeValue(fieldName);
}
}
}
}
if (!notNulls.isEmpty()) {
throw new DataSpecificationException(Language.L("%s 不允许为空", StringUtils.join(notNulls, " / ")));
}
if (!notWells.isEmpty()) {
throw new DataSpecificationException(Language.L("%s 格式不正确", StringUtils.join(notWells, " / ")));
}
}
use of com.rebuild.core.metadata.easymeta.EasyField in project rebuild by getrebuild.
the class GeneralEntityService method appendDefaultValue.
/**
* 补充默认值
*
* @param recordOfNew
*/
private void appendDefaultValue(Record recordOfNew) {
Assert.isNull(recordOfNew.getPrimary(), "Must be new record");
Entity entity = recordOfNew.getEntity();
if (MetadataHelper.isBizzEntity(entity) || !MetadataHelper.hasPrivilegesField(entity)) {
return;
}
for (Field field : entity.getFields()) {
if (MetadataHelper.isCommonsField(field) || recordOfNew.hasValue(field.getName(), true)) {
continue;
}
EasyField easyField = EasyMetaFactory.valueOf(field);
if (easyField.getDisplayType() == DisplayType.SERIES)
continue;
Object defaultValue = easyField.exprDefaultValue();
if (defaultValue != null) {
recordOfNew.setObjectValue(field.getName(), defaultValue);
}
}
}
use of com.rebuild.core.metadata.easymeta.EasyField in project rebuild by getrebuild.
the class ChartData method wrapAxisValue.
/**
* 获取纬度标签
*
* @param dimension
* @param value
* @return
*/
protected String wrapAxisValue(Dimension dimension, Object value) {
if (value == null) {
return ChartsHelper.VALUE_NONE;
}
EasyField axisField = EasyMetaFactory.valueOf(dimension.getField());
DisplayType axisType = axisField.getDisplayType();
String label;
if (axisType == DisplayType.REFERENCE || axisType == DisplayType.CLASSIFICATION || axisType == DisplayType.BOOL || axisType == DisplayType.PICKLIST || axisType == DisplayType.STATE) {
label = (String) FieldValueHelper.wrapFieldValue(value, axisField, true);
} else {
label = value.toString();
}
return label;
}
Aggregations