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

Examples of com.ikanow.infinit.e.data_model.store.social.sharing.SharePojo


        throw new RuntimeException("Saved query has invalid format");     
      }
      rp = ResponsePojo.fromDb(apiResultToConvert);
    }
    else if (null != oid) { // Support new user/doc queues
      SharePojo share = SharePojo.fromDb(DbManager.getSocial().getShare().findOne(jobQuery), SharePojo.class);
      if ((null == share) || (null == share.getShare()) ||
          (!share.getType().equals(DocumentQueueControlPojo.UserQueue) && !share.getType().equals(DocumentQueueControlPojo.SavedQueryQueue))
          )
      {
        throw new RuntimeException("Can't find saved query, or is a custom job not a query, or authorization error");               
      }
      else { // share.share is a  DocumentQueueControlPojo
        DocumentQueueControlPojo queue = DocumentQueueControlPojo.fromApi(share.getShare(), DocumentQueueControlPojo.class);
        BasicDBObject docQuery1 = new BasicDBObject(DocumentPojo._id_, new BasicDBObject(DbManager.in_, queue.getQueueList()));
        BasicDBObject docQuery2 = new BasicDBObject(DocumentPojo.updateId_, new BasicDBObject(DbManager.in_, queue.getQueueList()));
        BasicDBObject docQuery = new BasicDBObject(DbManager.or_, Arrays.asList(docQuery1, docQuery2));
        DBCursor dbc = DbManager.getDocument().getMetadata().find(docQuery).limit(query.score.numAnalyze);
        ScoringUtils scoreStats = new ScoringUtils();
        List<BasicDBObject> docs = null;
        StatisticsPojo stats = new StatisticsPojo();
        stats.setSavedScores(query.output.docs.skip, dbc.count());
        try {
          boolean lockAcquired = true;
          try {
            lockAcquired = this.acquireConcurrentAccessLock();
           
          } catch (InterruptedException e) {
            //(that's fine just carry on)
            lockAcquired = false;
          }
          if (!lockAcquired) {
            rp.setResponse(new ResponseObject("Query", false, "Query engine busy, please try again later."));
            return rp;
          }
          scoreStats.setAliasLookupTable(_aliasLookup);
          docs = scoreStats.calcTFIDFAndFilter(DbManager.getDocument().getMetadata(),
                              dbc, query.score, query.output, stats, false,
                              query.output.docs.skip, query.output.docs.numReturn,
                                    communityIdStrs,
                                    null, null,
                                    null,
                                    null,
                                    null, null,
                                    null, null);
        }
        finally {
          scoreStats.clearAsMuchMemoryAsPossible();
          this.releaseConcurrentAccessLock();
        }
        rp = new ResponsePojo();
        rp.setResponse(new ResponseObject("Query", true, "Saved Query: " + share.getTitle()));
        rp.setStats(stats);
        if ((null != docs) && (docs.size() > 0)) {
          rp.setData(docs, (BasePojoApiMap<BasicDBObject>)null);
        }
        else { // (ensure there's always an empty list)
View Full Code Here


 
  static AdvancedQueryPojo getStoredQueryArtefact(String shareIdStr, AdvancedQueryPojo query, String userIdStr) {
   
    ResponsePojo rp2 = new ShareHandler().getShare(userIdStr, shareIdStr, true);
    if ((null != rp2.getData() || !rp2.getResponse().isSuccess())) {
      SharePojo share = (SharePojo) rp2.getData();
      if (null != share) {
        if (share.getType().equalsIgnoreCase("dataset")) {
          query.input = new com.google.gson.Gson().fromJson(share.getShare(), AdvancedQueryPojo.QueryInputPojo.class);
        }
        else if (share.getType().equalsIgnoreCase("query")) {
          query = new com.google.gson.Gson().fromJson(share.getShare(), AdvancedQueryPojo.class);
        }
        else { // Unrecognized share
          throw new RuntimeException("Unexpected share type: " + share.getType());
        }
      }
      else {
        throw new RuntimeException("Invalid return from share: " + rp2.getData().toString());
      }
View Full Code Here

           rp = this.shareController.removeCommunity(personId, shareId, communityId);
         }
         else if (action.equals("getShare"))
         {     
           rp = this.shareController.getShare(personId, shareId, returnContent)
           SharePojo share = (SharePojo) rp.getData();
           if (null != share) {
             boolean bBinary = share.getType().equals("binary");
             if ( bBinary && returnContent )          
             {     
               try
               {              
                 ByteArrayOutputRepresentation rep = new ByteArrayOutputRepresentation(MediaType.valueOf(share.getMediaType()));
                 rep.setOutputBytes(share.getBinaryData());
                 return rep;              
               }
               catch (Exception ex )
               {
                 rp = new ResponsePojo(new ResponseObject("get Share",false,"error converting bytes to output: " + ex.getMessage()));
               }            
             }
             else if (!bBinary && jsonOnly) {
               try {
                 BasicDBObject dbo = (BasicDBObject) com.mongodb.util.JSON.parse(share.getShare());
                 rp.setData(dbo, null);
               }
               catch (Exception e) { // Try a list instead
                 BasicDBList dbo = (BasicDBList) com.mongodb.util.JSON.parse(share.getShare());
                 rp.setData(dbo, (BasePojoApiMap<BasicDBList>)null);                
               }
             }
           }
           //(else error)
View Full Code Here

      communityIdStr = allowCommunityRegex(ownerIdStr, communityIdStr);
     
      BasicDBObject dbo = (BasicDBObject)DbManager.getSocial().getShare().findOne(query);
      if (dbo != null)
      {
        SharePojo share = SharePojo.fromDb(dbo, SharePojo.class)

        List<ShareCommunityPojo> communities = share.getCommunities();

        // Check to see if the community is already in share.communities
        boolean removeCommunity = false;
        for (ShareCommunityPojo scp : communities)
        {
          if (scp.get_id().toString().equalsIgnoreCase(communityIdStr))
          {
            //Also remove endorsements...
            if (null != share.getEndorsed()) {
              share.getEndorsed().remove(scp.get_id());
            }//TESTED           
           
            // Also remove readWrite...
            if (null != share.getReadWrite()) {
              share.getReadWrite().remove(scp.get_id());
            }
           
            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;
          }
        }
View Full Code Here

      share_id = share.get_id().toString();
     
      ResponsePojo rp1 = getShare(cookieLookup, share_id, true);
      if ( rp1.getResponse().isSuccess() )
      {
        SharePojo previous_share = (SharePojo)rp1.getData();
        if ( share.getType() == null )
          share.setType(previous_share.getType());
        if ( share.getTitle() == null )
          share.setTitle(previous_share.getTitle());
        if ( share.getDescription() == null )
          share.setDescription(previous_share.getDescription());
        if ( share.getCommunities() == null )
          share.setCommunities(previous_share.getCommunities());

        if ( share.getShare() == null)
          share.setShare(previous_share.getShare());
        if ( share.getDocumentLocation() == null )
          share.setDocumentLocation(previous_share.getDocumentLocation());
        if ( share.getBinaryData() == null )
          share.setBinaryData(previous_share.getBinaryData());
        if ( share.getBinaryId() == null )
          share.setBinaryId(previous_share.getBinaryId());
      }
      else
      {
        //couldn't get previous share, return error
        return rp1;
      }
    }
   
    //STEP 1, call appropriate update/add function   
    if ( share.getBinaryData() != null )
    {
      //binary
      if ( share_id == null )
        rp = addBinary(cookieLookup, share.getType(), share.getTitle(), share.getDescription(), share.getMediaType(), share.getBinaryData());
      else
        rp = updateBinary(cookieLookup, share_id, share.getType(), share.getTitle(), share.getDescription(), share.getMediaType(), share.getBinaryData());
      if ( !rp.getResponse().isSuccess() )
        return rp;
      else
      {
        String saved_share_id = share_id;
        if ( rp.getData() != null )
          saved_share_id = (String)rp.getData();
        rp = getShare(cookieLookup, saved_share_id, false);
        if ( !rp.getResponse().isSuccess())
          return rp;
      }
    }
    else if ( share.getDocumentLocation() != null )
    {
      //ref
      if ( share_id == null )
        rp = addRef(cookieLookup, share.getType(), share.getDocumentLocation().getDatabase() + "." + share.getDocumentLocation().getCollection(), share.getDocumentLocation().get_id().toString(), share.getTitle(), share.getDescription());
      else
        rp = updateRef(cookieLookup, share_id, share.getType(), share.getDocumentLocation().getDatabase() + "." + share.getDocumentLocation().getCollection(), share.getDocumentLocation().get_id().toString(), share.getTitle(), share.getDescription());
      if ( !rp.getResponse().isSuccess() )
        return rp;
      else
      {
        String saved_share_id = share_id;
        if ( rp.getData() != null )
          saved_share_id = (String)rp.getData();
        rp = getShare(cookieLookup, saved_share_id, false);
        if ( !rp.getResponse().isSuccess())
          return rp;
      }
    }
    else
    {
      //json     
      rp = saveJson(cookieLookup, share_id, share.getType(), share.getTitle(), share.getDescription(), share.getShare());
      if ( !rp.getResponse().isSuccess() )
        return rp;
    }
    SharePojo saved_share = (SharePojo)rp.getData();
           
   
    //STEP 2, handle comms (loop over passed in comms, adding any that dont exist, remove any leftovers
    StringBuilder sb = new StringBuilder();
    List<ShareCommunityPojo> existingComms = saved_share.getCommunities();
    for ( ShareCommunityPojo scp : share.getCommunities() )
    {
      boolean found = false;
      for ( ShareCommunityPojo scp_existing : existingComms )
      {
        if ( scp_existing.get_id().equals(scp.get_id()) )
        {
          existingComms.remove(scp_existing);
          found = true;
          break;
        }
      }
      if ( !found )
      {
        rp = addCommunity(cookieLookup, saved_share.get_id().toString(), scp.get_id().toString(), scp.getComment(), readWrite);
        if ( !rp.getResponse().isSuccess() )
          sb.append(scp.get_id().toString() + " ");
      }
    }
    for ( ShareCommunityPojo scp : existingComms )
    {
      rp = removeCommunity(cookieLookup, saved_share.get_id().toString(), scp.get_id().toString());
      if ( !rp.getResponse().isSuccess() )
        sb.append(scp.get_id().toString() + " ");
    }
   
    //have to get share now to see it with updated comms
    rp = getShare(cookieLookup, saved_share.get_id().toString(), returnContent);   
    if ( sb.length() > 0 )
      rp.getResponse().setMessage("Error adding/removing some of the communities: " + sb.toString());
   
    return rp;
  }
View Full Code Here

    {
      if ( id != null )
      {   
        //GET A SPECIFIC SHARE
        rp = shareController.getShare(cookieLookup, id, returnContent)
        SharePojo share = (SharePojo) rp.getData();
        if (null != share)
        {
          boolean bBinary = share.getType().equals("binary");
          if ( bBinary && returnContent )          
          {     
            try
            {              
              ByteArrayOutputRepresentation rep = new ByteArrayOutputRepresentation(MediaType.valueOf(share.getMediaType()));
              rep.setOutputBytes(share.getBinaryData());
              return rep;              
            }
            catch (Exception ex )
            {
              rp = new ResponsePojo(new ResponseObject(ACTION,false,"error converting bytes to output: " + ex.getMessage()));
            }            
          }
          else if (!bBinary && jsonOnly)
          {
            try
            {
              BasicDBObject dbo = (BasicDBObject) com.mongodb.util.JSON.parse(share.getShare());
              rp.setData(dbo, null);
            }
            catch (Exception e)
            { // Try a list instead           
              BasicDBList dbo = (BasicDBList) com.mongodb.util.JSON.parse(share.getShare());
              rp.setData(dbo, (BasePojoApiMap<BasicDBList>)null);                
            }
          }
        }
      }
View Full Code Here

    ResponsePojo rp = new ResponsePojo();
    Date startTime = new Date();
   
    if ( cookieLookup != null )
    {
      SharePojo share = null;
      try
      {
        share = parseEntity(entity)
        share.set_id(null); //is create function, id can't exist
      }
      catch (Exception ex)
      {
        rp.setResponse(new ResponseObject(ACTION, false, ex.getMessage()));
        return returnRepresentation(rp, startTime);
View Full Code Here

  {
    ResponsePojo rp = new ResponsePojo();
    Date startTime = new Date();
    if ( cookieLookup != null )
    {
      SharePojo share = null;
      try
      {
        share = parseEntity(entity);
      }
      catch (Exception ex)
View Full Code Here

    if ( cookieLookup != null )
    {
      if ( id == null )
      {
        //check if its in the body
        SharePojo share = null;
        try
        {
          share = parseEntity(entity);
          if ( share != null && share.get_id() != null )
            id = share.get_id().toString();
         
        }
        catch (Exception ex)
        {
          //should just fail, this is fine
View Full Code Here

        return null;
      }
      // If we're here then it was a share

      BasicDBObject query = new BasicDBObject("_id", extractorId);
      SharePojo extractorInfo = SharePojo.fromDb(MongoDbManager.getSocial().getShare().findOne(query), SharePojo.class);
      if ((null != extractorInfo) && (null != extractorInfo.getBinaryId())) {
        // Check share owned by an admin:
        if (!AuthUtils.isAdmin(extractorInfo.getOwner().get_id())) {
          throw new RuntimeException("Extractor share owner must be admin");
        }//TESTED
        // Check >0 source communities are in the share communities
        int nMatches = 0;
        for (ShareCommunityPojo commObj: extractorInfo.getCommunities()) {
          if (source.getCommunityIds().contains(commObj.get_id())) {
            nMatches++;
            break;
          }
        }
        if (0 == nMatches) {
          throw new RuntimeException("Extractor not shared across source communities");         
        }//TESTED
       
        savedClassLoader = Thread.currentThread().getContextClassLoader();
       
        //HashMap<String, Class<?> > dynamicExtractorClassCache = null;
        if (null == dynamicExtractorClassCache) {
          dynamicExtractorClassCache = new HashMap<String, Class<?> >();
        }

        URL[] cachedJarFile = { new File(maintainJarFileCache(extractorInfo)).toURI().toURL() };       
       
        Class<?> classToLoad = dynamicExtractorClassCache.get(extractorInfo.getTitle());       
        if (null == classToLoad) {       
          URLClassLoader child = new URLClassLoader(cachedJarFile, savedClassLoader);
         
          Thread.currentThread().setContextClassLoader(child);
          classToLoad = Class.forName(extractorInfo.getTitle(), true, child);
          dynamicExtractorClassCache.put(extractorInfo.getTitle(), classToLoad);
        }

        if (bTextExtractor) {
          ITextExtractor txtExtractor = (ITextExtractor )classToLoad.newInstance();
          text_extractor_mappings.put(source.useTextExtractor(), txtExtractor);
View Full Code Here

TOP

Related Classes of com.ikanow.infinit.e.data_model.store.social.sharing.SharePojo

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.