Search in sources :

Example 1 with WkfModel

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

the class WkfModelServiceImpl method start.

@Override
@Transactional
public WkfModel start(WkfModel wkfModel) {
    wkfModel.setStatusSelect(WkfModelRepository.STATUS_ON_GOING);
    if (wkfModel.getPreviousVersion() != null) {
        WkfModel previousVersion = wkfModel.getPreviousVersion();
        previousVersion.setIsActive(false);
        wkfModel.setPreviousVersion(terminate(previousVersion));
    }
    return wkfModelRepository.save(wkfModel);
}
Also used : WkfModel(com.axelor.apps.bpm.db.WkfModel) Transactional(com.google.inject.persist.Transactional)

Example 2 with WkfModel

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

the class WkfModelServiceImpl method createNewVersion.

@Override
@Transactional
public WkfModel createNewVersion(WkfModel wkfModel) {
    if (wkfModel == null) {
        return null;
    }
    WkfModel newVersion = wkfModelRepository.all().filter("self.previousVersion.id = ?1", wkfModel.getId()).fetchOne();
    if (newVersion == null) {
        newVersion = wkfModelRepository.copy(wkfModel, true);
        newVersion.setPreviousVersion(wkfModel);
    }
    return wkfModelRepository.save(newVersion);
}
Also used : WkfModel(com.axelor.apps.bpm.db.WkfModel) Transactional(com.google.inject.persist.Transactional)

Example 3 with WkfModel

use of com.axelor.apps.bpm.db.WkfModel 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 WkfModel

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

the class WkfDisplayServiceImpl method getWkfNodeCountUrl.

@Override
@CallMethod
public String getWkfNodeCountUrl(WkfModel wkfModel) {
    try {
        Map<String, Integer> activityCountMap = new HashMap<>();
        List<WkfInstance> instances = Beans.get(WkfInstanceRepository.class).all().filter("self.wkfProcess.wkfModel.id = ?1", wkfModel.getId()).fetch();
        log.trace("Total process instances: {}", instances.size());
        for (WkfInstance instance : instances) {
            getActivityPassCount(instance.getInstanceId(), activityCountMap);
        }
        log.trace("Count map: {}", activityCountMap);
        String activityCount = activityCountMap.keySet().stream().map(it -> it + ":" + activityCountMap.get(it)).collect(Collectors.joining(","));
        String url = String.format(engineService.getWkfViewerUrl(), "id=" + wkfModel.getId(), null, activityCount);
        log.trace("Url created: {}", url);
        return url;
    } catch (Exception e) {
    }
    return null;
}
Also used : HistoryService(org.camunda.bpm.engine.HistoryService) CallMethod(com.axelor.meta.CallMethod) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) HistoricProcessInstanceQuery(org.camunda.bpm.engine.history.HistoricProcessInstanceQuery) ProcessEngineService(com.axelor.apps.bpm.service.init.ProcessEngineService) WkfInstanceRepository(com.axelor.apps.bpm.db.repo.WkfInstanceRepository) WkfInstanceService(com.axelor.apps.bpm.service.execution.WkfInstanceService) WkfInstance(com.axelor.apps.bpm.db.WkfInstance) Map(java.util.Map) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) HistoricVariableInstanceQuery(org.camunda.bpm.engine.history.HistoricVariableInstanceQuery) WkfTaskConfigRepository(com.axelor.apps.bpm.db.repo.WkfTaskConfigRepository) WkfModel(com.axelor.apps.bpm.db.WkfModel) JPA(com.axelor.db.JPA) Logger(org.slf4j.Logger) Model(com.axelor.db.Model) Iterator(java.util.Iterator) ActivityTypes(org.camunda.bpm.engine.ActivityTypes) Set(java.util.Set) ProcessEngine(org.camunda.bpm.engine.ProcessEngine) WkfProcess(com.axelor.apps.bpm.db.WkfProcess) Collectors(java.util.stream.Collectors) HistoricActivityInstance(org.camunda.bpm.engine.history.HistoricActivityInstance) List(java.util.List) Beans(com.axelor.inject.Beans) WkfTaskConfig(com.axelor.apps.bpm.db.WkfTaskConfig) Process(org.camunda.bpm.model.bpmn.instance.Process) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) RuntimeService(org.camunda.bpm.engine.RuntimeService) AuthUtils(com.axelor.auth.AuthUtils) User(com.axelor.auth.db.User) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord) Joiner(com.google.common.base.Joiner) HashMap(java.util.HashMap) WkfInstance(com.axelor.apps.bpm.db.WkfInstance) WkfInstanceRepository(com.axelor.apps.bpm.db.repo.WkfInstanceRepository) CallMethod(com.axelor.meta.CallMethod)

Example 5 with WkfModel

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

the class WkfModelController method showDashboard.

public void showDashboard(ActionRequest request, ActionResponse response) {
    try {
        WkfModel wkfModel = request.getContext().asType(WkfModel.class);
        wkfModel = wkfModelRepository.find(wkfModel.getId());
        if (CollectionUtils.isEmpty(wkfModel.getWkfProcessList())) {
            return;
        }
        if (wkfModel.getWkfProcessList().size() == 1) {
            response.setView(ActionView.define(I18n.get("Workflow dashboard")).add("dashboard", "dasbhoard-wkf-model").context("_wkfId", wkfModel.getId()).context("_process", wkfModel.getWkfProcessList().get(0).getName()).map());
        } else {
            response.setView(ActionView.define(I18n.get("Select process")).model(Wizard.class.getName()).add("form", "wfk-model-select-process-wizard-form").param("popup", "true").param("popup-save", "false").param("show-confirm", "false").param("show-toolbar", "false").context("_wkf", wkfModel).map());
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : WkfModel(com.axelor.apps.bpm.db.WkfModel) Wizard(com.axelor.apps.base.db.Wizard) AxelorException(com.axelor.exception.AxelorException)

Aggregations

WkfModel (com.axelor.apps.bpm.db.WkfModel)17 ArrayList (java.util.ArrayList)7 WkfProcess (com.axelor.apps.bpm.db.WkfProcess)4 User (com.axelor.auth.db.User)3 AxelorException (com.axelor.exception.AxelorException)3 Map (java.util.Map)3 WkfProcessConfig (com.axelor.apps.bpm.db.WkfProcessConfig)2 Transactional (com.google.inject.persist.Transactional)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Wizard (com.axelor.apps.base.db.Wizard)1 WkfInstance (com.axelor.apps.bpm.db.WkfInstance)1 WkfTaskConfig (com.axelor.apps.bpm.db.WkfTaskConfig)1 WkfInstanceRepository (com.axelor.apps.bpm.db.repo.WkfInstanceRepository)1 WkfModelRepository (com.axelor.apps.bpm.db.repo.WkfModelRepository)1 WkfTaskConfigRepository (com.axelor.apps.bpm.db.repo.WkfTaskConfigRepository)1 WkfModelService (com.axelor.apps.bpm.service.WkfModelService)1 BpmDeploymentService (com.axelor.apps.bpm.service.deployment.BpmDeploymentService)1 WkfInstanceService (com.axelor.apps.bpm.service.execution.WkfInstanceService)1 ProcessEngineService (com.axelor.apps.bpm.service.init.ProcessEngineService)1