Search in sources :

Example 6 with AggregationOutput

use of com.mongodb.AggregationOutput in project sissi by KimShen.

the class MongoMucRelationContext method mapping.

@Override
public JIDs mapping(JID group) {
    // {"$match":{"jid":group.bare}}, {"$unwind":"$roles"}, {"$match":{"roles.nick":Xxx}}, {"$project":{"roles":"$roles"}}, {"$group":{"_id":"$roles.jid","resource":{"$push":"$roles.resource"}}}
    AggregationOutput output = this.config.collection().aggregate(this.buildMatcher(group), this.unwindRoles, BasicDBObjectBuilder.start().add("$match", BasicDBObjectBuilder.start(Dictionary.FIELD_ROLES + "." + Dictionary.FIELD_NICK, group.resource()).get()).get(), this.projectRoles, this.groupMapping);
    @SuppressWarnings("deprecation") List<?> result = MongoUtils.asList(output.getCommandResult(), Dictionary.FIELD_RESULT);
    return result.isEmpty() ? this.jids : this.extract(DBObject.class.cast(result.get(0)));
}
Also used : AggregationOutput(com.mongodb.AggregationOutput)

Example 7 with AggregationOutput

use of com.mongodb.AggregationOutput in project sissi by KimShen.

the class MongoMucRelationContext method ourRelation.

/*
	 * {"$match":{"jid":group.bare}}, {"$unwind":"$roles"}, {"$unwind":"$affiliations"}, {"$match":{"roles.jid":Xxx,"roles.resource":Xxx}}, {"$project":{"jid":"$jid","activate":"$activate","creator":"$creator","roles":"$roles","affiliation":{"$cond":[{"$eq":["$affiliations.jid","$roles.jid"]},"$affiliations.affiliation",null]}}}, {"$match":{"affiliation":{"$exists":true}}}, {"$limit":1}
	 * 
	 * @see com.sissi.ucenter.relation.RelationContext#ourRelation(com.sissi.context.JID, com.sissi.context.JID)
	 */
@Override
public Relation ourRelation(JID from, JID to) {
    AggregationOutput output = this.config.collection().aggregate(this.buildMatcher(to), this.unwindRoles, this.unwindAffiliation, BasicDBObjectBuilder.start().add("$match", BasicDBObjectBuilder.start().add(Dictionary.FIELD_ROLES + "." + Dictionary.FIELD_JID, from.asStringWithBare()).add(Dictionary.FIELD_ROLES + "." + Dictionary.FIELD_RESOURCE, from.resource()).get()).get(), this.projectRelation, this.match, this.sort, this.limit);
    @SuppressWarnings("deprecation") List<?> result = MongoUtils.asList(output.getCommandResult(), Dictionary.FIELD_RESULT);
    return result.isEmpty() ? new NoneRelation(from, to, this.affiliation(from, to)) : new MongoRelation(DBObject.class.cast(result.get(0)));
}
Also used : AggregationOutput(com.mongodb.AggregationOutput)

Example 8 with AggregationOutput

use of com.mongodb.AggregationOutput in project sissi by KimShen.

the class MongoMucRelationContext method ourRelations.

/*
	 * {"$match":{"jid":group.bare}}, {"$unwind":"$roles"}, {"$match":{"roles.jid":Xxx}}, {"$group":{"_id":{"jid":"$jid","creator":"$creator","activate":"$activate","affiliations":"$affiliations"},"roles":{"$addToSet":"$roles"}}}, {"$project":{"jid":"$_id.jid","creator":"$_id.creator","activate":"$_id.activate","affiliations":"$_id.affiliations","roles":"$roles"}}
	 * 
	 * @see com.sissi.ucenter.relation.muc.MucRelationContext#ourRelations(com.sissi.context.JID, com.sissi.context.JID)
	 */
public Set<Relation> ourRelations(JID from, JID to) {
    AggregationOutput output = this.config.collection().aggregate(this.buildMatcher(to), this.unwindRoles, BasicDBObjectBuilder.start().add("$match", BasicDBObjectBuilder.start().add(Dictionary.FIELD_ROLES + "." + Dictionary.FIELD_JID, from.asStringWithBare()).get()).get(), this.groupRelations, this.projectRelations);
    @SuppressWarnings("deprecation") List<?> result = MongoUtils.asList(output.getCommandResult(), Dictionary.FIELD_RESULT);
    return result.isEmpty() ? this.relations : new MongoRelations(DBObject.class.cast(result.get(0)));
}
Also used : AggregationOutput(com.mongodb.AggregationOutput)

Example 9 with AggregationOutput

use of com.mongodb.AggregationOutput in project sissi by KimShen.

the class MongoMucRelationContext method whoSubscribedMe.

/*
	 * {"$match":{"jid":group.bare}}, {"$project":{"roles":"$roles"}}, {"$unwind":"$roles"}, {"$group":{"_id":"$_id","roles":{"$addToSet":"$roles"}}}
	 * 
	 * @see com.sissi.ucenter.relation.RelationContext#whoSubscribedMe(com.sissi.context.JID)
	 */
@Override
public Set<JID> whoSubscribedMe(JID from) {
    AggregationOutput output = this.config.collection().aggregate(this.buildMatcher(from), this.projectRoles, this.unwindRoles, this.groupSubscribe);
    @SuppressWarnings("deprecation") List<?> result = MongoUtils.asList(output.getCommandResult(), Dictionary.FIELD_RESULT);
    return result.isEmpty() ? this.jidset : new JIDGroup(MongoUtils.asList(DBObject.class.cast(result.get(0)), Dictionary.FIELD_ROLES));
}
Also used : AggregationOutput(com.mongodb.AggregationOutput) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 10 with AggregationOutput

use of com.mongodb.AggregationOutput in project sissi by KimShen.

the class MongoMucRelation4RoleContext method myRelations.

/*
	 * 角色相符的订阅关系
	 * 
	 * @see com.sissi.ucenter.relation.muc.MucRelationContext#myRelations(com.sissi.context.JID, java.lang.String)
	 */
public Set<Relation> myRelations(JID from, String role) {
    // {"$match":{"jid":group.bare}}, {"$unwind":"$roles"}, {"$match":{"roles.role":Xxx}}, {"$group":{"_id":{"jid":"$jid","creator":"$creator","affiliations":"$affiliations"},"roles":{"$addToSet":"$roles"}}}, {"$project":{"jid":"$_id.jid","creator":"$_id.creator","affiliations":"$_id.affiliations","roles":"$roles"}}
    AggregationOutput output = super.config.collection().aggregate(this.buildMatcher(from), super.unwindRoles, BasicDBObjectBuilder.start().add("$match", BasicDBObjectBuilder.start(Dictionary.FIELD_ROLES + "." + Dictionary.FIELD_ROLE, role).get()).get(), this.group, this.projectRole);
    @SuppressWarnings("deprecation") List<?> result = MongoUtils.asList(output.getCommandResult(), Dictionary.FIELD_RESULT);
    return result.isEmpty() ? this.relations : new MongoRelations(DBObject.class.cast(result.get(0)));
}
Also used : AggregationOutput(com.mongodb.AggregationOutput)

Aggregations

AggregationOutput (com.mongodb.AggregationOutput)10 BasicDBObject (com.mongodb.BasicDBObject)3 DBObject (com.mongodb.DBObject)3 CommandResult (com.mongodb.CommandResult)2 DBCollection (com.mongodb.DBCollection)2 AggregationOptions (com.mongodb.AggregationOptions)1 BasicDBObjectBuilder (com.mongodb.BasicDBObjectBuilder)1 DB (com.mongodb.DB)1 MongoException (com.mongodb.MongoException)1 WriteResult (com.mongodb.WriteResult)1 ArrayList (java.util.ArrayList)1 Configuration (org.apache.hadoop.conf.Configuration)1 InputSplit (org.apache.hadoop.mapreduce.InputSplit)1 AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)1 Test (org.junit.Test)1 Argument (org.teiid.language.Argument)1 Command (org.teiid.language.Command)1 Literal (org.teiid.language.Literal)1 MongoDBConnection (org.teiid.mongodb.MongoDBConnection)1 ExecutionContext (org.teiid.translator.ExecutionContext)1