Search in sources :

Example 1 with ValueMapper

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);
}
Also used : FullContext(com.axelor.apps.tool.context.FullContext) Context(com.axelor.rpc.Context) ValueMapper(com.axelor.studio.db.ValueMapper) ValueMapperRepository(com.axelor.studio.db.repo.ValueMapperRepository) FullContext(com.axelor.apps.tool.context.FullContext) Model(com.axelor.db.Model) ValueMapperService(com.axelor.studio.service.mapper.ValueMapperService) Map(java.util.Map) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord)

Aggregations

FullContext (com.axelor.apps.tool.context.FullContext)1 Model (com.axelor.db.Model)1 MetaJsonRecord (com.axelor.meta.db.MetaJsonRecord)1 Context (com.axelor.rpc.Context)1 ValueMapper (com.axelor.studio.db.ValueMapper)1 ValueMapperRepository (com.axelor.studio.db.repo.ValueMapperRepository)1 ValueMapperService (com.axelor.studio.service.mapper.ValueMapperService)1 Map (java.util.Map)1