public static JSONObject findReportsRaw() {
JSONArray reports = new JSONArray();
FindIterable<Document> result = findReports();
result.forEach(new Block<Document>() {
@Override
public void apply(final Document document) {
JSONObject jsonReport = new JSONObject();
jsonReport.put("id", document.getObjectId("_id").toString());
jsonReport.put("comment", document.getString("comment"));
jsonReport.put("city_item_id", document.getString("city_item_id"));
jsonReport.put("priority", document.getInteger("priority"));
jsonReport.put("resolved", document.getBoolean("resolved"));
jsonReport.put("report_date", document.getLong("report_date"));
reports.put(jsonReport);
}
});
JSONObject jsonResults = new JSONObject();
jsonResults.put("reports", reports);
return jsonResults;
}
java类com.mongodb.Block的实例源码
ReportDAO.java 文件源码
项目:Smart_City
阅读 31
收藏 0
点赞 0
评论 0
MongodbDatabase.java 文件源码
项目:StickyChunk
阅读 25
收藏 0
点赞 0
评论 0
public HashMap<UUID, ArrayList<LoadedRegion>> loadRegionData() {
HashMap<UUID, ArrayList<LoadedRegion>> regions = new HashMap<>();
MongoCollection<Document> collection = getDatabase().getCollection("chunks");
collection.find().forEach((Block<Document>) document -> {
UUID id = UUID.fromString(document.getString("_id"));
UUID owner = UUID.fromString(document.getString("owner"));
UUID world = UUID.fromString(document.getString("world"));
LoadedRegion.ChunkType type = LoadedRegion.ChunkType.valueOf(document.getString("type"));
int fromX = document.getInteger("fromX");
int fromZ = document.getInteger("fromZ");
int toX = document.getInteger("toX");
int toZ = document.getInteger("toZ");
Date date = (Date) document.getDate("created");
Region region = new Region(new Coordinate(fromX, fromZ), new Coordinate(toX, toZ), world);
if (regions.containsKey(id))
regions.get(id).add(new LoadedRegion(owner, id, region, date, type));
else
regions.put(id, Lists.newArrayList(new LoadedRegion(owner, id, region, date, type)));
});
return regions;
}
ReportDAO.java 文件源码
项目:Smart_City
阅读 23
收藏 0
点赞 0
评论 0
/**
* Returns all reports for view
*
* @return List
*/
public static List<ReportViewObject> findReportsForView() {
List<ReportViewObject> reports = new ArrayList<>();
FindIterable<Document> result = findReports();
result.forEach(new Block<Document>() {
@Override
public void apply(final Document document) {
Report.Builder b = new Report.Builder();
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
String reportDate = df.format(new Date(document.getLong("report_date")));
reports.add(new ReportViewObject(
document.getObjectId("_id").toString(),
Integer.toString(document.getInteger("priority")),
document.getString("city_item_id"),
reportDate,
document.getBoolean("resolved") ? "YES" : "NO"));
}
});
return reports;
}
MongoDBManager.java 文件源码
项目:Backend
阅读 22
收藏 0
点赞 0
评论 0
public int returnValueToURL(String URL)
{
Block<Document> printBlock = new Block<Document>() {
@Override
public void apply(final Document document) {
System.out.println(document.toJson());
}
};
MongoCollection<Document> collection = db.getCollection("ratings");
collection.aggregate(
Arrays.asList(
Aggregates.group("URL", Accumulators.avg("rating", 1))))
.forEach(printBlock);
System.out.println(printBlock.toString());
return 0;
}
MngToOrclReader.java 文件源码
项目:mongodb-rdbms-sync
阅读 27
收藏 0
点赞 0
评论 0
@Override
public void run() {
System.out.println("Reader started");
MongoCollection<Document> collection = DBCacheManager.INSTANCE.getCachedMongoPool(mongoDbName, mongoUserName)
.getDatabase(mongoDbName).getCollection(collectionName);
FindIterable<Document> it = collection.find().batchSize(batchSize);
it.forEach(new Block<Document>() {
@Override
public void apply(Document t) {
System.out.println("Document read " + t);
try {
dataBuffer.put(t);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
ActivityDaoBean.java 文件源码
项目:otus-api
阅读 28
收藏 0
点赞 0
评论 0
@Override
public List<SurveyActivity> findByCategory(String categoryName) {
ArrayList<SurveyActivity> activities = new ArrayList<>();
FindIterable<Document> result = collection.find(eq("category.name", categoryName));
result.forEach((Block<Document>) document -> activities.add(SurveyActivity.deserialize(document.toJson())));
return activities;
}
DeviceSetupRepository.java 文件源码
项目:HomeWire-Server
阅读 16
收藏 0
点赞 0
评论 0
public List<DeviceEntity> getAllDevicesByCategory(String category) {
List<DeviceEntity> result = new ArrayList<>();
Document filter;
if (category.isEmpty()) {
filter = new Document();
} else {
filter = new Document("category", category);
}
collection.find(filter)
.forEach((Block<? super Document>) document -> {
Short devId = document.getInteger("dev_id").shortValue();
String name = document.getString("name");
String cat = document.getString("category");
String type = document.getString("type");
boolean isTrusted = document.getBoolean("isTrusted");
result.add(new DeviceEntity(devId, name, cat, type, isTrusted));
});
return result;
}
DeviceSetupRepository.java 文件源码
项目:HomeWire-Server
阅读 28
收藏 0
点赞 0
评论 0
public List<DeviceEntity> getDeviceEntitiesByName(String name) {
Document query = new Document("name", name);
List<DeviceEntity> result = new ArrayList<>();
collection.find(query).forEach((Block<? super Document>) document -> {
Short devId = document.getInteger("dev_id").shortValue();
String category = document.getString("category");
String type = document.getString("type");
boolean isTrusted = document.getBoolean("isTrusted");
result.add(new DeviceEntity(devId, name, category, type, isTrusted));
});
return result;
}
DeviceSetupRepository.java 文件源码
项目:HomeWire-Server
阅读 26
收藏 0
点赞 0
评论 0
public List<DeviceEntity> getDeviceEntitiesByType(String type) {
Document query = new Document("type", type);
List<DeviceEntity> result = new ArrayList<>();
collection.find(query).forEach((Block<? super Document>) document -> {
Short devId = document.getInteger("dev_id").shortValue();
String category = document.getString("category");
String name = document.getString("name");
boolean isTrusted = document.getBoolean("isTrusted");
result.add(new DeviceEntity(devId, name, category, type, isTrusted));
});
return result;
}
RavelryConverterService.java 文件源码
项目:discoursedb-core
阅读 23
收藏 0
点赞 0
评论 0
public List<Integer> addPostings(int topic) {
List<Integer> postings = new ArrayList<Integer>();
BasicDBObject query = new BasicDBObject();
query.put("topic_id", topic);
BasicDBObject sortby = new BasicDBObject("post_number", 1);
log.info(" Querying postings in topic " + topic);
progress_counter = 0;
List<Document> lbd = new ArrayList<>();
mongoClient.getDatabase(mongoDbName).getCollection("postings").find(query).sort(sortby).forEach((Block<Document>) d -> { lbd.add(d); });
for (int clump=0; clump<= lbd.size(); clump += 300) {
log.info(" adding posts " + clump + " through " + Math.min(clump+300,lbd.size()));
postings.addAll(helper.addPostingGroup(topic, lbd.subList(clump, Math.min(clump+300,lbd.size())),this));
}
log.info("done with adding posts to this topic");
return postings;
}
InitializationPlugin.java 文件源码
项目:step
阅读 22
收藏 0
点赞 0
评论 0
private void migrateGeneralScriptFunctions(GlobalContext context) {
logger.info("Searching for functions of type 'step.plugins.functions.types.GeneralScriptFunction' to be migrated...");
com.mongodb.client.MongoCollection<Document> functions = MongoDBAccessorHelper.getMongoCollection_(context.getMongoClient(), "functions");
AtomicInteger i = new AtomicInteger();
Document filterCallFunction = new Document("type", "step.plugins.functions.types.GeneralScriptFunction");
functions.find(filterCallFunction).forEach(new Block<Document>() {
@Override
public void apply(Document t) {
t.replace("type", "step.plugins.java.GeneralScriptFunction");
Document filter = new Document("_id", t.get("_id"));
functions.replaceOne(filter, t);
i.incrementAndGet();
}
});
logger.info("Migrated "+i.get()+" functions of type 'step.plugins.functions.types.GeneralScriptFunction'");
}
InitializationPlugin.java 文件源码
项目:step
阅读 19
收藏 0
点赞 0
评论 0
private void renameArtefactType(GlobalContext context, String classFrom, String classTo) {
logger.info("Searching for artefacts of type '"+classFrom+"' to be migrated...");
com.mongodb.client.MongoCollection<Document> artefacts = MongoDBAccessorHelper.getMongoCollection_(context.getMongoClient(), "artefacts");
AtomicInteger i = new AtomicInteger();
Document filterCallFunction = new Document("_class", classFrom);
artefacts.find(filterCallFunction).forEach(new Block<Document>() {
@Override
public void apply(Document t) {
try {
i.incrementAndGet();
t.put("_class", classTo);
Document filter = new Document("_id", t.get("_id"));
artefacts.replaceOne(filter, t);
logger.info("Migrating "+classFrom+ " to "+t.toJson());
} catch(ClassCastException e) {
// ignore
}
}
});
logger.info("Migrated "+i.get()+" artefacts of type '"+classFrom+"'");
}
PersistedPages.java 文件源码
项目:reactive-hamster
阅读 28
收藏 0
点赞 0
评论 0
public boolean checkAndCleanup(String userId, String fileName) {
List<Document> l = query(new Query().equals(USERID, userId).addSortCriteria(CREATION_TIME, false));
if (l.size() >= maxPersistedPagesPerUser) {
Document oldest = l.iterator().next();
if ((System.currentTimeMillis() - oldest.get(CREATION_TIME).getTime()) < minimumDelay) {
//there have been to many page persistences for this user in a short time, so don't persist
return false;
} else {
//clean up oldest to free space for new persisted page
gridFS.find(Filters.eq("filename", oldest.get(FILENAME))).forEach(new Block<GridFSFile>() {
@Override
public void apply(GridFSFile file) {
gridFS.delete(file.getObjectId());
}
});
oldest.delete();
}
}
//create new entry
Document newOne = createNew();
newOne.set(USERID, userId);
newOne.set(FILENAME, fileName);
newOne.set(CREATION_TIME, new Date());
newOne.writeToDatabase(false);
return true;
}
DocumentCollection.java 文件源码
项目:reactive-hamster
阅读 21
收藏 0
点赞 0
评论 0
/**
* Fires an event on all objects in the cache, which fulfill the query
*
* @param event
* @param query
*/
public void fireEvent(final DataEvent event, BaseQuery query) {
//query only ids
FindIterable cursor = collection.find(query.getQuery());
cursor.forEach(new Block() {
@Override
public void apply(Object t) {
org.bson.Document dbObject = (org.bson.Document) t;
String id = "" + dbObject.get("_id");
synchronized (map) {
Document o = map.get(id);
if (o != null) {
o.fireChangedEvent(event);
}
}
}
});
}
DeploymentsDao.java 文件源码
项目:paasport
阅读 19
收藏 0
点赞 0
评论 0
public List<Deployment> getDeployments(String clusterId) {
List<Deployment> deployments = new ArrayList<>();
Block<Document> printBlock = new Block<Document>() {
@Override
public void apply(final Document document) {
Deployment deployment = new Deployment();
deployment.setUuid(document.getString("uuid"));
deployment.setStatus(document.getString("status"));
deployment.setHostCount(document.getInteger("hostCount"));
deployment.setCompletedCount(document.getInteger("completedCount"));
TarFile tarFile = new TarFile();
tarFile.setUrl(document.getString("sourceTar"));
deployment.setSourceTar(tarFile);
deployment.setTimestamp(document.getDate("timestamp"));
deployments.add(deployment);
}
};
connection.getCollection(DEPLOYMENTS_COLLECTION_NAME).find(eq("clusterId", clusterId)).forEach(printBlock);
return deployments;
}
MongoCollectionList.java 文件源码
项目:openbd-core
阅读 24
收藏 0
点赞 0
评论 0
public cfData execute(cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException {
MongoClient client = getMongoClient( _session, argStruct );
try{
cfArrayData arr = cfArrayData.createArray(1);
client.listDatabaseNames().forEach( new Block<String>(){
@Override
public void apply( String dbName ) {
try {
arr.addElement( new cfStringData( dbName ) );
} catch ( cfmRunTimeException e ) {}
}
});
return arr;
} catch (MongoException me){
throwException(_session, me.getMessage());
return null;
}
}
PeopleRegistry.java 文件源码
项目:bsoneer
阅读 24
收藏 0
点赞 0
评论 0
public static void main(String[] args) {
MongoClient mongoClient = new MongoClient();
MongoDatabase database = mongoClient.getDatabase("people-registry-example");
MongoCollection<Person> collection = BsoneeCodecRegistry.to(database.getCollection("people", Person.class));
try{
Person oldJohnny = new Person("John", "Doe", new Date(), GrowthStatus.ALIVE);
collection.insertOne(oldJohnny);
System.out.println("We have " + collection.count() + " person(s) registered");
collection.find().forEach(new Block<Person>() {
public void apply(Person t) {
System.out.println("Registered " + t);
}
});
}catch(Exception e) {
System.out.println("Example Failed");
e.printStackTrace();
}finally{
collection.drop();
database.drop();
mongoClient.close();
}
}
UsingMongoSavaFile.java 文件源码
项目:CS-FileTransfer
阅读 33
收藏 0
点赞 0
评论 0
public static void main(String[] args) {
// new client
MongoClient client = new MongoClient();
// get the data base
MongoDatabase db = client.getDatabase("other");
// here create a new collection
//db.createCollection("filestore");
// insert data into the collection
db.getCollection("filestore").insertOne(
new Document()
.append("name", "smile")
.append("age", 20));
// retrive the data
FindIterable<Document> iterable = db.getCollection("filestore").find();
// show data
iterable.forEach(new Block<Document>() {
@Override
public void apply(final Document document) {
System.out.println(document);
}
});
}
QueryController.java 文件源码
项目:nectar-server
阅读 22
收藏 0
点赞 0
评论 0
@SuppressWarnings("unchecked")
@RequestMapping(NectarServerApplication.ROOT_PATH + "/query/queryUsers")
public ResponseEntity queryUsers(@RequestParam(value = "token") String jwtRaw, HttpServletRequest request) {
ManagementSessionToken token = ManagementSessionToken.fromJSON(Util.getJWTPayload(jwtRaw));
if(token == null)
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid TOKENTYPE.");
if(!SessionController.getInstance().checkManagementToken(token)) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).body("Token expired/not valid.");
}
JSONObject returnJSON = new JSONObject();
MongoCollection<Document> clients = NectarServerApplication.getDb().getCollection("clients");
MongoCollection<Document> users = NectarServerApplication.getDb().getCollection("users");
users.find().forEach((Block<Document>) document -> {
String username = document.getString("username");
boolean admin = document.getBoolean("admin", false);
JSONObject userJSON = new JSONObject();
userJSON.put("admin", admin);
Document clientDoc = clients.find(Filters.eq("loggedInUser", username)).first();
if(clientDoc == null) {
userJSON.put("signedIn", false);
} else {
userJSON.put("signedIn", true);
}
returnJSON.put(username, userJSON);
});
return ResponseEntity.ok(returnJSON.toJSONString());
}
MongodbDatabase.java 文件源码
项目:StickyChunk
阅读 28
收藏 0
点赞 0
评论 0
public ArrayList<UserData> loadUserData() {
ArrayList<UserData> userDatas = new ArrayList<UserData>();
MongoCollection<Document> collection = getDatabase().getCollection("user");
collection.find().forEach((Block<Document>) document -> {
UUID player = UUID.fromString(document.getString("user"));
Date seen = (Date) document.getDate("seen");
Date joined = (Date) document.getDate("joined");
UserData userData = new UserData(player, joined, seen);
userDatas.add(userData);
});
return userDatas;
}
Database.java 文件源码
项目:Mp3Bib
阅读 24
收藏 0
点赞 0
评论 0
public CommonMetaData[] getAll() throws NotConnectedException {
CommonMetaData[] commonList = new CommonMetaData[(int) this.getCount()];
Block<Document> listBlock = new Block<Document>() {
private int i = 0;
@Override
public void apply(final Document document) {
commonList[i] = gson.fromJson(document.toJson(), CommonMetaData.class);
i++;
}
};
getCollection().find().forEach(listBlock);
return commonList;
}
SyncEventDao.java 文件源码
项目:mongodb-rdbms-sync
阅读 33
收藏 0
点赞 0
评论 0
public List<ObjectId> checkCancelledEvents(final Set<ObjectId> activeEventList) {
final List<ObjectId> cancelledEvents = new ArrayList<ObjectId>();
syncEvents
.find(Filters.and(Filters.in(SyncAttrs.ID, activeEventList),
Filters.eq(SyncAttrs.STATUS, SyncStatus.CANCELLED)), Document.class)
.projection(Projections.include(SyncAttrs.ID)).forEach(new Block<Document>() {
@Override
public void apply(Document arg0) {
cancelledEvents.add(arg0.getObjectId(SyncAttrs.ID));
}
});
return cancelledEvents;
}
OrclToMngSyncReader.java 文件源码
项目:mongodb-rdbms-sync
阅读 27
收藏 0
点赞 0
评论 0
private void processEventLogFlow() throws InterruptedException {
FindIterable<O2MSyncEventLog> it = getCursor();
retryCount = 0;
it.forEach(new Block<O2MSyncEventLog>() {
@Override
public void apply(O2MSyncEventLog eventLog) {
try {
if (marker.isFailed()) {
releaseReources();
return;
}
logCollection.findOneAndUpdate(Filters.eq(SyncAttrs.ID, eventLog.getLogId()),
Updates.set(O2MSyncEventLogCodec.STATUS, O2MSyncEventLogCodec.RUNNING));
logger.info("Processing filter : "+eventLog.getEventFilters());
if (eventLog.getOperation().equals(SyncConstants.DELETE)) {
processDeletedDoc(eventLog);
}else{
processMongoObject(map.getMapObject(), true, null, map.getMapObject().getCollectionName(),
eventLog);
}
logCollection.findOneAndUpdate(Filters.eq(SyncAttrs.ID, eventLog.getLogId()),
Updates.set(O2MSyncEventLogCodec.STATUS, O2MSyncEventLogCodec.COMPLETE));
logger.info("Processed filter : "+eventLog.getEventFilters());
} catch (SyncError e) {
logger.error("Error in O2M replication", e);
Mailer.sendmail(eventId, null, e, Mailer.FAILURE);
}
}
});
}
DataSourceDaoBean.java 文件源码
项目:otus-api
阅读 20
收藏 0
点赞 0
评论 0
@Override
public List<DataSource> find() {
ArrayList<DataSource> dataSources = new ArrayList<DataSource>();
FindIterable<Document> result = collection.find();
result.forEach((Block<Document>) document -> {
dataSources.add(DataSource.deserialize(document.toJson()));
});
return dataSources;
}
FieldCenterDaoBean.java 文件源码
项目:otus-api
阅读 22
收藏 0
点赞 0
评论 0
@Override
public ArrayList<FieldCenter> find() {
ArrayList<FieldCenter> fieldCenters = new ArrayList<>();
list().forEach((Block<Document>) document -> {
fieldCenters.add(new Gson().fromJson(document.toJson(), FieldCenter.class));
});
return fieldCenters;
}
SurveyDao.java 文件源码
项目:otus-api
阅读 17
收藏 0
点赞 0
评论 0
public List<SurveyForm> find() {
ArrayList<SurveyForm> surveys = new ArrayList<SurveyForm>();
list().forEach((Block<Document>) document -> {
surveys.add(SurveyForm.deserialize(document.toJson()));
});
return surveys;
}
SurveyDao.java 文件源码
项目:otus-api
阅读 21
收藏 0
点赞 0
评论 0
public List<SurveyForm> findByAcronym(String acronym) {
ArrayList<SurveyForm> surveys = new ArrayList<>();
collection.find(eq("surveyTemplate.identity.acronym", acronym)).forEach((Block<Document>) document -> {
surveys.add(SurveyForm.deserialize(document.toJson()));
});
return surveys;
}
SurveyDao.java 文件源码
项目:otus-api
阅读 19
收藏 0
点赞 0
评论 0
public List<SurveyForm> findByCustomId(Set<String> ids) {
ArrayList<SurveyForm> surveys = new ArrayList<>();
collection
.find(or(in("surveyTemplate.itemContainer.customID", ids),
in("surveyTemplate.itemContainer.options.customOptionID", ids)))
.forEach((Block<Document>) document -> {
surveys.add(SurveyForm.deserialize(document.toJson()));
});
return surveys;
}
ActivityDaoBean.java 文件源码
项目:otus-api
阅读 33
收藏 0
点赞 0
评论 0
/**
* Return activities considering that they were not discarded
* @param rn
* @return
*/
@Override
public List<SurveyActivity> find(long rn) {
ArrayList<SurveyActivity> activities = new ArrayList<SurveyActivity>();
FindIterable<Document> result = collection.find(and(eq("participantData.recruitmentNumber", rn), eq("isDiscarded", false)));
result.forEach((Block<Document>) document -> {
activities.add(SurveyActivity.deserialize(document.toJson()));
});
return activities;
}
ActivityConfigurationDaoBean.java 文件源码
项目:otus-api
阅读 28
收藏 0
点赞 0
评论 0
@Override
public List<ActivityCategory> findNonDeleted() {
ArrayList<ActivityCategory> categories = new ArrayList<>();
BasicDBObject query = new BasicDBObject();
query.put("objectType", "ActivityCategory");
query.put("disabled", false);
FindIterable<Document> documents = collection.find(query);
documents.forEach((Block<? super Document>) document -> categories.add(ActivityCategory.deserialize(document.toJson())));
return categories;
}