use of com.axelor.apps.tool.context.FullContext in project axelor-open-suite by axelor.
the class DmnServiceImpl method executeDmn.
@Override
@Transactional
public void executeDmn(String decisionDefinitionId, Model model) throws AxelorException {
ProcessEngine processEngine = Beans.get(ProcessEngineService.class).getEngine();
FullContext context = new FullContext(model);
String varName = Beans.get(WkfCommonService.class).getVarName(EntityHelper.getEntity(model));
Map<String, Object> modelMap = new HashMap<String, Object>();
modelMap.put(varName, context);
DmnDecisionTableResult dmnDecisionTableResult = processEngine.getDecisionService().evaluateDecisionTableByKey(decisionDefinitionId, modelMap);
List<Map<String, Object>> result = dmnDecisionTableResult.getResultList();
DmnTable dmnTable = Beans.get(DmnTableRepository.class).all().filter("self.decisionId = ?1", decisionDefinitionId).fetchOne();
if (dmnTable != null) {
Map<String, Object> res = result.get(0);
for (DmnField dmnField : dmnTable.getOutputDmnFieldList()) {
if (dmnField.getField() != null) {
addValue(context, dmnField.getField(), res.get(dmnField.getName()), model);
}
}
}
JpaRepository.of(EntityHelper.getEntityClass(model)).save(model);
}
use of com.axelor.apps.tool.context.FullContext in project axelor-open-suite by axelor.
the class AppLoaderExportServiceImpl method addJsonModelData.
protected void addJsonModelData(AppDataLoader dataLoader, File parentDir) {
try {
if (!allowRead(MetaJsonRecord.class)) {
return;
}
String modelName = dataLoader.getJsonModel().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());
Map<String, Object> jsonFieldMap = MetaStore.findJsonFields(modelName);
fixTargetName(jsonFieldMap);
for (FullContext record : records) {
if (!allowRead(MetaJsonRecord.class, (Long) record.get("id"))) {
continue;
}
fileWriter.write("<" + dasherizeModel + ">\n");
for (MetaJsonField jsonField : dataLoader.getJsonFieldSet()) {
String field = jsonField.getName();
Map<String, Object> fieldAttrs = (Map<String, Object>) jsonFieldMap.get(field);
fileWriter.write("\t<" + field + ">" + extractJsonFieldValue(record, fieldAttrs) + "</" + field + ">\n");
}
fileWriter.write("</" + dasherizeModel + ">\n\n");
}
fileWriter.write("</" + dasherizeModel + "s>\n");
fileWriter.close();
} catch (IOException e) {
TraceBackService.trace(e);
}
}
use of com.axelor.apps.tool.context.FullContext in project axelor-open-suite by axelor.
the class ValueMapperController method execute.
public void execute(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
Map<String, Object> valueMapperMap = (Map<String, Object>) context.get("valueMapper");
ValueMapper mapper = Beans.get(ValueMapperRepository.class).find(Long.parseLong(valueMapperMap.get("id").toString()));
if (mapper == null || mapper.getScript() == null) {
return;
}
String modelName = (String) context.get("modelName");
Model model = null;
if (context.get("recordId") != null && modelName != null) {
Long recordId = Long.parseLong(context.get("recordId").toString());
model = FullContextHelper.getRepository(modelName).find(recordId);
}
Object result = Beans.get(ValueMapperService.class).execute(mapper, model);
if (result != null && result instanceof FullContext && mapper.getScript().startsWith("def rec = $ctx.create(")) {
FullContext fullContext = (FullContext) result;
Object object = fullContext.getTarget();
String title = object.getClass().getSimpleName();
if (object instanceof MetaJsonRecord) {
title = ((MetaJsonRecord) object).getJsonModel();
}
response.setView(ActionView.define(I18n.get(title)).model(object.getClass().getName()).add("form").add("grid").context("_showRecord", fullContext.get("id")).map());
}
response.setCanClose(true);
}
Aggregations