io.elsci.signals.mock.assets.AssetsDao Maven / Gradle / Ivy
The newest version!
package io.elsci.signals.mock.assets;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import io.elsci.signals.sdk.assets.Asset;
import org.bson.Document;
import org.bson.conversions.Bson;
public class AssetsDao {
private final MongoClient mongo;
private final String dbName;
public AssetsDao(MongoClient mongo, String dbName) {
this.mongo = mongo;
this.dbName = dbName;
}
public Asset save(Asset asset) {
MongoCollection collection = entityCollection();
Document d = new Document("_id", asset.id)
.append("eid", asset.id)
.append("type", "asset")
.append("name", asset.name)
.append("createdAt", asset.createdAt)
.append("editedAt", asset.editedAt);
collection.insertOne(d);
return asset;
}
public FindIterable find(Bson filter) {
return entityCollection().find(filter);
}
private MongoCollection entityCollection() {
return mongo.getDatabase(dbName).getCollection("entities");
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy