Skip to content

Commit

Permalink
fix: change serialization string to lang (#50)
Browse files Browse the repository at this point in the history
* fix: change serialization string to lang

* fix: rename

* fix: use name to serialization
  • Loading branch information
mosoriob authored Nov 3, 2023
1 parent 2869693 commit c3b062f
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 27 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<name>Wings OPM Mapper</name>
<packaging>jar</packaging>
<description>Wings OPM (Open Provenance Model) Mapper</description>
<version>1.2.8</version>
<version>2.0.0</version>

<properties>
<log4j.version>2.16.0</log4j.version>
Expand Down Expand Up @@ -179,7 +179,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.0</version>
<version>2.8.10</version>
</dependency>
</dependencies>

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/edu/isi/kcap/wings/opmm/Catalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.apache.jena.rdf.model.Statement;
import org.apache.jena.rdf.model.StmtIterator;
import org.apache.jena.rdf.model.impl.ResourceImpl;
import org.apache.jena.riot.Lang;

/**
* Class designed to deal with the versioning of new catalog entities.
Expand Down Expand Up @@ -532,7 +533,7 @@ private String getCatalogTypeForObject(Resource wingsObjType) {
* @param directory FOLDER path where to export the catalog
* @throws IOException
*/
public String exportCatalog(String directory, String serialization) throws IOException {
public String exportCatalog(String directory, Lang serialization) throws IOException {
String exportPath;
// create directory if it does not exist
File dir;
Expand Down Expand Up @@ -590,7 +591,7 @@ public static void main(String[] args) throws IOException {
" is " + c.getCatalogTypeForComponentInstanceURI(
"http://www.wings-workflows.org/wings-omics-portal/export/users/alyssa/DataAbstractions/components/library.owl#SNPcaller-Polyphred"));

c.exportCatalog(null, "RDF/XML");
c.exportCatalog(null, Lang.RDFXML);
System.out.println("Catalog exported");

// note: local tests have been performed by modifying the catalog manually.
Expand Down
21 changes: 12 additions & 9 deletions src/main/java/edu/isi/kcap/wings/opmm/Mapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.io.FileNotFoundException;
import java.io.IOException;

import org.apache.jena.riot.Lang;

import edu.isi.kcap.wings.opmm.DataTypes.Links;
import edu.isi.kcap.wings.opmm.DataTypes.ProvenanceResponseSchema;
import edu.isi.kcap.wings.opmm.Publisher.TriplesPublisher;
Expand Down Expand Up @@ -35,17 +38,17 @@ public static ProvenanceResponseSchema main(String domain,
filePublisher, workflowPublisher);
exportExecution(executionDestinationFilePath, workflowPublisher.serialization, response,
executionExport);
exportExpandedTemplate(expandedTemplateDestinationFilePath, workflowPublisher.serialization,
response,
executionExport);
exportExpandedTemplate(expandedTemplateDestinationFilePath, workflowPublisher.serialization,
response,
executionExport);
WorkflowTemplateExport templateExport = executionExport.getConcreteTemplateExport();
exportAbstractTemplate(abstractFilePath, workflowPublisher.serialization, response,
templateExport);
exportAbstractTemplate(abstractFilePath, workflowPublisher.serialization, response,
templateExport);
exportCatalog(catalogRepository, catalogPublisher.serialization, response, catalog);
return response;
}

private static void exportCatalog(String catalogRepository, String serialization,
private static void exportCatalog(String catalogRepository, Lang serialization,
ProvenanceResponseSchema response,
Catalog catalog) throws IOException {
// Export the catalog
Expand All @@ -59,7 +62,7 @@ private static void exportCatalog(String catalogRepository, String serialization
response.setCatalog(links);
}

private static void exportExpandedTemplate(String expandedTemplateDestinationFilePath, String serialization,
private static void exportExpandedTemplate(String expandedTemplateDestinationFilePath, Lang serialization,
ProvenanceResponseSchema response, WorkflowExecutionExport executionExport) throws IOException {
String expandedTemplateGraphUri = executionExport.getConcreteTemplateExport().exportAsOPMW(
expandedTemplateDestinationFilePath,
Expand All @@ -74,7 +77,7 @@ private static void exportExpandedTemplate(String expandedTemplateDestinationFil
response.setWorkflowExpandedTemplate(links);
}

private static void exportExecution(String executionDestinationFilePath, String serialization,
private static void exportExecution(String executionDestinationFilePath, Lang serialization,
ProvenanceResponseSchema response, WorkflowExecutionExport executionExport)
throws IOException, FileNotFoundException {
String executionGraphUri = executionExport.exportAsOPMW(executionDestinationFilePath, serialization);
Expand All @@ -85,7 +88,7 @@ private static void exportExecution(String executionDestinationFilePath, String
response.setWorkflowExecution(links);
}

private static void exportAbstractTemplate(String abstractFilePath, String serialization,
private static void exportAbstractTemplate(String abstractFilePath, Lang serialization,
ProvenanceResponseSchema response,
WorkflowTemplateExport abstractTemplateExport) throws IOException {
if (abstractTemplateExport != null) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/edu/isi/kcap/wings/opmm/ModelUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.riot.Lang;
import org.apache.jena.util.FileManager;

/**
Expand Down Expand Up @@ -62,14 +63,14 @@ public static OntModel loadModel(String path) throws IllegalArgumentException {
* @param mode serialization to export the model in
* @throws IOException
*/
public static void exportRDFFile(String outFile, OntModel model, String mode)
public static void exportRDFFile(String outFile, OntModel model, Lang mode)
throws IOException, FileNotFoundException {
if (outFile == null) {
throw new FileNotFoundException("File not found");
}
OutputStream out;
out = new FileOutputStream(outFile);
model.write(out, mode);
model.write(out, mode.getName());
// model.write(out,"RDF/XML");
out.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.jena.datatypes.xsd.impl.RDFLangString;
import org.apache.jena.query.DatasetAccessor;
import org.apache.jena.query.DatasetAccessorFactory;
import org.apache.jena.query.QuerySolution;
import org.apache.jena.riot.Lang;
import org.apache.jena.vocabulary.RDF;

import edu.isi.kcap.wings.opmm.Constants;
import edu.isi.kcap.wings.opmm.ModelUtils;
Expand All @@ -25,12 +28,12 @@ public class TriplesPublisher {
public String queryEndpoint;
public String graphURI = null;
DatasetAccessor accessor;
public String serialization;
public Lang serialization;
public String exportUrl;

public TriplesPublisher(String endpointQueryURI, String endpointPostURI, String exportBaseUrl,
String exportPrefix,
String serialization) {
Lang serialization) {
this.updateEndpoint = endpointPostURI;
this.queryEndpoint = endpointQueryURI;
this.accessor = DatasetAccessorFactory.createHTTP(updateEndpoint);
Expand All @@ -53,9 +56,9 @@ private void uploadTriples(byte[] data, HttpPost request, CloseableHttpClient ht
throws UnsupportedEncodingException, IOException, ClientProtocolException {
ByteArrayEntity entity = new ByteArrayEntity(data);
request.setEntity(entity);
if (serialization == "TTL")
if (serialization == Lang.TURTLE || serialization == Lang.TTL)
request.setHeader("Content-Type", "text/turtle");
else if (serialization == "RDF/XML")
else if (serialization == Lang.RDFXML)
request.setHeader("Content-Type", "application/rdf+xml");
else
throw new UnsupportedEncodingException("Serialization not supported");
Expand Down Expand Up @@ -114,7 +117,7 @@ public void setAccessor(DatasetAccessor accessor) {
this.accessor = accessor;
}

public void setSerialization(String serialization) {
public void setSerialization(Lang serialization) {
this.serialization = serialization;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.apache.jena.query.ResultSet;
import org.apache.jena.rdf.model.Literal;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.riot.Lang;

import edu.isi.kcap.wings.opmm.Publisher.TriplesPublisher;

Expand Down Expand Up @@ -408,7 +409,7 @@ private String getExpandedTemplateURI() {
* @param serialization serialization of choice: RDF/XML, TTL, etc.
* @throws IOException
*/
public String exportAsOPMW(String filepath, String serialization) throws IOException, FileNotFoundException {
public String exportAsOPMW(String filepath, Lang serialization) throws IOException, FileNotFoundException {
if (transformedExecutionURI == null) {
this.transform();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.apache.jena.query.ResultSet;
import org.apache.jena.rdf.model.Literal;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.riot.Lang;

import edu.isi.kcap.wings.opmm.Publisher.TriplesPublisher;

Expand Down Expand Up @@ -454,7 +455,7 @@ private String convertTemplateToOPMW(Individual wingsTemplate, int versionNumber
* @return
* @throws IOException
*/
public String exportAsOPMW(String filepath, String serialization) throws IOException {
public String exportAsOPMW(String filepath, Lang serialization) throws IOException {
if (transformedTemplate == null) {
this.transform();
}
Expand Down Expand Up @@ -495,7 +496,7 @@ public String exportAsPPlan(String outFileDirectory, String serialization) {
* @return URI of the template
* @throws IOException
*/
public String exportAll(String outFileDirectory, String serialization) throws IOException {
public String exportAll(String outFileDirectory, Lang serialization) throws IOException {
// TO DO
System.out.println("Not done yet!");
// this.export_as_OPMW(outFilePath, serialization);
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/opmw_mapper/MapperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.List;

import org.apache.jena.ontology.OntModel;
import org.apache.jena.riot.Lang;
import org.apache.jena.sparql.function.library.e;
import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -38,8 +39,8 @@ public class MapperTest {

@Test
public void testMapperTurtle() throws IOException {
String serialization = "TTL";
File targetDirectory = new File(serialization);
Lang serialization = Lang.TTL;
File targetDirectory = new File(serialization.getName());
if (!targetDirectory.exists()) {
targetDirectory.mkdir();
}
Expand Down
7 changes: 5 additions & 2 deletions src/test/java/opmw_mapper/TriplePublisherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.riot.Lang;
import org.apache.jena.vocabulary.OWL;
import org.apache.jena.vocabulary.RDF;
import org.apache.jena.vocabulary.RDFS;
Expand All @@ -23,7 +24,8 @@ public class TriplePublisherTest {
@Test
public void publishTriplesTestTurtle() throws IOException {
String resourceUri = "http://example.org/example#example";
TriplesPublisher tp = new TriplesPublisher(queryEndpoint, updateEndpoint, graph, "", "TTL");
Lang serialization = Lang.TTL;
TriplesPublisher tp = new TriplesPublisher(queryEndpoint, updateEndpoint, graph, "", Lang.TTL);
tp.setGraphURI(graph);
File file = createTripleFile(resourceUri, "TTL");
tp.publish(file);
Expand All @@ -33,7 +35,8 @@ public void publishTriplesTestTurtle() throws IOException {
@Test
public void publishTriplesTestRDFXML() throws IOException {
String resourceUri = "http://example.org/example";
TriplesPublisher tp = new TriplesPublisher(queryEndpoint, updateEndpoint, resourceUri, "test", "RDF/XML");
Lang serialization = Lang.RDFXML;
TriplesPublisher tp = new TriplesPublisher(queryEndpoint, updateEndpoint, resourceUri, "test", serialization);
tp.setGraphURI(graph);
File file = createTripleFile(resourceUri, "RDF/XML");
tp.publish(file);
Expand Down

0 comments on commit c3b062f

Please sign in to comment.