Search in sources :

Example 76 with MetaFile

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

the class ImportCityServiceImpl method importCity.

/**
 * {@inheritDoc}}
 *
 * @throws AxelorException
 * @throws IOException
 */
@Override
public ImportHistory importCity(String typeSelect, MetaFile dataFile) throws AxelorException, IOException {
    ImportHistory importHistory = null;
    if (dataFile.getFileType().equals("text/plain") || dataFile.getFileType().equals("text/csv") || dataFile.getFileType().equals("application/zip")) {
        if (dataFile.getFileType().equals("application/zip")) {
            dataFile = this.extractCityZip(dataFile);
        }
        File configXmlFile = this.getConfigXmlFile(typeSelect);
        File dataCsvFile = this.getDataCsvFile(dataFile);
        importHistory = importCityData(configXmlFile, dataCsvFile);
        this.deleteTempFiles(configXmlFile, dataCsvFile);
    } else {
        printWriter.append(I18n.get(IExceptionMessage.INVALID_DATA_FILE_EXTENSION) + "\n");
    }
    return importHistory;
}
Also used : ZipFile(java.util.zip.ZipFile) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) ImportHistory(com.axelor.apps.base.db.ImportHistory)

Example 77 with MetaFile

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

the class ImportDemoDataServiceImpl method importDemoDataExcel.

@Override
public boolean importDemoDataExcel(File excelFile, File logFile) throws FileNotFoundException, IOException, AxelorException, ParseException, ClassNotFoundException {
    Workbook workBook = new XSSFWorkbook(new FileInputStream(excelFile));
    FileOutputStream out = new FileOutputStream(logFile);
    try {
        if (this.validateExcel(excelFile, out)) {
            out = new FileOutputStream(logFile);
            for (int i = 0; i < workBook.getNumberOfSheets(); i++) {
                Sheet sheet = workBook.getSheetAt(i);
                String[] importDetails = this.getImportDetailsFromSheet(sheet);
                File dataFile = File.createTempFile(importDetails[1], ".csv");
                excelToCSV.writeTOCSV(dataFile, sheet, 3, 1);
                File configFile = File.createTempFile(importDetails[2], ".xml");
                configFile = this.getConfigFile(importDetails[0], configFile, importDetails[2]);
                MetaFile logMetaFile = this.importFileData(dataFile, configFile, importDetails[1], importDetails[2]);
                File file = MetaFiles.getPath(logMetaFile).toFile();
                out.write(("Import: " + importDetails[1]).getBytes());
                ByteStreams.copy(new FileInputStream(file), out);
                out.write("\n\n".getBytes());
            }
            return true;
        }
    } finally {
        out.close();
    }
    return false;
}
Also used : FileOutputStream(java.io.FileOutputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) MetaFile(com.axelor.meta.db.MetaFile) Sheet(org.apache.poi.ss.usermodel.Sheet) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) FileInputStream(java.io.FileInputStream)

Example 78 with MetaFile

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

the class Importer method addHistory.

/**
 * Adds a new log in the history table for data configuration.
 *
 * @param listener
 * @return
 * @throws IOException
 */
protected ImportHistory addHistory(ImporterListener listener) throws IOException {
    ImportHistory importHistory = new ImportHistory(AuthUtils.getUser(), configuration.getDataMetaFile());
    File logFile = File.createTempFile("importLog", ".log");
    try (FileWriter writer = new FileWriter(logFile)) {
        writer.write(listener.getImportLog());
    }
    MetaFile logMetaFile = metaFiles.upload(new FileInputStream(logFile), "importLog-" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".log");
    importHistory.setLogMetaFile(logMetaFile);
    importHistory.setImportConfiguration(configuration);
    return importHistory;
}
Also used : FileWriter(java.io.FileWriter) MetaFile(com.axelor.meta.db.MetaFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) SimpleDateFormat(java.text.SimpleDateFormat) FileInputStream(java.io.FileInputStream) Date(java.util.Date) ImportHistory(com.axelor.apps.base.db.ImportHistory)

Example 79 with MetaFile

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

the class TemplateMessageServiceBaseImpl method getMetaFiles.

@Override
public Set<MetaFile> getMetaFiles(Template template, Templates templates, Map<String, Object> templatesContext) throws AxelorException, IOException {
    Set<MetaFile> metaFiles = super.getMetaFiles(template, templates, templatesContext);
    Set<BirtTemplate> birtTemplates = template.getBirtTemplateSet();
    if (CollectionUtils.isEmpty(birtTemplates)) {
        return metaFiles;
    }
    for (BirtTemplate birtTemplate : birtTemplates) {
        metaFiles.add(createMetaFileUsingBirtTemplate(null, birtTemplate, templates, templatesContext));
    }
    logger.debug("Metafile to attach: {}", metaFiles);
    return metaFiles;
}
Also used : BirtTemplate(com.axelor.apps.base.db.BirtTemplate) MetaFile(com.axelor.meta.db.MetaFile)

Example 80 with MetaFile

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

the class TemplateMessageServiceBaseImpl method createMetaFileUsingBirtTemplate.

public MetaFile createMetaFileUsingBirtTemplate(TemplateMaker maker, BirtTemplate birtTemplate, Templates templates, Map<String, Object> templatesContext) throws AxelorException, IOException {
    logger.debug("Generate birt metafile: {}", birtTemplate.getName());
    String fileName = birtTemplate.getName() + "-" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
    File file = generateBirtTemplate(maker, templates, templatesContext, fileName, birtTemplate.getTemplateLink(), birtTemplate.getFormat(), birtTemplate.getBirtTemplateParameterList());
    try (InputStream is = new FileInputStream(file)) {
        return Beans.get(MetaFiles.class).upload(is, fileName + "." + birtTemplate.getFormat());
    }
}
Also used : MetaFiles(com.axelor.meta.MetaFiles) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) FileInputStream(java.io.FileInputStream)

Aggregations

MetaFile (com.axelor.meta.db.MetaFile)87 File (java.io.File)50 FileInputStream (java.io.FileInputStream)25 IOException (java.io.IOException)24 AxelorException (com.axelor.exception.AxelorException)21 MetaFiles (com.axelor.meta.MetaFiles)18 Transactional (com.google.inject.persist.Transactional)17 ArrayList (java.util.ArrayList)13 Path (java.nio.file.Path)12 InputStream (java.io.InputStream)10 ZipFile (java.util.zip.ZipFile)9 FileOutputStream (java.io.FileOutputStream)8 MetaFileRepository (com.axelor.meta.db.repo.MetaFileRepository)7 ImportHistory (com.axelor.apps.base.db.ImportHistory)6 DMSFile (com.axelor.dms.db.DMSFile)6 HashMap (java.util.HashMap)6 ZipEntry (java.util.zip.ZipEntry)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ZipInputStream (java.util.zip.ZipInputStream)4 App (com.axelor.apps.base.db.App)3