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;
}
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;
}
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;
}
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;
}
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());
}
}
Aggregations