package com.axelor.apps.base.web;

import com.axelor.apps.base.db.Language;
import com.axelor.apps.base.db.repo.LanguageRepository;
import com.axelor.apps.message.db.Template;
import com.axelor.apps.message.db.repo.TemplateRepository;
import com.axelor.apps.message.service.TemplateMessageService;
import com.axelor.rpc.ActionRequest;
import com.axelor.rpc.ActionResponse;
import com.axelor.rpc.Context;
import com.google.inject.Inject;

import java.util.LinkedHashMap;
import java.util.Map;

public class GenerateMessageController {

    @Inject
    private TemplateMessageService templateMessageService;

    @Inject
    private TemplateRepository templateRepo;

    @Inject
    private LanguageRepository languageRepo;

    public void templateDomain(ActionRequest request, ActionResponse response) {
        Context context = request.getContext();

        String model = (String) context.get("_templateContextModel");

//        Object templateObj = context.get("_xTemplate");
//        Template template;
//        if (templateObj == null) {
//            template = null;
//        } else if (templateObj instanceof Map) {
//            Map<String, Object> templateMap = (Map<String, Object>) templateObj;
//            template = templateRepo.find( Long.parseLong(templateMap.get("id").toString()) );
//        } else if (templateObj instanceof Template) {
//            template = (Template) templateObj;
//        } else {
//            throw new IllegalArgumentException("erreur...");
//        }

        Object languageObj = context.get("language");
        Language language;
        if (languageObj == null) {
            language = null;
        } else if (languageObj instanceof Map) {
            Map<String, Object> languageMap = (Map<String, Object>) languageObj;
            language = languageRepo.find( Long.parseLong(languageMap.get("id").toString()) );
        } else if (languageObj instanceof Language) {
            language = (Language) languageObj;
        } else {
            throw new IllegalArgumentException("erreur...");
        }

        String domain;

        if (language == null) {
            domain = "self.metaModel.fullName = '" + model + "' and self.isSystem != true";
        } else {
            domain = "self.metaModel.fullName = '" + model + "' and self.isSystem != true and self.language.id = " + language.getId();
        }

        response.setAttr("_xTemplate","domain",domain);
    }

}

@@ -921,593 +921,8 @@
 );%0A%0A
-//        Object templateObj = context.get(%22_xTemplate%22);%0A//        Template template;%0A//        if (templateObj == null) %7B%0A//            template = null;%0A//        %7D else if (templateObj instanceof Map) %7B%0A//            Map%3CString, Object%3E templateMap = (Map%3CString, Object%3E) templateObj;%0A//            template = templateRepo.find( Long.parseLong(templateMap.get(%22id%22).toString()) );%0A//        %7D else if (templateObj instanceof Template) %7B%0A//            template = (Template) templateObj;%0A//        %7D else %7B%0A//            throw new IllegalArgumentException(%22erreur...%22);%0A//        %7D%0A%0A
     

Update GenerateMessageController.java