use of com.axelor.apps.tool.context.FullContext in project axelor-open-suite by axelor.
the class WkfUserActionServiceImpl method getModelCtx.
@Override
public FullContext getModelCtx(WkfTaskConfig wkfTaskConfig, DelegateExecution execution) throws ClassNotFoundException {
String modelName = null;
Class<? extends Model> modelClass = null;
if (wkfTaskConfig.getModelName() != null) {
modelName = wkfTaskConfig.getModelName();
modelClass = (Class<? extends Model>) Class.forName(Beans.get(MetaModelRepository.class).findByName(modelName).getFullName());
} else if (wkfTaskConfig.getJsonModelName() != null) {
modelName = wkfTaskConfig.getJsonModelName();
modelClass = MetaJsonRecord.class;
} else {
return null;
}
String varName = wkfService.getVarName(modelName);
Object id = execution.getVariable(varName + "Id");
FullContext wkfContext = null;
if (id != null && id instanceof Long) {
Model record = JPA.find(modelClass, Long.parseLong(id.toString()));
wkfContext = new FullContext(record);
}
return wkfContext;
}
use of com.axelor.apps.tool.context.FullContext in project axelor-open-suite by axelor.
the class DmnServiceImpl method findResult.
private Object findResult(Object value, String subField, String targetModel, boolean isCollection, boolean isSet) throws AxelorException {
Object params = getParameter(value);
String query = getQuery(subField, params instanceof Collection);
log.debug("Find result for: {} , value: {}, targetModel: {}", subField, value, targetModel);
if (isCollection) {
Collection resultCollection = null;
if (isSet) {
resultCollection = new HashSet<>();
} else {
resultCollection = new ArrayList<>();
}
if (params == null) {
return resultCollection;
}
for (FullContext res : FullContextHelper.filter(targetModel, query, params)) {
resultCollection.add(res.getTarget());
}
return resultCollection;
}
if (params == null) {
return null;
}
return WkfContextHelper.filterOne(targetModel, query, params).getTarget();
}
use of com.axelor.apps.tool.context.FullContext in project axelor-open-suite by axelor.
the class AxelorScriptEngine method eval.
@Override
public Object eval(String script, ScriptContext ctx) {
Bindings bindings = ctx.getBindings(ctx.getScopes().get(0));
bindings.put("$json", Beans.get(MetaJsonRecordRepository.class));
bindings.put("$ctx", WkfContextHelper.class);
bindings.put("$beans", Beans.class);
bindings.put("__user__", new FullContext(AuthUtils.getUser()));
return new GroovyScriptHelper(bindings).eval(script);
}
use of com.axelor.apps.tool.context.FullContext in project axelor-open-suite by axelor.
the class AppLoaderExportServiceImpl method addMetaModelData.
protected void addMetaModelData(AppDataLoader dataLoader, File parentDir) {
try {
Class klass = Class.forName(dataLoader.getMetaModel().getFullName());
if (!allowRead(klass)) {
return;
}
Mapper modelMapper = Mapper.of(klass);
String modelName = dataLoader.getMetaModel().getName();
String dasherizeModel = Inflector.getInstance().dasherize(modelName);
File dataFile = new File(parentDir, modelName + ".xml");
FileWriter fileWriter = createHeader(dasherizeModel, dataFile);
List<FullContext> records = FullContextHelper.filter(modelName, dataLoader.getFilterQuery());
for (FullContext record : records) {
if (!allowRead(klass, (Long) record.get("id"))) {
continue;
}
fileWriter.write("<" + dasherizeModel + ">\n");
for (MetaField metaField : dataLoader.getMetaFieldSet()) {
String field = metaField.getName();
fileWriter.write("\t<" + field + ">" + extractMetaFieldValue(record, modelMapper.getProperty(field)) + "</" + field + ">\n");
}
fileWriter.write("</" + dasherizeModel + ">\n\n");
}
fileWriter.write("</" + dasherizeModel + "s>\n");
fileWriter.close();
} catch (IOException | ClassNotFoundException e) {
TraceBackService.trace(e);
}
}
use of com.axelor.apps.tool.context.FullContext in project axelor-open-suite by axelor.
the class ValueMapperService method execute.
public Object execute(ValueMapper mapper, Model model) {
if (model == null || mapper == null) {
return null;
}
String modelName = getModelVariable(model);
Bindings bindings = new SimpleBindings();
bindings.put("$ctx", FullContextHelper.class);
bindings.put(modelName, new FullContext(model));
bindings.put(modelName + "Id", model.getId());
Object result = new GroovyScriptHelper(bindings).eval(mapper.getScript());
return result;
}
Aggregations