public InputStream disseminate(Context context, Item item)
      throws DSpaceSwordException, SwordError, SwordServerException {
    try {
      Abdera abdera = new Abdera();
      Feed feed = abdera.newFeed();

      this.addMetadata(feed, item);

      Bundle[] originals = item.getBundles("ORIGINAL");
      for (Bundle original : originals) {
        Bitstream[] bss = original.getBitstreams();
        for (Bitstream bitstream : bss) {
          Entry entry = feed.addEntry();
          this.populateEntry(context, entry, bitstream);
        }
      }

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      feed.writeTo(baos);
      ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
      return bais;
    } catch (SQLException e) {
      throw new DSpaceSwordException(e);
    } catch (IOException e) {
      throw new DSpaceSwordException(e);
    }
  }
 private void addTasksToFeed(
     RequestContext context, Feed feed, Task[] tasks, String token, String user) throws Exception {
   for (Task t : tasks) {
     Entry entry = feed.addEntry();
     entry.setId(t.getID());
     entry.setTitle(t.getDescription());
     entry.setUpdated(new Date());
     setLinkForTask(t, token, context, entry, user);
   }
 }
  private void addAtomManagedDatastream(Feed feed, String contentLocation) throws Exception {
    String dsId = "DS";

    Entry dsEntry = feed.addEntry();
    dsEntry.setId(feed.getId().toString() + "/" + dsId);

    Entry dsvEntry = feed.addEntry();
    dsvEntry.setId(dsEntry.getId().toString() + "/" + feed.getUpdatedString());

    dsEntry.setTitle(feed.getTitle());
    dsEntry.setUpdated(feed.getUpdated());
    dsEntry.addLink(dsvEntry.getId().toString(), Link.REL_ALTERNATE);
    dsEntry.addCategory(MODEL.STATE.uri, "A", null);
    dsEntry.addCategory(MODEL.CONTROL_GROUP.uri, "M", null);
    dsEntry.addCategory(MODEL.VERSIONABLE.uri, "true", null);

    dsvEntry.setTitle(feed.getTitle());
    dsvEntry.setUpdated(feed.getUpdated());
    ThreadHelper.addInReplyTo(dsvEntry, dsEntry.getId());
    dsvEntry.setSummary("summary");
    dsvEntry.setContent(new IRI(contentLocation), "text/plain");
  }
    public AdapterResponse<Feed> adapterResponse(int entriesOnFeed, boolean hasNextMarker) {
      final Feed feed = Abdera.getInstance().newFeed();

      for (int i = 1; i <= entriesOnFeed; i++) {
        Entry entry = Abdera.getInstance().newEntry();
        entry.setId(Integer.toString(i));
        feed.addEntry(entry);
      }

      if (hasNextMarker) {
        feed.addLink("next", REL_NEXT);
      }

      return new FeedSourceAdapterResponse<Feed>(feed, HttpStatus.OK, "");
    }
Example #5
0
  /** {@inheritDoc} */
  protected void addFeedDetails(Feed feed, RequestContext request) throws ResponseContextException {
    try {
      String objectId = getId(request);
      String propertyFilter = request.getParameter(AtomCMIS.PARAM_FILTER);
      boolean includeAllowableActions =
          getBooleanParameter(request, AtomCMIS.PARAM_INCLUDE_ALLOWABLE_ACTIONS, false);
      int maxItems =
          getIntegerParameter(request, AtomCMIS.PARAM_MAX_ITEMS, CmisConstants.MAX_ITEMS);
      int skipCount =
          getIntegerParameter(request, AtomCMIS.PARAM_SKIP_COUNT, CmisConstants.SKIP_COUNT);

      Connection connection = getConnection(request);

      List<CmisObject> list =
          connection.getAllVersions(objectId, includeAllowableActions, true, propertyFilter);

      if (list.size() > 0) {
        // add cmisra:numItems
        Element numItems = feed.addExtension(AtomCMIS.NUM_ITEMS);
        numItems.setText(Integer.toString(list.size()));
        // Paging inks
        addPageLinks(
            objectId,
            feed,
            "versions",
            maxItems,
            skipCount,
            list.size(),
            (skipCount + maxItems) < list.size(),
            request);

        for (CmisObject one : list) {
          Entry entry = feed.addEntry();
          IRI feedIri = new IRI(getFeedIriForEntry(one, request));
          addEntryDetails(request, entry, feedIri, one);
        }
      }
    } catch (FilterNotValidException fe) {
      throw new ResponseContextException(createErrorResponse(fe, 400));
    } catch (ObjectNotFoundException onfe) {
      throw new ResponseContextException(createErrorResponse(onfe, 404));
    } catch (InvalidArgumentException iae) {
      throw new ResponseContextException(createErrorResponse(iae, 400));
    } catch (Exception t) {
      throw new ResponseContextException(createErrorResponse(t, 500));
    }
  }
 @GET
 @Produces(MediaType.APPLICATION_ATOM_XML)
 public Response getResultFeed(
     @QueryParam(TYPE_ID) List<String> contentTypeId,
     @QueryParam(SEARCH_TERMS) String searchTerms,
     @QueryParam(STATUS) List<String> statuses,
     @QueryParam(WORKSPACE_ID) String workspaceId,
     @QueryParam(FIELD) List<String> fieldQuery,
     @QueryParam(CREATION_DATE) String creationDate,
     @QueryParam(LAST_MODIFIED_DATE) String lastModifiedDate,
     @QueryParam(INCLUDE_FRIENDLIES) @DefaultValue("true") boolean includeFriendlies,
     @QueryParam(START) int start,
     @QueryParam(COUNT) @DefaultValue("5") int count,
     @QueryParam(DISJUNCTION) boolean disJunction) {
   initParams(
       contentTypeId,
       searchTerms,
       statuses,
       workspaceId,
       fieldQuery,
       creationDate,
       lastModifiedDate,
       start,
       count,
       disJunction,
       includeFriendlies);
   ResponseBuilder responseBuilder;
   Filter filter = getFilter();
   final com.smartitengineering.cms.api.common.SearchResult result =
       SmartContentAPI.getInstance().getContentLoader().search(filter);
   final Collection<Content> searchContent = result.getResult();
   Feed feed = getFeed("search", "Content Search Result", new Date());
   feed.addLink(
       getLink(
           getUriInfo().getRequestUri().toASCIIString(),
           Link.REL_ALTERNATE,
           MediaType.APPLICATION_JSON));
   feed.addLink(
       getLink(
           new StringBuilder(getUriInfo().getBaseUri().toASCIIString())
               .append(getUriInfo().getPath())
               .toString(),
           "search",
           com.smartitengineering.util.opensearch.jaxrs.MediaType
               .APPLICATION_OPENSEARCHDESCRIPTION_XML));
   Query query = feed.<Query>addExtension(OpenSearchConstants.QUERY);
   query.setRole(Query.Role.REQUEST);
   query.setCount(count);
   query.setStartIndex(start);
   query.setSearchTerms(searchTerms);
   IntegerElement countElem =
       feed.<IntegerElement>addExtension(OpenSearchConstants.ITEMS_PER_PAGE);
   countElem.setValue(count);
   IntegerElement startIndexElem =
       feed.<IntegerElement>addExtension(OpenSearchConstants.START_INDEX);
   startIndexElem.setValue(start);
   IntegerElement totalResultsElem =
       feed.<IntegerElement>addExtension(OpenSearchConstants.TOTAL_RESULTS);
   totalResultsElem.setValue(Long.valueOf(result.getTotalResultsCount()).intValue());
   if (searchContent != null && !searchContent.isEmpty()) {
     feed.addLink(
         getLink(getNextPage().toASCIIString(), Link.REL_NEXT, MediaType.APPLICATION_ATOM_XML));
     if (getPreviousPage() != null) {
       feed.addLink(
           getLink(
               getPreviousPage().toASCIIString(),
               Link.REL_PREVIOUS,
               MediaType.APPLICATION_ATOM_XML));
     }
     for (Content content : searchContent) {
       final URI contentUri =
           ContentResource.getContentUri(getRelativeURIBuilder(), content.getContentId());
       Entry entry =
           getEntry(
               content.getContentId().toString(),
               new StringBuilder("Content ").append(content.getContentId().toString()).toString(),
               content.getLastModifiedDate(),
               getLink(contentUri, Link.REL_ALTERNATE, MediaType.APPLICATION_ATOM_XML),
               getLink(contentUri, Link.REL_ALTERNATE, MediaType.APPLICATION_JSON));
       feed.addEntry(entry);
     }
   }
   responseBuilder = Response.ok(feed);
   return responseBuilder.build();
 }