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

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


      ObjectId gridid = saveGridFile(bytes);
      share.setBinaryId(gridid);
     
      // Save the document to the share collection
      DbManager.getSocial().getShare().save(share.toDb());
      rp.setResponse(new ResponseObject("Share", true, "New binary share added successfully. ID in data field"));
      rp.setData(id.toString(), null);
    }
    catch (Exception e)
    {
      e.printStackTrace();
      logger.error("Exception Message: " + e.getMessage(), e);
      rp.setResponse(new ResponseObject("Share", false, "Unable to add share: " + e.getMessage()));
    }
    return rp;
  }
View Full Code Here


                bAdminOrModOfAllCommunities = false;
              }
            }//TESTED
           
            if (!bAdminOrModOfAllCommunities) {           
              rp.setResponse(new ResponseObject("Update Share",false,"Unable to update share: you are not owner or admin"));
              return rp;
            }
          }         
        }//end if not owner
       
        // Check: am I trying to update a reference or json?
        if (null == share.getBinaryId()) {
          rp.setResponse(new ResponseObject("Update Share",false,"Unable to update share: this is not a binary share"));
          return rp;         
        }

        if (!bAdminOrModOfAllCommunities) { // quick check whether I'm admin on-request - if so can endorse
          bAdminOrModOfAllCommunities = RESTTools.adminLookup(ownerIdStr, false);
        }//TESTED
       
        // Remove endorsements unless I'm admin (if I'm not admin I must be owner...)
        if (!bAdminOrModOfAllCommunities) { // Now need to check if I'm admin/mod/content publisher for each community..
          if (null == share.getEndorsed()) { // fill this with all allowed communities
            share.setEndorsed(new HashSet<ObjectId>());
            share.getEndorsed().add(share.getOwner().get_id()); // (will be added later)
            for (ShareCommunityPojo comm: share.getCommunities()) {
              if (SocialUtils.isOwnerOrModeratorOrContentPublisher(comm.get_id().toString(), ownerIdStr)) {
                share.getEndorsed().add(comm.get_id());
              }
            }
          }//TESTED
          else {
            for (ShareCommunityPojo comm: share.getCommunities()) {
              // (leave it as is except remove anything that I can't endorse)
              if (!SocialUtils.isOwnerOrModeratorOrContentPublisher(comm.get_id().toString(), ownerIdStr)) {
                share.getEndorsed().remove(comm.get_id());
              }         
            }
          }//TESTED 
        }//TESTED
        else {
          if (null == share.getEndorsed()) { // fill this with all communities
            share.setEndorsed(new HashSet<ObjectId>());
            share.getEndorsed().add(share.getOwner().get_id());
            for (ShareCommunityPojo comm: share.getCommunities()) {
              share.getEndorsed().add(comm.get_id());             
            }
          }
          //(else just leave with the same set of endorsements as before)
        }//TESTED
       
        share.setModified(new Date());
        share.setType(type);
        share.setTitle(title);
        share.setDescription(description);
        share.setMediaType(mediatype);
        share.setBinaryData(null);
        share.setBinaryId(updateGridFile(share.getBinaryId(), bytes));
       
        DbManager.getSocial().getShare().update(query, share.toDb());
       
        rp.setResponse(new ResponseObject("Update Share", true, "Binary share updated successfully"));
      }
      else
      {
        rp.setResponse(new ResponseObject("Update Share",false,"Shareid does not exist or you are not owner or admin"));
      }     
    }
    catch(Exception e)
    {
      logger.error("Exception Message: " + e.getMessage(), e);
      rp.setResponse(new ResponseObject("Update Share", false, "Unable to update share: " + e.getMessage()));
    }
    return rp;
  }
View Full Code Here

                  }                 
                }
              }//TESTED
             
              if (!readWriteCase) {
                rp.setResponse(new ResponseObject("Update Share",false,"Unable to update share: you are not owner or admin"));
                return rp;
              }
            }
          }         
        }//end if not owner
       
        // Check: am I trying to update a reference or binary?
        if ((null != share.getDocumentLocation()) || (null != share.getBinaryId())) {
          rp.setResponse(new ResponseObject("Update Share",false,"Unable to update share: this is not a JSON share"));
          return rp;         
        }
       
        if (!bAdminOrModOfAllCommunities) { // quick check whether I'm admin on-request - if so can endorse
          bAdminOrModOfAllCommunities = RESTTools.adminLookup(ownerIdStr, false);
        }//TESTED
               
        // Remove endorsements unless I'm admin (if I'm not admin I must be owner...)
        if (!bAdminOrModOfAllCommunities) { // Now need to check if I'm admin/mod/content publisher for each community..
          if (null == share.getEndorsed()) { // fill this with all allowed communities
            share.setEndorsed(new HashSet<ObjectId>());
            share.getEndorsed().add(share.getOwner().get_id()); // (will be added later)
            for (ShareCommunityPojo comm: share.getCommunities()) {
              if (SocialUtils.isOwnerOrModeratorOrContentPublisher(comm.get_id().toString(), ownerIdStr)) {
                share.getEndorsed().add(comm.get_id());
              }
            }
          }//TESTED
          else {
            for (ShareCommunityPojo comm: share.getCommunities()) {
              // (leave it as is except remove anything that I can't endorse)
              if (!SocialUtils.isOwnerOrModeratorOrContentPublisher(comm.get_id().toString(), ownerIdStr)) {
                share.getEndorsed().remove(comm.get_id());
              }         
            }
          }//TESTED 
        }//TESTED
        else {
          if (null == share.getEndorsed()) { // fill this with all communities
            share.setEndorsed(new HashSet<ObjectId>());
            share.getEndorsed().add(share.getOwner().get_id());
            for (ShareCommunityPojo comm: share.getCommunities()) {
              share.getEndorsed().add(comm.get_id());             
            }
          }
          //(else just leave with the same set of endorsements as before)
        }//TESTED
       
        share.setModified(new Date());
        share.setType(type);
        share.setTitle(title);
        share.setDescription(description);
        share.setShare(json);
       
        // Save the document to the share collection
        DbManager.getSocial().getShare().update(query, share.toDb());
        rp.setData(share, new SharePojoApiMap(null));
        rp.setResponse(new ResponseObject("Share", true, "Share updated successfully."));
      }
      // Create new share
      else
      {
        // Create a new SharePojo object
        share = new SharePojo();
        share.set_id(new ObjectId(shareIdStr));
        share.setCreated(new Date());
        share.setModified(new Date());
        share.setType(type);
        share.setTitle(title);
        share.setDescription(description);
        share.setShare(json);
       
        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
        DbManager.getSocial().getShare().save(share.toDb());
        rp.setData(share, new SharePojoApiMap(null));
        rp.setResponse(new ResponseObject("Share", true, "New share added successfully."));
      }
    }
    catch (Exception e)
    {
      logger.error("Exception Message: " + e.getMessage(), e);
      rp.setResponse(new ResponseObject("Share", false, "Unable to update share: " + e.getMessage()));
    }
    return rp;
  }
View Full Code Here

      setRefLocation(location, documentLocation);
      share.setDocumentLocation(documentLocation);
      if (null == documentLocation.getDatabase()) { // (local file)
        // Check, need to be admin:
        if (!RESTTools.adminLookup(ownerIdStr, false)) {
          rp.setResponse(new ResponseObject("Share", false, "Permission denied: you need to be admin to create a local file ref"));
          return rp;
        }       
        if ((null != type) && (type.equalsIgnoreCase("binary") || type.startsWith("binary:"))) {
          String[] binaryType = type.split(":", 2);
          if (binaryType.length > 1) {
            share.setMediaType(binaryType[1]);
            share.setType("binary");
          }
          else {
            share.setMediaType(MimeUtils.getMimeType(FilenameUtils.getExtension(idStr)));
          }
        }
        documentLocation.setCollection(idStr); // collection==file, database==id==null
      }//TESTED
      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)
      endorsedSet.add(new ObjectId(ownerIdStr));       

      // Set Personal Community
      share.setCommunities(getPersonalCommunity(owner));

      // Serialize the ID and Dates in the object to MongoDB format
      // Save the document to the share collection
      DbManager.getSocial().getShare().save(share.toDb());
      rp.setResponse(new ResponseObject("Share", true, "New share added successfully. ID in data field."));
      rp.setData(share.get_id().toString(), null);
    }
    catch (Exception e)
    {
      //logger.error("Exception Message: " + e.getMessage(), e);
      rp.setResponse(new ResponseObject("Share", false, "Unable to add new share: " + e.getMessage()));
    }
    return rp;
  }
View Full Code Here

                bAdminOrModOfAllCommunities = false;
              }
            }//TESTED
           
            if (!bAdminOrModOfAllCommunities) {           
              rp.setResponse(new ResponseObject("Update Share",false,"Unable to update share: you are not owner or admin"));
              return rp;
            }
          }         
        }//end if not owner
       
        // Check: am I trying to update a reference or json?
        if (null == share.getDocumentLocation()) {
          rp.setResponse(new ResponseObject("Update Share",false,"Unable to update share: this is not a reference share"));
          return rp;         
        }
       
        if (!bAdminOrModOfAllCommunities) { // quick check whether I'm admin on-request - if so can endorse
          bAdminOrModOfAllCommunities = RESTTools.adminLookup(ownerIdStr, false);
        }//TESTED
               
        // Remove endorsements unless I'm admin (if I'm not admin I must be owner...)
        if (!bAdminOrModOfAllCommunities) { // Now need to check if I'm admin/mod/content publisher for each community..
          if (null == share.getEndorsed()) { // fill this with all allowed communities
            share.setEndorsed(new HashSet<ObjectId>());
            share.getEndorsed().add(share.getOwner().get_id()); // (will be added later)
            for (ShareCommunityPojo comm: share.getCommunities()) {
              if (SocialUtils.isOwnerOrModeratorOrContentPublisher(comm.get_id().toString(), ownerIdStr)) {
                share.getEndorsed().add(comm.get_id());
              }
            }
          }//TESTED
          else {
            for (ShareCommunityPojo comm: share.getCommunities()) {
              // (leave it as is except remove anything that I can't endorse)
              if (!SocialUtils.isOwnerOrModeratorOrContentPublisher(comm.get_id().toString(), ownerIdStr)) {
                share.getEndorsed().remove(comm.get_id());
              }         
            }
          }//TESTED 
        }//TESTED
        else {
          if (null == share.getEndorsed()) { // fill this with all communities
            share.setEndorsed(new HashSet<ObjectId>());
            share.getEndorsed().add(share.getOwner().get_id());
            for (ShareCommunityPojo comm: share.getCommunities()) {
              share.getEndorsed().add(comm.get_id());             
            }
          }
          //(else just leave with the same set of endorsements as before)
        }//TESTED
       
        share.setType(type);
        share.setTitle(title);
        share.setDescription(description);
        share.setModified(new Date());

        // Create DocumentLocationPojo and add to the share
        DocumentLocationPojo documentLocation = new DocumentLocationPojo();
        setRefLocation(location, documentLocation);
        share.setDocumentLocation(documentLocation);
        if (null == documentLocation.getDatabase()) { // (local file)
          // Check, need to be admin:
          if (!RESTTools.adminLookup(ownerIdStr, false)) {
            rp.setResponse(new ResponseObject("Share", false, "Permission denied: you need to be admin to update a local file ref"));
            return rp;
          }       
          if ((null != type) && (type.equalsIgnoreCase("binary") || type.startsWith("binary:"))) {
            String[] binaryType = type.split(":", 2);
            if (binaryType.length > 1) {
              share.setMediaType(binaryType[1]);
              share.setType("binary");
            }
            else {
              share.setMediaType(MimeUtils.getMimeType(FilenameUtils.getExtension(idStr)));
            }
          }
          documentLocation.setCollection(idStr); // collection==file, database==id==null
        }//TESTED
        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));

        // Serialize the ID and Dates in the object to MongoDB format
        // Save the document to the share collection
        DbManager.getSocial().getShare().update(query, share.toDb());
        rp.setResponse(new ResponseObject("Share", true, "Share updated successfully."));
      }
      else
      {
        rp.setResponse(new ResponseObject("Share", false, "Unable to update share: only the owner of the share or admin can update it."));
        return rp;
      }
    }
    catch (Exception e)
    {
      //logger.error("Exception Message: " + e.getMessage(), e);
      rp.setResponse(new ResponseObject("Share", false, "Unable to update share: " + e.getMessage()));
    }
    return rp;
  }
View Full Code Here

      // Community owner
      // Community moderator
      boolean bAdmin = RESTTools.adminLookup(personIdStr, false);
      if (!bAdmin) {
        if (!SocialUtils.isOwnerOrModeratorOrContentPublisher(communityIdStr, personIdStr))  { 
          rp.setResponse(new ResponseObject("Share", false, "Unable to endorse share: insufficient permissions"));
          return rp;
        }
      }//TESTED
     
      // Now check if the share is even in our community...
      BasicDBObject query = new BasicDBObject(SharePojo._id_, new ObjectId(shareIdStr));
      query.put(ShareCommunityPojo.shareQuery_id_, communityId);
      BasicDBObject fields = new BasicDBObject(ShareOwnerPojo.shareQuery_id_, 1);
      fields.put(SharePojo.endorsed_, 1);
      BasicDBObject shareObj = (BasicDBObject) DbManager.getSocial().getShare().findOne(query, fields);
      SharePojo shareToEndorse = SharePojo.fromDb(shareObj, SharePojo.class);
      if (null == shareToEndorse) {
        rp.setResponse(new ResponseObject("Share", false, "Failed to locate share in community: " + shareIdStr + " vs " + communityIdStr));       
        return rp;
      }//TESTED
      // If we've got this far we're good to go
      BasicDBObject update = null;
      if ((null == shareToEndorse.getEndorsed()) && (null != shareToEndorse.getOwner())) {
        //Legacy case: create the owner's personal community in there
        update = new BasicDBObject(DbManager.addToSet_, new BasicDBObject(SharePojo.endorsed_, shareToEndorse.getOwner().get_id()));
        DbManager.getSocial().getShare().update(query, update, false, true);
      }//TESTED
      if (isEndorsed) {
        update = new BasicDBObject(DbManager.addToSet_, new BasicDBObject(SharePojo.endorsed_, communityId));
      }//TESTED
      else {
        update = new BasicDBObject(DbManager.pull_, new BasicDBObject(SharePojo.endorsed_, communityId));       
      }//TESTED
      DbManager.getSocial().getShare().update(query, update, false, true);
      rp.setResponse(new ResponseObject("Share", true, "Share endorsed successfully."));
    }
    catch (Exception e)
    {
      logger.error("Exception Message: " + e.getMessage(), e);
      rp.setResponse(new ResponseObject("Share", false, "Unable to endorse share: " + e.getMessage()));
    }
    return rp;
  }//TESTED
View Full Code Here

        if ( sp.getBinaryId() != null )
        {
          //remove gridfs
          DbManager.getSocial().getShareBinary().remove(sp.getBinaryId());
        }
        rp.setResponse(new ResponseObject("Share", true, "Share removed from database successfully"));
      }
      else
      {
        rp.setResponse(new ResponseObject("Share", false, "Unable to remove share from database successfully (reason: share does not exist or user does not own the share)."));
      }
    }
    catch (Exception e)
    {
      logger.error("Exception Message: " + e.getMessage(), e);
      rp.setResponse(new ResponseObject("Share", false, "Unable to remove share: " + e.getMessage()));
    }
    return rp;
  }
View Full Code Here

            //TESTED - adding as admin/community owner, not adding if not
          }         
          share.setModified(new Date());

          DbManager.getSocial().getShare().update(query, share.toDb());
          rp.setResponse(new ResponseObject("Share", true, "Community successfully added to the share"));
        }
        // Community already in share.communities
        else
        {
          rp.setResponse(new ResponseObject("Share", false, "Community has already been added to the share"));
        }
      }
      else
      {
        rp.setResponse(new ResponseObject("Share", false, "Unable to add community to share."));
      }
    }
    catch (Exception e)
    {
      logger.error("Exception Message: " + e.getMessage(), e);
      rp.setResponse(new ResponseObject("Share", false, "Unable to add community to share: " + e.getMessage()));
    }
    return rp;
  }
View Full Code Here

           
            removeCommunity = true;
            communities.remove(scp);
            share.setModified(new Date());
            DbManager.getSocial().getShare().update(query, share.toDb());
            rp.setResponse(new ResponseObject("Share", true, "Community successfully removed from the share"));
            break;
          }
        }

        if (!removeCommunity)
        {
          rp.setResponse(new ResponseObject("Share", false, "Unable to remove community (does not exist in share)"));
        }
      }
      else
      {
        rp.setResponse(new ResponseObject("Share", false, "Unable to remove community from share."));
      }
    }
    catch (Exception e)
    {
      logger.error("Exception Message: " + e.getMessage(), e);
      rp.setResponse(new ResponseObject("Share", false, "Unable to remove community from share: " + e.getMessage()));
    }
    return rp;
  }
View Full Code Here

          break;
        }//TESTED
      }     
    }
    rp.setData(dimlist);
    rp.setResponse(new ResponseObject("Suggestions",true,term));

    if (nSysTime > (lastSuggestLog + 5000)) {
      lastSuggestLog = nSysTime;
      logMsg.setLength(0);
      logMsg.append("knowledge/searchSuggest query=").append(escapedterm);
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.