Search in sources :

Example 1 with WkfProcessConfig

use of com.axelor.apps.bpm.db.WkfProcessConfig in project axelor-open-suite by axelor.

the class WkfModelServiceImpl method getProcessPerStatus.

@SuppressWarnings({ "serial", "unchecked" })
@Override
public List<Map<String, Object>> getProcessPerStatus(WkfModel wkfModel) {
    List<Map<String, Object>> dataList = new ArrayList<>();
    List<WkfProcess> processList = getProcesses(wkfModel);
    for (WkfProcess process : processList) {
        Map<String, Object> processMap = new HashMap<>();
        List<Map<String, Object>> configList = new ArrayList<>();
        List<WkfProcessConfig> processConfigs = process.getWkfProcessConfigList();
        this.sortProcessConfig(processConfigs);
        List<String> _modelList = new ArrayList<>();
        for (WkfProcessConfig processConfig : processConfigs) {
            final boolean isMetaModel = processConfig.getMetaModel() != null;
            final String modelName = isMetaModel ? processConfig.getMetaModel().getName() : processConfig.getMetaJsonModel().getName();
            if (_modelList.contains(modelName)) {
                continue;
            }
            _modelList.add(modelName);
            Map<String, Object> _map = this.computeStatus(isMetaModel, modelName, process, null);
            List<Long> recordIdsPerModel = (List<Long>) _map.get("recordIdsPerModel");
            List<Map<String, Object>> statusList = (List<Map<String, Object>>) _map.get("statuses");
            Map<String, Object> taskMap = (Map<String, Object>) _map.get("tasks");
            configList.add(new HashMap<String, Object>() {

                {
                    put("type", "model");
                    put("title", !StringUtils.isBlank(processConfig.getTitle()) ? processConfig.getTitle() : modelName);
                    put("modelName", modelName);
                    put("modelRecordCount", recordIdsPerModel.size());
                    put("isMetaModel", isMetaModel);
                    put("recordIdsPerModel", recordIdsPerModel);
                    put("statuses", statusList);
                    put("tasks", taskMap);
                }
            });
        }
        processMap.put("title", !StringUtils.isBlank(process.getDescription()) ? process.getDescription() : process.getName());
        processMap.put("itemList", configList);
        dataList.add(processMap);
    }
    return dataList;
}
Also used : WkfProcessConfig(com.axelor.apps.bpm.db.WkfProcessConfig) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WkfProcess(com.axelor.apps.bpm.db.WkfProcess) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with WkfProcessConfig

use of com.axelor.apps.bpm.db.WkfProcessConfig in project axelor-open-suite by axelor.

the class WkfModelServiceImpl method getProcessPerUser.

@SuppressWarnings({ "serial", "unchecked" })
@Override
public List<Map<String, Object>> getProcessPerUser(WkfModel wkfModel) {
    User user = AuthUtils.getUser();
    List<Map<String, Object>> dataList = new ArrayList<>();
    List<WkfProcess> processList = getProcesses(wkfModel);
    for (WkfProcess process : processList) {
        Map<String, Object> processMap = new HashMap<>();
        List<Map<String, Object>> configList = new ArrayList<>();
        WkfProcessConfig firstProcessConfig = null;
        List<WkfProcessConfig> processConfigs = process.getWkfProcessConfigList();
        this.sortProcessConfig(processConfigs);
        int taskAssignedToMe = 0;
        List<String> _modelList = new ArrayList<>();
        for (WkfProcessConfig processConfig : processConfigs) {
            boolean isDirectCreation = processConfig.getIsDirectCreation();
            firstProcessConfig = firstProcessConfig == null ? processConfig.getIsStartModel() ? processConfig : null : firstProcessConfig;
            boolean isMetaModel = processConfig.getMetaModel() != null;
            String modelName = isMetaModel ? processConfig.getMetaModel().getName() : processConfig.getMetaJsonModel().getName();
            if (_modelList.contains(modelName)) {
                continue;
            }
            _modelList.add(modelName);
            Map<String, Object> _map = this.computeStatus(isMetaModel, modelName, process, user);
            List<Long> recordIdsPerModel = (List<Long>) _map.get("recordIdsPerModel");
            List<Map<String, Object>> statusList = (List<Map<String, Object>>) _map.get("statuses");
            if (!statusList.isEmpty()) {
                taskAssignedToMe += statusList.stream().map(s -> (int) s.get("statusCount")).reduce(0, Integer::sum);
            }
            Map<String, Object> taskMap = (Map<String, Object>) _map.get("tasks");
            configList.add(new HashMap<String, Object>() {

                {
                    put("type", "model");
                    put("title", !StringUtils.isBlank(processConfig.getTitle()) ? processConfig.getTitle() : modelName);
                    put("modelRecordCount", recordIdsPerModel.size());
                    put("isMetaModel", isMetaModel);
                    put("recordIdsPerModel", recordIdsPerModel);
                    put("statuses", statusList);
                    put("tasks", taskMap);
                }
            });
            configList.add(new HashMap<String, Object>() {

                {
                    put("type", "button");
                    put("isDirectCreation", isDirectCreation);
                    put("modelName", modelName);
                    put("isMetaModel", isMetaModel);
                }
            });
        }
        processMap.put("title", !StringUtils.isBlank(process.getDescription()) ? process.getDescription() : process.getName());
        processMap.put("taskAssignedToMe", taskAssignedToMe);
        processMap.put("itemList", configList);
        processMap.put("processConfig", firstProcessConfig);
        dataList.add(processMap);
    }
    return dataList;
}
Also used : User(com.axelor.auth.db.User) WkfProcessConfig(com.axelor.apps.bpm.db.WkfProcessConfig) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WkfProcess(com.axelor.apps.bpm.db.WkfProcess) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with WkfProcessConfig

use of com.axelor.apps.bpm.db.WkfProcessConfig in project axelor-open-suite by axelor.

the class BpmDashboardServiceImpl method getData.

@SuppressWarnings({ "unchecked", "serial" })
@Override
public Map<String, Object> getData(int offset) {
    User user = AuthUtils.getUser();
    Map<String, Object> dataMap = new HashMap<>();
    List<Map<String, Object>> modelList = new ArrayList<>();
    List<WkfModel> wkfModelList = this.getWkfModelsByUser(user);
    long totalRecord = wkfModelList.size();
    List<WkfModel> showWkfModels = wkfModelList.stream().skip(offset).limit(FETCH_LIMIT).collect(Collectors.toList());
    for (WkfModel wkfModel : showWkfModels) {
        boolean isSuperAdmin = user.getCode().equals("admin");
        boolean isAdmin = wkfModelController.isAdmin(wkfModel, user);
        boolean isManager = wkfModelController.isManager(wkfModel, user);
        boolean isUser = wkfModelController.isUser(wkfModel, user);
        List<WkfProcess> processes = wkfModelService.getProcesses(wkfModel);
        List<Map<String, Object>> processList = new ArrayList<>();
        for (WkfProcess process : processes) {
            List<Map<String, Object>> configList = new ArrayList<>();
            List<WkfProcessConfig> processConfigs = process.getWkfProcessConfigList();
            wkfModelService.sortProcessConfig(processConfigs);
            List<String> _modelList = new ArrayList<>();
            for (WkfProcessConfig processConfig : processConfigs) {
                boolean isMetaModel = processConfig.getMetaModel() != null;
                String modelName = isMetaModel ? processConfig.getMetaModel().getName() : processConfig.getMetaJsonModel().getName();
                if (_modelList.contains(modelName)) {
                    continue;
                }
                _modelList.add(modelName);
                Map<String, Object> _map = this.computeConfigs(process, modelName, isMetaModel, user);
                List<Long> recordIdsUserPerModel = (List<Long>) _map.get("recordIdsUserPerModel");
                List<Map<String, Object>> statusUserList = (List<Map<String, Object>>) _map.get("statusUserList");
                List<Long> recordIdsPerModel = (List<Long>) _map.get("recordIdsPerModel");
                List<Map<String, Object>> statusList = (List<Map<String, Object>>) _map.get("statusList");
                List<Long> recordIdsModel = new ArrayList<>();
                if (isSuperAdmin || isAdmin || isManager) {
                    recordIdsModel.addAll(recordIdsPerModel);
                    recordIdsModel.addAll(recordIdsUserPerModel);
                } else if (isUser) {
                    recordIdsModel.addAll(recordIdsUserPerModel);
                }
                configList.add(new HashMap<String, Object>() {

                    {
                        put("type", "model");
                        put("title", !StringUtils.isBlank(processConfig.getTitle()) ? processConfig.getTitle() : modelName);
                        put("modelName", modelName);
                        put("modelRecordCount", recordIdsModel.size());
                        put("isMetaModel", isMetaModel);
                        put("recordIdsPerModel", recordIdsModel);
                        put("userStatuses", statusUserList);
                        put("statuses", statusList);
                    }
                });
            }
            processList.add(new HashMap<String, Object>() {

                {
                    put("title", !StringUtils.isBlank(process.getDescription()) ? process.getDescription() : process.getName());
                    put("itemList", configList);
                }
            });
        }
        modelList.add(new HashMap<String, Object>() {

            {
                put("title", wkfModel.getName());
                put("processList", processList);
                put("isSuperAdmin", isSuperAdmin);
                put("isAdmin", isAdmin);
                put("isManager", isManager);
                put("isUser", isUser);
            }
        });
    }
    dataMap.put("$modelList", modelList);
    dataMap.put("$offset", offset);
    dataMap.put("$limit", FETCH_LIMIT);
    dataMap.put("$totalRecord", totalRecord);
    return dataMap;
}
Also used : User(com.axelor.auth.db.User) WkfProcessConfig(com.axelor.apps.bpm.db.WkfProcessConfig) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WkfProcess(com.axelor.apps.bpm.db.WkfProcess) WkfModel(com.axelor.apps.bpm.db.WkfModel) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with WkfProcessConfig

use of com.axelor.apps.bpm.db.WkfProcessConfig in project axelor-open-suite by axelor.

the class WkfInstanceServiceImpl method addChildProcessInstanceId.

private void addChildProcessInstanceId(String processInstanceId, FullContext modelCtx, Map<String, Object> ctxMap) {
    RuntimeService runtimeService = engineService.getEngine().getRuntimeService();
    List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().superProcessInstanceId(processInstanceId).list();
    for (ProcessInstance processInstance : processInstances) {
        WkfInstance wkfInstance = wkfInstanceRepository.findByInstnaceId(processInstance.getProcessInstanceId());
        if (wkfInstance == null) {
            continue;
        }
        List<WkfProcessConfig> processConfigs = wkfInstance.getWkfProcess().getWkfProcessConfigList();
        for (WkfProcessConfig processConfig : processConfigs) {
            String configModel = null;
            if (processConfig.getMetaModel() != null) {
                configModel = processConfig.getMetaModel().getFullName();
            } else if (processConfig.getMetaJsonModel() != null) {
                configModel = processConfig.getMetaJsonModel().getName();
            }
            if (configModel == null) {
                continue;
            }
            Class klass = modelCtx.getContextClass();
            String ctxClass = klass.getName();
            if (klass.equals(MetaJsonRecord.class)) {
                ctxClass = (String) modelCtx.get("jsonModel");
            }
            if (ctxClass.equals(configModel) && evalCondition(ctxMap, processConfig.getPathCondition())) {
                modelCtx.put("processInstanceId", wkfInstance.getInstanceId());
                return;
            }
        }
    }
}
Also used : WkfProcessConfig(com.axelor.apps.bpm.db.WkfProcessConfig) RuntimeService(org.camunda.bpm.engine.RuntimeService) WkfInstance(com.axelor.apps.bpm.db.WkfInstance) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance)

Example 5 with WkfProcessConfig

use of com.axelor.apps.bpm.db.WkfProcessConfig in project axelor-open-suite by axelor.

the class WkfInstanceServiceImpl method createVariables.

private Map<String, Object> createVariables(String processInstanceId) {
    Map<String, Object> varMap = new HashMap<String, Object>();
    WkfInstance wkfInstance = Beans.get(WkfInstanceRepository.class).findByInstnaceId(processInstanceId);
    if (wkfInstance == null) {
        return varMap;
    }
    for (WkfProcessConfig wkfProcessConfig : wkfInstance.getWkfProcess().getWkfProcessConfigList()) {
        Model model = FullContextHelper.getRepository(wkfProcessConfig.getModel()).all().filter("self.processInstanceId = ?1", processInstanceId).fetchOne();
        if (model == null) {
            continue;
        }
        Object var = Variables.objectValue(new FullContext(model), true).serializationDataFormat(SerializationDataFormats.JSON).create();
        Long id = ((Model) model).getId();
        String varName = wkfService.getVarName(model);
        varMap.put(varName, var);
        varMap.put(varName + "Id", id);
    }
    return varMap;
}
Also used : WkfProcessConfig(com.axelor.apps.bpm.db.WkfProcessConfig) HashMap(java.util.HashMap) WkfInstance(com.axelor.apps.bpm.db.WkfInstance) FullContext(com.axelor.apps.tool.context.FullContext) WkfInstanceRepository(com.axelor.apps.bpm.db.repo.WkfInstanceRepository) Model(com.axelor.db.Model)

Aggregations

WkfProcessConfig (com.axelor.apps.bpm.db.WkfProcessConfig)13 HashMap (java.util.HashMap)8 WkfProcess (com.axelor.apps.bpm.db.WkfProcess)6 FullContext (com.axelor.apps.tool.context.FullContext)5 ArrayList (java.util.ArrayList)4 WkfInstance (com.axelor.apps.bpm.db.WkfInstance)3 List (java.util.List)3 Map (java.util.Map)3 WkfModel (com.axelor.apps.bpm.db.WkfModel)2 User (com.axelor.auth.db.User)2 Model (com.axelor.db.Model)2 AxelorException (com.axelor.exception.AxelorException)2 RuntimeService (org.camunda.bpm.engine.RuntimeService)2 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)2 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)2 NodeList (org.w3c.dom.NodeList)2 WkfInstanceRepository (com.axelor.apps.bpm.db.repo.WkfInstanceRepository)1 WkfProcessConfigRepository (com.axelor.apps.bpm.db.repo.WkfProcessConfigRepository)1 MetaJsonRecord (com.axelor.meta.db.MetaJsonRecord)1 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)1