use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class WkfDmnModelController method importDmnTable.
@SuppressWarnings("rawtypes")
public void importDmnTable(ActionRequest request, ActionResponse response) {
try {
MetaFile dataFile = Beans.get(MetaFileRepository.class).find(Long.parseLong(((Map) request.getContext().get("dataFile")).get("id").toString()));
Long dmnModelId = Long.parseLong(request.getContext().get("_dmnModelId").toString());
WkfDmnModel dmnModel = Beans.get(WkfDmnModelRepository.class).find(dmnModelId);
Beans.get(DmnImportService.class).importDmnTable(dataFile, dmnModel);
response.setCanClose(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class WkfDmnModelController method exportDmnTable.
public void exportDmnTable(ActionRequest request, ActionResponse response) {
try {
WkfDmnModel dmnModel = request.getContext().asType(WkfDmnModel.class);
dmnModel = Beans.get(WkfDmnModelRepository.class).find(dmnModel.getId());
File file = Beans.get(DmnExportService.class).exportDmnTable(dmnModel);
FileInputStream inStream = new FileInputStream(file);
MetaFile exportFile = Beans.get(MetaFiles.class).upload(inStream, dmnModel.getName() + ".xlsx");
inStream.close();
file.delete();
if (exportFile != null) {
response.setView(ActionView.define(I18n.get("Export file")).model(WkfDmnModel.class.getName()).add("html", "ws/rest/com.axelor.meta.db.MetaFile/" + exportFile.getId() + "/content/download?v=" + exportFile.getVersion()).param("download", "true").map());
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class UnitCostCalculationServiceImpl method exportUnitCostCalc.
@Override
public MetaFile exportUnitCostCalc(UnitCostCalculation unitCostCalculation, String fileName) throws IOException {
List<String[]> list = new ArrayList<>();
List<UnitCostCalcLine> unitCostCalcLineList = unitCostCalculation.getUnitCostCalcLineList();
Collections.sort(unitCostCalcLineList, new Comparator<UnitCostCalcLine>() {
@Override
public int compare(UnitCostCalcLine unitCostCalcLine1, UnitCostCalcLine unitCostCalcLine2) {
return unitCostCalcLine1.getProduct().getCode().compareTo(unitCostCalcLine2.getProduct().getCode());
}
});
for (UnitCostCalcLine unitCostCalcLine : unitCostCalcLineList) {
String[] item = new String[4];
item[0] = unitCostCalcLine.getProduct() == null ? "" : unitCostCalcLine.getProduct().getCode();
item[1] = unitCostCalcLine.getProduct() == null ? "" : unitCostCalcLine.getProduct().getName();
item[2] = unitCostCalcLine.getComputedCost().toString();
item[3] = unitCostCalcLine.getCostToApply().toString();
list.add(item);
}
File file = MetaFiles.createTempFile(fileName, ".csv").toFile();
log.debug("File located at: {}", file.getPath());
String[] headers = { I18n.get("Product_code"), I18n.get("Product_name"), I18n.get("Product_currency"), I18n.get("Computed_cost"), I18n.get("Cost_to_apply") };
CsvTool.csvWriter(file.getParent(), file.getName(), ';', '"', headers, list);
try (InputStream is = new FileInputStream(file)) {
DMSFile dmsFile = Beans.get(MetaFiles.class).attach(is, file.getName(), unitCostCalculation);
return dmsFile.getMetaFile();
}
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class ObjectDataExportServiceImpl method writeCSV.
private MetaFile writeCSV(Map<String, List<String[]>> data) throws IOException {
File zipFile = MetaFiles.createTempFile("Data", ".zip").toFile();
try (ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(zipFile))) {
for (Entry<String, List<String[]>> modelEntry : data.entrySet()) {
String key = modelEntry.getKey();
File modelFile = MetaFiles.createTempFile(key, ".csv").toFile();
CSVWriter writer = new CSVWriter(new FileWriter(modelFile), ';');
writer.writeAll(modelEntry.getValue());
writer.close();
zout.putNextEntry(new ZipEntry(key + ".csv"));
zout.write(IOUtils.toByteArray(new FileInputStream(modelFile)));
zout.closeEntry();
}
}
return metaFiles.upload(zipFile);
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class GlobalTrackingLogServiceImpl method removeGlobalTrackingLogs.
@Override
@Transactional
public void removeGlobalTrackingLogs(List<GlobalTrackingLog> globalTrackingLogList) {
for (GlobalTrackingLog globalTrackingLog : globalTrackingLogList) {
MetaFile metaFile = globalTrackingLog.getMetaFile();
globalTrackingLogRepo.remove(globalTrackingLog);
if (globalTrackingLog.getMetaFile() != null) {
File metaFileFile = new File(globalTrackingLog.getMetaFile().getFilePath());
metaFileFile.delete();
metaFileRepo.remove(metaFile);
}
}
JPA.flush();
}
Aggregations