Search in sources :

Example 61 with MetaFile

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

the class JobApplicationServiceImpl method setDMSFile.

@Override
@Transactional(rollbackOn = { Exception.class })
public void setDMSFile(JobApplication jobApplication) {
    if (jobApplication.getResume() == null) {
        DMSFile toDelete = dmsFileRepo.find(jobApplication.getResumeId());
        if (toDelete != null) {
            metaFiles.delete(toDelete);
        }
        jobApplication.setResumeId(null);
    } else {
        MetaFile resume = jobApplication.getResume();
        DMSFile resumeFile = metaFiles.attach(resume, resume.getFileName(), jobApplication);
        jobApplication.setResumeId(resumeFile.getId());
    }
    jobApplicationRepo.save(jobApplication);
}
Also used : DMSFile(com.axelor.dms.db.DMSFile) MetaFile(com.axelor.meta.db.MetaFile) Transactional(com.google.inject.persist.Transactional)

Example 62 with MetaFile

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

the class JobPositionServiceImpl method copyAttachments.

private void copyAttachments(JobApplication application, Message message) throws IOException {
    List<MetaAttachment> attachments = metaAttachmentRepo.all().filter("self.objectId = ?1 and self.objectName = ?2", message.getId(), Message.class.getName()).fetch();
    for (MetaAttachment attachment : attachments) {
        MetaFile file = attachment.getMetaFile();
        metaFiles.attach(file, file.getFileName(), application);
    }
}
Also used : MetaFile(com.axelor.meta.db.MetaFile) MetaAttachment(com.axelor.meta.db.MetaAttachment)

Example 63 with MetaFile

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

the class MetaGroupMenuAssistantService method createHeader.

private List<String[]> createHeader(MetaGroupMenuAssistant groupMenuAssistant) throws IOException {
    MetaFile metaFile = groupMenuAssistant.getMetaFile();
    List<String[]> rows = new ArrayList<>();
    if (metaFile != null) {
        File csvFile = MetaFiles.getPath(metaFile).toFile();
        logger.debug("File name: {}", csvFile.getAbsolutePath());
        logger.debug("File length: {}", csvFile.length());
        try (CSVReader csvReader = new CSVReader(new InputStreamReader(new FileInputStream(csvFile), StandardCharsets.UTF_8), ';')) {
            rows = csvReader.readAll();
            logger.debug("Rows size: {}", rows.size());
        }
    }
    if (!rows.isEmpty()) {
        rows.set(0, getGroupRow(rows.get(0), groupMenuAssistant));
    } else {
        rows.add(getGroupRow(null, groupMenuAssistant));
    }
    return rows;
}
Also used : InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) ArrayList(java.util.ArrayList) MetaFile(com.axelor.meta.db.MetaFile) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) FileInputStream(java.io.FileInputStream)

Example 64 with MetaFile

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

the class DMSImportWizardServiceImpl method createDmsTree.

@Transactional
public void createDmsTree(ZipInputStream zipInputStream, ZipFile zipfile) throws IOException {
    ZipEntry zipEntry = zipInputStream.getNextEntry();
    Map<String, DMSFile> dmsMap = new HashMap<>();
    while (zipEntry != null) {
        String fileName = getFileName(zipEntry);
        DMSFile dmsFile = new DMSFile();
        dmsFile.setFileName(fileName);
        String parentName = getParentName(zipEntry, fileName);
        dmsFile.setParent(dmsMap.get(parentName));
        LOG.debug("Praent file: {}", dmsFile.getParent());
        if (zipEntry.isDirectory()) {
            dmsFile.setIsDirectory(true);
            dmsFile = Beans.get(DMSFileRepository.class).save(dmsFile);
            dmsMap.put(zipEntry.getName(), dmsFile);
            LOG.debug("DMS Directory created: {}", dmsFile.getFileName());
        } else {
            String fileType = fileName.substring(fileName.indexOf(".") + 1);
            try {
                File tempDir = File.createTempFile("", "");
                File file = new File(tempDir, fileName);
                InputStream is = zipfile.getInputStream(zipEntry);
                FileUtils.copyInputStreamToFile(is, file);
                MetaFiles.checkType(file);
                MetaFile metaFile = metaFiles.upload(zipInputStream, fileName);
                dmsFile.setMetaFile(metaFile);
                dmsFile = Beans.get(DMSFileRepository.class).save(dmsFile);
                LOG.debug("DMS File created: {}", dmsFile.getFileName());
            } catch (IllegalArgumentException e) {
                LOG.debug("File type is not allowed : {}", fileType);
            }
        }
        zipEntry = zipInputStream.getNextEntry();
    }
}
Also used : HashMap(java.util.HashMap) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) DMSFile(com.axelor.dms.db.DMSFile) MetaFile(com.axelor.meta.db.MetaFile) DMSFile(com.axelor.dms.db.DMSFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) Transactional(com.google.inject.persist.Transactional)

Example 65 with MetaFile

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

the class PrintTemplateServiceImpl method getMetaFiles.

public Set<MetaFile> getMetaFiles(TemplateMaker maker, PrintTemplate printTemplate) throws AxelorException, IOException {
    Set<MetaFile> metaFiles = new HashSet<>();
    if (printTemplate.getBirtTemplateSet() == null) {
        return metaFiles;
    }
    for (BirtTemplate birtTemplate : printTemplate.getBirtTemplateSet()) {
        metaFiles.add(templateMessageService.createMetaFileUsingBirtTemplate(maker, birtTemplate, null, null));
    }
    LOG.debug("MetaFile to attach: {}", metaFiles);
    return metaFiles;
}
Also used : BirtTemplate(com.axelor.apps.base.db.BirtTemplate) MetaFile(com.axelor.meta.db.MetaFile) HashSet(java.util.HashSet)

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