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