use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.
the class TransformManager method getRawTransforms.
@SuppressWarnings("unchecked")
public List<ConfigBean> getRawTransforms(String sourceEntity) {
final String cKey = "TransformManager2.2-" + sourceEntity;
Object cached = Application.getCommonsCache().getx(cKey);
if (cached != null) {
return (List<ConfigBean>) cached;
}
Object[][] array = Application.createQueryNoFilter("select belongEntity,targetEntity,configId,config,isDisabled,name from TransformConfig where belongEntity = ?").setParameter(1, sourceEntity).array();
ArrayList<ConfigBean> entries = new ArrayList<>();
for (Object[] o : array) {
ConfigBean entry = new ConfigBean().set("source", o[0]).set("target", o[1]).set("id", o[2]).set("disabled", ObjectUtils.toBool(o[4], false)).set("name", o[5]);
JSON config = JSON.parseObject((String) o[3]);
entry.set("config", config);
entries.add(entry);
}
Application.getCommonsCache().putx(cKey, entries);
return entries;
}
use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.
the class ViewAddonsManager method getViewAddons.
/**
* @param entity
* @param user
* @param applyType
* @return
*/
private JSONObject getViewAddons(String entity, ID user, String applyType) {
final ConfigBean config = getLayout(user, entity, applyType);
final Permission useAction = TYPE_TAB.equals(applyType) ? BizzPermission.READ : BizzPermission.CREATE;
final Entity entityMeta = MetadataHelper.getEntity(entity);
final Set<Entity> mfRefs = hasMultiFieldsReferenceTo(entityMeta);
// 未配置则使用全部
if (config == null) {
JSONArray useRefs = new JSONArray();
for (Field field : entityMeta.getReferenceToFields(true)) {
Entity e = field.getOwnEntity();
if (e.getMainEntity() == null && Application.getPrivilegesManager().allow(user, e.getEntityCode(), useAction)) {
useRefs.add(getEntityShow(field, mfRefs, applyType));
}
}
// 跟进(动态)
useRefs.add(getEntityShow(MetadataHelper.getField("Feeds", "relatedRecord"), mfRefs, applyType));
// 任务(项目)
useRefs.add(getEntityShow(MetadataHelper.getField("ProjectTask", "relatedRecord"), mfRefs, applyType));
// 附件
if (TYPE_TAB.equals(applyType)) {
useRefs.add(getEntityShow(MetadataHelper.getField("Attachment", "relatedRecord"), mfRefs, applyType));
}
return JSONUtils.toJSONObject("items", useRefs);
}
// compatible: v2.2
JSON configJson = config.getJSON("config");
if (configJson instanceof JSONArray) {
configJson = JSONUtils.toJSONObject("items", configJson);
}
JSONArray addons = new JSONArray();
for (Object o : ((JSONObject) configJson).getJSONArray("items")) {
String key;
String label = null;
// compatible: v2.8
if (o instanceof JSONArray) {
key = (String) ((JSONArray) o).get(0);
label = (String) ((JSONArray) o).get(1);
} else {
key = o.toString();
}
// Entity.Field (v1.9)
String[] ef = key.split("\\.");
if (!MetadataHelper.containsEntity(ef[0])) {
continue;
}
Entity addonEntity = MetadataHelper.getEntity(ef[0]);
if (ef.length > 1 && !MetadataHelper.checkAndWarnField(addonEntity, ef[1])) {
continue;
}
if (Application.getPrivilegesManager().allow(user, addonEntity.getEntityCode(), useAction)) {
JSONObject show = ef.length > 1 ? getEntityShow(addonEntity.getField(ef[1]), mfRefs, applyType) : EasyMetaFactory.toJSON(addonEntity);
if (StringUtils.isNotBlank(label))
show.put("entityLabel", label);
addons.add(show);
}
}
return JSONUtils.toJSONObject(new String[] { "items", "autoExpand", "autoHide" }, new Object[] { addons, ((JSONObject) configJson).getBooleanValue("autoExpand"), ((JSONObject) configJson).getBooleanValue("autoHide") });
}
use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.
the class DataReportManager method getTemplateFile.
/**
* @param entity
* @param reportId
* @return
*/
public File getTemplateFile(Entity entity, ID reportId) {
String template = null;
for (ConfigBean e : getReportsRaw(entity)) {
if (e.getID("id").equals(reportId)) {
template = e.getString("template");
break;
}
}
if (template == null) {
throw new ConfigurationException("No template of report found : " + reportId);
}
File file = RebuildConfiguration.getFileOfData(template);
if (!file.exists()) {
throw new ConfigurationException("File of template not extsts : " + file);
}
return file;
}
use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.
the class ChartsFactory method create.
/**
* @param chartId
* @return
* @throws ChartsException
*/
public static ChartData create(ID chartId) throws ChartsException {
ConfigBean chart = ChartManager.instance.getChart(chartId);
if (chart == null) {
throw new ChartsException(Language.L("无效图表"));
}
JSONObject config = (JSONObject) chart.getJSON("config");
config.put("chartOwning", chart.getID("createdBy"));
return create(config, UserContextHolder.getUser());
}
use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.
the class ChartManager method richingCharts.
/**
* 丰富图表数据 title, type
*
* @param charts
* @param user [可选]
*/
public void richingCharts(JSONArray charts, ID user) {
for (Iterator<Object> iter = charts.iterator(); iter.hasNext(); ) {
JSONObject ch = (JSONObject) iter.next();
ID chartid = ID.valueOf(ch.getString("chart"));
ConfigBean e = getChart(chartid);
if (e == null) {
iter.remove();
continue;
}
ch.put("title", e.getString("title"));
ch.put("type", e.getString("type"));
if (user != null) {
ID createdBy = e.getID("createdBy");
ch.put("isManageable", UserHelper.isSelf(user, createdBy));
}
}
}
Aggregations