Example usage for com.mongodb QueryBuilder put

List of usage examples for com.mongodb QueryBuilder put

Introduction

In this page you can find the example usage for com.mongodb QueryBuilder put.

Prototype

public QueryBuilder put(final String key) 

Source Link

Document

Adds a new key to the query if not present yet.

Usage

From source file:net.atos.entng.forum.services.impl.MongoDbMessageService.java

License:Open Source License

protected void prepareIsSharedMethodQuery(final QueryBuilder query, final UserInfos user, final String threadId,
        final String sharedMethod) {
    // ThreadId/*w  w w .  j a va  2s . com*/
    query.put("_id").is(threadId);

    // Permissions
    List<DBObject> groups = new ArrayList<>();
    groups.add(QueryBuilder.start("userId").is(user.getUserId()).put(sharedMethod).is(true).get());
    for (String gpId : user.getProfilGroupsIds()) {
        groups.add(QueryBuilder.start("groupId").is(gpId).put(sharedMethod).is(true).get());
    }
    query.or(QueryBuilder.start("owner.userId").is(user.getUserId()).get(),
            QueryBuilder.start("visibility").is(VisibilityFilter.PUBLIC.name()).get(),
            QueryBuilder.start("visibility").is(VisibilityFilter.PROTECTED.name()).get(),
            QueryBuilder.start("shared")
                    .elemMatch(new QueryBuilder().or(groups.toArray(new DBObject[groups.size()])).get()).get());
}

From source file:net.atos.entng.forum.services.impl.MongoDbMessageService.java

License:Open Source License

protected void prepareIsSharedAnyQuery(final QueryBuilder query, final UserInfos user, final String threadId) {
    // ThreadId/*from   ww  w  . jav  a  2 s . c o m*/
    query.put("_id").is(threadId);

    // Permissions
    List<DBObject> groups = new ArrayList<>();
    groups.add(QueryBuilder.start("userId").is(user.getUserId()).get());
    for (String gpId : user.getProfilGroupsIds()) {
        groups.add(QueryBuilder.start("groupId").is(gpId).get());
    }
    query.or(QueryBuilder.start("owner.userId").is(user.getUserId()).get(),
            QueryBuilder.start("visibility").is(VisibilityFilter.PUBLIC.name()).get(),
            QueryBuilder.start("visibility").is(VisibilityFilter.PROTECTED.name()).get(),
            QueryBuilder.start("shared")
                    .elemMatch(new QueryBuilder().or(groups.toArray(new DBObject[groups.size()])).get()).get());
}

From source file:net.atos.entng.forum.services.impl.MongoDbSubjectService.java

License:Open Source License

@Override
public void retrieve(String categoryId, String subjectId, UserInfos user,
        Handler<Either<String, JsonObject>> handler) {
    // Query/*from   w ww  .j  a v  a 2s.  co  m*/
    QueryBuilder query = QueryBuilder.start("_id").is(subjectId);
    query.put("category").is(categoryId);

    // Projection
    JsonObject projection = new JsonObject();
    JsonObject slice = new JsonObject();
    slice.putNumber("$slice", -1);
    projection.putObject("messages", slice);

    mongo.findOne(subjects_collection, MongoQueryBuilder.build(query), projection, validResultHandler(handler));
}

From source file:net.atos.entng.forum.services.impl.MongoDbSubjectService.java

License:Open Source License

@Override
public void update(String categoryId, String subjectId, JsonObject body, UserInfos user,
        Handler<Either<String, JsonObject>> handler) {
    // Query/*w  w w. ja v  a2 s . co m*/
    QueryBuilder query = QueryBuilder.start("_id").is(subjectId);
    query.put("category").is(categoryId);

    // Clean data
    body.removeField("_id");
    body.removeField("category");
    body.removeField("messages");

    // Modifier
    MongoUpdateBuilder modifier = new MongoUpdateBuilder();
    for (String attr : body.getFieldNames()) {
        modifier.set(attr, body.getValue(attr));
    }
    modifier.set("modified", MongoDb.now());
    mongo.update(subjects_collection, MongoQueryBuilder.build(query), modifier.build(),
            validActionResultHandler(handler));
}

From source file:net.atos.entng.forum.services.impl.MongoDbSubjectService.java

License:Open Source License

@Override
public void delete(String categoryId, String subjectId, UserInfos user,
        Handler<Either<String, JsonObject>> handler) {
    QueryBuilder query = QueryBuilder.start("_id").is(subjectId);
    query.put("category").is(categoryId);
    mongo.delete(subjects_collection, MongoQueryBuilder.build(query), validActionResultHandler(handler));
}

From source file:net.atos.entng.forum.services.impl.MongoDbSubjectService.java

License:Open Source License

@Override
public void getSubjectTitle(String categoryId, String subjectId, UserInfos user,
        Handler<Either<String, JsonObject>> handler) {
    QueryBuilder query = QueryBuilder.start("_id").is(subjectId);
    query.put("category").is(categoryId);
    // Projection
    JsonObject projection = new JsonObject();
    projection.putNumber("title", 1);
    mongo.findOne(subjects_collection, MongoQueryBuilder.build(query), projection,
            validActionResultHandler(handler));
}

From source file:net.atos.entng.timelinegenerator.services.impl.EventServiceMongoImpl.java

License:Open Source License

@Override
public void retrieve(String timelineId, String eventId, UserInfos user,
        Handler<Either<String, JsonObject>> handler) {
    // Query//  w  w  w  . java  2 s  .c  om
    QueryBuilder query = QueryBuilder.start("_id").is(eventId);
    query.put("category").is(timelineId);

    // Projection
    JsonObject projection = new JsonObject();

    mongo.findOne(this.collection, MongoQueryBuilder.build(query), projection, validResultHandler(handler));
}

From source file:net.atos.entng.timelinegenerator.services.impl.EventServiceMongoImpl.java

License:Open Source License

@Override
public void update(String timelineId, String eventId, JsonObject body, UserInfos user,
        Handler<Either<String, JsonObject>> handler) {
    // Query/* w  w w .j  ava2 s  .  c om*/
    QueryBuilder query = QueryBuilder.start("_id").is(eventId);
    query.put("timeline").is(timelineId);

    // Clean data
    body.removeField("_id");
    body.removeField("timeline");

    // Modifier
    MongoUpdateBuilder modifier = new MongoUpdateBuilder();
    for (String attr : body.getFieldNames()) {
        modifier.set(attr, body.getValue(attr));
    }
    modifier.set("modified", MongoDb.now());
    mongo.update(this.collection, MongoQueryBuilder.build(query), modifier.build(),
            validActionResultHandler(handler));

}

From source file:net.atos.entng.timelinegenerator.services.impl.EventServiceMongoImpl.java

License:Open Source License

@Override
public void delete(String timelineId, String eventId, UserInfos user,
        Handler<Either<String, JsonObject>> handler) {
    QueryBuilder query = QueryBuilder.start("_id").is(eventId);
    query.put("timeline").is(timelineId);
    mongo.delete(this.collection, MongoQueryBuilder.build(query), validActionResultHandler(handler));

}

From source file:net.atos.entng.wiki.service.WikiServiceMongoImpl.java

License:Open Source License

/**
 * {@inheritDoc}/*from   w ww .j  a va  2s .c  om*/
 */
@Override
public void getDataForNotification(String idWiki, String idPage, Handler<Either<String, JsonObject>> handler) {
    QueryBuilder query = QueryBuilder.start("_id").is(idWiki);

    // Projection
    JsonObject projection = new JsonObject();
    projection.putNumber("owner", 1).putNumber("shared.userId", 1).putNumber("shared.groupId", 1)
            .putNumber("title", 1);

    if (idPage != null && !idPage.trim().isEmpty()) {
        query.put("pages._id").is(idPage);

        JsonObject matchId = new JsonObject().putString("_id", idPage);
        JsonObject elemMatch = new JsonObject().putObject("$elemMatch", matchId);
        projection.putObject("pages", elemMatch); // returns the whole page. Projection on a field (e.g. "title") of a subdocument of an array is not supported by mongo
    }

    // Send query to event bus
    mongo.findOne(collection, MongoQueryBuilder.build(query), projection,
            MongoDbResult.validResultHandler(handler));
}