use of com.axelor.db.Model 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.db.Model 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) {
}
}
}
}
use of com.axelor.db.Model in project axelor-open-suite by axelor.
the class WkfRequestListener method processUpdated.
private void processUpdated(BeforeTransactionComplete event, String tenantId) throws AxelorException {
Set<? extends Model> updated = new HashSet<Model>(event.getUpdated());
for (Model model : updated) {
String modelName = EntityHelper.getEntityClass(model).getName();
if (WkfCache.WKF_MODEL_CACHE.get(tenantId).containsValue(modelName)) {
try {
log.trace("Eval workflow from updated model: {}, id: {}", modelName, model.getId());
Beans.get(WkfInstanceService.class).evalInstance(model, null);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
if (!updated.containsAll(event.getUpdated())) {
processUpdated(event, tenantId);
}
}
use of com.axelor.db.Model 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);
}
use of com.axelor.db.Model in project axelor-open-suite by axelor.
the class WkfInstanceServiceImpl method checkSubProcess.
protected void checkSubProcess(Model model) {
String chldModel = model instanceof MetaJsonRecord ? ((MetaJsonRecord) model).getJsonModel() : model.getClass().getSimpleName();
List<WkfTaskConfig> taskConfigs = wkfTaskConfigRepository.all().filter("self.callModel = ?1 AND self.callLink IS NOT NULL", chldModel).fetch();
if (taskConfigs.isEmpty()) {
return;
}
FullContext modelCtx = WkfContextHelper.create(model);
Map<String, Object> ctxMap = ImmutableMap.of(wkfService.getVarName(model), modelCtx);
for (WkfTaskConfig taskConfig : taskConfigs) {
if (!evalCondition(ctxMap, taskConfig.getCallLinkCondition())) {
continue;
}
Object parentModel = modelCtx.get(taskConfig.getCallLink());
if (parentModel != null && parentModel instanceof FullContext) {
Model parent = (Model) ((FullContext) parentModel).getTarget();
if (parent.getProcessInstanceId() != null) {
addChildProcessInstanceId(parent.getProcessInstanceId(), modelCtx, ctxMap);
break;
}
}
}
}
Aggregations