use of com.axelor.studio.db.ValueMapper 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