/**
   * Add an new empty feed::dasextension element with only a completed management element to the
   * given Feed. Sets the responseTime value to now. Note: A proper sites::site element must be
   * added to the new feed::dasextension element for this new feed::dasextension element to be
   * valid.
   *
   * @param feed - mandatory
   * @return
   */
  private Feed addEmptyDasExtension(Feed feed) {

    // check to make sure there's a dasextension
    QName dasextensionQname = new QName(this.dasextensionNamespace, "dasextension");
    ExtensibleElement dasExt = feed.getExtension(dasextensionQname);
    if (NullChecker.isEmpty(dasExt)) {

      dasExt = feed.addExtension(dasextensionQname);

      // add the dasextension::management element
      QName managementQname = new QName(this.dasextensionNamespace, "management");
      ExtensibleElement management = dasExt.getExtension(managementQname);
      if (NullChecker.isEmpty(management)) {
        management = dasExt.addExtension(managementQname);
      }

      QName responseTimeQname = new QName(this.dasextensionNamespace, "responseTime");
      ExtensibleElement responseTime = management.getExtension(responseTimeQname);
      if (NullChecker.isEmpty(responseTime)) {
        responseTime = management.addExtension(responseTimeQname);
      }

      // set/reset the response time to now
      XMLGregorianCalendar xmlGregCalResponseTime =
          GregorianDateUtil.getGregorianCalendarByDate(new Date());
      responseTime.setText(xmlGregCalResponseTime.toString()); // TODO: Verify date format
    }
    return feed;
  }
Пример #2
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));
    }
  }
  /**
   * Merge the elements in the given dasextensionToMerge Element into the feed::dasextension element
   * in the given feed. Note: The dasextension::path::parameters and dasextension::query::parameters
   * values in the given dasextensionToMerge Element will only be merged into the given feed if the
   * given feed does not already have these Elements.
   *
   * @param feed - mandatory - must contain a valid feed::dasextension Element
   * @param extensionToMerge - mandatory - must contain a valid dasextension Element
   * @return
   */
  public Feed mergeDasExtension(Feed feed, final Element dasextensionToMerge) {

    if (NullChecker.isNotEmpty(feed)) {
      if (NullChecker.isNotEmpty(dasextensionToMerge)) {

        QName mergeExtQname = dasextensionToMerge.getQName();
        String mergeExtTagName = mergeExtQname.getLocalPart();

        // if dasextensionToMerge isn't a dasextension, ignore it
        if ("dasextension".equals(mergeExtTagName)) {
          ExtensibleElement feedDasExt =
              feed.getExtension(new QName(this.dasextensionNamespace, "dasextension"));

          if (NullChecker.isNotEmpty(feedDasExt)) {
            // feed contains an existing dasextension, so merge other dasextensionToMerge with it:

            // merge dasextension::path::parameters if none are already in feed
            boolean feedPathParametersExists = this.pathParametersExists(feedDasExt);
            boolean mergePathParametersExists =
                this.pathParametersExists((ExtensibleElement) dasextensionToMerge);
            if (false == feedPathParametersExists) {
              if (mergePathParametersExists) {
                ExtensibleElement mergePathParameters =
                    this.getPathParameters((ExtensibleElement) dasextensionToMerge);
                feed = this.addPathParameters(feed, mergePathParameters);
              }
            }

            // merge dasextension::query::parameters if none are already in feed
            boolean feedQueryParametersExists = this.queryParametersExists(feedDasExt);
            boolean mergeQueryParametersExists =
                this.queryParametersExists((ExtensibleElement) dasextensionToMerge);
            if (false == feedQueryParametersExists) {
              if (mergeQueryParametersExists) {
                ExtensibleElement mergeQueryParameters =
                    this.getQueryParameters((ExtensibleElement) dasextensionToMerge);
                feed = this.addQueryParameters(feed, mergeQueryParameters);
              }
            }

            // collect all of the current dasextension sites::site elements
            List<Element> siteElements = new ArrayList<Element>();
            ExtensibleElement mergeSites = this.getSites((ExtensibleElement) dasextensionToMerge);
            if (NullChecker.isNotEmpty(mergeSites)) {
              siteElements.addAll(mergeSites.getElements());
            }

            // add in the site elements into the feed's dasextension
            for (final Element siteElement : siteElements) {
              feed = this.addSite(feed, (ExtensibleElement) siteElement);
            }

            // collect all of the merge dasextension errors::error elements
            List<Element> errorElements = new ArrayList<Element>();
            ExtensibleElement mergeErrors = this.getErrors((ExtensibleElement) dasextensionToMerge);
            if (NullChecker.isNotEmpty(mergeErrors)) {
              errorElements.addAll(mergeErrors.getElements());
            }

            // add in the error elements into the feed's dasextension
            for (final Element errorElement : errorElements) {
              feed = this.addError(feed, (ExtensibleElement) errorElement);
            }

          } else {
            // feed has no existing dasextension element, so add in dasextensionToMerge
            feed.addExtension(dasextensionToMerge);
          }
        }
      }
    }
    return feed;
  }
 @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();
 }