Search in sources :

Example 6 with WkfInstance

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

the class WkfInstanceServiceImpl method evalInstance.

@Override
@Transactional
public String evalInstance(Model model, String signal) throws ClassNotFoundException, AxelorException {
    model = EntityHelper.getEntity(model);
    String helpText = null;
    if (model.getProcessInstanceId() == null) {
        checkSubProcess(model);
    }
    if (model.getProcessInstanceId() == null) {
        addRelatedProcessInstanceId(model);
        log.debug("Model process instanceId added: {}", model.getProcessInstanceId());
    }
    if (model.getProcessInstanceId() != null) {
        ProcessEngine engine = engineService.getEngine();
        WkfInstance wkfInstance = wkfInstanceRepository.findByInstnaceId(model.getProcessInstanceId());
        if (wkfInstance == null) {
            return helpText;
        }
        ProcessInstance processInstance = findProcessInstance(wkfInstance.getInstanceId(), engine.getRuntimeService());
        if (processInstance != null && wkfInstance != null && !processInstance.isEnded()) {
            helpText = Beans.get(WkfTaskService.class).runTasks(engine, wkfInstance, processInstance, signal);
        }
    }
    return helpText;
}
Also used : WkfInstance(com.axelor.apps.bpm.db.WkfInstance) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessEngine(org.camunda.bpm.engine.ProcessEngine) Transactional(com.google.inject.persist.Transactional)

Example 7 with WkfInstance

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

the class WkfDisplayServiceImpl method getInstanceUrl.

@Override
@CallMethod
public String getInstanceUrl(WkfInstance wkfInstance) {
    try {
        ProcessEngine engine = engineService.getEngine();
        String processInstanceId = wkfInstance.getInstanceId();
        List<String> activeIds = getActivityIds(processInstanceId);
        Map<String, Integer> activityCountMap = new HashMap<>();
        getActivityPassCount(wkfInstance.getInstanceId(), activityCountMap);
        WkfProcess wkfProcess = wkfInstance.getWkfProcess();
        BpmnModelInstance modelInstance = engine.getRepositoryService().getBpmnModelInstance(wkfProcess.getProcessId());
        Iterator<Process> processIter = modelInstance.getModelElementsByType(Process.class).iterator();
        HistoricVariableInstanceQuery variableQuery = engine.getHistoryService().createHistoricVariableInstanceQuery().processInstanceId(processInstanceId);
        while (processIter.hasNext()) {
            Process process = processIter.next();
            if (process.getId().equals(wkfProcess.getName())) {
                continue;
            }
            HistoricVariableInstance variableInstance = variableQuery.variableName(process.getId()).singleResult();
            if (variableInstance != null) {
                activeIds.addAll(getActivityIds((String) variableInstance.getValue()));
                getActivityPassCount((String) variableInstance.getValue(), activityCountMap);
            }
        }
        String activityCount = activityCountMap.keySet().stream().map(it -> it + ":" + activityCountMap.get(it)).collect(Collectors.joining(","));
        log.trace("Active node ids: {}", activeIds);
        String url = String.format(engineService.getWkfViewerUrl(), "instanceId=" + wkfInstance.getInstanceId(), Joiner.on(",").join(activeIds), activityCount);
        log.debug("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) WkfProcess(com.axelor.apps.bpm.db.WkfProcess) Process(org.camunda.bpm.model.bpmn.instance.Process) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) WkfProcess(com.axelor.apps.bpm.db.WkfProcess) HistoricVariableInstanceQuery(org.camunda.bpm.engine.history.HistoricVariableInstanceQuery) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) ProcessEngine(org.camunda.bpm.engine.ProcessEngine) CallMethod(com.axelor.meta.CallMethod)

Example 8 with WkfInstance

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

the class WkfDisplayServiceImpl method getWkfStatus.

@Override
public List<Map<String, Object>> getWkfStatus(Class<?> klass, Long id) {
    List<Map<String, Object>> statusList = new ArrayList<>();
    if (klass == null || id == null) {
        return statusList;
    }
    Model model = (Model) JPA.em().find(klass, id);
    if (model == null) {
        return statusList;
    }
    String processInstanceId = model.getProcessInstanceId();
    log.debug("Display wkf nodes of processInstanceId: {}", processInstanceId);
    if (processInstanceId != null) {
        WkfInstance wkfInstance = Beans.get(WkfInstanceRepository.class).findByInstnaceId(processInstanceId);
        if (wkfInstance == null) {
            return statusList;
        }
        String klassName = klass.getSimpleName();
        if (model instanceof MetaJsonRecord) {
            klassName = ((MetaJsonRecord) model).getJsonModel();
        }
        boolean valid = isValidDisplayModel(klassName, wkfInstance);
        log.debug("Is valid model to display wkf nodes : {}", valid);
        if (!valid) {
            return statusList;
        }
        addActiveNodes(statusList, wkfInstance, klassName);
    }
    return statusList;
}
Also used : WkfInstance(com.axelor.apps.bpm.db.WkfInstance) ArrayList(java.util.ArrayList) WkfModel(com.axelor.apps.bpm.db.WkfModel) Model(com.axelor.db.Model) WkfInstanceRepository(com.axelor.apps.bpm.db.repo.WkfInstanceRepository) HashMap(java.util.HashMap) Map(java.util.Map) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord)

Example 9 with WkfInstance

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

the class WkfExecutionListener method createWkfInstance.

private void createWkfInstance(DelegateExecution execution) {
    String instanceId = execution.getProcessInstanceId();
    WkfInstanceRepository instanceRepo = Beans.get(WkfInstanceRepository.class);
    WkfInstance wkfInstance = instanceRepo.findByInstnaceId(instanceId);
    log.debug("Process called with related wkfInstance: {}", wkfInstance);
    if (wkfInstance == null) {
        execution.setVariable(getProcessKey(execution, execution.getProcessDefinitionId()), execution.getProcessInstanceId());
        createWkfInstance(execution, instanceId, instanceRepo);
    }
}
Also used : WkfInstance(com.axelor.apps.bpm.db.WkfInstance) WkfInstanceRepository(com.axelor.apps.bpm.db.repo.WkfInstanceRepository)

Example 10 with WkfInstance

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

the class WkfInstanceServiceImpl method startInstance.

protected void startInstance(WkfProcessConfig wkfProcessConfig, Model model) throws AxelorException {
    WkfProcessConfig previousConfig = wkfService.findOldProcessConfig(model);
    if (previousConfig != null && previousConfig.getProcessPath() != null && addRelatedInstance(model, previousConfig)) {
        return;
    }
    log.debug("Start instance for the model: {}, id: {}", model.getClass().getName(), model.getId());
    WkfProcess wkfProcess = wkfProcessConfig.getWkfProcess();
    ProcessEngine engine = engineService.getEngine();
    RuntimeService runTimeService = engine.getRuntimeService();
    ProcessInstantiationBuilder builder = runTimeService.createProcessInstanceById(wkfProcess.getProcessId());
    Map<String, Object> modelMap = new HashMap<String, Object>();
    modelMap.put(wkfService.getVarName(model), new FullContext(model));
    builder.setVariables(wkfService.createVariables(modelMap));
    ProcessInstance processInstance = builder.executeWithVariablesInReturn();
    WkfInstance instance = wkfInstanceRepository.findByInstnaceId(model.getProcessInstanceId());
    if (instance != null) {
        instance.setModelId(model.getId());
        instance.setModelName(model.getClass().getName());
        instance.setProcessInstanceId(processInstance.getId());
    }
    model.setProcessInstanceId(processInstance.getId());
}
Also used : WkfProcess(com.axelor.apps.bpm.db.WkfProcess) WkfProcessConfig(com.axelor.apps.bpm.db.WkfProcessConfig) RuntimeService(org.camunda.bpm.engine.RuntimeService) HashMap(java.util.HashMap) FullContext(com.axelor.apps.tool.context.FullContext) WkfInstance(com.axelor.apps.bpm.db.WkfInstance) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessInstantiationBuilder(org.camunda.bpm.engine.runtime.ProcessInstantiationBuilder) ProcessEngine(org.camunda.bpm.engine.ProcessEngine)

Aggregations

WkfInstance (com.axelor.apps.bpm.db.WkfInstance)11 WkfInstanceRepository (com.axelor.apps.bpm.db.repo.WkfInstanceRepository)6 Model (com.axelor.db.Model)5 HashMap (java.util.HashMap)5 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)5 WkfProcess (com.axelor.apps.bpm.db.WkfProcess)4 Transactional (com.google.inject.persist.Transactional)4 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)4 RuntimeService (org.camunda.bpm.engine.RuntimeService)4 WkfModel (com.axelor.apps.bpm.db.WkfModel)3 WkfProcessConfig (com.axelor.apps.bpm.db.WkfProcessConfig)3 MetaJsonRecord (com.axelor.meta.db.MetaJsonRecord)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)3 WkfTaskConfig (com.axelor.apps.bpm.db.WkfTaskConfig)2 WkfTaskConfigRepository (com.axelor.apps.bpm.db.repo.WkfTaskConfigRepository)2 WkfInstanceService (com.axelor.apps.bpm.service.execution.WkfInstanceService)2 ProcessEngineService (com.axelor.apps.bpm.service.init.ProcessEngineService)2