Package com.ikanow.infinit.e.data_model.store.social.person

Examples of com.ikanow.infinit.e.data_model.store.social.person.PersonPojo


    }
   
    //Save both these objects to the DB
    try
    {         
      PersonPojo personQuery = new PersonPojo();
      if (null != personIdStr) {
        personQuery.set_id(new ObjectId(personIdStr));       
      }
      else {
        if (null == wpu.getWPUserID()) {
          if ((null == wpu.getEmail()) || wpu.getEmail().isEmpty()) {
            rp.setResponse(new ResponseObject("WP Update User",false,"Need to specify WPUserID (or email address if not integrated via WordPress)"));
            return rp;
          }
          else // If authentication username is set, use that because it means that we're trying to change
              // the email (and we're an admin user)
           
            if (null != wpa.getUsername()) { // I may be changing someone's name
              personQuery.setEmail(wpa.getUsername());
            }
            else { // I'm not changing anybody's name
              personQuery.setEmail(wpu.getEmail().get(0));
            }
          }
        }
        else {
          personQuery.setWPUserID(wpu.getWPUserID());
        }
      }     
      BasicDBObject dboperson = (BasicDBObject) DbManager.getSocial().getPerson().findOne(personQuery.toDb());
      if (null == dboperson) {
        rp.setResponse(new ResponseObject("WP Update User",false,"Can't find user specified by WPUserID"));
        return rp;       
      }
     
      PersonPojo pp = PersonPojo.fromDb(dboperson,PersonPojo.class);
     
      if ((null != wpu.getEmail()) && !wpu.getEmail().isEmpty()) {
        if (!pp.getEmail().equalsIgnoreCase(wpu.getEmail().get(0))) { // Email has changed...
          pp.setEmail(wpu.getEmail().get(0));
       
          // Check this is allowed (ie haven't taken a username already in use):
          personQuery = new PersonPojo();
          personQuery.setEmail(pp.getEmail());
          dboperson = (BasicDBObject) DbManager.getSocial().getPerson().findOne(personQuery.toDb());
          if (null != dboperson) {
            rp.setResponse(new ResponseObject("WP Update User",false,"This primary email address is not unique"));
            return rp;       
          }//TOTEST
         
          bNeedToUpdateCommunities = true;
        }
      }
      if (null != wpu.getFirstname()) {
        if ((null == pp.getFirstName()) || !pp.getFirstName().equals(wpu.getFirstname())) {
          pp.setFirstName(wpu.getFirstname());
          bNeedToUpdateCommunities = true;
        }
      }
      if (null != wpu.getLastname()) {
        if ((null == pp.getLastName()) || !pp.getLastName().equals(wpu.getLastname())) {
          pp.setLastName(wpu.getLastname());
          bNeedToUpdateCommunities = true;
        }
      }
      // Update display name
      StringBuffer displayName = new StringBuffer();
      if ((null != pp.getFirstName()) && !pp.getFirstName().isEmpty()) {
        displayName.append(pp.getFirstName());
      }
      if ((null != pp.getLastName()) && !pp.getLastName().isEmpty()) {
        if (displayName.length() > 0) {
          displayName.append(' ');
        }
        displayName.append(pp.getLastName());
      }//TOTESTx2
      pp.setDisplayName(displayName.toString());
     
      if (null != wpu.getPhone()) {
        pp.setPhone(wpu.getPhone());
      }
      if (null != wpu.getSubscriptionEndDate()) {
        pp.setSubscriptionEndDate(wpu.getSubscriptionEndDate());
      }
      if (null != wpu.getSubscriptionID()) {
        pp.setSubscriptionID(wpu.getSubscriptionID());
      }
      if (null != wpu.getSubscriptionStartDate()) {
        pp.setSubscriptionStartDate(wpu.getSubscriptionStartDate());
      }
      if (null != wpu.getSubscriptionTypeID()) {
        pp.setSubscriptionTypeID(wpu.getSubscriptionTypeID());
      }
      // (can't change WPUserId obv)
     
      AuthenticationPojo authQuery = new AuthenticationPojo();
      if (null != pp.get_id()) {
        authQuery.setProfileId(pp.get_id());
      }
      else {
        rp.setResponse(new ResponseObject("WP Update User",false,"Internal authentication error 1"));
        return rp;       
      }
      DBObject dboauth = DbManager.getSocial().getAuthentication().findOne(authQuery.toDb());
      if (null == dboauth) {
        rp.setResponse(new ResponseObject("WP Update User",false,"Internal authentication error 2"));
        return rp;       
      }     
      AuthenticationPojo ap = AuthenticationPojo.fromDb(dboauth, AuthenticationPojo.class);
     
      if ((null != wpu.getEmail()) && !wpu.getEmail().isEmpty()) {
        ap.setUsername(wpu.getEmail().get(0)); // (ap.username == email address, make life easy when resetting password)
      }
      if (null != wpa.getPassword()) {
        if (44 != wpa.getPassword().length()) { // hash if in the clear
          wpa.setPassword(PasswordEncryption.encrypt(wpa.getPassword()));
        }
        ap.setPassword(wpa.getPassword());
      }
      if (null != wpa.getAccountType()) {
        if (null == personIdStr) { // (this means you're admin and hence can upgrade users to admins)
          ap.setAccountType(wpa.getAccountType());
        }
      }
      // (can't change WPUserId obv)
     
      //Handle dates (just update modified times)
      pp.setModified(new Date());
      ap.setModified(new Date());
     
      if ((null != wpa.getApiKey()) && (0 == wpa.getApiKey().length()) && (null != ap.getApiKey()))     
      {
        // Delete existing API key
        // (We'll allow a user to update their own API key - just not create it, see below)
        CookiePojo removeMe = new CookiePojo();
        removeMe.setApiKey(ap.getApiKey());
        ap.setApiKey(null);       
        DbManager.getSocial().getCookies().remove(removeMe.toDb());
      }
      else if (null != wpa.getApiKey()) {
        // Change or create API key
        // Only admins can do this:
        if (null != personIdStr) { // (this is != null iff user isn't admin)
          // Check security settings
          PropertiesManager pm = new PropertiesManager();
          if (pm.getHarvestSecurity()) {
            rp.setResponse(new ResponseObject("WP Update User",false,"You must be admin in secure mode to set an API key"));
            return rp;
          }
        }//TESTED (admin, admin-enabled, non-admin - harvest.secure on and off)
       
        ap.setApiKey(wpa.getApiKey());
        CookiePojo cp = new CookiePojo();
        cp.set_id(ap.getProfileId());
        cp.setCookieId(cp.get_id());
        cp.setApiKey(wpa.getApiKey());
        cp.setStartDate(ap.getCreated());
        cp.setProfileId(ap.getProfileId());
        DbManager.getSocial().getCookies().save(cp.toDb());               
      }//TESTED
      //else if api key is null then leave alone, assume hasn't changed
     
      //update old entries
      DbManager.getSocial().getPerson().update(new BasicDBObject("_id", pp.get_id()), pp.toDb());
      DbManager.getSocial().getAuthentication().update(authQuery.toDb(), ap.toDb());     
      rp.setResponse(new ResponseObject("WP Update User",true,"User Updated Successfully"));
      rp.setData(ap, new AuthenticationPojoApiMap());
     
      //update communities if necessary
      if (bNeedToUpdateCommunities)
      {
        //set community members name and email, if they match on id
        BasicDBObject query = new BasicDBObject("members._id", pp.get_id());
        BasicDBObject update = new BasicDBObject("members.$.email", pp.getEmail());
        update.put("members.$.displayName", pp.getDisplayName());
        DbManager.getSocial().getCommunity().update(query, new BasicDBObject("$set", update), false, true);
          // (don't upsert, many times)
       
        //INF-1314 if the ownerid == pp_id, set new username
        BasicDBObject query1 = new BasicDBObject("ownerId", pp.get_id());
        BasicDBObject update1 = new BasicDBObject("ownerDisplayName", pp.getDisplayName());
        DbManager.getSocial().getCommunity().update(query1, new BasicDBObject("$set", update1), false, true);
      }//TOTEST
     
      // Just recreate personal community if necessary (means if something goes wrong can always just update user...)
      if (null != pp.get_id()) {
        GenericProcessingController.createCommunityDocIndex(pp.get_id().toString(), null, true, false, false);
      }
      //TESTED
     
      rp.setResponse(new ResponseObject("WP Update User",true,"User Updated Successfully"));
    }
View Full Code Here


    ResponsePojo rp = new ResponsePojo();
   
    // Work out which field to delete on
    BasicDBObject personDbo = null;
    try {
      PersonPojo personQuery = new PersonPojo();
      personQuery.set_id(new ObjectId(userIdStrOrEmailOrWP));
      personDbo = (BasicDBObject) DbManager.getSocial().getPerson().findOne(personQuery.toDb());
    }//TESTED
    catch (Exception e){ // Not an object id
      if (userIdStrOrEmailOrWP.indexOf('@') < 0) { // not an email
        PersonPojo personQuery = new PersonPojo();
        personQuery.setWPUserID(userIdStrOrEmailOrWP);
        personDbo = (BasicDBObject) DbManager.getSocial().getPerson().findOne(personQuery.toDb());       
      }
      else { // can be either an email address or a WPU
        BasicDBObject complexQuery_term1 = new BasicDBObject("WPUserID", userIdStrOrEmailOrWP);
        BasicDBObject complexQuery_term2 = new BasicDBObject("email", userIdStrOrEmailOrWP);
        BasicDBObject complexQuery = new BasicDBObject("$or", Arrays.asList(complexQuery_term1, complexQuery_term2));
        personDbo = (BasicDBObject) DbManager.getSocial().getPerson().findOne(complexQuery);       
      }
    }//TESTED
    if (null == personDbo) {
      rp.setResponse(new ResponseObject("WP Update User",false,"Can't find user to delete via id, WPUserId, or (primary) email"));
      return rp;             
    }//TESTED   
    PersonPojo pp = PersonPojo.fromDb(personDbo, PersonPojo.class);
   
    // Delete personal communities
    try {
      DbManager.getSocial().getCommunity().remove(new BasicDBObject("_id", pp.get_id()));
        // (can't use community pojo because it contains default params unfortunately)
    }
    catch (Exception e) {
      // We're past the point of no return so just carry on...
    }
   
    // Remove from index:
    GenericProcessingController.deleteCommunityDocIndex(pp.get_id().toString(), null, true);
    //TESTED
   
    // Remove from all (other) communities
    try {
      BasicDBObject query = new BasicDBObject("members._id", pp.get_id());
      CommunityMemberPojo cmp = new CommunityMemberPojo();
      cmp.set_id(pp.get_id());
      BasicDBObject actions = new BasicDBObject();
      actions.put("$pull", new BasicDBObject("members", new BasicDBObject("_id", pp.get_id())));
        // ie for communities for which he's a member...remove...any elements of the list members...with his _id
      actions.put("$inc", new BasicDBObject("numberOfMembers", -1));
        // ie decrement number of members
     
      DbManager.getSocial().getCommunity().update(query, actions, false, true);
        // (don't upsert, many times)     
    }
    catch (Exception e) {
      // We're past the point of no return so just carry on...
    }//TESTED
   
    // Remove from respective DBs
   
    PersonPojo personQuery = new PersonPojo();
    personQuery.set_id(pp.get_id());
    DbManager.getSocial().getPerson().remove(personQuery.toDb());
    //TESTED
   
    AuthenticationPojo authQuery = new AuthenticationPojo();
    if (null != authQuery.getWPUserID()) { // (Some older records have this and of course it deletes the entire auth DB...)
      authQuery.setWPUserID(pp.getWPUserID());
View Full Code Here

  {
    ResponsePojo rp = new ResponsePojo();
    try
    {
      // Find person record to update
      PersonPojo personQuery = new PersonPojo();
      personQuery.set_id(new ObjectId(personId));
      DBObject dbo = DbManager.getSocial().getPerson().findOne(personQuery.toDb());
     
      if (dbo != null)
      {
        // Get GsonBuilder object with MongoDb de/serializers registered
        PersonPojo person = PersonPojo.fromDb(dbo, PersonPojo.class);

        // Create a new PersonCommunityPojo object
        PersonCommunityPojo community = new PersonCommunityPojo();
        community.set_id(new ObjectId(communityId));
        community.setName(communityName);
       
        // Check to see if person is already a member of the community to be added
        List<PersonCommunityPojo> communities = person.getCommunities();
        Boolean alreadyMember = false;
        for (PersonCommunityPojo c : communities)
        {
          String idToTest = c.get_id().toStringMongod();         
          if (idToTest.equals(communityId))
          {
            alreadyMember = true;
            break;
          }
        }
       
        // Add the community to the list if it does not already exist
        if (!alreadyMember)
        {
          //TODO (INF-1214): (not thread safe)         
          communities.add(community)
          person.setModified(new Date());         
          DbManager.getSocial().getPerson().update(personQuery.toDb(), person.toDb());
          rp.setData(person, new PersonPojoApiMap());
          rp.setResponse(new ResponseObject("Add community status",true,"Community added successfully."))
        }         
        else
        {
View Full Code Here

  {
    ResponsePojo rp = new ResponsePojo()
    try
    {
      // Find person record to update
      PersonPojo personQuery = new PersonPojo();
      personQuery.set_id(new ObjectId(personId));
      DBObject dbo = DbManager.getSocial().getPerson().findOne(personQuery.toDb());
     
      if (dbo != null)
      {
        PersonPojo person = PersonPojo.fromDb(dbo, PersonPojo.class);
       
        // Check to see if person is already a member of the community to be added
        List<PersonCommunityPojo> communities = person.getCommunities();
        Boolean alreadyMember = false;
        int communityIndex = 0;
        for (PersonCommunityPojo c : communities)
        {
          String idToTest = c.get_id().toStringMongod();         
          if (idToTest.equals(communityId))
          {
            alreadyMember = true;
            break;
          }
          communityIndex++;
        }       
       
        // Remove the community from the list
        if (alreadyMember)
        {
          //TODO (INF-1214): (not thread safe)         
          communities.remove(communityIndex)
          person.setModified(new Date());         
          DbManager.getSocial().getPerson().update(personQuery.toDb(), person.toDb());
          rp.setData(person, new PersonPojoApiMap());
          rp.setResponse(new ResponseObject("Remove community status",true,"Community removed successfully."))
        }         
        else
        {
View Full Code Here

      share.setMediaType(mediatype);
      ObjectId id = new ObjectId();
      share.set_id(id);
     
      // Get ShareOwnerPojo object and personal community
      PersonPojo owner = getPerson(new ObjectId(ownerIdStr));
      share.setOwner(getOwner(owner));
      share.setCommunities(getPersonalCommunity(owner));

      // Serialize the ID and Dates in the object to MongoDB format
      //Save the binary objects into separate db
View Full Code Here

        HashSet<ObjectId> endorsedSet = new HashSet<ObjectId>();
        share.setEndorsed(endorsedSet); // (you're always endorsed within your own community)
        endorsedSet.add(new ObjectId(ownerIdStr));       
       
        // Get ShareOwnerPojo object and personal community
        PersonPojo owner = getPerson(new ObjectId(ownerIdStr));
        share.setOwner(getOwner(owner));
        share.setCommunities(getPersonalCommunity(owner));

        // Serialize the ID and Dates in the object to MongoDB format
        // Save the document to the share collection
View Full Code Here

      else {
        documentLocation.set_id(new ObjectId(idStr));       
      }
     
      // Get ShareOwnerPojo object
      PersonPojo owner = getPerson(new ObjectId(ownerIdStr));
      share.setOwner(getOwner(owner));
     
      // Endorsements:
      HashSet<ObjectId> endorsedSet = new HashSet<ObjectId>();
      share.setEndorsed(endorsedSet); // (you're always endorsed within your own community)
View Full Code Here

        else {
          documentLocation.set_id(new ObjectId(idStr));       
        }

        // Get ShareOwnerPojo object
        PersonPojo owner = getPerson(new ObjectId(ownerIdStr));
        share.setOwner(getOwner(owner));

        // Set Personal Community
        share.setCommunities(getPersonalCommunity(owner));
View Full Code Here

  {
    //
    BasicDBObject query = new BasicDBObject();
    query.put("_id", id);
   
    PersonPojo person = null;
    try
    {
      DBObject dbo = DbManager.getSocial().getPerson().findOne(query);

      if (dbo != null)
View Full Code Here

    {
      DBObject dboperson = DbManager.getSocial().getPerson().findOne(new BasicDBObject("_id", new ObjectId(userIdStr)));
     
      if ( dboperson != null )
      {
        PersonPojo person =  PersonPojo.fromDb(dboperson, PersonPojo.class);
        userName = person.getDisplayName();
        userEmail = person.getEmail();
     
        // Parent Community is Optional
        if (parentIdStr != null)
        {
          try {
            DBObject dboparent = DbManager.getSocial().getCommunity().findOne(new BasicDBObject("_id", new ObjectId(parentIdStr)));
            if ( dboparent != null )
            {
              CommunityPojo cp = CommunityPojo.fromDb(dboparent, CommunityPojo.class);
              parentName = cp.getName();
             
              if (cp.getIsPersonalCommunity()) {
                return new ResponsePojo(new ResponseObject("Add Community", false, "Can't create sub-community of personal community"));             
              }//TESTED
              if ((null == cp.getCommunityStatus()) || !cp.getCommunityStatus().equalsIgnoreCase("active")) {
                return new ResponsePojo(new ResponseObject("Add Community", false, "Can't create sub-community of inactive community"));             
              }//TESTED
              // Check attributes
              if (null != cp.getCommunityAttributes()) {
                CommunityAttributePojo attr = cp .getCommunityAttributes().get("usersCanCreateSubCommunities");
                if ((null == attr) || (null== attr.getValue()) || (attr.getValue().equals("false"))) {
                  if (!cp.isOwner(person.get_id()) && !SocialUtils.isModerator(userIdStr, cp) && !RESTTools.adminLookup(userIdStr)) {
                    return new ResponsePojo(new ResponseObject("Add Community", false, "Can't create sub-community when not permitted by parent"));
                  }//TESTED (owner+admin+mod)
                }
              }           
            }//TESTED - different restrictions as above
View Full Code Here

TOP

Related Classes of com.ikanow.infinit.e.data_model.store.social.person.PersonPojo

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.