use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class CatalogController method showPdf.
public void showPdf(ActionRequest request, ActionResponse response) {
try {
Catalog catalog = Beans.get(CatalogRepository.class).find(request.getContext().asType(Catalog.class).getId());
MetaFile pdf = catalog.getPdfFile();
String title = catalog.getName();
Path path = MetaFiles.getPath(pdf.getFileName());
String fileLink = PdfTool.getFileLinkFromPdfFile(PdfTool.printCopiesToFile(path.toFile(), 1), title + ".pdf");
response.setView(ActionView.define(title).add("html", fileLink).map());
} catch (Exception e) {
TraceBackService.trace(e);
}
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class InventoryService method exportInventoryAsCSV.
@Transactional(rollbackOn = { Exception.class })
public MetaFile exportInventoryAsCSV(Inventory inventory) throws IOException {
List<String[]> list = new ArrayList<>();
for (InventoryLine inventoryLine : inventory.getInventoryLineList()) {
String[] item = new String[9];
String realQty = "";
item[0] = (inventoryLine.getProduct() == null) ? "" : inventoryLine.getProduct().getName();
item[1] = (inventoryLine.getProduct() == null) ? "" : inventoryLine.getProduct().getCode();
item[2] = (inventoryLine.getProduct() == null) ? "" : ((inventoryLine.getProduct().getProductCategory() == null) ? "" : inventoryLine.getProduct().getProductCategory().getName());
item[3] = (inventoryLine.getRack() == null) ? "" : inventoryLine.getRack();
item[4] = (inventoryLine.getTrackingNumber() == null) ? "" : inventoryLine.getTrackingNumber().getTrackingNumberSeq();
item[5] = inventoryLine.getCurrentQty().toString();
if (inventoryLine.getRealQty() != null && inventory.getStatusSelect() != InventoryRepository.STATUS_DRAFT && inventory.getStatusSelect() != InventoryRepository.STATUS_PLANNED) {
realQty = inventoryLine.getRealQty().toString();
}
item[6] = realQty;
item[7] = (inventoryLine.getDescription() == null) ? "" : inventoryLine.getDescription();
String lastInventoryDateTString = "";
StockLocationLine stockLocationLine = stockLocationLineService.getStockLocationLine(inventory.getStockLocation(), inventoryLine.getProduct());
if (stockLocationLine != null) {
ZonedDateTime lastInventoryDateT = stockLocationLine.getLastInventoryDateT();
lastInventoryDateTString = lastInventoryDateT == null ? "" : lastInventoryDateT.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));
}
item[8] = lastInventoryDateTString;
list.add(item);
}
Collections.sort(list, new // sort the list by code product
Comparator<String[]>() {
@Override
public int compare(String[] strings, String[] otherStrings) {
return strings[1].compareTo(otherStrings[1]);
}
});
String fileName = computeExportFileName(inventory);
File file = MetaFiles.createTempFile(fileName, ".csv").toFile();
log.debug("File Located at: {}", file.getPath());
String[] headers = { PRODUCT_NAME, PRODUCT_CODE, PRODUCT_CATEGORY, RACK, TRACKING_NUMBER, CURRENT_QUANTITY, REAL_QUANTITY, DESCRIPTION, LAST_INVENTORY_DATE };
CsvTool.csvWriter(file.getParent(), file.getName(), ';', '"', headers, list);
try (InputStream is = new FileInputStream(file)) {
return Beans.get(MetaFiles.class).upload(is, fileName + ".csv");
}
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class ProductBaseRepository method save.
@Override
public Product save(Product product) {
try {
if (appBaseService.getAppBase().getGenerateProductSequence() && Strings.isNullOrEmpty(product.getCode())) {
product.setCode(Beans.get(ProductService.class).getSequence(product));
}
} catch (Exception e) {
TraceBackService.traceExceptionFromSaveMethod(e);
throw new PersistenceException(e.getMessage(), e);
}
product.setFullName(String.format(FULL_NAME_FORMAT, product.getCode(), product.getName()));
if (product.getId() != null) {
Product oldProduct = Beans.get(ProductRepository.class).find(product.getId());
translationService.updateFormatedValueTranslations(oldProduct.getFullName(), FULL_NAME_FORMAT, product.getCode(), product.getName());
} else {
translationService.createFormatedValueTranslations(FULL_NAME_FORMAT, product.getCode(), product.getName());
}
product = super.save(product);
if (product.getBarCode() == null && appBaseService.getAppBase().getActivateBarCodeGeneration()) {
try {
boolean addPadding = false;
InputStream inStream;
if (!appBaseService.getAppBase().getEditProductBarcodeType()) {
inStream = barcodeGeneratorService.createBarCode(product.getSerialNumber(), appBaseService.getAppBase().getBarcodeTypeConfig(), addPadding);
} else {
inStream = barcodeGeneratorService.createBarCode(product.getSerialNumber(), product.getBarcodeTypeConfig(), addPadding);
}
if (inStream != null) {
MetaFile barcodeFile = metaFiles.upload(inStream, String.format("ProductBarCode%d.png", product.getId()));
product.setBarCode(barcodeFile);
}
} catch (IOException e) {
e.printStackTrace();
} catch (AxelorException e) {
TraceBackService.traceExceptionFromSaveMethod(e);
throw new ValidationException(e);
}
}
return super.save(product);
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class CampaignServiceImpl method generateLog.
protected MetaFile generateLog(String errorPartners, String errorLeads, MetaFile metaFile, Long campaignId) {
if (metaFile == null) {
metaFile = new MetaFile();
metaFile.setFileName("EmailLog" + campaignId + ".text");
}
StringBuilder builder = new StringBuilder();
builder.append(I18n.get(IExceptionMessage.EMAIL_ERROR1));
builder.append("\n");
if (!errorPartners.isEmpty()) {
builder.append(I18n.get("Partners") + ":\n");
builder.append(errorPartners);
}
if (!errorLeads.isEmpty()) {
builder.append(I18n.get("Leads") + ":\n");
builder.append(errorLeads);
}
ByteArrayInputStream stream = new ByteArrayInputStream(builder.toString().getBytes());
try {
return Beans.get(MetaFiles.class).upload(stream, metaFile.getFileName());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class ImportService method importImg.
// Import methods specific for import from AppBuilder
private MetaFile importImg(String name, String data) {
if (data == null) {
return null;
}
byte[] img = Base64.getDecoder().decode(data);
ByteArrayInputStream inImg = new ByteArrayInputStream(img);
MetaFile metaFile = metaFileRepo.all().filter("self.fileName = ?1", name).fetchOne();
try {
if (metaFile != null) {
return metaFiles.upload(inImg, metaFile);
} else {
return metaFiles.upload(inImg, name);
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
Aggregations