Search in sources :

Example 6 with ConfigBean

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;
}
Also used : ArrayList(java.util.ArrayList) JSONObject(com.alibaba.fastjson.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List) JSON(com.alibaba.fastjson.JSON) ConfigBean(com.rebuild.core.configuration.ConfigBean)

Example 7 with ConfigBean

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") });
}
Also used : Entity(cn.devezhao.persist4j.Entity) Field(cn.devezhao.persist4j.Field) JSONObject(com.alibaba.fastjson.JSONObject) BizzPermission(cn.devezhao.bizz.privileges.impl.BizzPermission) Permission(cn.devezhao.bizz.privileges.Permission) JSONArray(com.alibaba.fastjson.JSONArray) JSON(com.alibaba.fastjson.JSON) JSONObject(com.alibaba.fastjson.JSONObject) ConfigBean(com.rebuild.core.configuration.ConfigBean)

Example 8 with ConfigBean

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;
}
Also used : ConfigurationException(com.rebuild.core.configuration.ConfigurationException) ConfigBean(com.rebuild.core.configuration.ConfigBean) File(java.io.File)

Example 9 with ConfigBean

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());
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) ConfigBean(com.rebuild.core.configuration.ConfigBean)

Example 10 with ConfigBean

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));
        }
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject) ID(cn.devezhao.persist4j.engine.ID) ConfigBean(com.rebuild.core.configuration.ConfigBean)

Aggregations

ConfigBean (com.rebuild.core.configuration.ConfigBean)52 ID (cn.devezhao.persist4j.engine.ID)26 JSONObject (com.alibaba.fastjson.JSONObject)23 JSONArray (com.alibaba.fastjson.JSONArray)16 JSON (com.alibaba.fastjson.JSON)9 GetMapping (org.springframework.web.bind.annotation.GetMapping)9 Entity (cn.devezhao.persist4j.Entity)8 ArrayList (java.util.ArrayList)7 Field (cn.devezhao.persist4j.Field)6 Record (cn.devezhao.persist4j.Record)5 ConfigurationException (com.rebuild.core.configuration.ConfigurationException)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ModelAndView (org.springframework.web.servlet.ModelAndView)4 DataSpecificationException (com.rebuild.core.service.DataSpecificationException)2 AdvFilterParser (com.rebuild.core.service.query.AdvFilterParser)2 List (java.util.List)2 Set (java.util.Set)2 Test (org.junit.jupiter.api.Test)2 Permission (cn.devezhao.bizz.privileges.Permission)1 BizzPermission (cn.devezhao.bizz.privileges.impl.BizzPermission)1