Search in sources :

Example 11 with WkfProcessConfig

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

Example 12 with WkfProcessConfig

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

the class WkfInstanceServiceImpl method addRelatedInstance.

private boolean addRelatedInstance(Model model, WkfProcessConfig wkfProcessConfig) throws AxelorException {
    log.debug("Find related instance for the model: {}, id: {}, path: {}", model.getClass().getName(), model.getId(), wkfProcessConfig.getProcessPath());
    Object object = wkfService.findRelatedRecord(model, wkfProcessConfig.getProcessPath());
    if (object != null && object instanceof FullContext) {
        FullContext relatedModel = (FullContext) object;
        log.debug("Related instance found with processInstanceId: {}", relatedModel.get("processInstanceId"));
        model.setProcessInstanceId((String) relatedModel.get("processInstanceId"));
        return true;
    } else {
        WkfProcessConfig oldProcessConfig = wkfService.findOldProcessConfig(model);
        if (oldProcessConfig == null || oldProcessConfig.getProcessPath() == null || oldProcessConfig.equals(wkfProcessConfig)) {
            return false;
        }
        return addRelatedInstance(model, oldProcessConfig);
    }
}
Also used : WkfProcessConfig(com.axelor.apps.bpm.db.WkfProcessConfig) FullContext(com.axelor.apps.tool.context.FullContext)

Example 13 with WkfProcessConfig

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

the class WkfModelController method setModelsDomain.

public void setModelsDomain(ActionRequest request, ActionResponse response) {
    try {
        WkfModel wkfModel = null;
        List<Long> jsonModelIds = new ArrayList<>();
        List<Long> metaModelIds = new ArrayList<>();
        if (request.getContext().get("wkfId") != null) {
            wkfModel = wkfModelRepository.find(Long.parseLong(request.getContext().get("wkfId").toString()));
        }
        String process = (String) request.getContext().get("_process");
        if (wkfModel != null) {
            for (WkfProcess wkfProcess : wkfModel.getWkfProcessList()) {
                if (CollectionUtils.isEmpty(wkfProcess.getWkfProcessConfigList()) || !wkfProcess.getName().equals(process)) {
                    continue;
                }
                for (WkfProcessConfig processConfig : wkfProcess.getWkfProcessConfigList()) {
                    if (processConfig.getMetaModel() != null) {
                        metaModelIds.add(processConfig.getMetaModel().getId());
                    }
                    if (processConfig.getMetaJsonModel() != null) {
                        jsonModelIds.add(processConfig.getMetaJsonModel().getId());
                    }
                }
            }
        }
        response.setAttr("metaJsonModel", "domain", !jsonModelIds.isEmpty() ? "self.id IN (" + StringUtils.join(jsonModelIds, ',') + ")" : "self.id IN (0)");
        response.setAttr("metaModel", "domain", !metaModelIds.isEmpty() ? "self.id IN (" + StringUtils.join(metaModelIds, ',') + ")" : "self.id IN (0)");
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : WkfProcess(com.axelor.apps.bpm.db.WkfProcess) WkfProcessConfig(com.axelor.apps.bpm.db.WkfProcessConfig) WkfModel(com.axelor.apps.bpm.db.WkfModel) ArrayList(java.util.ArrayList) AxelorException(com.axelor.exception.AxelorException)

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