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

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


 
  // UTILITY 
 
  public boolean hasSourceHarvested(String sourceId)
  {
    ResponseObject ro = new ResponseObject();
    return hasSourceHarvested(getSource(sourceId, ro));
  }
View Full Code Here


      System.out.println("*** CALL WITH username password as args");
      System.exit(-1);
    }
    InfiniteDriver.setDefaultApiRoot("http://localhost:8184/");
    InfiniteDriver infDriver = new InfiniteDriver();
    ResponseObject responseObject = new ResponseObject();
    infDriver.login(args[0], args[1], responseObject);
    System.out.println("DRIVER LOGIN = " + responseObject.isSuccess() + " : " + responseObject.getMessage());
    List<PersonPojo> people = infDriver.listPerson(responseObject);
    System.out.println("DRIVER LIST PEOPLE = " + responseObject.isSuccess() + " : " + responseObject.getMessage());
   
    if (null != people) {
      System.out.println("FOUND " + people.size());
      if (people.size() > 0) {
        System.out.println("EXAMPLE " + people.iterator().next().toDb());       
View Full Code Here

    if ((null == rp) || (null == rp.getResponse())) { // (this is likely some sort of internal error)
      if (null == rp)
      {
        rp = new ResponsePojo();
      }
      rp.setResponse(new ResponseObject("Query", false, "Unknown error"));
    }
    if (!rp.getResponse().isSuccess()) {
      rp.getResponse().setMessage(errorString.append('/').append(rp.getResponse().getMessage()).toString());
      return rp;
    }
View Full Code Here

        if ( dbc.count() > 0 )
        {
          List<CommunityPojo> communities = CommunityPojo.listFromDb(dbc, CommunityPojo.listType());
          filterCommunityMembers(communities, isSysAdmin, userIdStr);
          rp.setData(communities, new CommunityPojoApiMap());
          rp.setResponse(new ResponseObject("Community Info", true, "Community info returned successfully"));       
        }
        else
        {
          rp.setResponse(new ResponseObject("Community Info", true, "No communities returned"))
        }
      }
      else // Get all public communities and all private communities to which the user belongs
      {
        // Set up the query
        BasicDBObject queryTerm1 = new BasicDBObject("communityAttributes.isPublic.value", "true");
        BasicDBObject queryTerm2 = new BasicDBObject("members._id", new ObjectId(userIdStr));
        BasicDBObject queryTerm3 = new BasicDBObject("ownerId", new ObjectId(userIdStr));
        BasicDBObject query = new BasicDBObject(MongoDbManager.or_, Arrays.asList(queryTerm1, queryTerm2, queryTerm3));

        DBCursor dbc = DbManager.getSocial().getCommunity().find(query);       
        if ( dbc.count() > 0 )
        {
          List<CommunityPojo> communities = CommunityPojo.listFromDb(dbc, CommunityPojo.listType());
          filterCommunityMembers(communities, isSysAdmin, userIdStr);
          //add personal community
          DBObject dbo = DbManager.getSocial().getCommunity().findOne(new BasicDBObject("_id",new ObjectId(userIdStr)));
          if ( dbo != null )
          {
            communities.add(CommunityPojo.fromDb(dbo, CommunityPojo.class));
          }
          rp.setData(communities, new CommunityPojoApiMap());
          rp.setResponse(new ResponseObject("Community Info", true, "Community info returned successfully"));       
        }
        else
        {
          rp.setResponse(new ResponseObject("Community Info", true, "No communities returned"))
        }
      }
    }
    catch (Exception e)
    {
      logger.error("Exception Message: " + e.getMessage(), e);
      rp.setResponse(new ResponseObject("Community Info", false, "error returning community info"));
    }

    return rp;
  }
View Full Code Here

      if ( dbc.count() > 0 )
      {
        List<CommunityPojo> communities = CommunityPojo.listFromDb(dbc, CommunityPojo.listType());
        filterCommunityMembers(communities, isSysAdmin, userIdStr);
        rp.setData(communities, new CommunityPojoApiMap());
        rp.setResponse(new ResponseObject("Community Info", true, "Community info returned successfully"));       
      }
      else
      {
        rp.setResponse(new ResponseObject("Community Info", true, "No communities returned"))
      }
    }
    catch (Exception e)
    {
      logger.error("Exception Message: " + e.getMessage(), e);
      rp.setResponse(new ResponseObject("Community Info", false, "error returning community info"));
    }
    return rp;
  }
View Full Code Here

            community.setDocumentInfo(dc);
          }
        }
        community = filterCommunityMembers(community, RESTTools.adminLookup(userIdStr), userIdStr);
        rp.setData(community, new CommunityPojoApiMap());
        rp.setResponse(new ResponseObject("Community Info", true, "Community info returned successfully"));
      }
      else
      {
        rp.setResponse(new ResponseObject("Community Info", false, "Unable to return information for the community specified."));
      }
    }
    catch (Exception e)
    {
      //logger.error("Exception Message: " + e.getMessage(), e);
      rp.setResponse(new ResponseObject("Community Info", false, "Error returning community info: " + e.getMessage()));
    }
    return rp;
  }
View Full Code Here

            {
              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
            else
            {
              return new ResponsePojo(new ResponseObject("Add Community", false, "Parent community does not exist"));
            }//TESTED
          }
          catch (Exception e) {
            return new ResponsePojo(new ResponseObject("Add Community", false, "Invalid parent community id"));
          }//TESTED
        }
      }
      else
      {
        return new ResponsePojo(new ResponseObject("Add Community", false, "Error: Unable to get person record"));
      }
    }
    catch (Exception ex)
    {
      return new ResponsePojo(new ResponseObject("Add Community", false, "General Error: " + ex.getMessage()));
    }
    return addCommunity(userIdStr, name, description, parentIdStr, parentName, tags, userIdStr, userName, userEmail);
  }
View Full Code Here

        // Create the index form of the community:
        try {
          GenericProcessingController.createCommunityDocIndex(c.getId().toString(), c.getParentId(), c.getIsPersonalCommunity(), c.getIsSystemCommunity(), false);
        }
        catch (Exception e) { // Can't create community
          rp.setResponse(new ResponseObject("Add Community", false, "Error adding new community because of index failure: " + e.getMessage()));
          return rp;
        }
        //TESTED
       
        DbManager.getSocial().getCommunity().save(commObj);       
       
        // If a child, update the parent:
        if (null != c.getParentId()) {
          BasicDBObject updateQuery = new BasicDBObject("_id", c.getParentId());
          BasicDBObject updateUpdate = new BasicDBObject(DbManager.addToSet_, new BasicDBObject("children", c.getId()));
          DbManager.getSocial().getCommunity().update(updateQuery, updateUpdate, false, true);
        }
        //TESTED
       
        // Update the new community record to add the owner to the list of members
        rp = addCommunityMember(userId, oId.toStringMongod(), name, ownerIdStr, ownerEmail, ownerDisplayName, "owner", "active");
        rp.setResponse(new ResponseObject("Add Community", true, "The " + name + " community has " +
          "been added."));       
      }
      else
      {
        rp.setResponse(new ResponseObject("Add Community", false,
            "Error adding new community. A community with the name " + name + " " +
            "already exists."));
      }
     
    }
    catch (Exception e)
    {
      // If an exception occurs log the error
      logger.error("Exception Message: " + e.getMessage(), e);
      rp.setResponse(new ResponseObject("Add Community", false,
          "Error adding new community " + e.getMessage()));
    }
    return rp;
  }
View Full Code Here

            if ( cp.isOwner(new ObjectId(personIdStr)) || isSysAdmin )
            {
              if (cp.getCommunityStatus().equals("disabled")) { // Delete for good, this is going to be ugly...
               
                if ((null != cp.getChildren()) && !cp.getChildren().isEmpty()) {
                  rp.setResponse(new ResponseObject("Delete community", false, "Undeleted sub-communities exist, please delete them first"));
                  return rp;
                }
                //TESTED
               
                // 1] Remove from all shares (delete shares if that leaves them orphaned)
               
                BasicDBObject deleteQuery1 = new BasicDBObject(ShareCommunityPojo.shareQuery_id_, communityId);
                BasicDBObject deleteFields1 = new BasicDBObject(SharePojo.communities_, 1);
                List<SharePojo> shares = SharePojo.listFromDb(DbManager.getSocial().getShare().find(deleteQuery1, deleteFields1), SharePojo.listType());       
                for (SharePojo share: shares) {
                  if (1 == share.getCommunities().size()) { // delete this share
                    DbManager.getSocial().getShare().remove(new BasicDBObject(SharePojo._id_, share.get_id()));
                  }
                }
                BasicDBObject update1 = new BasicDBObject(DbManager.pull_, new BasicDBObject(SharePojo.communities_,
                                              new BasicDBObject(ShareOwnerPojo._id_, communityId)));
                DbManager.getSocial().getShare().update(deleteQuery1, update1, false, true);
               
                //TESTED (both types)
               
                // 2] Remove from all sources (also delete the documents)
                // (In most cases this will leave the source orphaned, so delete it)
               
                BasicDBObject deleteQuery2 = new BasicDBObject(SourcePojo.communityIds_, communityId);
                BasicDBObject deleteFields2 = new BasicDBObject(SourcePojo.communityIds_, 1);
                List<SourcePojo> sources = SourcePojo.listFromDb(DbManager.getIngest().getSource().find(deleteQuery2, deleteFields2), SourcePojo.listType());
                List<SourcePojo> failedSources = new ArrayList<SourcePojo>();
                for (SourcePojo source: sources)
                {
                  ResponsePojo rp1 = null;
                  SourceHandler tmpHandler = new SourceHandler();
                  if (1 == source.getCommunityIds().size()) { // delete this source
                    rp1 = tmpHandler.deleteSource(source.getId().toString(), communityIdStr, personIdStr, false);
                      // (deletes all docs and removes from the share)
                  }
                  else { // Still need to delete docs from this share from this community
                    rp1 = tmpHandler.deleteSource(source.getId().toString(), communityIdStr, personIdStr, true);                   
                  }
                  if ( rp1 != null && !rp1.getResponse().isSuccess() )
                  {
                    failedSources.add(source);
                  }
                }
               
                //if we have more than 1 failed source, bail out w/ error
                if (failedSources.size() > 0 )
                {
                  StringBuilder sb = new StringBuilder();
                  for ( SourcePojo source : failedSources )
                    sb.append(source.getId().toString() + " ");
                  rp.setResponse(new ResponseObject("Delete community", false, "Could not stop sources (they might be currently running): " + sb.toString()));
                  return rp;
                }
               
                BasicDBObject update2 = new BasicDBObject(DbManager.pull_, new BasicDBObject(SourcePojo.communityIds_, communityId));
                DbManager.getSocial().getShare().update(deleteQuery2, update2, false, true);

                //TESTED (both types, check docs deleted)
               
                // 3] Remove from all map reduce jobs (delete any that it is only comm left on)
                String customJobsMessage = removeCommunityFromJobs(personIdStr, communityId);
                if ( customJobsMessage.length() > 0)
                {
                  rp.setResponse(new ResponseObject("Delete community", false, "Could not stop all map reduce jobs (they might be currently running): " + customJobsMessage));
                  return rp;
                }
               
                // 4] Finally delete the object itself
               
                DbManager.getSocial().getCommunity().remove(new BasicDBObject("_id", communityId));
               
                // Remove from index:
                GenericProcessingController.deleteCommunityDocIndex(communityId.toString(), cp.getParentId(), false);
                //TESTED
               
                // 5] Finally finally remove from parent communities
                if (null != cp.getParentId()) {
                  BasicDBObject updateQuery = new BasicDBObject("_id", cp.getParentId());
                  BasicDBObject updateUpdate = new BasicDBObject(DbManager.pull_, new BasicDBObject("children", cp.getId()));
                  DbManager.getSocial().getCommunity().update(updateQuery, updateUpdate, false, true);                 
                }
                //TESTED
               
                rp.setResponse(new ResponseObject("Delete community", true, "Community deleted forever. " + customJobsMessage));
              }
              else { // First time, just remove all users and disable
                //at this point, we have verified, community/user exist, not a personal group, user is member and owner
                //set community as inactive (for some reason we don't delete it)
                DbManager.getSocial().getCommunity().update(new BasicDBObject("_id", communityId),
                                      new BasicDBObject(DbManager.set_, new BasicDBObject("communityStatus","disabled")));
               
                //remove all members
                for ( CommunityMemberPojo cmp : cp.getMembers())
                  removeCommunityMember(personIdStr, communityIdStr, cmp.get_id().toString());
                rp.setResponse(new ResponseObject("Delete community", true, "Community disabled successfully - call delete again to remove for good, including all sources, shares, and documents"));
              }
            }
            else
            {
              rp.setResponse(new ResponseObject("Delete community", false, "You are not the owner of this community"));
            }
          }
          else
          {
            rp.setResponse(new ResponseObject("Delete community", false, "Cannot delete personal community."));
          }         
        }
        else
        {
          rp.setResponse(new ResponseObject("Delete community", false, "Person ID was incorrect, no matching person found"));
        }
      }
      else
      {
        rp.setResponse(new ResponseObject("Delete community", false, "Community ID was incorrect, no matching commmunity found"));
      }

    }
    catch (Exception ex)
    {
      rp.setResponse(new ResponseObject("Delete community", false, "Error returning community info: " + ex.getMessage()));     
    }
   
    return rp;
  }
View Full Code Here

         
          CommunityPojo cp = CommunityPojo.fromDb(dbo,CommunityPojo.class);
          ObjectId personId = new ObjectId(personIdStr);
         
          if ( cp.isOwner(personId) && !userStatus.equalsIgnoreCase("active")) {           
            rp.setResponse(new ResponseObject("Update member status",false,"Can't change owner status, remove their ownership first"));
            return rp;
          }//TESTED (tried as owner+admin (failed both times), tested owner works fine if setting/keeping active)
          else if ( cp.isMember(personId) )
          {
            // Remove user:
            if (userStatus.equalsIgnoreCase("remove"))
            {
              //removeCommunityMember(callerIdStr, communityIdStr, personIdStr);
              rp = removeCommunityMember(callerIdStr, communityIdStr, personIdStr); //.setResponse(new ResponseObject("Update member status",true,"Member removed from community."));
            }
            else
            {
              //verified user, update status
              if ( cp.updateMemberStatus(personIdStr, userStatus) )
              {
                /////////////////////////////////////////////////////////////////////////////////////////////////
                // 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 status",true,"Updated member status successfully"));
              }
              else
              {
                rp.setResponse(new ResponseObject("Update member status",false,"Failed to update status"));
              }
            }
          }
          else
          {
            rp.setResponse(new ResponseObject("Update member status",false,"User was not a member of the community"));
          }
        }
        else
        {
          rp.setResponse(new ResponseObject("Update member status",false,"Caller must be admin, or a community owner or moderator"));
        }//TESTED - tried to update my status as member (failed), as admin (succeeded), as moderator (succeeded), as owner (succeeded) 
      }
      else
      {
        rp.setResponse(new ResponseObject("Update member status",false,"Community does not exist"));
      }     
    }
    catch(Exception ex)
    {
      rp.setResponse(new ResponseObject("Update member status",false,"General Error, bad params maybe? " + ex.getMessage()));
    }
    return rp;
  }//TESTED
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.