Search in sources :

Example 21 with MetaModel

use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.

the class AdvancedExportController method metaFieldDomain.

public void metaFieldDomain(ActionRequest request, ActionResponse response) throws ClassNotFoundException {
    AdvancedExportLine adv = request.getContext().asType(AdvancedExportLine.class);
    MetaModel metaModel = Beans.get(MetaModelRepository.class).findByName(adv.getCurrentDomain());
    List<MetaField> metaFields = metaModel.getMetaFields();
    List<Long> metaFieldList = new ArrayList<>();
    if (metaFields != null) {
        Class<?> klass = Class.forName(metaModel.getFullName());
        Mapper mapper = Mapper.of(klass);
        for (MetaField field : metaFields) {
            if (!mapper.getProperty(field.getName()).isTransient()) {
                metaFieldList.add(field.getId());
            }
        }
    }
    metaFieldList.add(0L);
    response.setAttr("metaField", "domain", "self.id in (" + Joiner.on(",").join(metaFieldList) + ")");
}
Also used : Mapper(com.axelor.db.mapper.Mapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MetaModel(com.axelor.meta.db.MetaModel) MetaModelRepository(com.axelor.meta.db.repo.MetaModelRepository) AdvancedExportLine(com.axelor.apps.base.db.AdvancedExportLine) MetaField(com.axelor.meta.db.MetaField) ArrayList(java.util.ArrayList)

Example 22 with MetaModel

use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.

the class BatchTimesheetReminder method process.

@Override
protected void process() {
    Template template = batch.getHrBatch().getTemplate();
    MetaModel metaModel = template.getMetaModel();
    try {
        if (metaModel != null) {
            if (metaModel.getName().equals(Employee.class.getSimpleName())) {
                sendReminderUsingEmployees(template);
            } else if (metaModel.getName().equals(Timesheet.class.getSimpleName())) {
                sendReminderUsingTimesheets(template);
            }
        }
    } catch (Exception e) {
        TraceBackService.trace(e, metaModel.getName(), batch.getId());
        incrementAnomaly();
    }
}
Also used : MetaModel(com.axelor.meta.db.MetaModel) Employee(com.axelor.apps.hr.db.Employee) MessagingException(javax.mail.MessagingException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) Template(com.axelor.apps.message.db.Template)

Example 23 with MetaModel

use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.

the class PrintTemplateLineController method checkTemplateLineExpression.

public void checkTemplateLineExpression(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    PrintTemplateLineTest printTemplateLineTest = context.asType(PrintTemplateLineTest.class);
    printTemplateLineTest = Beans.get(PrintTemplateLineTestRepository.class).find(printTemplateLineTest.getId());
    MetaModel metaModel = Beans.get(MetaModelRepository.class).all().filter("self.fullName = ?", printTemplateLineTest.getReference()).fetchOne();
    try {
        Beans.get(PrintTemplateLineService.class).checkExpression(Long.valueOf(printTemplateLineTest.getReferenceId().toString()), metaModel, printTemplateLineTest.getPrintTemplateLine());
    } catch (NumberFormatException | ClassNotFoundException | AxelorException | IOException e) {
        TraceBackService.trace(response, e);
    }
    response.setReload(true);
}
Also used : Context(com.axelor.rpc.Context) AxelorException(com.axelor.exception.AxelorException) MetaModel(com.axelor.meta.db.MetaModel) MetaModelRepository(com.axelor.meta.db.repo.MetaModelRepository) PrintTemplateLineTest(com.axelor.apps.base.db.PrintTemplateLineTest) IOException(java.io.IOException) PrintTemplateLineService(com.axelor.apps.base.service.PrintTemplateLineService)

Example 24 with MetaModel

use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.

the class PrintTemplateLineController method addItemToReferenceSelection.

@SuppressWarnings("unchecked")
public void addItemToReferenceSelection(ActionRequest request, ActionResponse response) {
    LinkedHashMap<String, Object> metaModelMap = (LinkedHashMap<String, Object>) request.getContext().get("metaModel");
    if (metaModelMap == null) {
        return;
    }
    Long metaModelId = Long.parseLong(metaModelMap.get("id").toString());
    MetaModel metaModel = Beans.get(MetaModelRepository.class).find(metaModelId);
    Beans.get(PrintTemplateLineService.class).addItemToReferenceSelection(metaModel);
    response.setNotify(I18n.get(IExceptionMessage.PRINT_TEMPLATE_LINE_TEST_REFRESH));
}
Also used : MetaModel(com.axelor.meta.db.MetaModel) MetaModelRepository(com.axelor.meta.db.repo.MetaModelRepository) PrintTemplateLineService(com.axelor.apps.base.service.PrintTemplateLineService) LinkedHashMap(java.util.LinkedHashMap)

Example 25 with MetaModel

use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.

the class FilterGroovyService method getMetaFieldType.

private String getMetaFieldType(MetaField field, String targetField, boolean isJson) throws AxelorException {
    if (targetField == null || !targetField.contains(".")) {
        return field.getTypeName();
    }
    targetField = targetField.substring(targetField.indexOf(".") + 1);
    String targetName = targetField.contains(".") ? targetField.substring(0, targetField.indexOf(".")) : targetField;
    MetaModel model = metaModelRepo.findByName(field.getTypeName());
    if (model == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, "No model found: %s ", field.getName());
    }
    MetaField subMeta = filterSqlService.findMetaField(targetName, model.getFullName());
    if (subMeta != null) {
        return getMetaFieldType(subMeta, targetField, isJson);
    } else if (isJson) {
        MetaJsonField subJson = filterSqlService.findJsonField(targetName, model.getName());
        if (subJson != null) {
            return getJsonFieldType(subJson, targetField);
        }
    }
    throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, "No sub field found field: %s model: %s ", targetName, model.getFullName());
}
Also used : AxelorException(com.axelor.exception.AxelorException) MetaModel(com.axelor.meta.db.MetaModel) MetaField(com.axelor.meta.db.MetaField) MetaJsonField(com.axelor.meta.db.MetaJsonField)

Aggregations

MetaModel (com.axelor.meta.db.MetaModel)41 MetaModelRepository (com.axelor.meta.db.repo.MetaModelRepository)12 AxelorException (com.axelor.exception.AxelorException)9 MetaField (com.axelor.meta.db.MetaField)9 ArrayList (java.util.ArrayList)8 Model (com.axelor.db.Model)7 Mapper (com.axelor.db.mapper.Mapper)6 IOException (java.io.IOException)6 Transactional (com.google.inject.persist.Transactional)5 List (java.util.List)5 App (com.axelor.apps.base.db.App)4 Property (com.axelor.db.mapper.Property)4 MetaJsonModel (com.axelor.meta.db.MetaJsonModel)4 Context (com.axelor.rpc.Context)4 AuditableModel (com.axelor.auth.db.AuditableModel)3 CSVInput (com.axelor.data.csv.CSVInput)3 MetaFile (com.axelor.meta.db.MetaFile)3 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)3 AppFilter (com.axelor.app.internal.AppFilter)2 AdvancedExport (com.axelor.apps.base.db.AdvancedExport)2