use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class ImportCityController method importCity.
/**
* Import cities
*
* @param request
* @param response
* @throws InterruptedException
*/
@SuppressWarnings("unchecked")
public void importCity(ActionRequest request, ActionResponse response) {
try {
List<ImportHistory> importHistoryList = null;
Map<String, Object> importCityMap = null;
MetaFile errorFile = null;
String typeSelect = (String) request.getContext().get("typeSelect");
if (CityRepository.TYPE_SELECT_GEONAMES.equals(typeSelect)) {
String importTypeSelect = (String) request.getContext().get("importTypeSelect");
switch(importTypeSelect) {
case CityRepository.IMPORT_TYPE_SELECT_AUTO:
String downloadFileName = (String) request.getContext().get("autoImportTypeSelect");
importCityMap = Beans.get(ImportCityService.class).importFromGeonamesAutoConfig(downloadFileName, typeSelect);
break;
case CityRepository.IMPORT_TYPE_SELECT_MANUAL:
Map<String, Object> map = (LinkedHashMap<String, Object>) request.getContext().get("metaFile");
importCityMap = Beans.get(ImportCityService.class).importFromGeonamesManualConfig(map, typeSelect);
break;
default:
break;
}
}
if (importCityMap.containsKey("importHistoryList") && importCityMap.containsKey("errorFile")) {
importHistoryList = (List<ImportHistory>) importCityMap.get("importHistoryList");
errorFile = (MetaFile) importCityMap.get("errorFile");
if (errorFile != null) {
response.setFlash(I18n.get(IExceptionMessage.CITIES_IMPORT_FAILED));
response.setAttr("errorFile", "hidden", false);
response.setValue("errorFile", errorFile);
} else {
response.setAttr("$importHistoryList", "hidden", false);
response.setAttr("errorFile", "hidden", true);
response.setAttr("$importHistoryList", "value", importHistoryList);
response.setFlash(I18n.get(ITranslation.BASE_GEONAMES_CITY_IMPORT_COMPLETED));
}
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class LunchVoucherMgtServiceImpl method export.
@Transactional(rollbackOn = { Exception.class })
public void export(LunchVoucherMgt lunchVoucherMgt) throws IOException {
MetaFile metaFile = new MetaFile();
metaFile.setFileName(I18n.get("LunchVoucherCommand") + " - " + appBaseService.getTodayDate(lunchVoucherMgt.getCompany()).format(DateTimeFormatter.ISO_DATE) + ".csv");
Path tempFile = MetaFiles.createTempFile(null, ".csv");
final OutputStream os = new FileOutputStream(tempFile.toFile());
try (final Writer writer = new OutputStreamWriter(os)) {
List<String> header = new ArrayList<>();
header.add(escapeCsv(I18n.get("Company code")));
header.add(escapeCsv(I18n.get("Lunch Voucher's number")));
header.add(escapeCsv(I18n.get("Employee")));
header.add(escapeCsv(I18n.get("Lunch Voucher format")));
writer.write(Joiner.on(";").join(header));
for (LunchVoucherMgtLine lunchVoucherMgtLine : lunchVoucherMgt.getLunchVoucherMgtLineList()) {
List<String> line = new ArrayList<>();
line.add(escapeCsv(lunchVoucherMgt.getCompany().getCode()));
line.add(escapeCsv(lunchVoucherMgtLine.getLunchVoucherNumber().toString()));
line.add(escapeCsv(lunchVoucherMgtLine.getEmployee().getName()));
line.add(escapeCsv(lunchVoucherMgtLine.getEmployee().getLunchVoucherFormatSelect().toString()));
writer.write("\n");
writer.write(Joiner.on(";").join(line));
}
Beans.get(MetaFiles.class).upload(tempFile.toFile(), metaFile);
} catch (Exception e) {
Throwables.propagate(e);
} finally {
Files.deleteIfExists(tempFile);
}
/*
*/
// lunchVoucherMgt.setExported(true);
lunchVoucherMgt.setCsvFile(metaFile);
lunchVoucherMgt.setExportDate(appBaseService.getTodayDate(lunchVoucherMgt.getCompany()));
lunchVoucherMgtRepository.save(lunchVoucherMgt);
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class ObjectDataExportServiceImpl method writeExcel.
private MetaFile writeExcel(Map<String, List<String[]>> data) throws IOException {
XSSFWorkbook workBook = new XSSFWorkbook();
for (Entry<String, List<String[]>> modelEntry : data.entrySet()) {
XSSFSheet sheet = workBook.createSheet(modelEntry.getKey());
int count = 0;
for (String[] recordArray : modelEntry.getValue()) {
XSSFRow row = sheet.createRow(count);
int cellCount = 0;
for (String val : recordArray) {
XSSFCell cell = row.createCell(cellCount);
cell.setCellValue(val);
cellCount++;
}
count++;
}
}
File excelFile = MetaFiles.createTempFile("Data", ".xls").toFile();
FileOutputStream out = new FileOutputStream(excelFile);
workBook.write(out);
out.close();
return metaFiles.upload(excelFile);
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class ImportAccountChart method importAccountChart.
public Object importAccountChart(Object bean, Map<String, Object> values) throws IOException {
assert bean instanceof AccountChart;
AccountChart accountChart = (AccountChart) bean;
File zipFile = this.getZipFile(accountChart);
try {
final MetaFile metaFile = metaFiles.upload(zipFile);
accountChart.setMetaFile(metaFile);
} catch (Exception e) {
e.printStackTrace();
LOG.warn("Can't load file {} for accountChart {}", zipFile.getName(), accountChart.getName());
}
FileUtils.deleteDirectory(zipFile.getParentFile());
return accountChart;
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class BpmDeploymentServiceImpl method addDmn.
protected void addDmn(DeploymentBuilder deploymentBuilder, Set<MetaFile> dmnFiles) {
MetaFileRepository metaFileRepo = Beans.get(MetaFileRepository.class);
for (MetaFile dmnFile : dmnFiles) {
dmnFile = metaFileRepo.find(dmnFile.getId());
deploymentBuilder.addModelInstance(dmnFile.getId() + ".dmn", Dmn.readModelFromFile(MetaFiles.getPath(dmnFile).toFile()));
}
}
Aggregations