Skip to content

Commit

Permalink
Merge pull request #114 from Teiid-Designer/teiiddes-1560
Browse files Browse the repository at this point in the history
teiiddes-1560:
  • Loading branch information
blafond committed Feb 25, 2013
2 parents 59d8786 + 9022edc commit a56b6cf
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
Expand Down Expand Up @@ -364,6 +365,8 @@ private static void createRestProcedureCollection( Procedure procedure,
String fullName,
List restfulProcedureArray ) {
String restMethod = getRestMethod(procedure);
LinkedList<String> queryParameterList = new LinkedList<String>();


if (restMethod != null) {
String uri = getUri(procedure);
Expand Down Expand Up @@ -391,6 +394,7 @@ private static void createRestProcedureCollection( Procedure procedure,

}

//Check for URI parameters
String uriString = uri;
for (int i = 0; i < uriString.length(); i++) {
String character = uriString.substring(i, i + 1);
Expand All @@ -399,11 +403,26 @@ private static void createRestProcedureCollection( Procedure procedure,
}
}

//Check for query parameters
if (uriString.indexOf("&")>-1){ //$NON-NLS-1$
String[] queryParameterArray = uriString.split("&"); //$NON-NLS-1$
int i = 0;
for (String param : queryParameterArray) {
i++;
if (i==1) {
uri= param; //Set the first token as our URI and continue
continue;
}
queryParameterList.addLast(param);
}
}

restProcedure.setCharSet(charSet);
restProcedure.setRestMethod(restMethod);
restProcedure.setUri(uri);
restProcedure.setProcedureName(name);
restProcedure.setFullyQualifiedProcedureName(fullName);
restProcedure.setQueryParameterList(queryParameterList);

// Create JSON version
RestProcedure jsonRestProcedure = new RestProcedure();
Expand All @@ -413,13 +432,13 @@ private static void createRestProcedureCollection( Procedure procedure,
jsonRestProcedure.setProcedureName(restProcedure.getProcedureName());
jsonRestProcedure.setRestMethod(restProcedure.getRestMethod());
jsonRestProcedure.setUri(restProcedure.getUri());

// If the parameterCount is greater than the number of parameters passed
// on the URI, we can expect more parameters via an input stream
// so the consumes annotation will need to be set. We will set for XML and JSON methods.

boolean hasInputStream = false;
if (uriParameterCount < parameterCount) {
if (uriParameterCount != parameterCount &&
queryParameterList.size() != parameterCount) {
hasInputStream = true;
restProcedure.setConsumesAnnotation("@Consumes( MediaType.APPLICATION_XML )"); //$NON-NLS-1$
jsonRestProcedure.setConsumesAnnotation("@Consumes( MediaType.APPLICATION_JSON )"); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
package org.teiid.designer.runtime.ui.wizards.webservices.util;

import java.util.LinkedList;

/**
* Domain class that defines a procedure to be exposed RESTFully. This class is used to generate the REST resource class in the
* generated REST war.
Expand All @@ -23,6 +25,7 @@ public class RestProcedure {
private String uri;
private String modelName;
private String charSet;
private LinkedList<String> queryParameterList;

/**
* @return consumesAnnotation
Expand Down Expand Up @@ -138,4 +141,20 @@ public void setUri( String uri ) {
this.uri = uri;
}

/**
* @return the queryParameterList
* @since 8.1
*/
public LinkedList<String> getQueryParameterList() {
return queryParameterList;
}

/**
* @param queryParameterList the queryParameterList to set
* @since 8.1
*/
public void setQueryParameterList(LinkedList<String> queryParameterList) {
this.queryParameterList = queryParameterList;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
Expand Down Expand Up @@ -516,7 +517,7 @@ protected void createResourceJavaClasses( File webInfLibDirectory,
/*Create a diagnostic controller, which holds the compilation problems*/
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
ArrayList<String> options = new ArrayList<String>();
options.add("-g");

CompilationTask task = compilerTool.getTask(null, fileManager, diagnostics, options, null, compilationUnits);
task.call();
List<Diagnostic<? extends JavaFileObject>> diagnosticList = diagnostics.getDiagnostics();
Expand Down Expand Up @@ -569,7 +570,7 @@ private void createXMLMethod( StringBuilder sb,
RestProcedure restProcedure ) {
commonRestMethodLogic(sb, restProcedure, ""); //$NON-NLS-1$
if (restProcedure.getConsumesAnnotation() != null && !restProcedure.getConsumesAnnotation().isEmpty()) {
sb.append("\tparameterMap = getInputs(is, \""+restProcedure.getCharSet()+ "\");" + newline + "\t"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
sb.append("\tparameterMap = getInputs(is);" + newline + "\t"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}

// Gen return and execute
Expand Down Expand Up @@ -625,8 +626,22 @@ private void commonRestMethodLogic( StringBuilder sb,
sb.append(", "); //$NON-NLS-1$
}
}
//Now check for query parameters
LinkedList<String> queryParamList = new LinkedList<String>();
if (pathParamCount==0 && (restProcedure.getQueryParameterList() != null && restProcedure.getQueryParameterList().size()>0)){
int queryParamCount = 0;
queryParamList = restProcedure.getQueryParameterList();
for (String param : queryParamList) {
queryParamCount++;
sb.append("@QueryParam( \"" + param + "\" ) String " + param); //$NON-NLS-1$ //$NON-NLS-2$
if (queryParamCount < queryParamList.size()) {
sb.append(", "); //$NON-NLS-1$
}
}

}
if (restProcedure.getConsumesAnnotation() != null && !restProcedure.getConsumesAnnotation().isEmpty()) {
if (pathParams.size() > 0) {
if (pathParams.size() > 0 || queryParamList.size() > 0 ) {
sb.append(", "); //$NON-NLS-1$
}
sb.append(" InputStream is ) { " + newline + "\t"); //$NON-NLS-1$ //$NON-NLS-2$
Expand All @@ -640,6 +655,11 @@ private void commonRestMethodLogic( StringBuilder sb,
sb.append("\tparameterMap.put(\"" + param + "\", " + param + ");" + newline + "\t"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
}
if (queryParamList.size() > 0) {
for (String param : queryParamList) {
sb.append("\tparameterMap.put(\"" + param + "\", " + param + ");" + newline + "\t"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
Expand Down

0 comments on commit a56b6cf

Please sign in to comment.