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;
}
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;
}
}
}
}
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;
}
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);
}
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) {
}
}
}
}
Aggregations