Search in sources :

Example 1 with AdvancedExportLine

use of com.axelor.apps.base.db.AdvancedExportLine in project axelor-open-suite by axelor.

the class AdvancedExportServiceImpl method getAdvancedExportQuery.

/**
 * This method split and join the all fields/columns which are selected by user and create the
 * query.
 *
 * @param advancedExport
 * @param criteria
 * @return
 * @throws AxelorException
 * @throws ClassNotFoundException
 */
@Override
public Query getAdvancedExportQuery(AdvancedExport advancedExport, List<Long> recordIds) throws AxelorException {
    StringBuilder selectFieldBuilder = new StringBuilder();
    StringBuilder orderByFieldBuilder = new StringBuilder();
    joinFieldSet.clear();
    selectionJoinFieldSet.clear();
    isNormalField = true;
    selectField = "";
    msi = 0;
    mt = 0;
    int col = 0;
    language = Optional.ofNullable(AuthUtils.getUser()).map(User::getLanguage).orElse(null);
    try {
        if (language == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get("Please select a language on user form."));
        }
        for (AdvancedExportLine advancedExportLine : advancedExport.getAdvancedExportLineList()) {
            String[] splitField = advancedExportLine.getTargetField().split("\\.");
            String alias = "Col_" + col;
            createQueryParts(splitField, 0, advancedExport.getMetaModel());
            selectFieldBuilder.append(aliasName + selectField + " AS " + alias + ",");
            if (advancedExportLine.getOrderBy()) {
                orderByFieldBuilder.append(alias + " " + advancedExportLine.getOrderByType() + ",");
            }
            selectField = "";
            aliasName = "";
            col++;
        }
        if (StringUtils.notEmpty(orderByFieldBuilder)) {
            orderByFieldBuilder.append("self.id asc,");
        }
    } catch (ClassNotFoundException e) {
        TraceBackService.trace(e);
        throw new AxelorException(e, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR);
    }
    return createQuery(createQueryBuilder(advancedExport, selectFieldBuilder, recordIds, orderByFieldBuilder));
}
Also used : AxelorException(com.axelor.exception.AxelorException) User(com.axelor.auth.db.User) AdvancedExportLine(com.axelor.apps.base.db.AdvancedExportLine)

Example 2 with AdvancedExportLine

use of com.axelor.apps.base.db.AdvancedExportLine in project axelor-open-suite by axelor.

the class ExcelExportGenerator method generateHeader.

@Override
public void generateHeader() {
    Row headerRow = sheet.createRow(sheet.getFirstRowNum());
    int colHeaderNum = 0;
    for (AdvancedExportLine advancedExportLine : advancedExport.getAdvancedExportLineList()) {
        Cell headerCell = headerRow.createCell(colHeaderNum++);
        headerCell.setCellValue(I18n.get(advancedExportLine.getTitle()));
    }
}
Also used : AdvancedExportLine(com.axelor.apps.base.db.AdvancedExportLine) Row(org.apache.poi.ss.usermodel.Row) Cell(org.apache.poi.ss.usermodel.Cell)

Example 3 with AdvancedExportLine

use of com.axelor.apps.base.db.AdvancedExportLine 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 4 with AdvancedExportLine

use of com.axelor.apps.base.db.AdvancedExportLine in project axelor-open-suite by axelor.

the class CsvExportGenerator method generateHeader.

@Override
public void generateHeader() {
    int index = 0;
    for (AdvancedExportLine advancedExportLine : advancedExport.getAdvancedExportLineList()) {
        totalCols[index++] = I18n.get(advancedExportLine.getTitle());
    }
    csvWriter.writeNext(totalCols);
}
Also used : AdvancedExportLine(com.axelor.apps.base.db.AdvancedExportLine)

Example 5 with AdvancedExportLine

use of com.axelor.apps.base.db.AdvancedExportLine in project axelor-open-suite by axelor.

the class PdfExportGenerator method generateHeader.

@Override
public void generateHeader() throws AxelorException {
    try {
        PdfPCell headerCell;
        for (AdvancedExportLine advancedExportLine : advancedExport.getAdvancedExportLineList()) {
            headerCell = new PdfPCell(new Phrase(I18n.get(advancedExportLine.getTitle()), new Font(BaseFont.createFont(), 8, 0, BaseColor.WHITE)));
            headerCell.setBackgroundColor(BaseColor.GRAY);
            headerCell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(headerCell);
        }
    } catch (DocumentException | IOException e) {
        TraceBackService.trace(e);
        throw new AxelorException(e, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) PdfPCell(com.itextpdf.text.pdf.PdfPCell) AdvancedExportLine(com.axelor.apps.base.db.AdvancedExportLine) DocumentException(com.itextpdf.text.DocumentException) Phrase(com.itextpdf.text.Phrase) IOException(java.io.IOException) Font(com.itextpdf.text.Font) BaseFont(com.itextpdf.text.pdf.BaseFont)

Aggregations

AdvancedExportLine (com.axelor.apps.base.db.AdvancedExportLine)5 AxelorException (com.axelor.exception.AxelorException)2 User (com.axelor.auth.db.User)1 Mapper (com.axelor.db.mapper.Mapper)1 MetaField (com.axelor.meta.db.MetaField)1 MetaModel (com.axelor.meta.db.MetaModel)1 MetaModelRepository (com.axelor.meta.db.repo.MetaModelRepository)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DocumentException (com.itextpdf.text.DocumentException)1 Font (com.itextpdf.text.Font)1 Phrase (com.itextpdf.text.Phrase)1 BaseFont (com.itextpdf.text.pdf.BaseFont)1 PdfPCell (com.itextpdf.text.pdf.PdfPCell)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Cell (org.apache.poi.ss.usermodel.Cell)1 Row (org.apache.poi.ss.usermodel.Row)1