org.apache.stanbol.contenthub.web.resources
Class StoreResource

java.lang.Object
  extended by org.apache.stanbol.commons.web.base.resource.BaseStanbolResource
      extended by org.apache.stanbol.contenthub.web.resources.StoreResource

public class StoreResource
extends org.apache.stanbol.commons.web.base.resource.BaseStanbolResource

Resource to provide a CRU[D] REST API for content items and there related enhancements.

Creation is achieved using either POST requests on the root of the store or as PUT requests on the expected content item URI.

Retrieval is achieved using simple GET requests on the content item or enhancement public URIs.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.stanbol.commons.web.base.resource.BaseStanbolResource
org.apache.stanbol.commons.web.base.resource.BaseStanbolResource.MenuItem
 
Field Summary
static Set<String> RDF_MEDIA_TYPES
           
 
Fields inherited from class org.apache.stanbol.commons.web.base.resource.BaseStanbolResource
LINK_RESOURCES, NAVIGATION_LINKS, ROOT_URL, SCRIPT_RESOURCES, servletContext, STATIC_RESOURCES_ROOT_URL, SYSTEM_CONSOLE
 
Constructor Summary
StoreResource(javax.servlet.ServletContext context, javax.ws.rs.core.UriInfo uriInfo, String indexName)
           
 
Method Summary
 javax.ws.rs.core.Response createContentItem(org.apache.stanbol.enhancer.servicesapi.ContentItem ci, String title, String chain, javax.ws.rs.core.HttpHeaders headers)
           HTTP POST method to create a content item in Contenthub.
 javax.ws.rs.core.Response createContentItemFromForm(String uri, String content, String url, String title, String chain, javax.ws.rs.core.HttpHeaders headers)
          HTTP POST method to create a content item in Contenthub.
 javax.ws.rs.core.Response createContentItemWithRawData(byte[] data, String uri, String title, String chain, javax.ws.rs.core.HttpHeaders headers)
          HTTP POST method to create a content item in Contenthub.
 javax.ws.rs.core.Response deleteContentItem(String uri, javax.ws.rs.core.HttpHeaders headers)
          HTTP DELETE method to delete a content item from Contenhub.
 javax.ws.rs.core.Response deleteContentItemByForm(String uri, javax.ws.rs.core.HttpHeaders headers)
          This method deletes the ContentItem specified by the given QueryParam.
 javax.ws.rs.core.Response downloadContentItem(String type, String uri, String format, javax.ws.rs.core.HttpHeaders headers)
          HTTP GET method specific for download operations.
 javax.ws.rs.core.Response getContent(String uri, javax.ws.rs.core.HttpHeaders headers)
          Cool URI handler for the uploaded resource.
 javax.ws.rs.core.Response getContentItemMetaData(String uri, String format, javax.ws.rs.core.HttpHeaders headers)
          HTTP GET method to retrieve the metadata of the content item.
 ContentItemResource getContentItemView(String uri)
           
 String getIndexName()
           
 URI getMoreRecentItemsUri()
           
 URI getOlderItemsUri()
           
 javax.ws.rs.core.Response getRawContent(String uri, javax.ws.rs.core.HttpHeaders headers)
          HTTP GET method to retrieve the raw content item.
 List<org.apache.stanbol.contenthub.servicesapi.search.featured.DocumentResult> getRecentlyEnhancedItems()
           
 org.apache.stanbol.commons.viewable.Viewable getView(javax.servlet.ServletContext context, int offset, int pageSize)
           
 javax.ws.rs.core.Response handleCorsPreflight(javax.ws.rs.core.HttpHeaders headers)
           
 javax.ws.rs.core.Response handleCorsPreflightContent(javax.ws.rs.core.HttpHeaders headers)
           
 javax.ws.rs.core.Response handleCorsPreflightDownload(javax.ws.rs.core.HttpHeaders headers)
           
 javax.ws.rs.core.Response handleCorsPreflightMetadata(javax.ws.rs.core.HttpHeaders headers)
           
 javax.ws.rs.core.Response handleCorsPreflightRaw(javax.ws.rs.core.HttpHeaders headers)
           
 javax.ws.rs.core.Response handleCorsPreflightURI(javax.ws.rs.core.HttpHeaders headers)
           
 
Methods inherited from class org.apache.stanbol.commons.web.base.resource.BaseStanbolResource
getConsoleBaseUri, getMainMenuItems, getNavigationLinks, getPublicBaseUri, getRegisteredLinkResources, getRegisteredScriptResources, getRequestUri, getRootUrl, getStaticRootUrl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RDF_MEDIA_TYPES

public static final Set<String> RDF_MEDIA_TYPES
Constructor Detail

StoreResource

public StoreResource(@Context
                     javax.servlet.ServletContext context,
                     @Context
                     javax.ws.rs.core.UriInfo uriInfo,
                     String indexName)
Parameters:
context -
uriInfo -
indexName - Name of the LDPath program (name of the Solr core/index) to be used while storing this content item. LDPath programs can be managed through SemanticIndexManagerResource or SemanticIndexManager
Method Detail

handleCorsPreflight

public javax.ws.rs.core.Response handleCorsPreflight(@Context
                                                     javax.ws.rs.core.HttpHeaders headers)

handleCorsPreflightContent

public javax.ws.rs.core.Response handleCorsPreflightContent(@Context
                                                            javax.ws.rs.core.HttpHeaders headers)

handleCorsPreflightDownload

public javax.ws.rs.core.Response handleCorsPreflightDownload(@Context
                                                             javax.ws.rs.core.HttpHeaders headers)

handleCorsPreflightMetadata

public javax.ws.rs.core.Response handleCorsPreflightMetadata(@Context
                                                             javax.ws.rs.core.HttpHeaders headers)

handleCorsPreflightRaw

public javax.ws.rs.core.Response handleCorsPreflightRaw(@Context
                                                        javax.ws.rs.core.HttpHeaders headers)

handleCorsPreflightURI

public javax.ws.rs.core.Response handleCorsPreflightURI(@Context
                                                        javax.ws.rs.core.HttpHeaders headers)

getContent

public javax.ws.rs.core.Response getContent(String uri,
                                            @Context
                                            javax.ws.rs.core.HttpHeaders headers)
                                     throws org.apache.stanbol.contenthub.servicesapi.store.StoreException
Cool URI handler for the uploaded resource. Based on the Accept header this service redirects the incoming request to different endpoints in the following way:

Parameters:
uri - The URI of the resource in the Stanbol Contenthub store
headers - HTTP headers
Returns:
a redirection to either a browser view, the RDF metadata or the raw binary content
Throws:
org.apache.stanbol.contenthub.servicesapi.store.StoreException

downloadContentItem

public javax.ws.rs.core.Response downloadContentItem(String type,
                                                     String uri,
                                                     String format,
                                                     @Context
                                                     javax.ws.rs.core.HttpHeaders headers)
                                              throws IOException,
                                                     org.apache.stanbol.contenthub.servicesapi.store.StoreException
HTTP GET method specific for download operations. Raw data (content item) or only metadata of the content item can be downloaded.

Parameters:
type - Type can be "metadata" or "raw". Based on the type, related parts of the content item will be prepared for download.
uri - URI of the ContentItem in the Contenthub
format - Rdf serialization format of metadata
Returns:
Raw content item or metadata of the content item.
Throws:
IOException
org.apache.stanbol.contenthub.servicesapi.store.StoreException

getContentItemMetaData

public javax.ws.rs.core.Response getContentItemMetaData(String uri,
                                                        String format,
                                                        @Context
                                                        javax.ws.rs.core.HttpHeaders headers)
                                                 throws IOException,
                                                        org.apache.stanbol.contenthub.servicesapi.store.StoreException
HTTP GET method to retrieve the metadata of the content item. Generally, metadata contains the enhancements of the content item.

Parameters:
uri - URI id of the resource in the Stanbol Contenthub store
Returns:
RDF representation of the metadata of the content item.
Throws:
IOException
org.apache.stanbol.contenthub.servicesapi.store.StoreException

getRawContent

public javax.ws.rs.core.Response getRawContent(String uri,
                                               @Context
                                               javax.ws.rs.core.HttpHeaders headers)
                                        throws IOException,
                                               org.apache.stanbol.contenthub.servicesapi.store.StoreException
HTTP GET method to retrieve the raw content item.

Parameters:
uri - URI of the resource in the Stanbol Contenthub store
Returns:
Raw data of the content item.
Throws:
IOException
org.apache.stanbol.contenthub.servicesapi.store.StoreException

createContentItem

public javax.ws.rs.core.Response createContentItem(org.apache.stanbol.enhancer.servicesapi.ContentItem ci,
                                                   String title,
                                                   String chain,
                                                   @Context
                                                   javax.ws.rs.core.HttpHeaders headers)
                                            throws org.apache.stanbol.contenthub.servicesapi.store.StoreException,
                                                   URISyntaxException

HTTP POST method to create a content item in Contenthub. This method takes a ContentItem object directly. This means that the values provided for this service will be parsed by the multipart mime serialization of Content Items. (see the following links: Content Item Multipart Serialization and Using the multi-part content item RESTful API extensions)

If the passed ContentItem does already have the metadata part, it is not sent to Stanbol enhancer to be enhanced.

Parameters:
ci - ContentItem to be stored.
title - The title for the content item. Titles can be used to present summary of the actual content. For example, search results are presented by showing the titles of resultant content items.
chain - name of a particular Chain in which the enhancement engines are ordered according to a specific use case or need
headers - HTTP Headers
Returns:
URI of the newly created contentitem
Throws:
org.apache.stanbol.contenthub.servicesapi.store.StoreException
URISyntaxException

createContentItemWithRawData

public javax.ws.rs.core.Response createContentItemWithRawData(byte[] data,
                                                              String uri,
                                                              String title,
                                                              String chain,
                                                              @Context
                                                              javax.ws.rs.core.HttpHeaders headers)
                                                       throws URISyntaxException,
                                                              org.apache.stanbol.enhancer.servicesapi.EngineException,
                                                              org.apache.stanbol.contenthub.servicesapi.store.StoreException
HTTP POST method to create a content item in Contenthub.

Parameters:
data - Raw data of the content item
uri - URI for the content item. If not supplied, Contenthub automatically assigns a unique ID (uri) to the content item.
title - The title for the content item. Titles can be used to present summary of the actual content. For example, search results are presented by showing the titles of resultant content items.
chain - name of a particular Chain in which the enhancement engines are ordered according to a specific use case or need
headers - HTTP headers
Returns:
Redirects to "contenthub/{indexName}/store/content/uri" which shows the content item in the HTML view.
Throws:
URISyntaxException
org.apache.stanbol.enhancer.servicesapi.EngineException
org.apache.stanbol.contenthub.servicesapi.store.StoreException

createContentItemFromForm

public javax.ws.rs.core.Response createContentItemFromForm(String uri,
                                                           String content,
                                                           String url,
                                                           String title,
                                                           String chain,
                                                           @Context
                                                           javax.ws.rs.core.HttpHeaders headers)
                                                    throws URISyntaxException,
                                                           org.apache.stanbol.enhancer.servicesapi.EngineException,
                                                           MalformedURLException,
                                                           IOException,
                                                           org.apache.stanbol.contenthub.servicesapi.store.StoreException
HTTP POST method to create a content item in Contenthub. This method requires the content to be text-based.

Parameters:
uri - Optional URI for the content item to be created.
content - Actual content in text format. If this parameter is supplied, url is ommitted.
url - URL where the actual content resides. If this parameter is supplied (and content is null, then the content is retrieved from this url.
title - The title for the content item. Titles can be used to present summary of the actual content. For example, search results are presented by showing the titles of resultant content items.
chain - name of a particular Chain in which the enhancement engines are ordered according to a specific use case or need
headers - HTTP headers (optional)
Returns:
Redirects to "contenthub/{indexName}/store/content/uri" which shows the content item in the HTML view.
Throws:
URISyntaxException
org.apache.stanbol.enhancer.servicesapi.EngineException
MalformedURLException
IOException
org.apache.stanbol.contenthub.servicesapi.store.StoreException

deleteContentItemByForm

public javax.ws.rs.core.Response deleteContentItemByForm(String uri,
                                                         @Context
                                                         javax.ws.rs.core.HttpHeaders headers)
                                                  throws org.apache.stanbol.contenthub.servicesapi.store.StoreException
This method deletes the ContentItem specified by the given QueryParam.

Parameters:
uri - URI of the ContentItem to be deleted.
headers -
Returns:
Response.ok() if the removal is successful
Throws:
org.apache.stanbol.contenthub.servicesapi.store.StoreException

deleteContentItem

public javax.ws.rs.core.Response deleteContentItem(String uri,
                                                   @Context
                                                   javax.ws.rs.core.HttpHeaders headers)
                                            throws org.apache.stanbol.contenthub.servicesapi.store.StoreException
HTTP DELETE method to delete a content item from Contenhub.

Parameters:
uri - URI of the content item to be deleted.
Returns:
HTTP OK
Throws:
org.apache.stanbol.contenthub.servicesapi.store.StoreException

getView

public org.apache.stanbol.commons.viewable.Viewable getView(@Context
                                                            javax.servlet.ServletContext context,
                                                            int offset,
                                                            int pageSize)
                                                     throws IllegalArgumentException,
                                                            IOException,
                                                            org.osgi.framework.InvalidSyntaxException
Throws:
IllegalArgumentException
IOException
org.osgi.framework.InvalidSyntaxException

getContentItemView

public ContentItemResource getContentItemView(String uri)
                                       throws IOException,
                                              org.apache.stanbol.contenthub.servicesapi.store.StoreException
Throws:
IOException
org.apache.stanbol.contenthub.servicesapi.store.StoreException

getRecentlyEnhancedItems

public List<org.apache.stanbol.contenthub.servicesapi.search.featured.DocumentResult> getRecentlyEnhancedItems()
                                                                                                        throws org.apache.clerezza.rdf.core.sparql.ParseException
Throws:
org.apache.clerezza.rdf.core.sparql.ParseException

getMoreRecentItemsUri

public URI getMoreRecentItemsUri()

getOlderItemsUri

public URI getOlderItemsUri()

getIndexName

public String getIndexName()


Copyright © 2011-2013 The Apache Software Foundation. All Rights Reserved.