use of com.axelor.apps.tool.context.FullContext in project axelor-open-suite by axelor.
the class WkfCommonServiceImpl method findRelatedRecord.
@Override
public Object findRelatedRecord(Model model, String path) throws AxelorException {
Object object = null;
FullContext wkfModel = new FullContext(model);
if (path.startsWith("_find(")) {
List<String> params = Arrays.asList(path.replace("_find(", "").replace(")", "").split(","));
if (params.size() >= 2) {
List<Object> queryParams = params.stream().map(it -> evalExpression(wkfModel, it)).collect(Collectors.toList());
String queryModel = (String) queryParams.get(0);
queryParams.remove(0);
String query = (String) queryParams.get(0);
queryParams.remove(0);
log.debug("Find model: {}, query: {}, params: {}", queryModel, query, queryParams);
object = WkfContextHelper.filterOne(queryModel, query, queryParams.toArray());
}
} else {
object = evalExpression(new FullContext(model), path);
}
return object;
}
use of com.axelor.apps.tool.context.FullContext in project axelor-open-suite by axelor.
the class WkfCommonServiceImpl method createVariables.
@Override
public Map<String, Object> createVariables(Map<String, Object> modelMap) {
Map<String, Object> varMap = new HashMap<String, Object>();
for (String name : modelMap.keySet()) {
Object model = modelMap.get(name);
if (model == null) {
varMap.put(name, Variables.objectValue(null, true).create());
continue;
}
ObjectValue var = null;
Long id = null;
if (model instanceof Model) {
var = Variables.objectValue(model, true).serializationDataFormat(JPAVariableSerializer.NAME).create();
id = ((Model) model).getId();
} else {
var = Variables.objectValue(model, true).serializationDataFormat(SerializationDataFormats.JSON).create();
if (model instanceof FullContext) {
id = (Long) ((FullContext) model).get("id");
}
}
varMap.put(name, var);
if (id != null) {
varMap.put(name + "Id", Variables.longValue(id));
}
}
log.debug("Process variables: {}", varMap);
return varMap;
}
use of com.axelor.apps.tool.context.FullContext 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.apps.tool.context.FullContext 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;
}
}
}
}
use of com.axelor.apps.tool.context.FullContext 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;
}
Aggregations