Search in sources :

Example 1 with MetaModel

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

the class DataImportServiceImpl method createDataFileName.

private String createDataFileName(FileTab fileTab) {
    String fileName = null;
    MetaModel model = fileTab.getMetaModel();
    Long fileTabId = fileTab.getId();
    try {
        Mapper mapper = advancedImportService.getMapper(model.getFullName());
        fileName = inflector.camelize(mapper.getBeanClass().getSimpleName(), true) + fileTabId + ".csv";
    } catch (ClassNotFoundException e) {
        TraceBackService.trace(e);
    }
    return fileName;
}
Also used : Mapper(com.axelor.db.mapper.Mapper) MetaModel(com.axelor.meta.db.MetaModel)

Example 2 with MetaModel

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

the class FileFieldServiceImpl method getSubFieldType.

private String[] getSubFieldType(String[] subFields, int index, MetaField parentField) {
    String[] types = new String[2];
    if (index < subFields.length) {
        types[0] = parentField.getTypeName();
        types[1] = parentField.getRelationship();
        MetaModel childModel = metaModelRepo.findByName(parentField.getTypeName());
        if (childModel != null) {
            MetaField childField = metaFieldRepo.findByModel(subFields[index], childModel);
            if (childField == null) {
                return types;
            }
            if (childField.getRelationship() != null) {
                if (!types[0].equals("MetaFile")) {
                    types[0] = childField.getTypeName();
                }
                types[1] = childField.getRelationship();
                types = this.getSubFieldType(subFields, index + 1, childField);
            } else {
                if (!types[0].equals("MetaFile")) {
                    types[0] = childField.getTypeName();
                }
            }
        }
    } else {
        if ((!Strings.isNullOrEmpty(types[0]) && !types[0].equals("MetaFile")) || Strings.isNullOrEmpty(types[0])) {
            types[0] = parentField.getTypeName();
        }
        types[1] = parentField.getRelationship();
    }
    return types;
}
Also used : MetaModel(com.axelor.meta.db.MetaModel) MetaField(com.axelor.meta.db.MetaField)

Example 3 with MetaModel

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

the class PrintTemplateServiceImpl method generatePrint.

@SuppressWarnings("unchecked")
@Override
@Transactional(rollbackOn = { AxelorException.class, Exception.class })
public Print generatePrint(Long objectId, PrintTemplate printTemplate) throws AxelorException, IOException, ClassNotFoundException {
    MetaModel metaModel = printTemplate.getMetaModel();
    if (metaModel == null) {
        return null;
    }
    String model = metaModel.getFullName();
    String simpleModel = metaModel.getName();
    // debug
    LOG.debug("");
    LOG.debug("model : {}", model);
    LOG.debug("simpleModel : {}", simpleModel);
    LOG.debug("object id : {}", objectId);
    LOG.debug("printTemplate : {}", printTemplate);
    LOG.debug("");
    Locale locale = Optional.ofNullable(printTemplate.getLanguage()).map(Language::getCode).map(Locale::new).orElseGet(AppFilter::getLocale);
    TemplateMaker maker = initMaker(objectId, model, simpleModel, locale);
    Print print = new Print();
    if (StringUtils.notEmpty(printTemplate.getDocumentName())) {
        maker.setTemplate(printTemplate.getDocumentName());
        print.setDocumentName(maker.make());
    }
    print.setMetaModel(metaModel);
    print.setObjectId(objectId);
    print.setCompany(printTemplate.getCompany());
    print.setLanguage(printTemplate.getLanguage());
    print.setHidePrintSettings(printTemplate.getHidePrintSettings());
    print.setFormatSelect(printTemplate.getFormatSelect());
    print.setDisplayTypeSelect(printTemplate.getDisplayTypeSelect());
    print.setIsEditable(printTemplate.getIsEditable());
    print.setAttach(printTemplate.getAttach());
    print.setMetaFileField(printTemplate.getMetaFileField());
    if (!printTemplate.getHidePrintSettings()) {
        if (StringUtils.notEmpty(printTemplate.getPrintTemplatePdfHeader())) {
            maker.setTemplate(printTemplate.getPrintTemplatePdfHeader());
            print.setPrintPdfHeader(maker.make());
        }
        if (StringUtils.notEmpty(printTemplate.getPrintTemplatePdfFooter())) {
            maker.setTemplate(printTemplate.getPrintTemplatePdfFooter());
            print.setPrintPdfFooter(maker.make());
            print.setFooterFontSize(printTemplate.getFooterFontSize());
            print.setFooterFontType(printTemplate.getFooterFontType());
            print.setFooterTextAlignment(printTemplate.getFooterTextAlignment());
            print.setIsFooterUnderLine(printTemplate.getIsFooterUnderLine());
            print.setFooterFontColor(printTemplate.getFooterFontColor());
        }
        print.setLogoPositionSelect(printTemplate.getLogoPositionSelect());
        print.setLogoWidth(printTemplate.getLogoWidth());
        print.setHeaderContentWidth(printTemplate.getHeaderContentWidth());
    }
    Context scriptContext = null;
    if (StringUtils.notEmpty(model)) {
        Class<? extends Model> modelClass = (Class<? extends Model>) Class.forName(model);
        Model modelObject = JPA.find(modelClass, objectId);
        if (ObjectUtils.notEmpty(modelObject)) {
            scriptContext = new Context(Mapper.toMap(modelObject), modelClass);
        }
    }
    rank = 0;
    int level = 1;
    if (CollectionUtils.isNotEmpty(printTemplate.getPrintTemplateLineList())) {
        processPrintTemplateLineList(printTemplate.getPrintTemplateLineList(), print, null, scriptContext, maker, level);
    }
    if (CollectionUtils.isNotEmpty(printTemplate.getPrintTemplateSet())) {
        for (PrintTemplate subPrintTemplate : printTemplate.getPrintTemplateSet()) {
            Long subObjectId = objectId;
            if (StringUtils.notEmpty(subPrintTemplate.getMetaModelDefaultPath())) {
                Object subMetaModelObject = templateContextService.computeTemplateContext(subPrintTemplate.getMetaModelDefaultPath(), scriptContext);
                Class<? extends Model> subModelClass = (Class<? extends Model>) Class.forName(subPrintTemplate.getMetaModel().getFullName());
                subObjectId = (Long) Mapper.of(subModelClass).get(subMetaModelObject, "id");
            }
            Print subPrint = generatePrint(subObjectId, subPrintTemplate);
            print.addPrintSetItem(subPrint);
        }
    }
    print = printRepo.save(print);
    printService.attachMetaFiles(print, getMetaFiles(maker, printTemplate));
    return print;
}
Also used : Locale(java.util.Locale) TemplateContext(com.axelor.apps.message.db.TemplateContext) Context(com.axelor.rpc.Context) PrintTemplate(com.axelor.apps.base.db.PrintTemplate) Print(com.axelor.apps.base.db.Print) Print(com.axelor.apps.base.db.Print) MetaModel(com.axelor.meta.db.MetaModel) AppFilter(com.axelor.app.internal.AppFilter) Language(com.axelor.apps.base.db.Language) TemplateMaker(com.axelor.tool.template.TemplateMaker) Model(com.axelor.db.Model) MetaModel(com.axelor.meta.db.MetaModel) Transactional(com.google.inject.persist.Transactional)

Example 4 with MetaModel

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

the class AdvancedImportServiceImpl method setFileTabConfig.

protected void setFileTabConfig(String[] row, FileTab fileTab, int rowIndex) throws AxelorException {
    final String KEY_OBJECT = "object";
    final String KEY_IMPORT_TYPE = "importtype";
    final String KEY_SEARCH_FIELD_SET = "searchfieldset";
    final String KEY_ACTIONS = "actions";
    final String KEY_SEARCH_CALL = "search-call";
    final List<String> KEY_LIST = Arrays.asList(KEY_IMPORT_TYPE, KEY_OBJECT, KEY_SEARCH_FIELD_SET, KEY_ACTIONS, KEY_SEARCH_CALL);
    Map<String, String> tabConfigDataMap = getTabConfigDataMap(row, KEY_LIST);
    MetaModel model = metaModelRepo.findByName(tabConfigDataMap.get(KEY_OBJECT));
    fileTab.setMetaModel(model);
    if (tabConfigDataMap.containsKey(KEY_IMPORT_TYPE)) {
        Integer importType = this.getImportType(null, tabConfigDataMap.get(KEY_IMPORT_TYPE));
        fileTab.setImportType(importType);
        if (importType != FileFieldRepository.IMPORT_TYPE_NEW) {
            if (!tabConfigDataMap.containsKey(KEY_SEARCH_FIELD_SET) && !tabConfigDataMap.containsKey(KEY_SEARCH_CALL)) {
                throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.ADVANCED_IMPORT_6), fileTab.getName());
            }
            if (tabConfigDataMap.containsKey(KEY_SEARCH_CALL)) {
                fileTab.setSearchCall(tabConfigDataMap.get(KEY_SEARCH_CALL));
            } else {
                searchFieldList = Arrays.asList(tabConfigDataMap.get(KEY_SEARCH_FIELD_SET).split("\\,"));
            }
        }
    }
    fileTab.setActions(tabConfigDataMap.get(KEY_ACTIONS));
}
Also used : AxelorException(com.axelor.exception.AxelorException) MetaModel(com.axelor.meta.db.MetaModel)

Example 5 with MetaModel

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

the class FileTabServiceImpl method getSubImportField.

private String getSubImportField(MetaField importField) throws ClassNotFoundException {
    String modelName = importField.getTypeName();
    MetaModel metaModel = Beans.get(MetaModelRepository.class).findByName(modelName);
    AdvancedImportService advancedImportService = Beans.get(AdvancedImportService.class);
    Mapper mapper = advancedImportService.getMapper(metaModel.getFullName());
    return (mapper != null && mapper.getNameField() != null) ? mapper.getNameField().getName() : null;
}
Also used : Mapper(com.axelor.db.mapper.Mapper) MetaModel(com.axelor.meta.db.MetaModel) MetaModelRepository(com.axelor.meta.db.repo.MetaModelRepository)

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