diff --git a/pom.xml b/pom.xml index df32e41..b3bc460 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 de.isas.mztab mztab-validator-webapp - 1.0.23 + 1.0.24 jar A web-based validator for mzTab format version 1.0 onwards. MzTab validator webapplication. @@ -45,12 +45,12 @@ 1.8 UTF-8 1.8 - 3.0.4 + 3.0.9 1.0.4 ${project.version} 2.9.2 27.0.1-jre - 2.1.7.RELEASE + 2.2.2.RELEASE isas 1.4.10 1.18.4 @@ -62,8 +62,8 @@ 1.0.3 1.5.16 2.22.2 - 2.9.9 - 2.9.9.2 + 2.10.1 + 2.10.1 2.9.9 6.0.7.Final 1.7.25 @@ -269,6 +269,7 @@ com.fasterxml.jackson.dataformat jackson-dataformat-xml + ${jackson.version} com.fasterxml.jackson.jaxrs @@ -688,6 +689,14 @@ jcenter http://jcenter.bintray.com + + + false + + bintray-lifs-maven + bintray-lifs + https://dl.bintray.com/lifs/maven + false diff --git a/src/main/java/de/isas/lipidomics/mztab/validator/webapp/service/validation/IsasValidator.java b/src/main/java/de/isas/lipidomics/mztab/validator/webapp/service/validation/IsasValidator.java index b39b244..5648745 100644 --- a/src/main/java/de/isas/lipidomics/mztab/validator/webapp/service/validation/IsasValidator.java +++ b/src/main/java/de/isas/lipidomics/mztab/validator/webapp/service/validation/IsasValidator.java @@ -24,7 +24,6 @@ import de.isas.mztab2.model.MzTab; import de.isas.mztab2.model.ValidationMessage; import de.isas.mztab2.validation.CvMappingValidator; -import java.io.File; import java.io.IOException; import java.io.StringWriter; import java.nio.file.Path; @@ -37,8 +36,11 @@ import java.util.logging.Logger; import javax.xml.bind.JAXBException; import de.isas.mztab2.io.MzTabFileParser; +import java.io.PrintWriter; +import java.util.Optional; +import lombok.extern.slf4j.Slf4j; import uk.ac.ebi.pride.jmztab2.model.MZTabConstants; -import uk.ac.ebi.pride.jmztab2.utils.errors.MZTabErrorOverflowException; +import uk.ac.ebi.pride.jmztab2.utils.errors.MZTabErrorList; import uk.ac.ebi.pride.jmztab2.utils.errors.MZTabErrorType; import uk.ac.ebi.pride.jmztab2.utils.errors.MZTabException; @@ -46,6 +48,7 @@ * * @author Nils Hoffmann <nils.hoffmann@isas.de> */ +@Slf4j public class IsasValidator implements WebValidator { private final CvParameterLookupService lookupService; @@ -56,51 +59,49 @@ public IsasValidator(CvParameterLookupService lookupService) { @Override public List validate(Path filepath, - String validationLevel, int maxErrors, boolean checkCvMapping, Path validationFile) throws IllegalStateException, IOException { + String validationLevel, int maxErrors, boolean checkCvMapping, Path validationFile) throws IllegalStateException, IOException { MzTabFileParser parser = null; List validationResults = new ArrayList<>(); try { parser = new MzTabFileParser(filepath.toFile()); - parser.parse( - System.out, MZTabErrorType.findLevel(validationLevel), maxErrors); - } catch (MZTabErrorOverflowException ex) { - Logger.getLogger(IsasValidator.class.getName()). - log(Level.SEVERE, null, ex); + MZTabErrorList errorList = parser.parse( + System.out, MZTabErrorType.findLevel(validationLevel), maxErrors); + errorList.convertToValidationMessages(); + } catch (Exception e) { + log.error("Caught Exception in IsasValidator:", e); ValidationMessage vm = new ValidationMessage(); - vm.setCategory(ValidationMessage.CategoryEnum.CROSS_CHECK); + vm.setCategory( + ValidationMessage.CategoryEnum.FORMAT); vm.setCode(""); vm.setLineNumber(-1l); vm.setMessageType( - ValidationMessage.MessageTypeEnum.ERROR); - vm.setMessage(ex.getMessage()); + ValidationMessage.MessageTypeEnum.ERROR); + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + e.printStackTrace(pw); + vm.setMessage(e.getMessage()!=null?e.getMessage():"Caught an Exception while parsing '"+filepath.getFileName()+"'. Please check your file's tabular structure and inspect further validation messages!" + "\n" +sw.toString()); validationResults.add(vm); } finally { if (parser != null) { validationResults.addAll(parser.getErrorList(). - convertToValidationMessages()); + convertToValidationMessages()); if (checkCvMapping) { try { CvMappingValidator cvValidator = CvMappingValidator.of( -// IsasValidator.class.getResource( -// "/static/examples/mzTab-M-mapping.xml"), - validationFile.toFile(), - lookupService, checkCvMapping); - validationResults.addAll(cvValidator.validate(parser. - getMZTabFile())); - } catch (JAXBException ex) { - Logger.getLogger(IsasValidator.class.getName()). - log(Level.SEVERE, null, ex); - throw new IOException(ex); - } catch (IllegalArgumentException iae) { - Logger.getLogger(IsasValidator.class.getName()). - log(Level.SEVERE, null, iae); + validationFile.toFile(), + lookupService, checkCvMapping); + List messages = cvValidator.validate(parser. + getMZTabFile()); + validationResults.addAll(Optional.ofNullable(messages).orElse(Collections.emptyList())); + } catch (JAXBException | IllegalArgumentException iae) { + log.error("Caught Exception in IsasValidator, semantic validation:", iae); ValidationMessage vm = new ValidationMessage(); vm.setCategory( - ValidationMessage.CategoryEnum.CROSS_CHECK); + ValidationMessage.CategoryEnum.FORMAT); vm.setCode(""); vm.setLineNumber(-1l); vm.setMessageType( - ValidationMessage.MessageTypeEnum.ERROR); + ValidationMessage.MessageTypeEnum.ERROR); vm.setMessage(iae.getMessage()); validationResults.add(vm); } @@ -112,11 +113,11 @@ public List validate(Path filepath, @Override public Map>> parse(Path filepath, - String validationLevel, int maxErrors) throws IOException { + String validationLevel, int maxErrors) throws IOException { MzTabFileParser parser = new MzTabFileParser(filepath.toFile()); try { parser.parse( - System.out, MZTabErrorType.findLevel(validationLevel), maxErrors); + System.out, MZTabErrorType.findLevel(validationLevel), maxErrors); } finally { MzTab mzTabFile = parser.getMZTabFile(); if (mzTabFile != null) { @@ -124,27 +125,27 @@ public Map>> parse(Path filepath, CsvMapper mapper = writerDefaults.metadataMapper(); CsvSchema schema = writerDefaults.metaDataSchema(mapper); if (mzTabFile.getMetadata(). - getMzTabVersion() == null) { + getMzTabVersion() == null) { //set default version if not set mzTabFile.getMetadata(). - mzTabVersion(MZTabConstants.VERSION_MZTAB_M); + mzTabVersion(MZTabConstants.VERSION_MZTAB_M); } StringWriter writer = new StringWriter(); try { mapper.writer(schema). - writeValue(writer, mzTabFile.getMetadata()); + writeValue(writer, mzTabFile.getMetadata()); } catch (JsonProcessingException ex) { Logger.getLogger(MzTabNonValidatingWriter.class.getName()). - log(Level.SEVERE, null, ex); + log(Level.SEVERE, null, ex); } Map>> mzTabLines = new LinkedHashMap<>(); String[] metaDataLines = writer.toString(). - split(MZTabConstants.NEW_LINE); + split(MZTabConstants.NEW_LINE); List> metaData = new ArrayList<>(); int lineNumber = 1; for (int i = 0; i < metaDataLines.length; i++) { String[] metaDataLine = metaDataLines[i].split( - MZTabConstants.TAB_STRING); + MZTabConstants.TAB_STRING); Map lineMap = new LinkedHashMap<>(); lineMap.put("LINE_NUMBER", lineNumber + ""); lineMap.put("PREFIX", metaDataLine[0]); @@ -158,29 +159,29 @@ public Map>> parse(Path filepath, mapper = writerDefaults.smallMoleculeSummaryMapper(); try { schema = writerDefaults. - smallMoleculeSummarySchema(mapper, mzTabFile); + smallMoleculeSummarySchema(mapper, mzTabFile); writer = new StringWriter(); mapper.writer(schema). - writeValue(writer, mzTabFile.getSmallMoleculeSummary()); + writeValue(writer, mzTabFile.getSmallMoleculeSummary()); } catch (JsonProcessingException ex) { Logger.getLogger(MzTabNonValidatingWriter.class.getName()). - log(Level.SEVERE, null, ex); + log(Level.SEVERE, null, ex); } catch (MZTabException ex) { Logger.getLogger(IsasValidator.class.getName()). - log(Level.SEVERE, null, ex); + log(Level.SEVERE, null, ex); throw new IOException(ex); } String[] summaryDataLines = writer.toString(). - split(MZTabConstants.NEW_LINE); + split(MZTabConstants.NEW_LINE); String[] summaryHeader = summaryDataLines[0].split( - MZTabConstants.TAB_STRING); + MZTabConstants.TAB_STRING); List> summaryData = new ArrayList<>(); //due to the header lineNumber++; for (int i = 1; i < summaryDataLines.length; i++) { String[] dataLine = summaryDataLines[i].split( - MZTabConstants.TAB_STRING); + MZTabConstants.TAB_STRING); Map lineMap = new LinkedHashMap<>(); lineMap.put("LINE_NUMBER", lineNumber + ""); for (int j = 0; j < summaryHeader.length; j++) { @@ -194,28 +195,28 @@ public Map>> parse(Path filepath, mapper = writerDefaults.smallMoleculeFeatureMapper(); try { schema = writerDefaults. - smallMoleculeFeatureSchema(mapper, mzTabFile); + smallMoleculeFeatureSchema(mapper, mzTabFile); writer = new StringWriter(); mapper.writer(schema). - writeValue(writer, mzTabFile.getSmallMoleculeFeature()); + writeValue(writer, mzTabFile.getSmallMoleculeFeature()); } catch (JsonProcessingException ex) { Logger.getLogger(MzTabNonValidatingWriter.class.getName()). - log(Level.SEVERE, null, ex); + log(Level.SEVERE, null, ex); } catch (MZTabException ex) { Logger.getLogger(IsasValidator.class.getName()). - log(Level.SEVERE, null, ex); + log(Level.SEVERE, null, ex); throw new IOException(ex); } String[] featureDataLines = writer.toString(). - split(MZTabConstants.NEW_LINE); + split(MZTabConstants.NEW_LINE); String[] featureHeader = featureDataLines[0].split( - MZTabConstants.TAB_STRING); + MZTabConstants.TAB_STRING); List> featureData = new ArrayList<>(); //due to the header lineNumber++; for (int i = 1; i < featureDataLines.length; i++) { String[] dataLine = featureDataLines[i].split( - MZTabConstants.TAB_STRING); + MZTabConstants.TAB_STRING); Map lineMap = new LinkedHashMap<>(); lineMap.put("LINE_NUMBER", lineNumber + ""); for (int j = 0; j < featureHeader.length; j++) { @@ -229,28 +230,28 @@ public Map>> parse(Path filepath, mapper = writerDefaults.smallMoleculeEvidenceMapper(); try { schema = writerDefaults.smallMoleculeEvidenceSchema(mapper, - mzTabFile); + mzTabFile); writer = new StringWriter(); mapper.writer(schema). - writeValue(writer, mzTabFile.getSmallMoleculeEvidence()); + writeValue(writer, mzTabFile.getSmallMoleculeEvidence()); } catch (JsonProcessingException ex) { Logger.getLogger(MzTabNonValidatingWriter.class.getName()). - log(Level.SEVERE, null, ex); + log(Level.SEVERE, null, ex); } catch (MZTabException ex) { Logger.getLogger(IsasValidator.class.getName()). - log(Level.SEVERE, null, ex); + log(Level.SEVERE, null, ex); throw new IOException(ex); } String[] evidenceDataLines = writer.toString(). - split(MZTabConstants.NEW_LINE); + split(MZTabConstants.NEW_LINE); String[] evidenceHeader = evidenceDataLines[0].split( - MZTabConstants.TAB_STRING); + MZTabConstants.TAB_STRING); List> evidenceData = new ArrayList<>(); //due to the header lineNumber++; for (int i = 1; i < evidenceDataLines.length; i++) { String[] dataLine = evidenceDataLines[i].split( - MZTabConstants.TAB_STRING); + MZTabConstants.TAB_STRING); Map lineMap = new LinkedHashMap<>(); lineMap.put("LINE_NUMBER", lineNumber + ""); for (int j = 0; j < evidenceHeader.length; j++) { diff --git a/src/main/java/de/isas/lipidomics/mztab/validator/webapp/service/validation/MzTabValidationService.java b/src/main/java/de/isas/lipidomics/mztab/validator/webapp/service/validation/MzTabValidationService.java index 8e63834..0a88b5d 100644 --- a/src/main/java/de/isas/lipidomics/mztab/validator/webapp/service/validation/MzTabValidationService.java +++ b/src/main/java/de/isas/lipidomics/mztab/validator/webapp/service/validation/MzTabValidationService.java @@ -264,10 +264,13 @@ public CompletableFuture runValidation(MzTabVersion mzTabVersion, try { List validationResults = new ArrayList<>(); status.setStatus(Status.RUNNING); - validationResults.addAll( - validate(mzTabVersion, filepath, validationLevel, - maxErrors, checkCvMapping, storageService.load( - mappingFile, StorageService.SLOT.MAPPINGFILE))); + Path mappingFilePath = storageService.load(mappingFile, StorageService.SLOT.MAPPINGFILE); + if (!mappingFilePath.toFile().exists()) { + throw new IOException("Semantic validation file "+mappingFilePath+" does not exist!"); + } + List messages = validate(mzTabVersion, filepath, validationLevel, + maxErrors, checkCvMapping, mappingFilePath); + validationResults.addAll(messages); tracker.stopped(userSessionFile.getSessionId(), "validation", "success"); status.setMessages(validationResults); @@ -287,7 +290,15 @@ public CompletableFuture runValidation(MzTabVersion mzTabVersion, status.setMessages(Arrays.asList(mex.getError(). toValidationMessage())); } else { - throw new RuntimeException(ex); + ValidationMessage vm = new ValidationMessage(); + vm.setCategory( + ValidationMessage.CategoryEnum.CROSS_CHECK); + vm.setCode(""); + vm.setLineNumber(-1l); + vm.setMessageType( + ValidationMessage.MessageTypeEnum.ERROR); + vm.setMessage(ex.getMessage()); + status.setMessages(Arrays.asList(vm)); } resultService.addResultFor(userSessionId, status); tracker. diff --git a/src/main/resources/examples.properties b/src/main/resources/examples.properties index fdbbaa5..02cb583 100644 --- a/src/main/resources/examples.properties +++ b/src/main/resources/examples.properties @@ -82,3 +82,11 @@ example.exampleFile[8].description=default CV term mapping file example.exampleFile[8].version=2.0 example.exampleFile[8].focus=mzTab-M example.exampleFile[8].createdBy=Manual + +example.exampleFile[9].section=mapping +example.exampleFile[9].name=mzTab_2_0-M-lipidomics_mapping.xml +example.exampleFile[9].uri=https://raw.githubusercontent.com/lipidomics-standards-initiative/mzTab-L/master/drafts/1_0-Lipidomics/mzTab_2_0-M-lipidomics_mapping.xml +example.exampleFile[9].description=draft mzTab-L CV term mapping file +example.exampleFile[9].version=DRAFT +example.exampleFile[9].focus=mzTab-L +example.exampleFile[9].createdBy=Manual \ No newline at end of file