Skip to content

Commit

Permalink
POST for indices now takes params arg.
Browse files Browse the repository at this point in the history
Indices can now be configured with name/value pairs via the REST API.
  • Loading branch information
spmallette committed Mar 10, 2012
1 parent 253a9c0 commit 663cfcf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.textile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ h3. Version 0.9 (NOT OFFICIALLY RELEASED YET)
</dependency>
```

* REST API for POSTing new indices supports @params@ argument which constructs a parameter map which will configure the newly created index.

==<hr/>==

!https://github.com/tinkerpop/rexster/raw/master/doc/images/rexster-santas-little-helper.png!
Expand Down
2 changes: 1 addition & 1 deletion rexster-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<groupId>com.tinkerpop.blueprints</groupId>
<artifactId>blueprints-neo4j-graph</artifactId>
<version>${blueprints.version}</version>
<scope>provided</scope>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.tinkerpop.blueprints</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.tinkerpop.blueprints.pgm.Index;
import com.tinkerpop.blueprints.pgm.IndexableGraph;
import com.tinkerpop.blueprints.pgm.Vertex;
import com.tinkerpop.blueprints.pgm.impls.Parameter;
import com.tinkerpop.blueprints.pgm.util.io.graphson.GraphSONFactory;
import com.tinkerpop.rexster.extension.HttpMethod;
import com.tinkerpop.rexster.util.ElementHelper;
Expand All @@ -29,8 +30,10 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -428,17 +431,18 @@ public Response postIndex(@PathParam("graphname") String graphName, @PathParam("
String clazz = null;
String type = null;
Set<String> keys = null;
Parameter<Object, Object>[] indexParameters = null;

final JSONObject theRequestObject = this.getRequestObject();

Object temp = theRequestObject.opt(Tokens.CLASS);
if (null != temp)
if (temp != null)
clazz = temp.toString();
temp = theRequestObject.opt(Tokens.TYPE);
if (null != temp)
if (temp != null)
type = temp.toString();
temp = theRequestObject.opt(Tokens.KEYS);
if (null != temp) {
if (temp != null) {
try {
JSONArray ks;
if (temp instanceof String) {
Expand All @@ -456,8 +460,21 @@ public Response postIndex(@PathParam("graphname") String graphName, @PathParam("
JSONObject error = generateErrorObject("Automatic index keys must be in an array: " + temp);
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity(error).build());
}
} else {
keys = null;
}

temp = theRequestObject.opt("params");
if (temp != null){
JSONObject idxParamsJson = (JSONObject) temp;
ArrayList<Parameter<Object, Object>> idxParamsList = new ArrayList<Parameter<Object, Object>>();

Iterator idxParamKeys = idxParamsJson.keys();
while(idxParamKeys.hasNext()) {
String nextIdxParamKey = (String) idxParamKeys.next();
idxParamsList.add(new Parameter<Object, Object>(nextIdxParamKey, idxParamsJson.optString(nextIdxParamKey)));
}

indexParameters = new Parameter[idxParamsList.size()];
idxParamsList.toArray(indexParameters);
}

final Index index = this.getIndexFromGraph(graphName, indexName);
Expand Down Expand Up @@ -492,21 +509,20 @@ else if (clazz.equals(Tokens.EDGE))
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity(error).build());
}

// why do we need this local "i" variable?
Index i;
Index newIndex;
try {
if (t == Index.Type.MANUAL)
i = graph.createManualIndex(indexName, c);
newIndex = graph.createManualIndex(indexName, c, indexParameters);
else
i = graph.createAutomaticIndex(indexName, c, keys);
newIndex = graph.createAutomaticIndex(indexName, c, keys, indexParameters);
} catch (Exception e) {
logger.info(e.getMessage());
JSONObject error = generateErrorObject(e.getMessage());
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity(error).build());
}
try {
this.resultObject.put(Tokens.QUERY_TIME, this.sh.stopWatch());
this.resultObject.put(Tokens.RESULTS, createJSONObject(i));
this.resultObject.put(Tokens.RESULTS, createJSONObject(newIndex));
} catch (JSONException ex) {
logger.error(ex);

Expand Down

0 comments on commit 663cfcf

Please sign in to comment.