You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sa...@apache.org on 2013/09/24 00:57:39 UTC
svn commit: r1525727 - in /airavata/trunk/modules:
distribution/airavata-server/pom.xml rest/service/pom.xml
rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/UserWorkflowRegistryResource.java
Author: samindaw
Date: Mon Sep 23 22:57:38 2013
New Revision: 1525727
URL: http://svn.apache.org/r1525727
Log:
https://issues.apache.org/jira/browse/AIRAVATA-912
Modified:
airavata/trunk/modules/distribution/airavata-server/pom.xml
airavata/trunk/modules/rest/service/pom.xml
airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/UserWorkflowRegistryResource.java
Modified: airavata/trunk/modules/distribution/airavata-server/pom.xml
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/distribution/airavata-server/pom.xml?rev=1525727&r1=1525726&r2=1525727&view=diff
==============================================================================
--- airavata/trunk/modules/distribution/airavata-server/pom.xml (original)
+++ airavata/trunk/modules/distribution/airavata-server/pom.xml Mon Sep 23 22:57:38 2013
@@ -335,6 +335,11 @@
</dependency>
<dependency>
<groupId>org.apache.airavata</groupId>
+ <artifactId>json</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.airavata</groupId>
<artifactId>airavata-messenger-client</artifactId>
<version>${project.version}</version>
</dependency>
Modified: airavata/trunk/modules/rest/service/pom.xml
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/service/pom.xml?rev=1525727&r1=1525726&r2=1525727&view=diff
==============================================================================
--- airavata/trunk/modules/rest/service/pom.xml (original)
+++ airavata/trunk/modules/rest/service/pom.xml Mon Sep 23 22:57:38 2013
@@ -43,6 +43,12 @@
<version>1.2.1</version>
</dependency>
+ <dependency>
+ <groupId>de.odysseus.staxon</groupId>
+ <artifactId>staxon</artifactId>
+ <version>1.2</version>
+ </dependency>
+
<!-- Airavata -->
<dependency>
<groupId>org.apache.airavata</groupId>
Modified: airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/UserWorkflowRegistryResource.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/UserWorkflowRegistryResource.java?rev=1525727&r1=1525726&r2=1525727&view=diff
==============================================================================
--- airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/UserWorkflowRegistryResource.java (original)
+++ airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/UserWorkflowRegistryResource.java Mon Sep 23 22:57:38 2013
@@ -21,6 +21,9 @@
package org.apache.airavata.services.registry.rest.resources;
+import de.odysseus.staxon.json.JsonXMLConfig;
+import de.odysseus.staxon.json.JsonXMLConfigBuilder;
+import de.odysseus.staxon.json.JsonXMLOutputFactory;
import org.apache.airavata.registry.api.AiravataRegistry2;
import org.apache.airavata.registry.api.exception.worker.UserWorkflowAlreadyExistsException;
import org.apache.airavata.registry.api.exception.worker.UserWorkflowDoesNotExistsException;
@@ -35,6 +38,11 @@ import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLEventWriter;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -156,11 +164,15 @@ public class UserWorkflowRegistryResourc
@GET
@Path(ResourcePathConstants.UserWFConstants.GET_WORKFLOWGRAPH)
@Produces({MediaType.APPLICATION_FORM_URLENCODED, MediaType.APPLICATION_JSON})
- public Response getWorkflowGraphXML(@QueryParam("workflowName") String workflowName) {
+ public Response getWorkflowGraphXML(@DefaultValue("false") @QueryParam("isJson") boolean isJson,
+ @QueryParam("workflowName") String workflowName) {
AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry(context);
try {
String workflowGraphXML = airavataRegistry.getWorkflowGraphXML(workflowName);
if (workflowGraphXML != null) {
+ if (isJson && workflowGraphXML.startsWith("<")) {
+ workflowGraphXML = getJSONWorkflowGraph(workflowGraphXML);
+ }
Response.ResponseBuilder builder = Response.status(Response.Status.OK);
builder.entity(workflowGraphXML);
return builder.build();
@@ -189,7 +201,7 @@ public class UserWorkflowRegistryResourc
@GET
@Path(ResourcePathConstants.UserWFConstants.GET_WORKFLOWS)
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
- public Response getWorkflows() {
+ public Response getWorkflows(@DefaultValue("false") @QueryParam("isJson") boolean isJson) {
AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry(context);
try {
Map<String, String> workflows = airavataRegistry.getWorkflows();
@@ -198,7 +210,11 @@ public class UserWorkflowRegistryResourc
for (String workflowName : workflows.keySet()) {
Workflow workflow = new Workflow();
workflow.setWorkflowName(workflowName);
- workflow.setWorkflowGraph(workflows.get(workflowName));
+ String workflowGraph = workflows.get(workflowName);
+ if (isJson && workflowGraph.startsWith("<")) {
+ workflowGraph = getJSONWorkflowGraph(workflowGraph);
+ }
+ workflow.setWorkflowGraph(workflowGraph);
workflowsModels.add(workflow);
}
workflowList.setWorkflowList(workflowsModels);
@@ -242,4 +258,34 @@ public class UserWorkflowRegistryResourc
}
}
}
+
+
+ private String getJSONWorkflowGraph(String workflowGraphXML) throws XMLStreamException, IOException {
+ String workflowGraphJSON;
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ ByteArrayInputStream input = new ByteArrayInputStream(workflowGraphXML.getBytes());
+ try {
+ JsonXMLConfig config = new JsonXMLConfigBuilder()
+ .autoArray(true)
+ .autoPrimitive(true)
+ .prettyPrint(true)
+ .build();
+ XMLEventReader reader = XMLInputFactory.newInstance().
+ createXMLEventReader(input);
+
+ XMLEventWriter writer = new JsonXMLOutputFactory(config).createXMLEventWriter(output);
+ writer.add(reader);
+ reader.close();
+ workflowGraphJSON = output.toString("UTF-8");
+ writer.close();
+ } finally {
+ /*
+ * As per StAX specification, XMLEventReader/Writer.close() doesn't close
+ * the underlying stream.
+ */
+ output.close();
+ input.close();
+ }
+ return workflowGraphJSON;
+ }
}