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