// Attempt to retrieve the invite from the social.communityapprove collection
DBObject dbo = DbManager.getSocial().getCommunityApprove().findOne(new BasicDBObject("_id", new ObjectId(requestIdStr)));
if (dbo != null )
{
CommunityApprovePojo cap = CommunityApprovePojo.fromDb(dbo, CommunityApprovePojo.class);
if ( cap.getType().equals("source"))
{
//approving a source
if ( resp.equals("true"))
{
rp = sourceHandler.approveSource(cap.getSourceId(), cap.getCommunityId(), cap.getRequesterId());
}
else
{
rp = sourceHandler.denySource(cap.getSourceId(), cap.getCommunityId(), cap.getRequesterId());
}
if ( rp.getResponse().isSuccess() )
{
//remove request object now
DbManager.getSocial().getCommunityApprove().remove(new BasicDBObject("_id",new ObjectId(requestIdStr)));
}
}
else
{
//approving a user joining a community
BasicDBObject query = new BasicDBObject("_id",new ObjectId(cap.getCommunityId()));
DBObject dboComm = DbManager.getSocial().getCommunity().findOne(query);
//get user
BasicDBObject queryPerson = new BasicDBObject("_id",new ObjectId(cap.getPersonId()));
DBObject dboperson = DbManager.getSocial().getPerson().findOne(queryPerson);
PersonPojo pp = PersonPojo.fromDb(dboperson, PersonPojo.class);
if ( dboComm != null )
{
CommunityPojo cp = CommunityPojo.fromDb(dboComm, CommunityPojo.class);
boolean isStillPending = isMemberPending(cp, pp);
//make sure the user is still waiting to join the community, otherwise remove this request and return
if ( isStillPending )
{
if ( resp.equals("false"))
{
//if response is false (deny), always just remove user from community
cp.removeMember(new ObjectId(cap.getPersonId()));
/////////////////////////////////////////////////////////////////////////////////////////////////
// TODO (INF-1214): Make this code more robust to handle changes to the community that need to
// Caleb: this means change update to $set
/////////////////////////////////////////////////////////////////////////////////////////////////
DbManager.getSocial().getCommunity().update(query, cp.toDb());
}
else
{
//if response is true (allow), always just add community info to user, and change status to active
if ( dboperson != null)
{
cp.updateMemberStatus(cap.getPersonId(), "active");
cp.setNumberOfMembers(cp.getNumberOfMembers()+1);
/////////////////////////////////////////////////////////////////////////////////////////////////
// TODO (INF-1214): Make this code more robust to handle changes to the community that need to
// Caleb: this means change update to $set
/////////////////////////////////////////////////////////////////////////////////////////////////