Search in sources :

Example 86 with InvalidFormatException

use of org.apache.poi.openxml4j.exceptions.InvalidFormatException in project selenium_java by sergueik.

the class ExcelTestNGRunner method run.

/**
 * this is the main method that parses the input file(s) into TestNG
 * XmlSuite(s) and then runs them using TestNG.run()
 */
public void run() {
    File srcFile = new File(source);
    // if source is a directory, this will hold the
    File[] filesList = null;
    // make sure the file source exists
    if (!srcFile.exists()) {
        throw new IllegalArgumentException("The source for the Excel " + "file(s) cannot be found.");
    }
    // if source is a folder, get all excel files within it
    if (srcFile.isDirectory()) {
        filesList = srcFile.listFiles(new ExcelFileNameFilter());
    } else {
        filesList = new File[] { srcFile };
    }
    if (this.testng == null) {
        this.testng = new TestNG();
    }
    // if no custom parser is specified, use default
    if (this.parser == null) {
        if (this.parserMap == null)
            this.parser = new ExcelSuiteParser();
        else
            this.parser = new ExcelSuiteParser(parserMap);
    }
    // this will keep a list of all XmlSuites to be run
    List<XmlSuite> allSuites = new ArrayList<XmlSuite>();
    // parse each file and each worksheet into an XmlSuite
    for (File file : filesList) {
        List<XmlSuite> suites = new ArrayList<XmlSuite>();
        try {
            suites = parser.getXmlSuites(file, false);
        } catch (InvalidFormatException e) {
            // any issues with parsing, skip this suite and continue
            continue;
        } catch (IOException e) {
            // any issues with parsing, skip this suite and continue
            continue;
        }
        for (XmlSuite suite : suites) {
            allSuites.add(suite);
        }
    }
    testng.setXmlSuites(allSuites);
    testng.run();
}
Also used : XmlSuite(org.testng.xml.XmlSuite) TestNG(org.testng.TestNG) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException)

Example 87 with InvalidFormatException

use of org.apache.poi.openxml4j.exceptions.InvalidFormatException in project goci by EBISPOT.

the class AssociationFileUploadService method processAndValidateAssociationFile.

/**
 * Process uploaded file and return a list of errors
 *
 * @param file XLSX file supplied by user
 */
public ValidationSummary processAndValidateAssociationFile(File file, String validationLevel) throws FileNotFoundException, SheetProcessingException {
    ValidationSummary validationSummary = new ValidationSummary();
    Collection<RowValidationSummary> rowValidationSummaries = new ArrayList<>();
    Collection<AssociationSummary> associationSummaries = new ArrayList<>();
    Collection<AssociationUploadRow> fileRows = new ArrayList<>();
    if (file.exists()) {
        // Create sheet
        XSSFSheet sheet = null;
        try {
            // Create a sheet for reading
            sheet = sheetCreationService.createSheet(file.getAbsolutePath());
            // Process file, depending on validation level, into a generic row object
            UploadSheetProcessor uploadSheetProcessor = uploadSheetProcessorBuilder.buildProcessor(validationLevel);
            fileRows = uploadSheetProcessor.readSheetRows(sheet);
        } catch (InvalidFormatException | InvalidOperationException | IOException | NullPointerException e) {
            getLog().error("File: " + file.getName() + " cannot be processed", e);
            file.delete();
            throw new SheetProcessingException("File: " + file.getName() + " cannot be processed", e);
        }
    } else {
        getLog().error("File: " + file.getName() + " cannot be found");
        throw new FileNotFoundException("File does not exist");
    }
    String eRelease = ensemblRestTemplateService.getRelease();
    // Error check each row
    if (!fileRows.isEmpty()) {
        // Check for missing values and syntax errors that would prevent code creating an association
        for (AssociationUploadRow row : fileRows) {
            getLog().info("Syntax checking row: " + row.getRowNumber() + " of file, " + file.getAbsolutePath());
            RowValidationSummary rowValidationSummary = createRowValidationSummary(row, eRelease);
            // Only store summary if there is an error
            if (!rowValidationSummary.getErrors().isEmpty()) {
                rowValidationSummaries.add(rowValidationSummary);
            }
        }
        if (rowValidationSummaries.isEmpty()) {
            // Proceed to carry out full checks of values
            fileRows.forEach(row -> {
                associationSummaries.add(createAssociationSummary(row, validationLevel, eRelease));
            });
        }
    }
    validationSummary.setAssociationSummaries(associationSummaries);
    validationSummary.setRowValidationSummaries(rowValidationSummaries);
    return validationSummary;
}
Also used : SheetProcessingException(uk.ac.ebi.spot.goci.exception.SheetProcessingException) RowValidationSummary(uk.ac.ebi.spot.goci.model.RowValidationSummary) RowValidationSummary(uk.ac.ebi.spot.goci.model.RowValidationSummary) ValidationSummary(uk.ac.ebi.spot.goci.model.ValidationSummary) AssociationSummary(uk.ac.ebi.spot.goci.model.AssociationSummary) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) InvalidOperationException(org.apache.poi.openxml4j.exceptions.InvalidOperationException) AssociationUploadRow(uk.ac.ebi.spot.goci.model.AssociationUploadRow)

Example 88 with InvalidFormatException

use of org.apache.poi.openxml4j.exceptions.InvalidFormatException in project qiuyj-code by qiuyuanjun.

the class ExcelOpsFactory method getExcelImporter.

@SuppressWarnings("unchecked")
public static ExcelImporter getExcelImporter(InputStream in, Class<?> beanCls) {
    Objects.requireNonNull(in);
    Workbook wb;
    try {
        wb = WorkbookFactory.create(in);
    } catch (InvalidFormatException | IOException e) {
        // 关闭流
        StreamUtils.closeQuietly(in);
        throw new IllegalStateException("Error parsing excel file.\n Caused by: " + e, e);
    }
    if (Objects.isNull(beanCls)) {
        return new MapExcelImporter(wb);
    } else {
        return new BeanExcelImporter(wb, beanCls);
    }
}
Also used : MapExcelImporter(com.qiuyj.excel.importer.MapExcelImporter) IOException(java.io.IOException) BeanExcelImporter(com.qiuyj.excel.importer.BeanExcelImporter) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException) Workbook(org.apache.poi.ss.usermodel.Workbook)

Example 89 with InvalidFormatException

use of org.apache.poi.openxml4j.exceptions.InvalidFormatException in project ImmunogeneticDataTools by nmdp-bioinformatics.

the class GLStringUtilities method checkAntigenRecognitionSite.

/**
 * @param locus
 * @param alleleBuffer
 * @param match
 * @return
 * @throws UnexpectedAlleleException
 */
public static boolean checkAntigenRecognitionSite(String allele, String referenceAllele) {
    String matchedValue = convertToProteinLevel(allele);
    AntigenRecognitionSiteLoader instance = null;
    try {
        instance = AntigenRecognitionSiteLoader.getInstance();
    } catch (IOException | InvalidFormatException e) {
        LOGGER.warning("Could not load ars data.");
        e.printStackTrace();
    }
    HashMap<String, HashSet<String>> arsMap = instance.getArsMap();
    if (arsMap.containsKey(referenceAllele)) {
        for (String arsCode : arsMap.keySet()) {
            if (arsCode.equals(referenceAllele) && arsMap.get(arsCode).contains(matchedValue)) {
                return true;
            }
        }
    }
    return false;
}
Also used : IOException(java.io.IOException) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException) AntigenRecognitionSiteLoader(org.dash.valid.ars.AntigenRecognitionSiteLoader) HashSet(java.util.HashSet)

Aggregations

InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)89 IOException (java.io.IOException)39 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)22 OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)18 PackageRelationship (org.apache.poi.openxml4j.opc.PackageRelationship)18 PackagePartName (org.apache.poi.openxml4j.opc.PackagePartName)16 InputStream (java.io.InputStream)15 PackageRelationshipCollection (org.apache.poi.openxml4j.opc.PackageRelationshipCollection)15 Workbook (org.apache.poi.ss.usermodel.Workbook)14 ArrayList (java.util.ArrayList)12 InvalidOperationException (org.apache.poi.openxml4j.exceptions.InvalidOperationException)11 Sheet (org.apache.poi.ss.usermodel.Sheet)11 Test (org.junit.Test)10 URI (java.net.URI)9 FileInputStream (java.io.FileInputStream)8 POIXMLException (org.apache.poi.POIXMLException)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 TikaException (org.apache.tika.exception.TikaException)7 XmlException (org.apache.xmlbeans.XmlException)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6