use of com.axelor.dms.db.DMSFile 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.dms.db.DMSFile in project axelor-open-suite by axelor.
the class TemplateMessageServiceImpl method getMetaFiles.
@Override
public Set<MetaFile> getMetaFiles(Template template, Templates templates, Map<String, Object> templatesContext) throws AxelorException, IOException {
List<DMSFile> metaAttachments = Query.of(DMSFile.class).filter("self.relatedId = ?1 AND self.relatedModel = ?2", template.getId(), EntityHelper.getEntityClass(template).getName()).fetch();
Set<MetaFile> metaFiles = Sets.newHashSet();
for (DMSFile metaAttachment : metaAttachments) {
if (!metaAttachment.getIsDirectory())
metaFiles.add(metaAttachment.getMetaFile());
}
log.debug("Metafile to attach: {}", metaFiles);
return metaFiles;
}
use of com.axelor.dms.db.DMSFile in project axelor-open-suite by axelor.
the class DeclarationOfExchangesExporter method attach.
protected String attach(String path) {
DMSFile dmsFile;
try (InputStream is = new FileInputStream(path)) {
dmsFile = Beans.get(MetaFiles.class).attach(is, getFileName(), declarationOfExchanges);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
MetaFile metaFile = dmsFile.getMetaFile();
return String.format("ws/rest/com.axelor.meta.db.MetaFile/%d/content/download?v=%d/%s", metaFile.getId(), metaFile.getVersion(), path);
}
use of com.axelor.dms.db.DMSFile 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.dms.db.DMSFile 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();
}
}
Aggregations