コード例 #1
0
ファイル: SQLRESTService.java プロジェクト: simonemur/library
  private List<String> selectViewCodes(String schema) throws UnknownHostException {
    // Initiate variables
    List<String> l = new ArrayList<String>();
    MongoDBConnectionManager mgr = MongoDBConnectionManager.getInstance();
    Mongo mongo = mgr.getMongo();
    DB db = mongo.getDB(schema);
    DBCollection collection = db.getCollection("views");

    // Compose NoSQL query
    BasicDBObject groupFiels = new BasicDBObject("_id", "$view_id");
    BasicDBObject group = new BasicDBObject("$group", groupFiels);
    BasicDBObject sortFiels = new BasicDBObject("_id", 1);
    BasicDBObject sort = new BasicDBObject("$sort", sortFiels);

    // Create the output
    AggregationOutput output = collection.aggregate(group, sort);
    Iterable<DBObject> results = output.results();
    for (DBObject result : results) {
      try {
        l.add(result.get("_id").toString());
      } catch (NullPointerException e) {
        System.out.println("Skipping NULL");
      }
    }

    // Return the result
    return l;
  }
コード例 #2
0
ファイル: SQLRESTService.java プロジェクト: simonemur/library
  private String selectBooks(String collectionType, String type, String text, String schema)
      throws UnknownHostException {
    System.out.println(type);
    System.out.println(schema);
    List<String> l = new ArrayList<String>();
    MongoDBConnectionManager mgr = MongoDBConnectionManager.getInstance();
    Mongo mongo = mgr.getMongo();
    DB db = mongo.getDB(schema);
    // collectionType = "view"
    try {
      DBCollection collection = db.getCollection(collectionType);
      BasicDBObject searchQuery = new BasicDBObject();
      BasicDBObject regexQuery = new BasicDBObject();
      // regexQuery.put("title", new BasicDBObject("$regex", "^.*mi.*$").append("$options", "i"));

      regexQuery.put(type, new BasicDBObject("$regex", text).append("$options", "i"));

      DBCursor cursor = collection.find(regexQuery);
      while (cursor.hasNext()) l.add(cursor.next().toString());
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }
    System.out.println(l);
    if (l.size() > 0) return l.toString();
    return "error";
  }
コード例 #3
0
ファイル: SQLRESTService.java プロジェクト: simonemur/library
  private String selectBooks(
      String schema, String collection, String title, String author, String isbn)
      throws UnknownHostException {
    System.out.println(schema);
    System.out.println(collection);
    System.out.println(title);
    System.out.println(author);
    List<String> l = new ArrayList<String>();
    MongoDBConnectionManager mgr = MongoDBConnectionManager.getInstance();
    Mongo mongo = mgr.getMongo();
    DB db = mongo.getDB(schema);

    try {
      DBCollection c = db.getCollection(collection);
      BasicDBObject titleQuery = new BasicDBObject();
      titleQuery.put("title", new BasicDBObject("$regex", title));
      BasicDBObject authorQuery = new BasicDBObject();
      authorQuery.put("author", new BasicDBObject("$regex", author));

      BasicDBList or = new BasicDBList();
      or.add(titleQuery);
      or.add(titleQuery);

      DBObject query = new BasicDBObject("$and", or);

      DBCursor cursor = c.find(titleQuery);
      while (cursor.hasNext()) l.add(cursor.next().toString());
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }
    System.out.println(l);
    if (l.size() > 0) return l.toString();
    else return null;
  }
コード例 #4
0
ファイル: SQLRESTService.java プロジェクト: simonemur/library
 private void saveJson(String schema, String collection, String json) throws UnknownHostException {
   MongoDBConnectionManager mgr = MongoDBConnectionManager.getInstance();
   Mongo mongo = mgr.getMongo();
   DB db = mongo.getDB(schema);
   DBCollection c = db.getCollection(collection);
   DBObject dbObject = (DBObject) JSON.parse(json);
   c.insert(dbObject);
 }
コード例 #5
0
ファイル: Live.java プロジェクト: sdsu-its/fit-welcome
  /**
   * Get all events since the last event provided
   *
   * @param lastEvent {@link Integer} EventID of the last Event Recieved
   * @return {@link Response} All events since as JSON Document
   */
  @GET
  @Path("getEvents")
  @Consumes(MediaType.WILDCARD)
  @Produces(MediaType.APPLICATION_JSON)
  public Response getEvents(@QueryParam("id") String id, @QueryParam("last") Integer lastEvent) {
    Staff staff =
        id != null
            ? Staff.getStaff(id.replace(" ", "+"))
            : null; // JavaScript Converts +s to Spaces, that's Bad!
    if (staff == null) {
      return Response.status(Response.Status.FORBIDDEN).build();
    }

    Log.info(
        String.format("Recieved Request: [GET] GETEVENTS - id = %s & last = %d", id, lastEvent));
    if (lastEvent == null || lastEvent == 0) {
      lastEvent = DB.numEvents() - 10;
    }

    final List<Event> eventList = DB.getEventsSince(lastEvent);
    final Event[] results = new Event[eventList.size()];

    for (int e = 0; e < eventList.size(); e++) {
      Event event = eventList.get(e);

      // Checks for notify
      // ID: 999999999 is used to designate unknown IDs
      if ("Meet an ID".equals(event.type) && event.owner.id != 999999999) {
        Log.debug("Event's goal is to meet with ID, setting Notify to True");
        event.notify = true;
      } else if ("Use ParScore".equals(event.type)
          && "Walk In".equals(event.params)
          && event.owner.id != 999999999) {
        Log.debug("Event is a ParScore Walk In, setting Notify to True");
        event.notify = true;
      }
      event.timeString = event.time.toString("hh:mm a");

      results[e] = event;
    }

    final Gson gson = new Gson();
    return Response.status(Response.Status.OK).entity(gson.toJson(results)).build();
  }