Package com.ikanow.infinit.e.data_model.api.ResponsePojo

Examples of com.ikanow.infinit.e.data_model.api.ResponsePojo.ResponseObject


    ResponsePojo rp = new ResponsePojo();
    try
    {
      if (!userType.equalsIgnoreCase("owner") && !userType.equalsIgnoreCase("moderator") && !userType.equalsIgnoreCase("member") && !userType.equalsIgnoreCase("content_publisher"))
      {
        rp.setResponse(new ResponseObject("Update member type",false,"Invalid user type: " + userType));
        return rp;
      }//TESTED - tested all the types work, hacked members.jsp to insert invalid type
     
      //verify user is in this community, then update status
      communityIdStr = allowCommunityRegex(callerIdStr, communityIdStr);
      BasicDBObject query = new BasicDBObject("_id",new ObjectId(communityIdStr));
      DBObject dbo = DbManager.getSocial().getCommunity().findOne(query);
      if ( dbo != null )
      {
        // PersonId can be _id or username/email
        BasicDBObject dboPerson = (BasicDBObject) DbManager.getSocial().getPerson().findOne(new BasicDBObject("email", personIdStr));
        if (null == dboPerson) { // (ie personId isn't an email address... convert to ObjectId and try again)
          dboPerson = (BasicDBObject) DbManager.getSocial().getPerson().findOne(new BasicDBObject("_id", new ObjectId(personIdStr)));
        }
        else {
          personIdStr = dboPerson.getString("_id");
        }
        // OK from here on, personId is the object Id...

        CommunityPojo cp = CommunityPojo.fromDb(dbo,CommunityPojo.class);
       
        boolean bOwnershipChangeRequested = userType.equalsIgnoreCase("owner");
        boolean bAuthorized = isSysAdmin;
        if (!bAuthorized) {
          if (bOwnershipChangeRequested) { // must be owner or admin       
            bAuthorized = cp.isOwner(new ObjectId(callerIdStr));
          }//TESTED - tried to update myself as moderator to owner (failed), gave up my community (succeeded), changed ownership as admin (FAILED)
          else { // Can also be moderator
            bAuthorized = SocialUtils.isOwnerOrModerator(communityIdStr, callerIdStr);         
          }//TESTED - tried to update my role as member (failed), as admin->moderator (succeeded), as moderator (succeeded)
        }
       
        if (bAuthorized) // (see above)
        {
          if ( cp.isMember(new ObjectId(personIdStr)))
          {
            boolean bChangedMembership = false;
            boolean bChangedOwnership = !bOwnershipChangeRequested;
           
            ObjectId personId = new ObjectId(personIdStr);
           
            // Check that not trying to downgrade owner...
            if (cp.isOwner(personId) && !bOwnershipChangeRequested) {
              rp.setResponse(new ResponseObject("Update member type",false,"To change ownership, set new owner, will automatically downgrade existing owner to moderator"));
              return rp;
            }//TESTED
           
            String personDisplayName = null;
            //verified user, update status
            for ( CommunityMemberPojo cmp : cp.getMembers())
            {
              if ( cmp.get_id().equals(personId) )
              {
                cmp.setUserType(userType)
                personDisplayName = cmp.getDisplayName();
                bChangedMembership = true;
               
                if (bChangedOwnership) { // (includes case where didn't need to)
                  break;
                }
               
              }//TESTED
              if (bOwnershipChangeRequested && cmp.get_id().equals(cp.getOwnerId())) {
                cmp.setUserType("moderator");
                bChangedOwnership = true;
               
                if (bChangedMembership) {
                  break;
                }
               
              }//TESTED
            }
            if (bChangedMembership) {
              if (bOwnershipChangeRequested) {
                cp.setOwnerId(personId);
                cp.setOwnerDisplayName(personDisplayName);
              }//TESTED
             
              /////////////////////////////////////////////////////////////////////////////////////////////////
              // 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());
              rp.setResponse(new ResponseObject("Update member type",true,"Updated member type successfully"));
            }//TESTED                 
          }
          else
          {
            rp.setResponse(new ResponseObject("Update member type",false,"User was not a member of the community"));
          }
        }
        else
        {
          rp.setResponse(new ResponseObject("Update member type",false,"Caller must be admin/owner/moderator (unless changing ownership)"));
        }
      }
      else
      {
        rp.setResponse(new ResponseObject("Update member type",false,"Community does not exist"));
      }     
    }
    catch(Exception ex)
    {
      rp.setResponse(new ResponseObject("Update member type",false,"General Error, bad params maybe? " + ex.getMessage()));
    }
    return rp;
  }//TESTED (see sub-clauses for details)
View Full Code Here


               
                SendMail mail = new SendMail(new PropertiesManager().getAdminEmailAddress(), toAddresses, subject, body);
               
                if (mail.send("text/html"))
                {
                  rp.setResponse(new ResponseObject("Join Community",true,"Joined community successfully, awaiting owner approval"));
                  rp.setData(new CommunityApprovalPojo(false));
                }
                else
                {
                  rp.setResponse(new ResponseObject("Join Community",false,"The system was uable to send an email to the owner"));               
                }
              }
              else
              {
                cp.addMember(pp);
                pp.addCommunity(cp);
                //write both objects back to db now
                /////////////////////////////////////////////////////////////////////////////////////////////////
                // 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());
                DbManager.getSocial().getPerson().update(queryPerson, pp.toDb());
                rp.setResponse(new ResponseObject("Join Community",true,"Joined community successfully"));
                rp.setData(new CommunityApprovalPojo(true));
              }           
            }
            else
            {
              rp.setResponse(new ResponseObject("Join Community",false,"You must be invited to this community"));
            }
          }
          else
          {
            rp.setResponse(new ResponseObject("Join Community",false,"You are already a member of this community"));
          }
        }
        else
        {
          rp.setResponse(new ResponseObject("Join Community",false,"Cannot add members to personal community"));
        }
      }
      else
      {
        rp.setResponse(new ResponseObject("Join Community",false,"Community does not exist"));
      }
    }
    catch(Exception ex)
    {
      rp.setResponse(new ResponseObject("Join Community",false,"General Error, bad params maybe? " + ex.getMessage()));
    }
    return rp;
  }
View Full Code Here

          // 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());
          DbManager.getSocial().getPerson().update(queryPerson, pp.toDb());
          rp.setResponse(new ResponseObject("Leave Community",true,"Left community successfully"));
        }
        else
        {
          rp.setResponse(new ResponseObject("Leave Community",false,"Cannot leave personal community"));
        }
      }
      else
      {
        rp.setResponse(new ResponseObject("Leave Community",false,"Community does not exist"));
      }
    }
    catch(Exception ex)
    {
      rp.setResponse(new ResponseObject("Leave Community",false,"General Error, bad params maybe? " + ex.getMessage()));
    }
    return rp;
  }
View Full Code Here

    ResponsePojo rp = new ResponsePojo();
    try {
      communityIdStr = allowCommunityRegex(userIdStr, communityIdStr);
    }
    catch (Exception e) {
      rp.setResponse(new ResponseObject("Invite Community", false, "Error returning community info: " + e.getMessage()));
      return rp;
    }
   
    boolean skipInvite = ((null != skipInvitation) && (skipInvitation.equalsIgnoreCase("true"))) ? true : false;
   
    /////////////////////////////////////////////////////////////////////////////////////////////////
    // Note: Only Sys Admins, Community Owner, and Community Moderators can invite users to
    // private communities however any member can be able to invite someone to a public community
    boolean isOwnerOrModerator = SocialUtils.isOwnerOrModerator(communityIdStr, userIdStr);
    boolean isSysAdmin = RESTTools.adminLookup(userIdStr);
    boolean canInvite = (isOwnerOrModerator || isSysAdmin) ? true : false;

    try
    {
      BasicDBObject query = new BasicDBObject("_id",new ObjectId(communityIdStr));
      DBObject dboComm = DbManager.getSocial().getCommunity().findOne(query);
     
      if ( dboComm != null )
      {
        CommunityPojo cp = CommunityPojo.fromDb(dboComm, CommunityPojo.class);
       
        // Make sure this isn't a personal community
        if ( !cp.getIsPersonalCommunity() )
        {
          // Check to see if the user has permissions to invite or selfregister
          boolean selfRegister = canSelfRegister(cp);
          if ( canInvite || cp.getOwnerId().toString().equalsIgnoreCase(userIdStr) || selfRegister )
          {
            BasicDBObject dboPerson = (BasicDBObject) DbManager.getSocial().getPerson().findOne(new BasicDBObject("email", personIdStr));
            if (null == dboPerson) { // (ie personId isn't an email address... convert to ObjectId and try again)
              dboPerson = (BasicDBObject) DbManager.getSocial().getPerson().findOne(new BasicDBObject("_id", new ObjectId(personIdStr)));
            }
            else {
              personIdStr = dboPerson.getString("_id");
            }
            // OK from here on, personId is the object Id...
           
            if ( dboPerson != null )
            {
              PersonPojo pp = PersonPojo.fromDb(dboPerson,PersonPojo.class);             
              //need to check for if a person is pending, and skipInvite and isSysAdmin, otherwise
              //they would just get sent an email again, so leave it be
              boolean isPending = false;
              if ( isSysAdmin && skipInvite )
              {
                isPending = isMemberPending(cp, pp);
              }
             
              if ( selfRegister )
              {
                //If the comm allows for self registering, just call join community
                //instead of invite, it will handle registration
                return this.joinCommunity(pp.get_id().toString(), communityIdStr, isSysAdmin);
              }
              else if ( !cp.isMember(pp.get_id()) || isPending )
              {
                if (isSysAdmin && skipInvite) // Can only skip invite if user is Admin
                {
                  // Update community with new member
                  cp.addMember(pp, false); // Member status set to Active
                  cp.setNumberOfMembers(cp.getNumberOfMembers() + 1); // Increment number of members
                  /////////////////////////////////////////////////////////////////////////////////////////////////
                  // 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());
                 
                  // Add community to persons object and save to db
                  pp.addCommunity(cp);
                  /////////////////////////////////////////////////////////////////////////////////////////////////
                  // 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().getPerson().update(new BasicDBObject("_id", pp.get_id()), pp.toDb());
                 
                  rp.setResponse(new ResponseObject("Invite Community",true,"User added to community successfully."));
                }
                else
                {
                  cp.addMember(pp, true); // Member status set to Pending
                  /////////////////////////////////////////////////////////////////////////////////////////////////
                  // 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());
                 
                  //send email out inviting user
                  CommunityApprovePojo cap = cp.createCommunityApprove(personIdStr,communityIdStr,"invite",userIdStr);
                  DbManager.getSocial().getCommunityApprove().insert(cap.toDb());
                 
                  PropertiesManager propManager = new PropertiesManager();
                  String rootUrl = propManager.getUrlRoot();
                 
                  if (null == rootUrl) {
                    rp.setResponse(new ResponseObject("Invite Community",false,"The system was unable to email the invite because an invite was required and root.url is not set up."));
                    return rp;
                  }
                 
                  String subject = "Invite to join infinit.e community: " + cp.getName();
                  String body = "You have been invited to join the community " + cp.getName() +
                    "<br/><a href=\"" + rootUrl + "social/community/requestresponse/"+cap.get_id().toString() + "/true\">Accept</a> " +
                    "<a href=\"" + rootUrl + "social/community/requestresponse/"+cap.get_id().toString() + "/false\">Deny</a>";
                 
                  SendMail mail = new SendMail(new PropertiesManager().getAdminEmailAddress(), pp.getEmail(), subject, body);
                 
                  if (mail.send("text/html"))
                  {
                    if (isSysAdmin) {
                      rp.setResponse(new ResponseObject("Invite Community",true,"Invited user to community successfully: " + cap.get_id().toString()));
                    }
                    else {
                      rp.setResponse(new ResponseObject("Invite Community",true,"Invited user to community successfully"));                 
                    }
                  }
                  else
                  {
                    rp.setResponse(new ResponseObject("Invite Community",false,"The system was unable to email the invite for an unknown reason (eg an invite was required and the mail server is not setup)."));
                  }
                }
              }
              else
              {               
                //otherwise just return we failed
                rp.setResponse(new ResponseObject("Invite Community",false,"The user is already a member of this community."));
              }
            }
            else
            {
              rp.setResponse(new ResponseObject("Invite Community",false,"Person does not exist"));
            }
          }
          else
          {
            rp.setResponse(new ResponseObject("Invite Community",false,"You must be owner to invite other members, if you received an invite, you must accept it through that"));
          }
        }
        else
        {
          rp.setResponse(new ResponseObject("Invite Community",false,"Cannot invite members to personal community"));
        }
      }
      else
      {
        rp.setResponse(new ResponseObject("Invite Community",false,"Community does not exist"));
      }
    }
    catch(Exception ex)
    {
      rp.setResponse(new ResponseObject("Invite Community",false,"General Error, bad params maybe? " + ex.getMessage()));
    }
    return rp;
  }
View Full Code Here

                    /////////////////////////////////////////////////////////////////////////////////////////////////
                    DbManager.getSocial().getPerson().update(queryPerson, pp.toDb());
                  }
                  else
                  {
                    rp.setResponse(new ResponseObject("Request Response",false,"The person does not exist."));
                  }
                }
                //return successfully
                rp.setResponse(new ResponseObject("Request Response",true,"Request answered successfully!"));
              }
              else
              {
                //return fail
                rp.setResponse(new ResponseObject("Request Response",false,"Request has already been answered!"));
              }
              //remove request object now
              DbManager.getSocial().getCommunityApprove().remove(new BasicDBObject("_id",new ObjectId(requestIdStr)));
             
            }
            else
            {
              rp.setResponse(new ResponseObject("Request Response",false,"The community does not exist."));
            }
          }
        }
        else
        {
          rp.setResponse(new ResponseObject("Request Response",false,"This request does not exist, possibly answered already?"));
        }
      }
      else
      {
        rp.setResponse(new ResponseObject("Request Response",false,"Reponse must be true or false"));
      }
    }
    catch(Exception ex)
    {
      rp.setResponse(new ResponseObject("Request Response",false,"General Error, bad params maybe?"  + ex.getMessage()));
    }
    return rp;
  }
View Full Code Here

    ResponsePojo rp = new ResponsePojo();
    try {
      communityIdStr = allowCommunityRegex(userIdStr, communityIdStr);
    }
    catch (Exception e) {
      rp.setResponse(new ResponseObject("Update Community", false, "Error returning community info: " + e.getMessage()));
      return rp;
    }
   
    /////////////////////////////////////////////////////////////////////////////////////////////////
    // Note: Only Sys Admins, Community Owner, and Community Moderators can add update communities
    boolean isOwnerOrModerator = SocialUtils.isOwnerOrModerator(communityIdStr, userIdStr);
    boolean isSysAdmin = RESTTools.adminLookup(userIdStr);
    boolean canUpdate = (isOwnerOrModerator || isSysAdmin) ? true : false
    if (!canUpdate)
    {
      rp.setResponse(new ResponseObject("Update Community",false,"User does not have permission to update the community."));
      return rp;
    }
   
    /////////////////////////////////////////////////////////////////////////////////////////////////
    // Attempt to parse the JSON passed in to a CommunityPojo
    CommunityPojo updateCommunity = null;
    try
    {
      updateCommunity = ApiManager.mapFromApi(json, CommunityPojo.class, new CommunityPojoApiMap());
    }
    catch (Exception ex)
    {
      rp.setResponse(new ResponseObject("Update Community",false,"Update json is badly formatted, could not deserialize."));
      return rp;
    }
   
    try
    {
      // Retrieve community we are trying to update from the database
      BasicDBObject query = new BasicDBObject("_id", new ObjectId(communityIdStr));
      DBObject dbo = DbManager.getSocial().getCommunity().findOne(query);
      String originalName = null;
     
      if ( dbo != null )
      {
       
        CommunityPojo cp = CommunityPojo.fromDb(dbo, CommunityPojo.class);
       
        if (null == cp) {
          rp.setResponse(new ResponseObject("Update Community",false,"Community to update does not exist"));
          return rp;
        }
        // Here are the fields you are allowed to change:
        // name:
        if (null != updateCommunity.getName())
        {
          // If you're changing name then ensure it's unique for consistency
          //TODO (INF-1214): see addCommunity, this is currently something of a security hole
          BasicDBObject nameCheck = new BasicDBObject("name", updateCommunity.getName());
          nameCheck.put("_id", new BasicDBObject(MongoDbManager.ne_, cp.getId()));
          if (null != MongoDbManager.getSocial().getCommunity().findOne(nameCheck)) {
            rp.setResponse(new ResponseObject("Update Community",false,"Can't change name to an existing community"));
            return rp;           
          }//TESTED (tested changing names of existing community works...)   
          originalName = cp.getName();
          cp.setName(updateCommunity.getName());
        }
        if (null != updateCommunity.getDescription()) {
          cp.setDescription(updateCommunity.getDescription());         
        }
        if (null != updateCommunity.getTags()) {
          cp.setTags(updateCommunity.getTags());         
        }
        if ((null != updateCommunity.getCommunityAttributes() && !updateCommunity.getCommunityAttributes().isEmpty()))
        {
          cp.setCommunityAttributes(updateCommunity.getCommunityAttributes());         
        }
        if ((null != updateCommunity.getCommunityUserAttribute() && !updateCommunity.getCommunityUserAttribute().isEmpty()))
        {
          cp.setCommunityUserAttribute(updateCommunity.getCommunityUserAttribute());         
        }
        // Change owner: not allowed here, use community/update/status
        if ((null != updateCommunity.getOwnerId()) && !updateCommunity.getOwnerId().equals(cp.getOwnerId()))
        {
          rp.setResponse(new ResponseObject("Update Community",false,"Use community/update/status to change ownership"));
          return rp;
        }//TESTED
               
        DbManager.getSocial().getCommunity().update(query, cp.toDb());
               
        // Community name has changed, member records need to be updated to reflect the name change
        if (originalName != null)
        {
          DBObject query_person = new BasicDBObject("communities.name", originalName);
          DBObject update_person = new BasicDBObject("$set",new BasicDBObject("communities.$.name", updateCommunity.getName()));         
          DbManager.getSocial().getPerson().update(query_person, update_person, false, true);
         
          //Also need to update share community names to reflect the name change
          DBObject query_share = new BasicDBObject("communities.name", originalName);
          DBObject update_share = new BasicDBObject("$set",new BasicDBObject("communities.$.name", updateCommunity.getName()));         
          DbManager.getSocial().getShare().update(query_share, update_share, false, true);
        }
       
       
        /////////////////////////////////////////////////////////////////////////////////////////////////
        // TODO (INF-1214): Make this code more robust to handle changes to the community that need to
        // propagate out to other records like Person
        // caleb note: 1/7 (change this to use $set is what this means,
        // including above DbManager.getSocial().getCommunity().update(query, cp.toDb()); )
        // and the below unwritten communityuserattri
        /////////////////////////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////////////////////////////////
        // Community.communityUserAttribute
        // If user attributes have changed we might need to update member records...

       
        rp.setResponse(new ResponseObject("Update Community", true, "Community updated successfully."));
      }
      else
      {
        rp.setResponse(new ResponseObject("Update Community",false,"Community does not exist"));
      }
    }
    catch (Exception ex)
    {
      rp.setResponse(new ResponseObject("Update Community",false,"Unable to update community. Error:" + ex.getMessage()));
    }
    return rp;
  }
View Full Code Here

            PersonHandler person = new PersonHandler();
            person.addCommunity(personIdStr, communityIdStr, communityName);

            rp.setData(community, new CommunityPojoApiMap());

            rp.setResponse(new ResponseObject("Add member to community", true, "Person has been added as member of community"))
          }         
          else
          {
            rp.setResponse(new ResponseObject("Add member to community",true,"Person is already a member of the community."))
          }
        }
        else
        {
          rp.setResponse(new ResponseObject("Add member to community", false, "Community not found."));
        }
      }
      catch (Exception e)
      {     
        // If an exception occurs log the error
        logger.error("Exception Message: " + e.getMessage(), e);
        rp.setResponse(new ResponseObject("Add member to community", false,
            "Error adding member to community " + e.getMessage()));
     
    }
    else
    {
      rp.setResponse(new ResponseObject("Add member to community", false,
        "The user does not have permissions to add a user to the community."));
    }
   
    return rp;
  }
View Full Code Here

            PersonHandler person = new PersonHandler();
            person.removeCommunity(personIdStr, communityIdStr);

            rp.setData(community, new CommunityPojoApiMap());
            rp.setResponse(new ResponseObject("Remove member from community", true, "Member has been removed from community"))
          }         
          else
          {
            rp.setResponse(new ResponseObject("Remove member from community",true,"Person is not a member of this community."))
          }
        }
        else
        {
          rp.setResponse(new ResponseObject("Remove member from community", false, "Community not found."));
        }
      }
      catch (Exception e)
      {     
        // If an exception occurs log the error
        logger.error("Exception Message: " + e.getMessage(), e);
        rp.setResponse(new ResponseObject("Remove member from community", false,
            "Error removing member from community " + e.getMessage()));
     
    }
    else
    {
      rp.setResponse(new ResponseObject("Remove member from community", false,
          "The user does not have permissions to remove a user from the community."));
    }
   
    return rp;
  }
View Full Code Here

              else { // text
                share.setShare(getReferenceString(share));               
              }//TESTED
            }
            catch (Exception e) {
              rp.setResponse(new ResponseObject("Get Share", false, "Unable to get share reference: " + e.getMessage()));           
              return rp;
            }//TESTED
         
          // (else share.share already set)
        }
        else { // don't return content
          share.setShare(null);         
        }//TESTED
       
        rp.setData(share, new SharePojoApiMap(memberOf));               
        rp.setResponse(new ResponseObject("Share", true, "Share returned successfully"));
      }
      else {
        rp.setResponse(new ResponseObject("Get Share", false, "Unable to get share, not found or no access permission"));       
      }
    }
    catch (Exception e)
    {
      logger.error("Exception Message: " + e.getMessage(), e);
      rp.setResponse(new ResponseObject("Get Share", false, "Unable to get share: " + e.getMessage()));
    }
    return rp;
  }
View Full Code Here

            }
          }
        }//TESTED
       
        rp.setData(shares, new SharePojoApiMap(memberOf));
        rp.setResponse(new ResponseObject("Share", true, "Shares returned successfully"));       
      }
      else {
        rp.setResponse(new ResponseObject("Share", true, "No shares matching search critera found."));       
      }
    }
    catch (Exception e)
    {
      logger.error("Exception Message: " + e.getMessage(), e);
      rp.setResponse(new ResponseObject("Share", false, "Unable to search for shares: " + e.getMessage()));
    }
    return rp;
  }
View Full Code Here

TOP

Related Classes of com.ikanow.infinit.e.data_model.api.ResponsePojo.ResponseObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.