use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class ImportCityServiceImpl method extractCityZip.
protected MetaFile extractCityZip(MetaFile dataFile) throws AxelorException, IOException {
ZipEntry entry;
MetaFile metaFile;
File txtFile = File.createTempFile("city", ".txt");
String requiredFileName = dataFile.getFileName().replace(".zip", ".txt");
byte[] buffer = new byte[1024];
int len;
boolean txtFileFound = false;
try (ZipInputStream zipFileInStream = new ZipInputStream(new FileInputStream(MetaFiles.getPath(dataFile).toFile()))) {
while ((entry = zipFileInStream.getNextEntry()) != null) {
if (entry.getName().equals(requiredFileName)) {
try (FileOutputStream fos = new FileOutputStream(txtFile)) {
while ((len = zipFileInStream.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
}
txtFileFound = true;
break;
}
}
if (!txtFileFound) {
printWriter.append(String.format(I18n.get(IExceptionMessage.NO_TEXT_FILE_FOUND), requiredFileName, dataFile.getFileName()) + "\n");
}
}
metaFile = metaFiles.upload(txtFile);
FileUtils.forceDelete(txtFile);
return metaFile;
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class ImportCityServiceImpl method importFromGeonamesManualConfig.
/**
* Imports cities from a custom Geonames file. This is useful for the countries not present in the
* predefined list.
*
* @param map
* @param typeSelect
* @return
*/
public Map<String, Object> importFromGeonamesManualConfig(Map<String, Object> map, String typeSelect) {
List<ImportHistory> importHistoryList = new ArrayList<>();
Map<String, Object> importCityMap = new HashMap<>();
try {
File tempDir = Files.createTempDir();
errorFile = new File(tempDir.getAbsolutePath(), "Error-File.txt");
printWriter = new PrintWriter(errorFile);
if (map != null) {
MetaFile dataFile = metaFileRepo.find(Long.parseLong(map.get("id").toString()));
importHistoryList.add(this.importCity(typeSelect + "-dump", dataFile));
}
} catch (Exception e) {
printWriter.append(e.getLocalizedMessage() + " at " + e.getStackTrace()[0] + "\n");
}
printWriter.close();
importCityMap.put("importHistoryList", importHistoryList);
importCityMap.put("errorFile", this.getMetaFile(errorFile));
return importCityMap;
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class ImportDemoDataServiceImpl method importFileData.
private MetaFile importFileData(File dataFile, File configFile, String dataFileName, String configFileName) throws IOException, AxelorException {
ImportConfiguration config = new ImportConfiguration();
MetaFile configMetaFile = metaFiles.upload(new FileInputStream(configFile), configFileName + ".xml");
MetaFile dataMetaFile = metaFiles.upload(new FileInputStream(dataFile), dataFileName + ".csv");
config.setBindMetaFile(configMetaFile);
config.setDataMetaFile(dataMetaFile);
config.setTypeSelect("csv");
ImportHistory importHistory = factoryImporter.createImporter(config).run();
MetaFiles.getPath(configMetaFile).toFile().delete();
MetaFiles.getPath(dataMetaFile).toFile().delete();
return importHistory.getLogMetaFile();
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class BatchEmploymentContractExport method employmentContractExportSilae.
@Transactional(rollbackOn = { Exception.class })
public MetaFile employmentContractExportSilae(List<EmploymentContract> employmentContractList) throws IOException {
List<String[]> list = new ArrayList<>();
for (EmploymentContract employmentContract : employmentContractList) {
Beans.get(EmploymentContractService.class).employmentContractExportSilae(employmentContract, list);
total++;
incrementDone();
}
File tempFile = MetaFiles.createTempFile(Beans.get(EmploymentContractService.class).employmentContractExportName(), ".csv").toFile();
String[] headers = Beans.get(EmploymentContractService.class).employmentContractExportHeaders();
CsvTool.csvWriter(tempFile.getParent(), tempFile.getName(), ';', headers, list);
MetaFiles metaFiles = Beans.get(MetaFiles.class);
MetaFile metaFile = metaFiles.upload(tempFile);
tempFile.delete();
return metaFile;
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class BatchPayrollPreparationExport method nibelisExport.
@Transactional(rollbackOn = { Exception.class })
public MetaFile nibelisExport(List<PayrollPreparation> payrollPreparationList) throws IOException, AxelorException {
List<String[]> list = new ArrayList<>();
for (PayrollPreparation payrollPreparation : payrollPreparationList) {
payrollPreparation.addBatchListItem(batch);
payrollPreparationService.exportNibelis(payrollPreparation, list);
total++;
}
String fileName = Beans.get(PayrollPreparationService.class).getPayrollPreparationExportName();
File file = MetaFiles.createTempFile(fileName, ".csv").toFile();
CsvTool.csvWriter(file.getParent(), file.getName(), ';', Beans.get(PayrollPreparationService.class).getPayrollPreparationMeilleurGestionExportHeader(), list);
FileInputStream inStream = new FileInputStream(file);
MetaFile metaFile = Beans.get(MetaFiles.class).upload(inStream, file.getName());
return metaFile;
}
Aggregations