Search in sources :

Example 1 with WkfInstanceRepository

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

Example 2 with WkfInstanceRepository

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

Aggregations

WkfInstance (com.axelor.apps.bpm.db.WkfInstance)2 WkfInstanceRepository (com.axelor.apps.bpm.db.repo.WkfInstanceRepository)2 Model (com.axelor.db.Model)1 AxelorException (com.axelor.exception.AxelorException)1 Transactional (com.google.inject.persist.Transactional)1 HashSet (java.util.HashSet)1