Ejemplo n.º 1
0
 public static void reloadGroups() {
   synchronized (groups) {
     saveGroups();
     groups.clear();
     MongoConnection.loadGroups();
   }
 }
Ejemplo n.º 2
0
  public void removeInheritance(Group group) {
    inherits.remove(group.getName());

    MongoCollection<Document> collection = MongoConnection.getCollection("perms", "groups");
    Document doc = collection.find(eq("group", name)).first();
    doc.put("inherits", inherits);
    collection.replaceOne(eq("group", name), doc);
  }
Ejemplo n.º 3
0
  public static List<String> queryMongoForSimilar(String courtId, String facets) throws Exception {
    // Query mongo for other facets with these values.
    System.out.println("Court id is: " + courtId);
    initializeMap();
    List<String> facetList = facetStringToListOfKeys(facets);
    // Facet list has the keys to get. Query mongo for the document with given courtId, then pull
    // the values of these keys.

    MongoConnection mc = new MongoConnection("supremeCourtDataDB.properties");
    MongoCollection<Document> collection = mc.getCollection();

    int courtIdInt = Integer.parseInt(courtId);
    Document d = collection.find(eq("courtId", courtIdInt)).first();
    System.out.println("Doc with this court id: " + d);

    Document queryDoc = new Document();
    // Build query based on given keys and their values in this doc.
    for (int i = 0; i < facetList.size(); i++) {
      String key = facetList.get(i);
      String tempString;
      int tempInt;
      try {
        tempString = d.getString(key);
        // queryJSON.put(key, tempString);
        queryDoc.put(key, tempString);
      } catch (ClassCastException c) {
        tempInt = d.getInteger(key);
        queryDoc.put(key, tempInt);
        // queryJSON.put(key, tempInt);
      }
    }

    List<String> resultList = new ArrayList<String>();

    System.out.println("Querying mongo.");
    FindIterable<Document> result = collection.find(queryDoc);

    for (Document doc : result) {
      String temp = Integer.toString(doc.getInteger("courtId"));
      resultList.add(temp);
    }

    System.out.println("Done!");
    return resultList;
  }
Ejemplo n.º 4
0
 public static void saveGroups() {
   MongoCollection<Document> collection = MongoConnection.getCollection("perms", "groups");
   for (Group group : groups) {
     collection.replaceOne(
         eq("group", group.getName()),
         new Document("group", group.getName())
             .append("permissions", group.permissions)
             .append("inherits", group.inherits));
   }
 }
Ejemplo n.º 5
0
  // Constructor
  private MongoStore() throws DBConnectionFailureException {

    // Get Mongo Client
    mongo = MongoConnection.getMongoClient();

    // Morphia
    morphia = new Morphia();

    // Map all the classes of model package.
    morphia.mapPackage("solutions.model");
  }
Ejemplo n.º 6
0
 /** Constructor for the ExamRepository, creates a MongoDB connection */
 public ExamRepository() {
   DB db = MongoConnection.getInstance().getDB();
   coll = db.getCollection("exams");
 }