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);
}
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);
}
}
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;
}
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();
}
}
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;
}
Aggregations