use of com.axelor.apps.bpm.db.WkfProcessConfig in project axelor-open-suite by axelor.
the class WkfModelController method newInstance.
@SuppressWarnings({ "unchecked", "rawtypes" })
public void newInstance(ActionRequest request, ActionResponse response) {
try {
LinkedHashMap<String, Object> _map = (LinkedHashMap<String, Object>) request.getData().get("context");
WkfProcessConfig config = Beans.get(WkfProcessConfigRepository.class).find(Long.valueOf(((Map) _map.get("processConfig")).get("id").toString()));
boolean isMetaModel = config.getMetaModel() != null;
String modelName = isMetaModel ? config.getMetaModel().getName() : config.getMetaJsonModel().getName();
ActionViewBuilder actionViewBuilder = this.viewNewRecord(modelName, isMetaModel);
response.setView(actionViewBuilder.map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.bpm.db.WkfProcessConfig in project axelor-open-suite by axelor.
the class WkfTaskServiceImpl method getContext.
protected Map<String, Object> getContext(WkfInstance instance) throws ClassNotFoundException {
WkfProcess wkfProcess = instance.getWkfProcess();
Map<String, Object> modelMap = new HashMap<>();
for (WkfProcessConfig processConfig : wkfProcess.getWkfProcessConfigList()) {
Model model = null;
String klassName;
if (processConfig.getMetaJsonModel() != null) {
klassName = MetaJsonRecord.class.getName();
} else {
klassName = processConfig.getMetaModel().getFullName();
}
@SuppressWarnings("unchecked") final Class<? extends Model> klass = (Class<? extends Model>) Class.forName(klassName);
String query = "self.processInstanceId = ?";
if (processConfig.getMetaJsonModel() != null) {
query += " AND self.jsonModel = '" + processConfig.getMetaJsonModel().getName() + "'";
}
if (model == null)
model = JpaRepository.of(klass).all().filter(query, instance.getInstanceId()).order("-id").fetchOne();
if (model != null) {
model = EntityHelper.getEntity(model);
String name = wkfService.getVarName(model);
modelMap.put(name, new FullContext(model));
} else {
log.debug("Model not found with processInstanceId: {}", instance.getInstanceId());
}
}
log.debug("Variable map used: {}", modelMap);
return modelMap;
}
use of com.axelor.apps.bpm.db.WkfProcessConfig in project axelor-open-suite by axelor.
the class WkfCache method initWkfModelCache.
public static void initWkfModelCache() {
List<WkfProcessConfig> wkfProcessConfigs = JPA.all(WkfProcessConfig.class).fetch();
Map<Long, String> modelMap = new HashMap<Long, String>();
modelMap.put(0L, "");
for (WkfProcessConfig config : wkfProcessConfigs) {
modelMap.put(config.getId(), config.getModel());
}
WKF_MODEL_CACHE.put(BpmTools.getCurentTenant(), modelMap);
}
use of com.axelor.apps.bpm.db.WkfProcessConfig in project axelor-open-suite by axelor.
the class BpmDeploymentServiceImpl method addProcessConfig.
private void addProcessConfig(BpmnModelInstance bpmInstance, WkfProcess process) {
BaseElement processElement = bpmInstance.getModelElementById(process.getName());
ExtensionElements extensionElements = processElement.getExtensionElements();
if (extensionElements == null) {
return;
}
ModelBuilderImpl builderImpl = new ModelBuilderImpl(null);
ModelElementType processConfigType = builderImpl.defineGenericType("processConfiguration", BpmnParser.CAMUNDA_BPMN_EXTENSIONS_NS);
List<ModelElementInstance> processConfigElements = extensionElements.getElementsQuery().filterByType(processConfigType).list();
if (processConfigElements == null || processConfigElements.size() == 0) {
return;
}
ModelElementInstance processConfigElement = processConfigElements.get(0);
Map<String, WkfProcessConfig> configMap = createConfigMap(process);
ModelElementType processConfigParamType = builderImpl.defineGenericType("processConfigurationParameter", BpmnParser.CAMUNDA_BPMN_EXTENSIONS_NS);
Collection<ModelElementInstance> configParams = processConfigElement.getChildElementsByType(processConfigParamType);
for (ModelElementInstance configParam : configParams) {
WkfProcessConfig config = getProcessCofig(configMap, configParam);
config = (WkfProcessConfig) wkfService.addProperties(WkfPropertyMapper.PROCESS_CONFIG_PROPERTIES, config, configParam);
process.addWkfProcessConfigListItem(config);
}
}
use of com.axelor.apps.bpm.db.WkfProcessConfig in project axelor-open-suite by axelor.
the class WkfCommonServiceImpl method findProcessConfig.
protected WkfProcessConfig findProcessConfig(Model model, boolean isActive, int status) {
List<WkfProcessConfig> configs = wkfProcessConfigRepository.all().filter("(self.metaModel.fullName = ?1 OR self.metaJsonModel.name = ?1) " + "AND self.wkfProcess.wkfModel.statusSelect = ?2 " + "AND self.wkfProcess.wkfModel.isActive is ?3 " + "AND (self.isStartModel is true OR self.processPath is not null)", getModelName(model), status, isActive).order("pathCondition").fetch();
Map<String, Object> ctxMap = new HashMap<String, Object>();
ctxMap.put(getVarName(model), new FullContext(model));
for (WkfProcessConfig config : configs) {
boolean condition = true;
if (config.getPathCondition() != null) {
condition = (boolean) evalExpression(ctxMap, config.getPathCondition());
}
if (condition) {
return config;
}
}
return null;
}
Aggregations