airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From samin...@apache.org
Subject svn commit: r1520701 - in /airavata/sandbox/api-mock: airavata-mock-service-utils/src/main/java/org/apache/airavata/service/utils/help/ airavata-mock-service/src/main/java/org/apache/airavata/service/
Date Fri, 06 Sep 2013 21:21:29 GMT
Author: samindaw
Date: Fri Sep  6 21:21:29 2013
New Revision: 1520701

URL: http://svn.apache.org/r1520701
Log:
path refactor

Added:
    airavata/sandbox/api-mock/airavata-mock-service/src/main/java/org/apache/airavata/service/HelpService.java
  (with props)
Modified:
    airavata/sandbox/api-mock/airavata-mock-service-utils/src/main/java/org/apache/airavata/service/utils/help/HelpData.java
    airavata/sandbox/api-mock/airavata-mock-service-utils/src/main/java/org/apache/airavata/service/utils/help/MethodUtils.java
    airavata/sandbox/api-mock/airavata-mock-service/src/main/java/org/apache/airavata/service/ApplicationService.java
    airavata/sandbox/api-mock/airavata-mock-service/src/main/java/org/apache/airavata/service/ExperimentService.java

Modified: airavata/sandbox/api-mock/airavata-mock-service-utils/src/main/java/org/apache/airavata/service/utils/help/HelpData.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/api-mock/airavata-mock-service-utils/src/main/java/org/apache/airavata/service/utils/help/HelpData.java?rev=1520701&r1=1520700&r2=1520701&view=diff
==============================================================================
--- airavata/sandbox/api-mock/airavata-mock-service-utils/src/main/java/org/apache/airavata/service/utils/help/HelpData.java
(original)
+++ airavata/sandbox/api-mock/airavata-mock-service-utils/src/main/java/org/apache/airavata/service/utils/help/HelpData.java
Fri Sep  6 21:21:29 2013
@@ -8,7 +8,7 @@ import java.util.Map;
 public class HelpData {
 	private String title;
 	private String description;
-	private String syntax;
+	private List<String> syntax;
 	private Map<String,String> parameters;
 	private List<String> examples;
 	private List<String> notes;
@@ -29,10 +29,13 @@ public class HelpData {
 	public void setDescription(String description) {
 		this.description = description;
 	}
-	public String getSyntax() {
+	public List<String> getSyntax() {
+		if (syntax==null){
+			syntax=new ArrayList<String>();
+		}
 		return syntax;
 	}
-	public void setSyntax(String syntax) {
+	public void setSyntax(List<String> syntax) {
 		this.syntax = syntax;
 	}
 	public Map<String, String> getParameters() {

Modified: airavata/sandbox/api-mock/airavata-mock-service-utils/src/main/java/org/apache/airavata/service/utils/help/MethodUtils.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/api-mock/airavata-mock-service-utils/src/main/java/org/apache/airavata/service/utils/help/MethodUtils.java?rev=1520701&r1=1520700&r2=1520701&view=diff
==============================================================================
--- airavata/sandbox/api-mock/airavata-mock-service-utils/src/main/java/org/apache/airavata/service/utils/help/MethodUtils.java
(original)
+++ airavata/sandbox/api-mock/airavata-mock-service-utils/src/main/java/org/apache/airavata/service/utils/help/MethodUtils.java
Fri Sep  6 21:21:29 2013
@@ -2,14 +2,59 @@ package org.apache.airavata.service.util
 
 
 public class MethodUtils {
+	
 	public static String getHelpString(HelpData data){
+		if (data instanceof HTMLHelpData){
+			return getHTMLHelp(data);
+		}else{
+			return getPlainHelp(data);
+		}
+	}
+	
+	private static String getHTMLHelp(HelpData data) {
+		String help="<html><body>";
+		help+="<h1>"+data.getTitle()+"</h1>"+"\n\n";
+		help+="<p>Usage: "+data.getDescription()+"</p>\n\n";
+		help+="<br />";
+		if (data.getSyntax().size()>0){
+			help+="<p>"+"Syntax:\n<br />";
+			for (String syntax : data.getSyntax()) {
+				help+="\t"+syntax+"\n";
+			}
+		}
+		help+="\n\n";
+		help+="Supported Parameters/Operations\n\n";
+		for (String parameterName : data.getParameters().keySet()) {
+			help+=parameterName+"\t\t"+data.getParameters().get(parameterName)+"\n";
+		} 
+		help+="\n";
+		if (data.getExamples().size()>0){
+			help+="Examples:\n";
+			for (String example : data.getExamples()) {
+				help+="\t"+example+"\n";
+			}
+			help+="\n";
+		}
+		if (data.getNotes().size()>0){
+			help+="Notes:\n";
+			for (String note : data.getNotes()) {
+				help+=note+"\n";
+			}
+		}
+		help+="</body></html>";
+		return help;
+	}
+	private static String getPlainHelp(HelpData data) {
 		String help=data.getTitle()+"\n\n";
 		help+="Usage: "+data.getDescription()+"\n\n";
-		if (data.getSyntax()!=null){
-			help+="Syntax:\n\t"+data.getSyntax();
+		if (data.getSyntax().size()>0){
+			help+="Syntax:\n";
+			for (String syntax : data.getSyntax()) {
+				help+="\t"+syntax+"\n";
+			}
 		}
 		help+="\n\n";
-		help+="Parameters\n\n";
+		help+="Supported Parameters/Operations\n\n";
 		for (String parameterName : data.getParameters().keySet()) {
 			help+=parameterName+"\t\t"+data.getParameters().get(parameterName)+"\n";
 		} 

Modified: airavata/sandbox/api-mock/airavata-mock-service/src/main/java/org/apache/airavata/service/ApplicationService.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/api-mock/airavata-mock-service/src/main/java/org/apache/airavata/service/ApplicationService.java?rev=1520701&r1=1520700&r2=1520701&view=diff
==============================================================================
--- airavata/sandbox/api-mock/airavata-mock-service/src/main/java/org/apache/airavata/service/ApplicationService.java
(original)
+++ airavata/sandbox/api-mock/airavata-mock-service/src/main/java/org/apache/airavata/service/ApplicationService.java
Fri Sep  6 21:21:29 2013
@@ -25,6 +25,7 @@ import org.apache.airavata.service.utils
 import org.apache.airavata.service.utils.json.ConversionUtils;
 import org.apache.airavata.service.utils.model.ApplicationDescriptorJSONFacotry;
 import org.apache.airavata.service.utils.model.DataList;
+import org.apache.airavata.service.utils.path.ApplicationPath;
 import org.codehaus.jackson.JsonGenerationException;
 import org.codehaus.jackson.map.JsonMappingException;
 import org.codehaus.jackson.map.ObjectMapper;
@@ -35,12 +36,12 @@ import org.codehaus.jackson.map.ObjectMa
  * http://127.0.0.1:9090/orders-server/orders/list
  */
 
-@Path("/applications/")
+@Path(ApplicationPath.SERVICE_PATH)
 public class ApplicationService {
 	@Context
 	UriInfo uriInfo;
 	
-	@Path("add")
+	@Path(ApplicationPath.ADD_APPLICATION)
 	@GET
 	@Produces(MediaType.TEXT_PLAIN)
 	public String add(@QueryParam("application") String application) {
@@ -56,14 +57,14 @@ public class ApplicationService {
 		
 	}
 	
-	@Path("add/help")
+	@Path(ApplicationPath.ADD_APPLICATION_HELP)
 	@GET
 	@Produces(MediaType.TEXT_PLAIN)
 	public String showHelp() {
 		HelpData helpData = new HelpData("Add Application Description","Add the details of how
to access an application from Airavata");
 		try {
 			URI uri = ServiceUtils.getServiceOperationURIFromHelpURI(uriInfo);
-			helpData.setSyntax(uri.toString()+"?application=<JSONString>");
+			helpData.getSyntax().add(uri.toString()+"?application=<JSONString>");
 			helpData.getParameters().put("application", "Describes the application access data in
JSON format. The supported JSON types are listed in the 'Notes' section.");
 			List<Class<?>> types = ApplicationDescriptorJSONFacotry.getInstance().getTypes();
 			for (Class<?> cl : types) {

Modified: airavata/sandbox/api-mock/airavata-mock-service/src/main/java/org/apache/airavata/service/ExperimentService.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/api-mock/airavata-mock-service/src/main/java/org/apache/airavata/service/ExperimentService.java?rev=1520701&r1=1520700&r2=1520701&view=diff
==============================================================================
--- airavata/sandbox/api-mock/airavata-mock-service/src/main/java/org/apache/airavata/service/ExperimentService.java
(original)
+++ airavata/sandbox/api-mock/airavata-mock-service/src/main/java/org/apache/airavata/service/ExperimentService.java
Fri Sep  6 21:21:29 2013
@@ -16,14 +16,15 @@ import javax.ws.rs.WebApplicationExcepti
 import javax.ws.rs.core.MediaType;
 
 import org.apache.airavata.core.application.ExperimentData;
+import org.apache.airavata.service.utils.path.ExperimentPath;
 
-@Path("/experiments/")
+@Path(ExperimentPath.SERVICE_PATH)
 public class ExperimentService {
 	private static Map<String,String> templates=new HashMap<String, String>();
 	private static Map<String,String> experiments=new HashMap<String, String>();
 	private static Map<String,ExperimentData> experimentData=new HashMap<String, ExperimentData>();
 
-	@Path("add/template/{templateId}")
+	@Path(ExperimentPath.ADD_TEMPLATE+"/{templateId}")
 	@GET
 	@Produces(MediaType.TEXT_PLAIN)
 	public String addTemplate(@PathParam("templateId") String templateId, @QueryParam("experimentTemplate")
String experimentTemplate) {
@@ -33,14 +34,14 @@ public class ExperimentService {
 		return templateId;
 	}
 	
-	@Path("list/templates")
+	@Path(ExperimentPath.LIST_TEMPLATES)
 	@GET
 	@Produces(MediaType.APPLICATION_JSON)
 	public List<String> getTemplates() {
 		return (Arrays.asList(templates.keySet().toArray(new String[]{})));
 	}
 
-	@Path("run/{templateId}")
+	@Path(ExperimentPath.RUN_EXPERIMENTS+"/{templateId}")
 	@GET
 	@Produces(MediaType.TEXT_PLAIN)
 	public String runExperiment(@PathParam("templateId") String templateId, @QueryParam("experimentInput")
String experimentInput) {
@@ -55,14 +56,14 @@ public class ExperimentService {
 		return uuid.toString();
 	}
 	
-	@Path("list/experiments")
+	@Path(ExperimentPath.LIST_EXPERIMENTS)
 	@GET
 	@Produces(MediaType.APPLICATION_JSON)
 	public List<String> getExperiments() {
 		return (Arrays.asList(experiments.keySet().toArray(new String[]{})));
 	}
 	
-	@Path("results/{experimentId}")
+	@Path(ExperimentPath.GET_RESULTS+"/{experimentId}")
 	@GET
 	@Produces(MediaType.APPLICATION_JSON)
 	public ExperimentData getExperimentData(@PathParam ("experimentId") String experimentId)
{

Added: airavata/sandbox/api-mock/airavata-mock-service/src/main/java/org/apache/airavata/service/HelpService.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/api-mock/airavata-mock-service/src/main/java/org/apache/airavata/service/HelpService.java?rev=1520701&view=auto
==============================================================================
--- airavata/sandbox/api-mock/airavata-mock-service/src/main/java/org/apache/airavata/service/HelpService.java
(added)
+++ airavata/sandbox/api-mock/airavata-mock-service/src/main/java/org/apache/airavata/service/HelpService.java
Fri Sep  6 21:21:29 2013
@@ -0,0 +1,48 @@
+package org.apache.airavata.service;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.airavata.service.utils.ServiceUtils;
+import org.apache.airavata.service.utils.help.HTMLHelpData;
+import org.apache.airavata.service.utils.help.HelpData;
+import org.apache.airavata.service.utils.help.MethodUtils;
+import org.apache.airavata.service.utils.path.ApplicationPath;
+import org.apache.airavata.service.utils.path.ExperimentPath;
+import org.apache.airavata.service.utils.path.MainHelpPath;
+
+/**
+ * curl -X PUT http://127.0.0.1:9090/orders-server/orders/1?customer_name=bob
+ * curl -X GET http://127.0.0.1:9090/orders-server/orders/1 curl -X GET
+ * http://127.0.0.1:9090/orders-server/orders/list
+ */
+
+@Path(MainHelpPath.SERVICE_PATH)
+public class HelpService {
+	@Context
+	UriInfo uriInfo;
+	
+	@Path(MainHelpPath.ENTRY)
+	@GET
+	@Produces(MediaType.TEXT_PLAIN)
+	public String add() throws URISyntaxException {
+		URI url = ServiceUtils.getServiceOperationURIFromHelpURI(uriInfo);
+		HelpData helpData = new HTMLHelpData("Airavata Mock API", "Welcome to Airavata API!!!");
+		helpData.getParameters().put("<a href='"+url.toString()+ApplicationPath.SERVICE_PATH+ApplicationPath.ADD_APPLICATION_HELP+"'>New
Application</a>", "Add new application to Airavata system");
+		helpData.getParameters().put("<a href='"+url.toString()+ExperimentPath.SERVICE_PATH+ExperimentPath.ADD_TEMPLATE_HELP+"'>New
Experiment Template</a>", "Add new application to Airavata system");
+		helpData.getParameters().put("<a href='"+url.toString()+ExperimentPath.SERVICE_PATH+ExperimentPath.RUN_EXPERIMENTS_HELP+"'>Launch
Experiment</a>", "Launch an experiment from a experiment template in Airavata system");
+		helpData.getParameters().put("<a href='"+url.toString()+ExperimentPath.SERVICE_PATH+ExperimentPath.GET_RESULTS_HELP+"'>Get
Experiment Results</a>", "Return the results of launching the experiment");
+		helpData.getParameters().put("<a href='"+url.toString()+ExperimentPath.SERVICE_PATH+ExperimentPath.LIST_TEMPLATES_HELP+"'>Templates</a>",
"List of templates available.");
+		helpData.getParameters().put("<a href='"+url.toString()+ExperimentPath.SERVICE_PATH+ExperimentPath.LIST_EXPERIMENTS_HELP+"'>Experiments</a>",
"List of experiments available.");
+		return MethodUtils.getHelpString(helpData);
+	}
+	
+
+}
\ No newline at end of file

Propchange: airavata/sandbox/api-mock/airavata-mock-service/src/main/java/org/apache/airavata/service/HelpService.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message