use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.
the class DataListManager method getWidgetCharts.
// --
/**
* 列表-SIDE图表
*
* @param user
* @param entity
* @return
*/
public ConfigBean getWidgetCharts(ID user, String entity) {
ConfigBean e = getLayout(user, entity, TYPE_WCHARTS);
if (e == null) {
return null;
}
// 补充图表信息
JSONArray charts = (JSONArray) e.getJSON("config");
ChartManager.instance.richingCharts(charts, null);
return e.set("config", charts).set("shareTo", null);
}
use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.
the class FormsBuilder method buildModel.
/**
* @param entity
* @param user
* @param record
* @param viewMode 视图模式
* @return
*/
private JSON buildModel(String entity, ID user, ID record, boolean viewMode) {
Assert.notNull(entity, "[entity] cannot be null");
Assert.notNull(user, "[user] cannot be null");
final Entity entityMeta = MetadataHelper.getEntity(entity);
if (record != null) {
Assert.isTrue(entityMeta.getEntityCode().equals(record.getEntityCode()), "[entity] and [record] do not match");
}
// 如果明细实体
final Entity hasMainEntity = entityMeta.getMainEntity();
// 审批流程(状态)
ApprovalState approvalState;
// 新建
if (record == null) {
if (hasMainEntity != null) {
ID mainid = FormBuilderContextHolder.getMainIdOfDetail();
Assert.notNull(mainid, "Call `FormBuilderContextHolder#setMainIdOfDetail` first!");
approvalState = EntityHelper.isUnsavedId(mainid) ? null : getHadApproval(hasMainEntity, mainid);
if ((approvalState == ApprovalState.PROCESSING || approvalState == ApprovalState.APPROVED)) {
return formatModelError(approvalState == ApprovalState.APPROVED ? Language.L("主记录已完成审批,不能添加明细") : Language.L("主记录正在审批中,不能添加明细"));
}
// 明细无需审批
approvalState = null;
if (!EntityHelper.isUnsavedId(mainid) && !Application.getPrivilegesManager().allowUpdate(user, mainid)) {
return formatModelError(Language.L("你没有添加明细权限"));
}
} else if (!Application.getPrivilegesManager().allowCreate(user, entityMeta.getEntityCode())) {
return formatModelError(Language.L("你没有新建权限"));
} else {
approvalState = getHadApproval(entityMeta, null);
}
} else // 查看(视图)
if (viewMode) {
if (!Application.getPrivilegesManager().allowRead(user, record)) {
return formatModelError(Language.L("无权读取此记录或记录已被删除"));
}
approvalState = getHadApproval(entityMeta, record);
} else // 编辑
{
if (!Application.getPrivilegesManager().allowUpdate(user, record)) {
return formatModelError(Language.L("你没有修改此记录的权限"));
}
approvalState = getHadApproval(entityMeta, record);
if (approvalState != null) {
String recordType = hasMainEntity == null ? Language.L("记录") : Language.L("主记录");
if (approvalState == ApprovalState.APPROVED) {
return formatModelError(Language.L("%s已完成审批,禁止编辑", recordType));
} else if (approvalState == ApprovalState.PROCESSING) {
return formatModelError(Language.L("%s正在审批中,禁止编辑", recordType));
}
}
}
ConfigBean model = getFormLayout(entity, user);
JSONArray elements = (JSONArray) model.getJSON("elements");
if (elements == null || elements.isEmpty()) {
return formatModelError(Language.L("此表单布局尚未配置,请配置后使用"));
}
Record data = null;
if (record != null) {
data = findRecord(record, user, elements);
if (data == null) {
return formatModelError(Language.L("无权读取此记录或记录已被删除"));
}
}
// 自动只读
Set<String> roAutos = EasyMetaFactory.getAutoReadonlyFields(entity);
for (Object o : elements) {
JSONObject field = (JSONObject) o;
if (roAutos.contains(field.getString("field"))) {
field.put("readonly", true);
}
}
buildModelElements(elements, entityMeta, data, user, !viewMode);
if (elements.isEmpty()) {
return formatModelError(Language.L("此表单布局尚未配置,请配置后使用"));
}
// 主/明细实体处理
if (hasMainEntity != null) {
model.set("mainMeta", EasyMetaFactory.toJSON(hasMainEntity));
} else if (entityMeta.getDetailEntity() != null) {
model.set("detailMeta", EasyMetaFactory.toJSON(entityMeta.getDetailEntity()));
}
if (data != null && data.hasValue(EntityHelper.ModifiedOn)) {
model.set("lastModified", data.getDate(EntityHelper.ModifiedOn).getTime());
}
if (approvalState != null) {
model.set("hadApproval", approvalState.getState());
}
// Clean form's ID of config
model.set("id", null);
return model.toJSON();
}
use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.
the class MultiSelectManager method getLabels.
/**
* @param maskValue
* @param field
* @return
*/
public String[] getLabels(long maskValue, Field field) {
if (maskValue <= 0) {
return new String[0];
}
List<String> labels = new ArrayList<>();
ConfigBean[] entries = getPickListRaw(field, false);
for (ConfigBean e : entries) {
long m = e.get("mask", Long.class);
if ((maskValue & m) != 0) {
labels.add(e.getString("text"));
}
}
return labels.toArray(new String[0]);
}
use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.
the class PickListManager method getPickListRaw.
/**
* @param entity
* @param field
* @param includeHide
* @return
*/
public ConfigBean[] getPickListRaw(String entity, String field, boolean includeHide) {
final String ckey = String.format("PickList-%s.%s", entity, field);
ConfigBean[] cached = (ConfigBean[]) Application.getCommonsCache().getx(ckey);
if (cached == null) {
Object[][] array = Application.createQueryNoFilter("select itemId,text,isDefault,isHide,maskValue from PickList where belongEntity = ? and belongField = ? order by seq asc").setParameter(1, entity).setParameter(2, field).array();
List<ConfigBean> list = new ArrayList<>();
for (Object[] o : array) {
ConfigBean entry = new ConfigBean().set("id", o[0]).set("text", o[1]).set("default", o[2]).set("hide", o[3]).set("mask", o[4]);
list.add(entry);
}
cached = list.toArray(new ConfigBean[0]);
Application.getCommonsCache().putx(ckey, cached);
}
List<ConfigBean> ret = new ArrayList<>();
for (ConfigBean entry : cached) {
if (includeHide || !entry.getBoolean("hide")) {
ret.add(entry.clone());
}
}
return ret.toArray(new ConfigBean[0]);
}
use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.
the class TransformManager method getTransforms.
/**
* 前端使用
*
* @param sourceEntity
* @return
*/
public JSONArray getTransforms(String sourceEntity, ID user) {
JSONArray data = new JSONArray();
for (ConfigBean c : getRawTransforms(sourceEntity)) {
// 过滤尚未配置或禁用的
if (c.getJSON("config") == null || c.getBoolean("disabled"))
continue;
// 无字段映射
JSONObject fieldsMapping = ((JSONObject) c.getJSON("config")).getJSONObject("fieldsMapping");
if (fieldsMapping == null || fieldsMapping.isEmpty())
continue;
String target = c.getString("target");
Entity targetEntity = MetadataHelper.getEntity(target);
if (targetEntity.getMainEntity() == null) {
if (!Application.getPrivilegesManager().allowCreate(user, targetEntity.getEntityCode())) {
continue;
}
} else {
// To 明细
if (!Application.getPrivilegesManager().allowUpdate(user, targetEntity.getMainEntity().getEntityCode())) {
continue;
}
}
JSONObject item = EasyMetaFactory.toJSON(targetEntity);
item.put("transid", c.getID("id"));
data.add(item);
}
return data;
}
Aggregations