Search in sources :

Example 1 with WkfInstance

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

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

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

Example 4 with WkfInstance

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

the class WkfExecutionListener method createWkfInstance.

@Transactional
public void createWkfInstance(DelegateExecution execution, String instanceId, WkfInstanceRepository instanceRepo) {
    WkfInstance wkfInstance;
    wkfInstance = new WkfInstance();
    wkfInstance.setInstanceId(instanceId);
    WkfProcess wkfProcess = Beans.get(WkfProcessRepository.class).all().filter("self.processId = ?1", execution.getProcessDefinitionId()).fetchOne();
    wkfInstance.setName(wkfProcess.getProcessId() + " : " + instanceId);
    wkfInstance.setWkfProcess(wkfProcess);
    instanceRepo.save(wkfInstance);
}
Also used : WkfProcess(com.axelor.apps.bpm.db.WkfProcess) WkfInstance(com.axelor.apps.bpm.db.WkfInstance) WkfProcessRepository(com.axelor.apps.bpm.db.repo.WkfProcessRepository) Transactional(com.google.inject.persist.Transactional)

Example 5 with WkfInstance

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

the class WkfRequestListener method processDeleted.

@Transactional
public void processDeleted(BeforeTransactionComplete event, String tenantId) {
    Set<? extends Model> deleted = new HashSet<Model>(event.getDeleted());
    WkfInstanceRepository wkfInstanceRepository = Beans.get(WkfInstanceRepository.class);
    for (Model model : deleted) {
        String modelName = EntityHelper.getEntityClass(model).getName();
        if (WkfCache.WKF_MODEL_CACHE.get(tenantId).containsValue(modelName)) {
            try {
                log.trace("Remove wkf instance of deleted model: {}, id: {}", modelName, model.getId());
                WkfInstance wkfInstance = wkfInstanceRepository.findByInstnaceId(model.getProcessInstanceId());
                if (wkfInstance != null && wkfInstance.getWkfProcess().getWkfProcessConfigList().size() == 1) {
                    wkfInstanceRepository.remove(wkfInstance);
                }
            } catch (Exception e) {
            }
        }
    }
}
Also used : WkfInstance(com.axelor.apps.bpm.db.WkfInstance) WkfInstanceRepository(com.axelor.apps.bpm.db.repo.WkfInstanceRepository) Model(com.axelor.db.Model) AxelorException(com.axelor.exception.AxelorException) HashSet(java.util.HashSet) Transactional(com.google.inject.persist.Transactional)

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