Skip to content

Commit

Permalink
Fixes #33 in the validator client. Also bumped Spring version.
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorRodchenkov committed Feb 3, 2024
1 parent 4a830a4 commit 8b91a48
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<File> 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)?

Expand All @@ -123,18 +121,19 @@ 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)!");
return;
}

HttpEntity httpEntity = meb.build();
// if(log.isDebugEnabled()) httpEntity.writeTo(System.err);
String content = Executor.newInstance()
.execute(Request.Post(url).body(httpEntity))
.returnContent().asString();
Expand Down Expand Up @@ -237,8 +236,7 @@ public static void main(String[] argv) throws IOException
}

// collect files
Collection<File> files = new HashSet<>();

List<File> files = new ArrayList<>();
if (fileOrDir.isDirectory()) {
// validate all the OWL files in the folder
FilenameFilter filter = (dir, name) -> (name.endsWith(".owl"));
Expand All @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*
*/
import java.io.*;
import java.util.List;

import jakarta.xml.bind.JAXBException;

Expand All @@ -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<File> 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<File> 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());
Expand Down
23 changes: 23 additions & 0 deletions biopax-validator-client/src/test/resources/testSyntaxErrors.owl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:bp="http://www.biopax.org/release/biopax-level3.owl#">
<owl:Ontology rdf:about="">
<owl:imports rdf:resource="http://www.biopax.org/release/biopax-level3.owl#" />
</owl:Ontology>

<bp:BioSource rdf:about="biosource_10090">
<bp:comment>test: using wrong property name 'taxonXref' (should be 'xref')</bp:comment>
<bp:standardName rdf:datatype = "xsd:string">Mus musculus</bp:standardName>
<bp:taxonXref rdf:resource="Taxonomy_UnificationXref_10090" />
<bp:displayName rdf:datatype = "xsd:string">Mouse</bp:displayName>
</bp:BioSource>

<bp:UnificationXref rdf:about="Taxonomy_UnificationXref_10090">
<bp:db rdf:datatype = "xsd:string">TAXONOMY</bp:db>
<bp:id rdf:datatype = "xsd:string">10090</bp:id>
</bp:UnificationXref>

</rdf:RDF>
4 changes: 2 additions & 2 deletions biopax-validator-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.15</version>
<version>2.7.18</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -96,7 +96,7 @@
</developers>

<properties>
<!-- <spring-framework.version>5.3.29</spring-framework.version>--><!-- defined in the parent pom -->
<!-- <spring-framework.version>5.3.31</spring-framework.version>--><!-- is defined in the parent pom -->
<start-class>org.biopax.validator.web.Application</start-class>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String,MultipartFile> 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)
Expand Down

0 comments on commit 8b91a48

Please sign in to comment.