Search in sources :

Example 41 with ConfigBean

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

the class ProjectTaskService method create.

@Override
public Record create(Record record) {
    final ID user = UserContextHolder.getUser();
    checkModifications(user, record.getID("projectId"));
    ID projectId = record.getID("projectId");
    ID projectPlanId = record.getID("projectPlanId");
    ConfigBean p = ProjectManager.instance.getPlanOfProject(projectPlanId, projectId);
    if (p.getInteger("flowStatus") == ProjectPlanConfigService.FLOW_STATUS_PROCESSING) {
        throw new DataSpecificationException(Language.L("该任务面板不可新建任务"));
    }
    record.setLong("taskNumber", getNextTaskNumber(projectId));
    applyFlowStatus(record);
    record.setInt("seq", getNextSeqViaMidValue(projectPlanId));
    record = super.create(record);
    if (record.hasValue("executor", false)) {
        sendNotification(record.getPrimary());
    }
    return record;
}
Also used : DataSpecificationException(com.rebuild.core.service.DataSpecificationException) ID(cn.devezhao.persist4j.engine.ID) ConfigBean(com.rebuild.core.configuration.ConfigBean)

Example 42 with ConfigBean

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

the class ProjectTaskService method applyFlowStatus.

/**
 * 自动完成
 *
 * @param newOrUpdate
 */
private int applyFlowStatus(Record newOrUpdate) {
    if (newOrUpdate.hasValue("projectPlanId")) {
        ConfigBean c = ProjectManager.instance.getPlanOfProject(newOrUpdate.getID("projectPlanId"), newOrUpdate.getID("projectId"));
        int fs = c.getInteger("flowStatus");
        if (fs == ProjectPlanConfigService.FLOW_STATUS_END) {
            newOrUpdate.setInt("status", 1);
        } else if (fs == ProjectPlanConfigService.FLOW_STATUS_PROCESSING) {
            newOrUpdate.setDate("startTime", CalendarUtils.now());
        }
        return fs;
    }
    return -1;
}
Also used : ConfigBean(com.rebuild.core.configuration.ConfigBean)

Example 43 with ConfigBean

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

the class BaseTaskService method checkModifications.

/**
 * 是否成员;是否已归档
 *
 * @param user
 * @param taskOrProject
 * @return
 */
protected boolean checkModifications(ID user, ID taskOrProject) {
    if (user == null)
        user = UserContextHolder.getUser();
    Assert.notNull(taskOrProject, "taskOrProject");
    ConfigBean c = taskOrProject.getEntityCode() == EntityHelper.ProjectTask ? ProjectManager.instance.getProjectByX(taskOrProject, null) : ProjectManager.instance.getProject(taskOrProject, null);
    if (c == null || !c.get("members", Set.class).contains(user)) {
        throw new DataSpecificationException(Language.L("非项目成员禁止操作"));
    }
    if (c.getInteger("status") == ProjectManager.STATUS_ARCHIVED) {
        throw new DataSpecificationException(Language.L("已归档项目禁止操作"));
    }
    return true;
}
Also used : Set(java.util.Set) DataSpecificationException(com.rebuild.core.service.DataSpecificationException) ConfigBean(com.rebuild.core.configuration.ConfigBean)

Example 44 with ConfigBean

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

the class RobotTriggerManager method filterActions.

/**
 * @param record
 * @param entity
 * @param when
 * @return
 */
private TriggerAction[] filterActions(Entity entity, ID record, TriggerWhen... when) {
    List<TriggerAction> actions = new ArrayList<>();
    for (ConfigBean cb : getConfig(entity)) {
        if (allowedWhen(cb, when)) {
            if (record == null || QueryHelper.isMatchAdvFilter(record, (JSONObject) cb.getJSON("whenFilter"))) {
                ActionContext ctx = new ActionContext(record, entity, cb.getJSON("actionContent"), cb.getID("id"));
                TriggerAction o = ActionFactory.createAction(cb.getString("actionType"), ctx);
                actions.add(o);
                if (log.isDebugEnabled()) {
                    TRIGGERS_CHAIN_4DEBUG.get().add(String.format("%s (%s) on %s %s (%s)", o.getType(), ctx.getConfigId(), when[0], entity.getName(), record));
                }
            }
        }
    }
    if (!TRIGGERS_CHAIN_4DEBUG.get().isEmpty()) {
        log.info("Record ({}) triggers chain : \n  > {}", record, StringUtils.join(TRIGGERS_CHAIN_4DEBUG.get(), "\n  > "));
    }
    return actions.toArray(new TriggerAction[0]);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) ConfigBean(com.rebuild.core.configuration.ConfigBean)

Example 45 with ConfigBean

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

the class RobotTriggerManager method getConfig.

/**
 * @param entity
 * @return
 */
@SuppressWarnings("unchecked")
protected List<ConfigBean> getConfig(Entity entity) {
    final String cKey = "RobotTriggerManager-" + entity.getName();
    Object cached = Application.getCommonsCache().getx(cKey);
    if (cached != null) {
        return (List<ConfigBean>) cached;
    }
    Object[][] array = Application.createQueryNoFilter("select when,whenFilter,actionType,actionContent,configId from RobotTriggerConfig" + " where belongEntity = ? and when > 0 and isDisabled = 'F' order by priority desc").setParameter(1, entity.getName()).array();
    ArrayList<ConfigBean> entries = new ArrayList<>();
    for (Object[] o : array) {
        ConfigBean entry = new ConfigBean().set("when", o[0]).set("whenFilter", JSON.parseObject((String) o[1])).set("actionType", o[2]).set("actionContent", JSON.parseObject((String) o[3])).set("id", o[4]);
        entries.add(entry);
    }
    Application.getCommonsCache().putx(cKey, entries);
    return entries;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) 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