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