Search in sources :

Example 21 with MetaFile

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);
    }
}
Also used : MetaFileRepository(com.axelor.meta.db.repo.MetaFileRepository) WkfDmnModelRepository(com.axelor.apps.bpm.db.repo.WkfDmnModelRepository) DmnImportService(com.axelor.apps.dmn.service.DmnImportService) WkfDmnModel(com.axelor.apps.bpm.db.WkfDmnModel) MetaFile(com.axelor.meta.db.MetaFile) AxelorException(com.axelor.exception.AxelorException)

Example 22 with MetaFile

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);
    }
}
Also used : MetaFiles(com.axelor.meta.MetaFiles) WkfDmnModel(com.axelor.apps.bpm.db.WkfDmnModel) MetaFile(com.axelor.meta.db.MetaFile) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) DmnExportService(com.axelor.apps.dmn.service.DmnExportService) FileInputStream(java.io.FileInputStream) AxelorException(com.axelor.exception.AxelorException)

Example 23 with MetaFile

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();
    }
}
Also used : MetaFiles(com.axelor.meta.MetaFiles) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream) UnitCostCalcLine(com.axelor.apps.production.db.UnitCostCalcLine) DMSFile(com.axelor.dms.db.DMSFile) DMSFile(com.axelor.dms.db.DMSFile) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile)

Example 24 with MetaFile

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);
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) FileWriter(java.io.FileWriter) ZipEntry(java.util.zip.ZipEntry) CSVWriter(com.opencsv.CSVWriter) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) FileInputStream(java.io.FileInputStream)

Example 25 with MetaFile

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();
}
Also used : GlobalTrackingLog(com.axelor.apps.base.db.GlobalTrackingLog) MetaFile(com.axelor.meta.db.MetaFile) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) Transactional(com.google.inject.persist.Transactional)

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