use of com.axelor.rpc.Context in project axelor-open-suite by axelor.
the class WkfModelController method showRecord.
@SuppressWarnings("unchecked")
public void showRecord(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
String status = context.get("status").toString();
String tableName = null;
String jsonModel = null;
ActionViewBuilder actionViewBuilder = null;
if (context.get("metaModel") != null) {
Long id = Long.parseLong(((Map<String, Object>) context.get("metaModel")).get("id").toString());
MetaModel metaModel = Beans.get(MetaModelRepository.class).find(id);
tableName = metaModel.getTableName();
actionViewBuilder = createActionBuilder(status, metaModel);
} else if (context.get("metaJsonModel") != null) {
Long id = Long.parseLong(((Map<String, Object>) context.get("metaJsonModel")).get("id").toString());
MetaJsonModel metaJsonModel = Beans.get(MetaJsonModelRepository.class).find(id);
jsonModel = metaJsonModel.getName();
tableName = MetaJsonRecord.class.getAnnotation(Table.class).name();
actionViewBuilder = createActionBuilder(status, metaJsonModel);
}
List<Long> idList = getRecordIds(context, tableName, jsonModel);
response.setView(actionViewBuilder.context("ids", !idList.isEmpty() ? idList : 0).map());
response.setCanClose(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.rpc.Context in project axelor-open-suite by axelor.
the class WkfModelController method cancelNode.
public void cancelNode(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
String processInstanceId = (String) context.get("processInstanceId");
String activityId = (String) context.get("activityId");
if (processInstanceId != null && activityId != null) {
Beans.get(WkfInstanceService.class).cancelNode(processInstanceId, activityId);
}
response.setFlash(I18n.get("Node cancelled"));
}
use of com.axelor.rpc.Context in project axelor-open-suite by axelor.
the class WkfModelController method restart.
public void restart(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
String processInstanceId = (String) context.get("processInstanceId");
String activityId = (String) context.get("activityId");
if (processInstanceId != null && activityId != null) {
Beans.get(WkfInstanceService.class).restart(processInstanceId, activityId);
}
response.setFlash(I18n.get("Instance Restarted"));
}
use of com.axelor.rpc.Context in project axelor-open-suite by axelor.
the class WkfModelController method deploy.
@SuppressWarnings("unchecked")
public void deploy(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
WkfModel wkfModel = context.asType(WkfModel.class);
Map<String, Map<String, String>> migrationMap = (Map<String, Map<String, String>>) context.get("wkfMigrationMap");
Boolean isMigrateOld = (Boolean) context.get("isMigrateOld");
if (isMigrateOld != null && !isMigrateOld) {
migrationMap = null;
}
wkfModel = wkfModelRepository.find(wkfModel.getId());
Beans.get(BpmDeploymentService.class).deploy(wkfModel, migrationMap);
response.setReload(true);
}
use of com.axelor.rpc.Context in project axelor-open-suite by axelor.
the class WkfRequestListener method onRequest.
public void onRequest(@Observes PostAction postAction) throws AxelorException {
Context context = postAction.getContext();
if (context == null || postAction.getName().equals("com.axelor.meta.web.MetaController:moreAttrs")) {
return;
}
String signal = (String) context.get("_signal");
if (signal == null) {
return;
}
Boolean wkfEvaluated = (Boolean) context.get("_wkfEvaluated");
if (wkfEvaluated != null && wkfEvaluated) {
return;
}
String tenantId = BpmTools.getCurentTenant();
if (!WkfCache.WKF_MODEL_CACHE.containsKey(tenantId)) {
WkfCache.initWkfModelCache();
}
Map<Long, String> modelMap = WkfCache.WKF_MODEL_CACHE.get(tenantId);
Class<? extends Model> model = (Class<? extends Model>) context.getContextClass();
if (modelMap != null && modelMap.containsValue(model.getName())) {
Long id = (Long) context.get("id");
if (!WkfCache.WKF_BUTTON_CACHE.containsKey(tenantId)) {
WkfCache.initWkfButttonCache();
}
MultiMap multiMap = WkfCache.WKF_BUTTON_CACHE.get(tenantId);
if (multiMap != null && multiMap.containsValue(signal) && id != null) {
try {
log.trace("Wkf button cache: {}", WkfCache.WKF_BUTTON_CACHE);
log.trace("Eval wkf from button model: {}, id: {}", model.getName(), id);
String helpText = Beans.get(WkfInstanceService.class).evalInstance(JPA.find(model, id), signal);
Object res = postAction.getResult();
if (res instanceof ActionResponse && helpText != null) {
((ActionResponse) res).setAlert(helpText);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
context.put("_wkfEvaluated", true);
}
Aggregations