diff --git a/biopax-validator-client/src/main/java/org/biopax/validator/BiopaxValidatorClient.java b/biopax-validator-client/src/main/java/org/biopax/validator/BiopaxValidatorClient.java index 29cc069c..88ec0d8e 100644 --- a/biopax-validator-client/src/main/java/org/biopax/validator/BiopaxValidatorClient.java +++ b/biopax-validator-client/src/main/java/org/biopax/validator/BiopaxValidatorClient.java @@ -12,9 +12,6 @@ import org.apache.commons.logging.LogFactory; import org.apache.http.Header; import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.ResponseHandler; import org.apache.http.client.fluent.Executor; import org.apache.http.client.fluent.Request; import org.apache.http.entity.ContentType; @@ -105,13 +102,14 @@ public BiopaxValidatorClient() { * @throws IOException */ public void validate(boolean autofix, String profile, RetFormat retFormat, Behavior filterBy, - Integer maxErrs, String biopaxUrl, File[] biopaxFiles, OutputStream out) throws IOException + Integer maxErrs, String biopaxUrl, List biopaxFiles, OutputStream out) throws IOException { MultipartEntityBuilder meb = MultipartEntityBuilder.create(); meb.setCharset(Charset.forName("UTF-8")); - if(autofix) - meb.addTextBody("autofix", "true"); + if(autofix) { + meb.addTextBody("autofix", "true"); + } //TODO: add extra options (normalizer.fixDisplayName, normalizer.xmlBase)? @@ -123,10 +121,12 @@ public void validate(boolean autofix, String profile, RetFormat retFormat, Behav meb.addTextBody("filter", filterBy.toString()); if(maxErrs != null && maxErrs > 0) meb.addTextBody("maxErrors", maxErrs.toString()); - if(biopaxFiles != null && biopaxFiles.length > 0) - for (File f : biopaxFiles) //important: use MULTIPART_FORM_DATA content-type - meb.addBinaryBody("file", f, ContentType.MULTIPART_FORM_DATA, f.getName()); - else if(biopaxUrl != null) { + if(biopaxFiles != null) { + int i = 0; + for (File f : biopaxFiles) { //important: use MULTIPART_FORM_DATA content-type + meb.addBinaryBody("file_"+(i++), f, ContentType.MULTIPART_FORM_DATA, f.getName()); + } + } else if(biopaxUrl != null) { meb.addTextBody("url", biopaxUrl); } else { log.error("Nothing to do (no BioPAX data specified)!"); @@ -134,7 +134,6 @@ else if(biopaxUrl != null) { } HttpEntity httpEntity = meb.build(); -// if(log.isDebugEnabled()) httpEntity.writeTo(System.err); String content = Executor.newInstance() .execute(Request.Post(url).body(httpEntity)) .returnContent().asString(); @@ -237,8 +236,7 @@ public static void main(String[] argv) throws IOException } // collect files - Collection files = new HashSet<>(); - + List files = new ArrayList<>(); if (fileOrDir.isDirectory()) { // validate all the OWL files in the folder FilenameFilter filter = (dir, name) -> (name.endsWith(".owl")); @@ -254,7 +252,7 @@ public static void main(String[] argv) throws IOException if (!files.isEmpty()) { BiopaxValidatorClient val = new BiopaxValidatorClient(); val.validate(fix, profile, outf, level, maxErrs, - null, files.toArray(new File[]{}), new FileOutputStream(output)); + null, files, new FileOutputStream(output)); } } diff --git a/biopax-validator-client/src/test/java/BiopaxValidatorClientTest.java b/biopax-validator-client/src/test/java/BiopaxValidatorClientTest.java index e0bbc339..a0c7e6bf 100644 --- a/biopax-validator-client/src/test/java/BiopaxValidatorClientTest.java +++ b/biopax-validator-client/src/test/java/BiopaxValidatorClientTest.java @@ -2,6 +2,7 @@ * */ import java.io.*; +import java.util.List; import jakarta.xml.bind.JAXBException; @@ -12,45 +13,49 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -// remove @Ignore when biopax.org/biopax-validator/ is available +/* +Uncomment when biopax.org/biopax-validator/ is available, +or run the web app locally (see readme) and this test with -Dbiopax.validator.url=http://localhost:8080/check JVM opt. +or use client.setUrl in the test case below. +*/ @Disabled public class BiopaxValidatorClientTest { @Test public void testClientHtml() throws IOException { BiopaxValidatorClient client = new BiopaxValidatorClient(); - - File[] files = new File[] { - new File(getClass().getResource( - File.separator + "testBiopaxElementIdRule.owl").getFile()) - }; - + List files = List.of( + new File(getClass().getResource(File.separator + "testBiopaxElementIdRule.owl").getFile()), + new File(getClass().getResource(File.separator + "testSyntaxErrors.owl").getFile()) + ); ByteArrayOutputStream baos = new ByteArrayOutputStream(); client.validate(false, null, RetFormat.HTML, null, null, null, files, baos); - - System.out.println(baos.toString()); + String res = baos.toString(); + + Assertions.assertAll( + () -> Assertions.assertTrue(baos.size()>0), + () -> Assertions.assertTrue(res.contains("testBiopaxElementIdRule.owl")), + () -> Assertions.assertTrue(res.contains("testSyntaxErrors.owl")) + ); +// System.out.println(baos); } @Test public void testClientXml() throws IOException, JAXBException { BiopaxValidatorClient client = new BiopaxValidatorClient(); - - File[] files = new File[] { - new File(getClass().getResource( - File.separator + "testBiopaxElementIdRule.owl").getFile()) - }; - + List files = List.of( + new File(getClass().getResource(File.separator + "testBiopaxElementIdRule.owl").getFile()), + new File(getClass().getResource(File.separator + "testSyntaxErrors.owl").getFile()) + ); ByteArrayOutputStream baos = new ByteArrayOutputStream(); client.validate(true, null, RetFormat.XML, null, null, null, files, baos); - - //System.out.println(baos.toString()); - - Assertions.assertTrue(baos.size()>0); - ValidatorResponse resp = client.unmarshal(baos.toString()); - - Assertions.assertNotNull(resp); - Assertions.assertFalse(resp.getValidation().isEmpty()); + + Assertions.assertAll( + () -> Assertions.assertTrue(baos.size()>0), + () -> Assertions.assertNotNull(resp), + () -> Assertions.assertEquals(2, resp.getValidation().size()) + ); System.out.println(resp.getValidation().get(0).getSummary() + "; cases: " + resp.getValidation().get(0).getTotalProblemsFound()); diff --git a/biopax-validator-client/src/test/resources/testSyntaxErrors.owl b/biopax-validator-client/src/test/resources/testSyntaxErrors.owl new file mode 100644 index 00000000..6a0773f5 --- /dev/null +++ b/biopax-validator-client/src/test/resources/testSyntaxErrors.owl @@ -0,0 +1,23 @@ + + + + + + + + test: using wrong property name 'taxonXref' (should be 'xref') + Mus musculus + + Mouse + + + + TAXONOMY + 10090 + + + \ No newline at end of file diff --git a/biopax-validator-web/pom.xml b/biopax-validator-web/pom.xml index 5f3d10ac..0d46d8a3 100644 --- a/biopax-validator-web/pom.xml +++ b/biopax-validator-web/pom.xml @@ -7,7 +7,7 @@ org.springframework.boot spring-boot-starter-parent - 2.7.15 + 2.7.18 @@ -96,7 +96,7 @@ - + org.biopax.validator.web.Application UTF-8 UTF-8 diff --git a/biopax-validator-web/src/main/java/org/biopax/validator/web/controller/ValidatorController.java b/biopax-validator-web/src/main/java/org/biopax/validator/web/controller/ValidatorController.java index 785b512a..ce1a82ed 100644 --- a/biopax-validator-web/src/main/java/org/biopax/validator/web/controller/ValidatorController.java +++ b/biopax-validator-web/src/main/java/org/biopax/validator/web/controller/ValidatorController.java @@ -127,10 +127,9 @@ public String check(HttpServletRequest request, HttpServletResponse response, } else if (request instanceof MultipartHttpServletRequest) { MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request; - Map files = multiRequest.getFileMap(); + Map files = multiRequest.getFileMap(); Assert.state(!files.isEmpty(), "No files to validate"); - for (Object o : files.values()) { - MultipartFile file = (MultipartFile) o; + for (MultipartFile file : files.values()) { String filename = file.getOriginalFilename(); // a workaround (for some reason there is always a no-name-file; // this might be a javascript isue)