public void updateDeviceLog(String productId, String[] vids, Modal model) {
   MongoCollection<Document> deviceLog = getDeviceLog();
   Document filter = new Document("product-id", productId);
   Document doc = getDeviceLog().find(filter).first();
   if (doc != null && model != null) {
     List<Document> models = doc.get("models", List.class);
     Document m = convertModel(vids, model);
     if (models != null) {
       models.add(m);
     } else {
       models = new ArrayList<>();
       models.add(m);
     }
     doc.append("models", models);
     deviceLog.replaceOne(filter, doc);
   } else {
     Device device = new Device();
     device.setProductId(productId);
     doc = toDocument(device);
     List<Document> models = new ArrayList<>();
     models.add(convertModel(vids, model));
     doc.append("models", models);
     deviceLog.insertOne(doc);
   }
 }
Esempio 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);
  }
Esempio n. 3
0
 @Override
 public UpdateResult replaceOne(Bson arg0, Document arg1, UpdateOptions arg2) {
   if (tx.started()) {
     tx.beforeUpdateOne(coll, arg0);
     return tx.getTxCollection().replaceOne(modifyQuery(arg0), arg1, arg2);
   } else {
     return coll.replaceOne(arg0, arg1, arg2);
   }
 }
Esempio 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));
   }
 }
Esempio n. 5
0
  public void putRecipeSummary(RecipeSummary recipeSummary) {
    MongoCollection<BsonDocument> collectionRecipeSummary =
        database.getCollection("recipeSummary", BsonDocument.class);
    BsonDocument bsonDocument = BsonDocument.parse(recipeSummary.toJson());
    bsonDocument.put("_id", new BsonString(recipeSummary.getRecipeId()));
    LOG.info("put bsonDocument = {}", bsonDocument.toString());

    collectionRecipeSummary.replaceOne(
        eq("_id", recipeSummary.getRecipeId()), bsonDocument, new UpdateOptions().upsert(true));
    //        collectionRecipeSummary.insertOne(bsonDocument);
  }