use of com.axelor.apps.bpm.db.WkfModel in project axelor-open-suite by axelor.
the class WkfModelServiceImpl method start.
@Override
@Transactional
public WkfModel start(WkfModel wkfModel) {
wkfModel.setStatusSelect(WkfModelRepository.STATUS_ON_GOING);
if (wkfModel.getPreviousVersion() != null) {
WkfModel previousVersion = wkfModel.getPreviousVersion();
previousVersion.setIsActive(false);
wkfModel.setPreviousVersion(terminate(previousVersion));
}
return wkfModelRepository.save(wkfModel);
}
use of com.axelor.apps.bpm.db.WkfModel in project axelor-open-suite by axelor.
the class WkfModelServiceImpl method createNewVersion.
@Override
@Transactional
public WkfModel createNewVersion(WkfModel wkfModel) {
if (wkfModel == null) {
return null;
}
WkfModel newVersion = wkfModelRepository.all().filter("self.previousVersion.id = ?1", wkfModel.getId()).fetchOne();
if (newVersion == null) {
newVersion = wkfModelRepository.copy(wkfModel, true);
newVersion.setPreviousVersion(wkfModel);
}
return wkfModelRepository.save(newVersion);
}
use of com.axelor.apps.bpm.db.WkfModel in project axelor-open-suite by axelor.
the class BpmDashboardServiceImpl method getData.
@SuppressWarnings({ "unchecked", "serial" })
@Override
public Map<String, Object> getData(int offset) {
User user = AuthUtils.getUser();
Map<String, Object> dataMap = new HashMap<>();
List<Map<String, Object>> modelList = new ArrayList<>();
List<WkfModel> wkfModelList = this.getWkfModelsByUser(user);
long totalRecord = wkfModelList.size();
List<WkfModel> showWkfModels = wkfModelList.stream().skip(offset).limit(FETCH_LIMIT).collect(Collectors.toList());
for (WkfModel wkfModel : showWkfModels) {
boolean isSuperAdmin = user.getCode().equals("admin");
boolean isAdmin = wkfModelController.isAdmin(wkfModel, user);
boolean isManager = wkfModelController.isManager(wkfModel, user);
boolean isUser = wkfModelController.isUser(wkfModel, user);
List<WkfProcess> processes = wkfModelService.getProcesses(wkfModel);
List<Map<String, Object>> processList = new ArrayList<>();
for (WkfProcess process : processes) {
List<Map<String, Object>> configList = new ArrayList<>();
List<WkfProcessConfig> processConfigs = process.getWkfProcessConfigList();
wkfModelService.sortProcessConfig(processConfigs);
List<String> _modelList = new ArrayList<>();
for (WkfProcessConfig processConfig : processConfigs) {
boolean isMetaModel = processConfig.getMetaModel() != null;
String modelName = isMetaModel ? processConfig.getMetaModel().getName() : processConfig.getMetaJsonModel().getName();
if (_modelList.contains(modelName)) {
continue;
}
_modelList.add(modelName);
Map<String, Object> _map = this.computeConfigs(process, modelName, isMetaModel, user);
List<Long> recordIdsUserPerModel = (List<Long>) _map.get("recordIdsUserPerModel");
List<Map<String, Object>> statusUserList = (List<Map<String, Object>>) _map.get("statusUserList");
List<Long> recordIdsPerModel = (List<Long>) _map.get("recordIdsPerModel");
List<Map<String, Object>> statusList = (List<Map<String, Object>>) _map.get("statusList");
List<Long> recordIdsModel = new ArrayList<>();
if (isSuperAdmin || isAdmin || isManager) {
recordIdsModel.addAll(recordIdsPerModel);
recordIdsModel.addAll(recordIdsUserPerModel);
} else if (isUser) {
recordIdsModel.addAll(recordIdsUserPerModel);
}
configList.add(new HashMap<String, Object>() {
{
put("type", "model");
put("title", !StringUtils.isBlank(processConfig.getTitle()) ? processConfig.getTitle() : modelName);
put("modelName", modelName);
put("modelRecordCount", recordIdsModel.size());
put("isMetaModel", isMetaModel);
put("recordIdsPerModel", recordIdsModel);
put("userStatuses", statusUserList);
put("statuses", statusList);
}
});
}
processList.add(new HashMap<String, Object>() {
{
put("title", !StringUtils.isBlank(process.getDescription()) ? process.getDescription() : process.getName());
put("itemList", configList);
}
});
}
modelList.add(new HashMap<String, Object>() {
{
put("title", wkfModel.getName());
put("processList", processList);
put("isSuperAdmin", isSuperAdmin);
put("isAdmin", isAdmin);
put("isManager", isManager);
put("isUser", isUser);
}
});
}
dataMap.put("$modelList", modelList);
dataMap.put("$offset", offset);
dataMap.put("$limit", FETCH_LIMIT);
dataMap.put("$totalRecord", totalRecord);
return dataMap;
}
use of com.axelor.apps.bpm.db.WkfModel 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.WkfModel in project axelor-open-suite by axelor.
the class WkfModelController method showDashboard.
public void showDashboard(ActionRequest request, ActionResponse response) {
try {
WkfModel wkfModel = request.getContext().asType(WkfModel.class);
wkfModel = wkfModelRepository.find(wkfModel.getId());
if (CollectionUtils.isEmpty(wkfModel.getWkfProcessList())) {
return;
}
if (wkfModel.getWkfProcessList().size() == 1) {
response.setView(ActionView.define(I18n.get("Workflow dashboard")).add("dashboard", "dasbhoard-wkf-model").context("_wkfId", wkfModel.getId()).context("_process", wkfModel.getWkfProcessList().get(0).getName()).map());
} else {
response.setView(ActionView.define(I18n.get("Select process")).model(Wizard.class.getName()).add("form", "wfk-model-select-process-wizard-form").param("popup", "true").param("popup-save", "false").param("show-confirm", "false").param("show-toolbar", "false").context("_wkf", wkfModel).map());
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations