예제 #1
0
 public String parseJSONFind(String workspaceID, String jsonString) {
   StringBuffer ret = new StringBuffer();
   ret.append("{\n");
   System.out.println(workspaceID);
   System.out.println(jsonString);
   int counter = 0;
   DB db = m.getDB(Tokens.WORKSPACE_DATABASE);
   DBCollection coll = db.getCollection(workspaceID);
   BasicDBObject query =
       (BasicDBObject) JSON.parse(jsonString); // FixStrings.usr2mongo(jsonString)
   System.out.println("query: " + query.toString());
   DBCursor find = coll.find(query);
   Iterator<DBObject> iter = find.iterator();
   while (iter.hasNext()) {
     counter++;
     if (counter > 1) ret.append(",\n");
     DBObject next = iter.next();
     Map toMap = next.toMap();
     ret.append("\"" + toMap.get("_id").toString() + "\" : ");
     // remove the redundant id
     next.removeField("_id");
     // ret+= "\"kbid" + counter + "\" : ";
     String rec = FixStrings.mongo2usr(next.toString());
     ret.append(rec);
   }
   ret.append("\n}\n");
   // System.out.println(workspaceID);
   return ret.toString();
 }
예제 #2
0
 /**
  * save a document to the workspace provided
  *
  * @param workspaceID
  * @return
  */
 @PUT
 @Path("/document/{workspaceid}")
 // @Consumes("application/json")
 @Produces("application/json")
 public String saveDocument(
     @PathParam("workspaceid") String workspaceID, String jsonString) { // , String jsonString
   // System.out.println(jsonString);
   // System.out.println(workspaceID);
   // System.out.println(jsonString);
   jsonString = FixStrings.usr2mongo(jsonString);
   System.out.println(jsonString);
   DB db = m.getDB(Tokens.WORKSPACE_DATABASE);
   DBCollection coll = db.getCollection(workspaceID);
   BasicDBObject bo = (BasicDBObject) JSON.parse(jsonString);
   WriteResult save = coll.save(bo);
   // System.out.println(workspaceID);
   return FixStrings.mongo2usr(bo.toString()) + "\n";
 }