Search in sources :

Example 86 with MetaFile

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

the class ExcelReaderService method initialize.

@Override
public boolean initialize(MetaFile input, String separator) {
    if (input == null) {
        return false;
    }
    File inFile = MetaFiles.getPath(input).toFile();
    if (!inFile.exists()) {
        return false;
    }
    try {
        FileInputStream inSteam = new FileInputStream(inFile);
        book = new XSSFWorkbook(inSteam);
        if (book.getNumberOfSheets() == 0) {
            return false;
        }
        formatter = new DataFormatter();
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
Also used : XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) IOException(java.io.IOException) MetaFile(com.axelor.meta.db.MetaFile) File(java.io.File) FileInputStream(java.io.FileInputStream) DataFormatter(org.apache.poi.ss.usermodel.DataFormatter)

Example 87 with MetaFile

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

the class ProductImport method importProduct.

public Object importProduct(Object bean, Map context) {
    Product product = (Product) bean;
    final Path path = (Path) context.get("__path__");
    try {
        final Path image = ImportUtils.findByFileName(path.resolve(PRODUCT_IMAGES_DIR), product.getCode());
        if (image != null && image.toFile().exists()) {
            final MetaFile metaFile = Beans.get(MetaFiles.class).upload(image.toFile());
            product.setImage(metaFile);
        }
    } catch (Exception e) {
    // ignore
    }
    return product;
}
Also used : Path(java.nio.file.Path) MetaFiles(com.axelor.meta.MetaFiles) Product(com.axelor.sale.db.Product) MetaFile(com.axelor.meta.db.MetaFile)

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