@GET @Produces(MediaType.APPLICATION_JSON) public Response get( @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); Collection<Content> searchContent; ResponseBuilder responseBuilder; Filter filter = getFilter(); final com.smartitengineering.cms.api.common.SearchResult searchResult = SmartContentAPI.getInstance().getContentLoader().search(filter); searchContent = searchResult.getResult(); if (searchContent.isEmpty() || searchContent == null) { responseBuilder = Response.status(Response.Status.NO_CONTENT); } else { SearchResult result = new SearchResult(); result.setTotalResults(searchResult.getTotalResultsCount()); result.setResult(adapter.convert(searchContent.toArray(new Content[searchContent.size()]))); result.setCount(count); result.setStart(start); result.setNext(getNextPage()); result.setPrevious(getPreviousPage()); responseBuilder = Response.ok(result); } return responseBuilder.build(); }
@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(); }