Search in sources :

Example 66 with MetaFile

use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.

the class EbicsController method sendFULRequest.

public void sendFULRequest(ActionRequest request, ActionResponse response) {
    EbicsUser ebicsUser = Beans.get(EbicsUserRepository.class).find(request.getContext().asType(EbicsUser.class).getId());
    try {
        MetaFile testDataMetaFile = ebicsUser.getTestDataFile();
        MetaFile testSignatureMetaFile = ebicsUser.getTestSignatureFile();
        BankOrderFileFormat bankOrderFileFormat = ebicsUser.getTestBankOrderFileFormat();
        if (testDataMetaFile != null && bankOrderFileFormat != null) {
            File testSignatureFile = null;
            if (ebicsUser.getEbicsPartner().getEbicsTypeSelect() == EbicsPartnerRepository.EBICS_TYPE_TS && testSignatureMetaFile != null) {
                testSignatureFile = MetaFiles.getPath(testSignatureMetaFile).toFile();
            }
            Beans.get(EbicsService.class).sendFULRequest(ebicsUser, ebicsUser.getTestSignatoryEbicsUser(), null, MetaFiles.getPath(testDataMetaFile).toFile(), bankOrderFileFormat, testSignatureFile);
        } else {
            response.setFlash(I18n.get(IExceptionMessage.EBICS_TEST_MODE_NOT_ENABLED));
        }
    } catch (Exception e) {
        response.setFlash(stripClass(e.getLocalizedMessage()));
    }
    response.setReload(true);
}
Also used : EbicsUserRepository(com.axelor.apps.bankpayment.db.repo.EbicsUserRepository) EbicsUser(com.axelor.apps.bankpayment.db.EbicsUser) MetaFile(com.axelor.meta.db.MetaFile) BankOrderFileFormat(com.axelor.apps.bankpayment.db.BankOrderFileFormat) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) EbicsService(com.axelor.apps.bankpayment.ebics.service.EbicsService) GeneralSecurityException(java.security.GeneralSecurityException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) CertificateEncodingException(java.security.cert.CertificateEncodingException)

Example 67 with MetaFile

use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.

the class WkfModelController method importWkfModels.

@SuppressWarnings("unchecked")
@Transactional
public void importWkfModels(ActionRequest request, ActionResponse response) throws AxelorException {
    boolean isTranslate = request.getContext().get("isTranslate") == null ? false : (boolean) request.getContext().get("isTranslate");
    String sourceLanguage = (String) request.getContext().get("sourceLanguageSelect");
    String targetLanguage = (String) request.getContext().get("targetLanguageSelect");
    String metaFileId = ((Map<String, Object>) request.getContext().get("dataFile")).get("id").toString();
    MetaFile metaFile = Beans.get(MetaFileRepository.class).find(Long.parseLong(metaFileId));
    String logText = wkfModelService.importWkfModels(metaFile, isTranslate, sourceLanguage, targetLanguage);
    if (Strings.isNullOrEmpty(logText)) {
        response.setCanClose(true);
    } else {
        response.setValue("importLog", logText);
    }
}
Also used : MetaFileRepository(com.axelor.meta.db.repo.MetaFileRepository) MetaFile(com.axelor.meta.db.MetaFile) Transactional(com.google.inject.persist.Transactional)

Example 68 with MetaFile

use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.

the class MpsChargeController method print.

public void print(ActionRequest request, ActionResponse response) throws AxelorException {
    String name = I18n.get(ITranslation.MPS_CHARGE);
    LocalDate startMonthDate = (LocalDate) request.getContext().get("startMonthDate");
    LocalDate endMonthDate = (LocalDate) request.getContext().get("endMonthDate");
    if (startMonthDate == null || endMonthDate == null) {
        return;
    }
    String fileLink = ReportFactory.createReport(IReport.MPS_CHARGE, name + "-${date}").addParam("mpsId", request.getContext().get("id")).addParam("logoPath", Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).map(Company::getLogo).map(MetaFile::getFilePath).orElse(null)).addParam("startMonthDate", startMonthDate.format(DateTimeFormatter.ofPattern("dd/MM/YYYY"))).addParam("endMonthDate", endMonthDate.format(DateTimeFormatter.ofPattern("dd/MM/YYYY"))).generate().getFileLink();
    LOG.debug("Printing {}", name);
    response.setView(ActionView.define(name).add("html", fileLink).map());
}
Also used : User(com.axelor.auth.db.User) MetaFile(com.axelor.meta.db.MetaFile) LocalDate(java.time.LocalDate)

Example 69 with MetaFile

use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.

the class UnitCostCalculationController method importUnitCostCalc.

@SuppressWarnings("unchecked")
public void importUnitCostCalc(ActionRequest request, ActionResponse response) throws IOException {
    try {
        LinkedHashMap<String, Object> map = (LinkedHashMap<String, Object>) request.getContext().get("metaFile");
        MetaFile dataFile = Beans.get(MetaFileRepository.class).find(((Integer) map.get("id")).longValue());
        File csvFile = MetaFiles.getPath(dataFile).toFile();
        Long unitCostCalculationId = Long.valueOf(request.getContext().get("_id").toString());
        UnitCostCalculation unitCostCalculation = Beans.get(UnitCostCalculationRepository.class).find(unitCostCalculationId);
        if (Files.getFileExtension(csvFile.getName()).equals("csv")) {
            Beans.get(UnitCostCalculationService.class).importUnitCostCalc(dataFile, unitCostCalculation);
            response.setCanClose(true);
        } else {
            response.setError(IExceptionMessage.UNIT_COST_CALCULATION_IMPORT_CSV_ERROR);
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : UnitCostCalculationService(com.axelor.apps.production.service.costsheet.UnitCostCalculationService) MetaFileRepository(com.axelor.meta.db.repo.MetaFileRepository) UnitCostCalculation(com.axelor.apps.production.db.UnitCostCalculation) MetaFile(com.axelor.meta.db.MetaFile) UnitCostCalculationRepository(com.axelor.apps.production.db.repo.UnitCostCalculationRepository) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) IOException(java.io.IOException) AxelorException(com.axelor.exception.AxelorException) LinkedHashMap(java.util.LinkedHashMap)

Example 70 with MetaFile

use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.

the class OperationOrderServiceImpl method createBarcode.

@Override
public void createBarcode(OperationOrder operationOrder) {
    try {
        String stringId = operationOrder.getId().toString();
        boolean addPadding = true;
        InputStream inStream = barcodeGeneratorService.createBarCode(stringId, appProductionService.getAppProduction().getBarcodeTypeConfig(), addPadding);
        if (inStream != null) {
            MetaFile barcodeFile = metaFiles.upload(inStream, String.format("OppOrderBarcode%d.png", operationOrder.getId()));
            operationOrder.setBarCode(barcodeFile);
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (AxelorException e) {
        throw new ValidationException(e);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) ValidationException(javax.validation.ValidationException) InputStream(java.io.InputStream) MetaFile(com.axelor.meta.db.MetaFile) IOException(java.io.IOException)

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