Search in sources :

Example 16 with ConfigBean

use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.

the class ProtocolFilterParser method parseVia.

/**
 * @param viaId
 * @param refField
 * @return
 */
public String parseVia(String viaId, String refField) {
    final ID anyId = ID.isId(viaId) ? ID.valueOf(viaId) : null;
    if (anyId == null)
        return null;
    JSONObject filterExp = null;
    // via Charts
    if (anyId.getEntityCode() == EntityHelper.ChartConfig) {
        ConfigBean chart = ChartManager.instance.getChart(anyId);
        if (chart != null)
            filterExp = ((JSONObject) chart.getJSON("config")).getJSONObject("filter");
    } else // via AdvFilter
    if (anyId.getEntityCode() == EntityHelper.FilterConfig) {
        ConfigBean filter = AdvFilterManager.instance.getAdvFilter(anyId);
        if (filter != null)
            filterExp = (JSONObject) filter.getJSON("filter");
    } else // via OTHERS
    if (refField != null) {
        String[] entityAndField = refField.split("\\.");
        Assert.isTrue(entityAndField.length == 2, "Bad `via` filter defined");
        JSONObject item = JSONUtils.toJSONObject(new String[] { "field", "op", "value" }, new Object[] { entityAndField[1], ParseHelper.EQ, anyId });
        filterExp = JSONUtils.toJSONObject("entity", entityAndField[0]);
        filterExp.put("items", Collections.singletonList(item));
    }
    return filterExp == null ? null : new AdvFilterParser(filterExp).toSqlWhere();
}
Also used : AdvFilterParser(com.rebuild.core.service.query.AdvFilterParser) JSONObject(com.alibaba.fastjson.JSONObject) ID(cn.devezhao.persist4j.engine.ID) ConfigBean(com.rebuild.core.configuration.ConfigBean)

Example 17 with ConfigBean

use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.

the class ProjectController method getPlans.

@GetMapping("{projectId}/details")
public RespBody getPlans(@PathVariable String projectId, HttpServletRequest request) throws IOException {
    final ID user = getRequestUser(request);
    JSONObject details;
    try {
        ConfigBean p = ProjectManager.instance.getProject(ID.valueOf(projectId), user);
        details = JSONUtils.toJSONObject(new String[] { "projectName", "isMember", "projectStatus" }, new Object[] { p.getString("projectName"), p.get("members", Set.class).contains(user), p.getInteger("status") });
    } catch (ConfigurationException ex) {
        return RespBody.error(ex.getLocalizedMessage(), 403);
    }
    ConfigBean[] plans = ProjectManager.instance.getPlansOfProject(ID.valueOf(projectId));
    JSONArray array = new JSONArray();
    for (ConfigBean cb : plans) {
        array.add(cb.toJSON());
    }
    details.put("projectPlans", array);
    return RespBody.ok(details);
}
Also used : Set(java.util.Set) JSONObject(com.alibaba.fastjson.JSONObject) ConfigurationException(com.rebuild.core.configuration.ConfigurationException) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) ID(cn.devezhao.persist4j.engine.ID) ConfigBean(com.rebuild.core.configuration.ConfigBean) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 18 with ConfigBean

use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.

the class ProjectController method pageProject.

@GetMapping("{projectId}/tasks")
public ModelAndView pageProject(@PathVariable String projectId, HttpServletRequest request, HttpServletResponse response) throws IOException {
    final ID projectId2 = ID.isId(projectId) ? ID.valueOf(projectId) : null;
    if (projectId2 == null) {
        response.sendError(404);
        return null;
    }
    final ID user = getRequestUser(request);
    ConfigBean p;
    try {
        p = ProjectManager.instance.getProject(projectId2, getRequestUser(request));
    } catch (ConfigurationException ex) {
        response.sendError(403, ex.getLocalizedMessage());
        return null;
    }
    ModelAndView mv = createModelAndView("/project/project-tasks");
    mv.getModel().put("projectId", p.getID("id"));
    mv.getModel().put("iconName", p.getString("iconName"));
    mv.getModel().put("projectCode", p.getString("projectCode"));
    mv.getModel().put("projectName", p.getString("projectName"));
    mv.getModel().put("isMember", p.get("members", Set.class).contains(user));
    mv.getModel().put("scope", p.getInteger("scope"));
    mv.getModel().put("status", p.getInteger("status"));
    // 分组显示
    JSONArray plansList = new JSONArray();
    String group = getParameter(request, "group");
    if (GROUP_PRIORITY.equalsIgnoreCase(group)) {
        plansList.add(newCustomPlan(GROUP_PRIORITY + "-3", Language.L("非常紧急")));
        plansList.add(newCustomPlan(GROUP_PRIORITY + "-2", Language.L("紧急")));
        plansList.add(newCustomPlan(GROUP_PRIORITY + "-1", Language.L("普通")));
        plansList.add(newCustomPlan(GROUP_PRIORITY + "-0", Language.L("较低")));
    } else if (GROUP_DEADLINE.equalsIgnoreCase(group)) {
        plansList.add(newCustomPlan(GROUP_DEADLINE + "-1", Language.L("已逾期")));
        plansList.add(newCustomPlan(GROUP_DEADLINE + "-2", Language.L("今天")));
        plansList.add(newCustomPlan(GROUP_DEADLINE + "-3", Language.L("7 天内")));
        plansList.add(newCustomPlan(GROUP_DEADLINE + "-4", Language.L("以后或未安排")));
    } else if (GROUP_MODIFIED.equalsIgnoreCase(group)) {
        plansList.add(newCustomPlan(GROUP_MODIFIED + "-1", Language.L("今天")));
        plansList.add(newCustomPlan(GROUP_MODIFIED + "-2", Language.L("7 天内")));
        plansList.add(newCustomPlan(GROUP_MODIFIED + "-3", Language.L("14 天内")));
        plansList.add(newCustomPlan(GROUP_MODIFIED + "-4", Language.L("更早")));
    } else {
        final ConfigBean[] plans = ProjectManager.instance.getPlansOfProject(projectId2);
        for (ConfigBean e : plans) {
            plansList.add(e.toJSON());
        }
    }
    mv.getModel().put("projectPlans", plansList.toJSONString());
    return mv;
}
Also used : ConfigurationException(com.rebuild.core.configuration.ConfigurationException) ModelAndView(org.springframework.web.servlet.ModelAndView) JSONArray(com.alibaba.fastjson.JSONArray) ID(cn.devezhao.persist4j.engine.ID) ConfigBean(com.rebuild.core.configuration.ConfigBean) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 19 with ConfigBean

use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.

the class PickListController method picklistGet.

@RequestMapping({ "picklist-gets", "multiselect-gets" })
public void picklistGet(HttpServletRequest request, HttpServletResponse response) {
    String entity = getParameterNotNull(request, "entity");
    String field = getParameterNotNull(request, "field");
    boolean isAll = "true".equals(getParameter(request, "isAll"));
    Field fieldMeta = MetadataHelper.getField(entity, field);
    ConfigBean[] entries = PickListManager.instance.getPickListRaw(fieldMeta, isAll);
    writeSuccess(response, JSONUtils.toJSONArray(entries));
}
Also used : Field(cn.devezhao.persist4j.Field) ConfigBean(com.rebuild.core.configuration.ConfigBean) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with ConfigBean

use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.

the class ViewAddonsController method gets.

@GetMapping("{entity}/view-addons")
public JSON gets(@PathVariable String entity, HttpServletRequest request) {
    final ID user = getRequestUser(request);
    String applyType = getParameter(request, "type", ViewAddonsManager.TYPE_TAB);
    ConfigBean config = ViewAddonsManager.instance.getLayout(user, entity, applyType);
    // compatible: v2.2
    JSON configJson = config == null ? null : config.getJSON("config");
    if (configJson instanceof JSONArray) {
        configJson = JSONUtils.toJSONObject("items", configJson);
    }
    Entity entityMeta = MetadataHelper.getEntity(entity);
    Set<Entity> mfRefs = ViewAddonsManager.hasMultiFieldsReferenceTo(entityMeta);
    List<String[]> refs = new ArrayList<>();
    for (Field field : entityMeta.getReferenceToFields(true)) {
        Entity e = field.getOwnEntity();
        if (e.getMainEntity() != null) {
            continue;
        }
        String label = EasyMetaFactory.getLabel(e);
        if (mfRefs.contains(e)) {
            label = EasyMetaFactory.getLabel(field) + " (" + label + ")";
        }
        refs.add(new String[] { e.getName() + ViewAddonsManager.EF_SPLIT + field.getName(), label });
    }
    // 跟进(动态)
    refs.add(new String[] { "Feeds.relatedRecord", Language.L("动态") });
    // 任务(项目)
    refs.add(new String[] { "ProjectTask.relatedRecord", Language.L("任务") });
    // 附件
    if (ViewAddonsManager.TYPE_TAB.equals(applyType)) {
        refs.add(new String[] { "Attachment.relatedRecord", Language.L("附件") });
    }
    return JSONUtils.toJSONObject(new String[] { "config", "refs" }, new Object[] { configJson, refs });
}
Also used : Entity(cn.devezhao.persist4j.Entity) Field(cn.devezhao.persist4j.Field) JSONArray(com.alibaba.fastjson.JSONArray) ArrayList(java.util.ArrayList) JSON(com.alibaba.fastjson.JSON) 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