use of com.rebuild.core.metadata.easymeta.DisplayType 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.DisplayType in project rebuild by getrebuild.
the class Dimension method getSqlName.
@Override
public String getSqlName() {
DisplayType dt = EasyMetaFactory.getDisplayType(getField());
if (dt == DisplayType.DATE || dt == DisplayType.DATETIME) {
switch(getFormatCalc()) {
case Y:
return String.format("DATE_FORMAT(%s,'%s')", super.getSqlName(), "%Y");
case Q:
return MessageFormat.format("CONCAT(YEAR({0}),'' Q'',QUARTER({0}))", super.getSqlName());
case M:
return String.format("DATE_FORMAT(%s,'%s')", super.getSqlName(), "%Y-%m");
case H:
return String.format("DATE_FORMAT(%s,'%s')", super.getSqlName(), "%Y-%m-%d %HH");
default:
return String.format("DATE_FORMAT(%s,'%s')", super.getSqlName(), "%Y-%m-%d");
}
} else if (dt == DisplayType.TIME) {
if (getFormatCalc() == FormatCalc.H) {
return String.format("DATE_FORMAT(%s,'%s')", super.getSqlName(), "%H");
} else {
return String.format("DATE_FORMAT(%s,'%s')", super.getSqlName(), "%H:%i");
}
} else if (dt == DisplayType.CLASSIFICATION && getFormatCalc() != null && getFormatCalc().name().startsWith("L")) {
int useLevel = ClassificationManager.instance.getOpenLevel(getField()) + 1;
int selectLevel = Integer.parseInt(getFormatCalc().name().substring(1));
// Last
if (selectLevel >= useLevel || selectLevel == 4) {
return super.getSqlName();
}
StringBuilder sqlName = new StringBuilder(super.getSqlName());
for (int i = 0; i < useLevel - selectLevel; i++) {
sqlName.append(".parent");
}
return sqlName.toString();
} else {
return super.getSqlName();
}
}
use of com.rebuild.core.metadata.easymeta.DisplayType 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;
}
use of com.rebuild.core.metadata.easymeta.DisplayType in project rebuild by getrebuild.
the class MetaschemaImporter method performField.
private Field performField(JSONObject schemaField, Entity belong) {
String fieldName = schemaField.getString("field");
String fieldLabel = schemaField.getString("fieldLabel");
String displayType = schemaField.getString("displayType");
JSON extConfig = schemaField.getJSONObject("extConfig");
DisplayType dt = DisplayType.valueOf(displayType);
if (dt == DisplayType.ID || MetadataHelper.isCommonsField(fieldName)) {
return null;
}
Field unsafeField = new Field2Schema(this.getUser()).createUnsafeField(belong, fieldName, fieldLabel, dt, schemaField.getBooleanValue("nullable"), true, schemaField.getBooleanValue("updatable"), !schemaField.containsKey("repeatable") || schemaField.getBooleanValue("repeatable"), !schemaField.containsKey("queryable") || schemaField.getBooleanValue("queryable"), schemaField.getString("comments"), schemaField.getString("refEntity"), null, extConfig, schemaField.getString("defaultValue"));
if (DisplayType.PICKLIST == dt || DisplayType.MULTISELECT == dt) {
picklistHolders.put(unsafeField, performPickList(schemaField.getJSONArray("items")));
}
return unsafeField;
}
use of com.rebuild.core.metadata.easymeta.DisplayType in project rebuild by getrebuild.
the class ReferenceSearchController method resultSearch.
private List<Object> resultSearch(String sqlWhere, Entity entity, int maxResults) {
Field nameField = entity.getNameField();
String sql = MessageFormat.format("select {0},{1} from {2} where {3}", entity.getPrimaryField().getName(), nameField.getName(), entity.getName(), sqlWhere);
if (!sqlWhere.contains(" order by ")) {
DisplayType dt = EasyMetaFactory.getDisplayType(nameField);
if (dt != DisplayType.ID) {
sql += " order by " + nameField.getName();
} else if (entity.containsField(EntityHelper.ModifiedOn)) {
sql += " order by modifiedOn desc";
}
}
Object[][] array = QueryHelper.createQuery(sql, entity).setLimit(maxResults).array();
List<Object> result = new ArrayList<>();
for (Object[] o : array) {
ID recordId = (ID) o[0];
if (MetadataHelper.isBizzEntity(entity) && (!UserHelper.isActive(recordId) || recordId.equals(UserService.SYSTEM_USER))) {
continue;
}
String label = (String) FieldValueHelper.wrapFieldValue(o[1], nameField, true);
if (StringUtils.isBlank(label)) {
label = FieldValueHelper.NO_LABEL_PREFIX + recordId.toLiteral().toUpperCase();
}
result.add(FieldValueHelper.wrapMixValue(recordId, label));
}
return result;
}
Aggregations