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 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.

Update is achieved by issue a PUT request on an existing content item public URI.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.stanbol.commons.web.base.resource.BaseStanbolResource
BaseStanbolResource.MenuItem
 
Field Summary
static java.util.Set<java.lang.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
 
Constructor Summary
StoreResource(javax.servlet.ServletContext context, javax.ws.rs.core.UriInfo uriInfo, java.lang.String indexName)
           
 
Method Summary
 javax.ws.rs.core.Response createContentItem(byte[] data, javax.ws.rs.core.HttpHeaders headers)
          HTTP POST method to create a content item in Contenthub.
 javax.ws.rs.core.Response createContentItemFromForm(java.io.File file, com.sun.jersey.core.header.FormDataContentDisposition disposition, com.sun.jersey.multipart.FormDataBodyPart body, java.lang.String jsonCons, java.lang.String title, javax.ws.rs.core.HttpHeaders headers)
          HTTP POST method to create a content item from file.
 javax.ws.rs.core.Response createContentItemFromForm(java.lang.String content, java.lang.String url, java.lang.String jsonCons, java.lang.String title, javax.ws.rs.core.HttpHeaders headers)
          HTTP POST method to create a content item in Contenthub.
 javax.ws.rs.core.Response createContentItemWithId(java.lang.String contentURI, byte[] data, javax.ws.rs.core.HttpHeaders headers)
          HTTP POST method to create a content item in Contenthub.
 javax.ws.rs.core.Response deleteContentItem(java.lang.String contentURI, javax.ws.rs.core.HttpHeaders headers)
          HTTP DELETE method to delete a content item from Contenhub.
 javax.ws.rs.core.Response downloadContentItem(java.lang.String type, java.lang.String contentURI, javax.ws.rs.core.HttpHeaders headers)
          HTTP GET method specific for download operations.
 javax.ws.rs.core.Response editContentItem(java.lang.String contentURI, javax.ws.rs.core.HttpHeaders headers)
          This method creates the JSON string of a content item (to be edited) to display it in the HTML view.
 javax.ws.rs.core.Response getContent(java.lang.String contentURI, javax.ws.rs.core.HttpHeaders headers)
          Cool URI handler for the uploaded resource.
 javax.ws.rs.core.Response getContentItemMetaData(java.lang.String contentURI, javax.ws.rs.core.HttpHeaders headers)
          HTTP GET method to retrieve the metadata of the content item.
 ContentItemResource getContentItemView(java.lang.String contentURI)
           
 java.lang.String getIndexName()
           
 java.net.URI getMoreRecentItemsUri()
           
 java.net.URI getOlderItemsUri()
           
 javax.ws.rs.core.Response getRawContent(java.lang.String contentURI, javax.ws.rs.core.HttpHeaders headers)
          HTTP GET method to retrieve the raw content item.
 java.util.List<DocumentResult> getRecentlyEnhancedItems()
           
 com.sun.jersey.api.view.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 handleCorsPreflightEdit(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 handleCorsPreflightUpdate(javax.ws.rs.core.HttpHeaders headers)
           
 javax.ws.rs.core.Response handleCorsPreflightURI(javax.ws.rs.core.HttpHeaders headers)
           
 javax.ws.rs.core.Response updateContentItemFromForm(java.lang.String contentURI, java.io.File file, com.sun.jersey.core.header.FormDataContentDisposition disposition, com.sun.jersey.multipart.FormDataBodyPart body, java.lang.String jsonCons, java.lang.String title, javax.ws.rs.core.HttpHeaders headers)
          HTTP POST method to update an existing content item.
 javax.ws.rs.core.Response updateContentItemFromForm(java.lang.String contentURI, java.lang.String content, java.lang.String url, java.lang.String jsonCons, java.lang.String title, javax.ws.rs.core.HttpHeaders headers)
          HTTP POST method to update an existing content item.
 
Methods inherited from class org.apache.stanbol.commons.web.base.resource.BaseStanbolResource
getMainMenuItems, getNavigationLinks, getPublicBaseUri, getRegisteredLinkResources, getRegisteredScriptResources, 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 java.util.Set<java.lang.String> RDF_MEDIA_TYPES
Constructor Detail

StoreResource

public StoreResource(@Context
                     javax.servlet.ServletContext context,
                     @Context
                     javax.ws.rs.core.UriInfo uriInfo,
                     java.lang.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)

handleCorsPreflightEdit

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

handleCorsPreflightURI

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

handleCorsPreflightUpdate

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

getContent

public javax.ws.rs.core.Response getContent(java.lang.String contentURI,
                                            @Context
                                            javax.ws.rs.core.HttpHeaders headers)
                                     throws StoreException
Cool URI handler for the uploaded resource.

Parameters:
contentURI - 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:
StoreException

downloadContentItem

public javax.ws.rs.core.Response downloadContentItem(java.lang.String type,
                                                     java.lang.String contentURI,
                                                     @Context
                                                     javax.ws.rs.core.HttpHeaders headers)
                                              throws java.io.IOException,
                                                     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.
contentURI - URI of the resource in the Stanbol Contenthub store
Returns:
Raw content item or metadata of the content item.
Throws:
java.io.IOException
StoreException

getContentItemMetaData

public javax.ws.rs.core.Response getContentItemMetaData(java.lang.String contentURI,
                                                        @Context
                                                        javax.ws.rs.core.HttpHeaders headers)
                                                 throws java.io.IOException,
                                                        StoreException
HTTP GET method to retrieve the metadata of the content item. Generally, metadata contains the enhancements of the content item.

Parameters:
contentURI - URI id of the resource in the Stanbol Contenthub store
Returns:
RDF representation of the metadata of the content item.
Throws:
java.io.IOException
StoreException

getRawContent

public javax.ws.rs.core.Response getRawContent(java.lang.String contentURI,
                                               @Context
                                               javax.ws.rs.core.HttpHeaders headers)
                                        throws java.io.IOException,
                                               StoreException
HTTP GET method to retrieve the raw content item.

Parameters:
contentURI - URI of the resource in the Stanbol Contenthub store
Returns:
Raw data of the content item.
Throws:
java.io.IOException
StoreException

editContentItem

public javax.ws.rs.core.Response editContentItem(java.lang.String contentURI,
                                                 @Context
                                                 javax.ws.rs.core.HttpHeaders headers)
                                          throws StoreException
This method creates the JSON string of a content item (to be edited) to display it in the HTML view.

Parameters:
contentURI - URI id of the resource in the Stanbol Contenthub store
Returns:
JSON representation of the SolrContentItem
Throws:
StoreException

createContentItem

public javax.ws.rs.core.Response createContentItem(byte[] data,
                                                   @Context
                                                   javax.ws.rs.core.HttpHeaders headers)
                                            throws java.net.URISyntaxException,
                                                   EngineException,
                                                   StoreException
HTTP POST method to create a content item in Contenthub. This is the very basic method to create the content item. The payload of the POST method should include the raw data of the content item to be created. This method stores the content in the default Solr index ("contenthub").

Parameters:
data - Raw data of the content item
headers - HTTP Headers
Returns:
Redirects to "contenthub/{indexName}/store/content/uri" which shows the content item in the HTML view.
Throws:
java.net.URISyntaxException
EngineException
StoreException

createContentItemWithId

public javax.ws.rs.core.Response createContentItemWithId(java.lang.String contentURI,
                                                         byte[] data,
                                                         @Context
                                                         javax.ws.rs.core.HttpHeaders headers)
                                                  throws java.net.URISyntaxException,
                                                         EngineException,
                                                         StoreException
HTTP POST method to create a content item in Contenthub.

Parameters:
contentURI - URI for the content item. If not supplied, Contenthub automatically assigns a unique ID (uri) to the content item.
data - Raw data of the content item
headers - HTTP headers
Returns:
Redirects to "contenthub/{indexName}/store/content/uri" which shows the content item in the HTML view.
Throws:
java.net.URISyntaxException
EngineException
StoreException

createContentItemFromForm

public javax.ws.rs.core.Response createContentItemFromForm(java.lang.String content,
                                                           java.lang.String url,
                                                           java.lang.String jsonCons,
                                                           java.lang.String title,
                                                           @Context
                                                           javax.ws.rs.core.HttpHeaders headers)
                                                    throws java.net.URISyntaxException,
                                                           EngineException,
                                                           java.net.MalformedURLException,
                                                           java.io.IOException,
                                                           StoreException
HTTP POST method to create a content item in Contenthub. This method requires the content to be text-based.

Parameters:
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.
jsonCons - Constraints in JSON format. Constraints are used to add supplementary metadata to the content item. For example, author of the content item may be supplied as {author: "John Doe"}. Then, this constraint is added to the Solr and will be indexed if the corresponding Solr schema includes the author field. Solr indexed can be created/adjusted through LDPath programs.
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.
headers - HTTP headers (optional)
Returns:
Redirects to "contenthub/{indexName}/store/content/uri" which shows the content item in the HTML view.
Throws:
java.net.URISyntaxException
EngineException
java.net.MalformedURLException
java.io.IOException
StoreException

createContentItemFromForm

public javax.ws.rs.core.Response createContentItemFromForm(java.io.File file,
                                                           com.sun.jersey.core.header.FormDataContentDisposition disposition,
                                                           com.sun.jersey.multipart.FormDataBodyPart body,
                                                           java.lang.String jsonCons,
                                                           java.lang.String title,
                                                           @Context
                                                           javax.ws.rs.core.HttpHeaders headers)
                                                    throws java.net.URISyntaxException,
                                                           EngineException,
                                                           java.net.MalformedURLException,
                                                           java.io.IOException,
                                                           StoreException
HTTP POST method to create a content item from file. File is read and loaded as the actual content.

Parameters:
file - File which contains the content for the content item.
disposition - Additional information about the file parameter
jsonCons - Constraints in JSON format. Constraints are used to add supplementary metadata to the content item. For example, author of the content item may be supplied as {author: "John Doe"}. Then, this constraint is added to the Solr and will be indexed if the corresponding Solr schema includes the author field. Solr indexed can be created/adjusted through LDPath programs.
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.
headers - HTTP headers (optional)
Returns:
Redirects to "contenthub/{indexName}/store/content/uri" which shows the content item in the HTML view.
Throws:
java.net.URISyntaxException
EngineException
java.net.MalformedURLException
java.io.IOException
StoreException

updateContentItemFromForm

public javax.ws.rs.core.Response updateContentItemFromForm(java.lang.String contentURI,
                                                           java.lang.String content,
                                                           java.lang.String url,
                                                           java.lang.String jsonCons,
                                                           java.lang.String title,
                                                           @Context
                                                           javax.ws.rs.core.HttpHeaders headers)
                                                    throws java.net.URISyntaxException,
                                                           EngineException,
                                                           java.net.MalformedURLException,
                                                           java.io.IOException,
                                                           StoreException
HTTP POST method to update an existing content item.

Parameters:
contentURI - URI of the content item to be updated.
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.
jsonCons - Constraints in JSON format. Constraints are used to add supplementary metadata to the content item. For example, author of the content item may be supplied as {author: "John Doe"}. Then, this constraint is added to the Solr and will be indexed if the corresponding Solr schema includes the author field. Solr indexed can be created/adjusted through LDPath programs.
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.
headers - HTTP headers (optional)
Returns:
Redirects to "contenthub/{indexName}/store/content/uri" which shows the content item in the HTML view.
Throws:
java.net.URISyntaxException
EngineException
java.net.MalformedURLException
java.io.IOException
StoreException

updateContentItemFromForm

public javax.ws.rs.core.Response updateContentItemFromForm(java.lang.String contentURI,
                                                           java.io.File file,
                                                           com.sun.jersey.core.header.FormDataContentDisposition disposition,
                                                           com.sun.jersey.multipart.FormDataBodyPart body,
                                                           java.lang.String jsonCons,
                                                           java.lang.String title,
                                                           @Context
                                                           javax.ws.rs.core.HttpHeaders headers)
                                                    throws java.net.URISyntaxException,
                                                           EngineException,
                                                           java.net.MalformedURLException,
                                                           java.io.IOException,
                                                           StoreException
HTTP POST method to update an existing content item.

Parameters:
contentURI - URI of the content item to be updated.
file - File which contains the content for the content item.
disposition - Additional information about the file parameter
jsonCons - Constraints in JSON format. Constraints are used to add supplementary metadata to the content item. For example, author of the content item may be supplied as {author: "John Doe"}. Then, this constraint is added to the Solr and will be indexed if the corresponding Solr schema includes the author field. Solr indexed can be created/adjusted through LDPath programs.
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.
headers - HTTP headers (optional)
Returns:
Redirects to "contenthub/{indexName}/store/content/uri" which shows the content item in the HTML view.
Throws:
java.net.URISyntaxException
EngineException
java.net.MalformedURLException
java.io.IOException
StoreException

deleteContentItem

public javax.ws.rs.core.Response deleteContentItem(java.lang.String contentURI,
                                                   @Context
                                                   javax.ws.rs.core.HttpHeaders headers)
                                            throws StoreException
HTTP DELETE method to delete a content item from Contenhub.

Parameters:
contentURI - URI of the content item to be deleted.
Returns:
HTTP OK
Throws:
StoreException

getView

public com.sun.jersey.api.view.Viewable getView(@Context
                                                javax.servlet.ServletContext context,
                                                int offset,
                                                int pageSize)
                                         throws java.lang.IllegalArgumentException,
                                                java.io.IOException,
                                                org.osgi.framework.InvalidSyntaxException
Throws:
java.lang.IllegalArgumentException
java.io.IOException
org.osgi.framework.InvalidSyntaxException

getContentItemView

public ContentItemResource getContentItemView(java.lang.String contentURI)
                                       throws java.io.IOException,
                                              StoreException
Throws:
java.io.IOException
StoreException

getRecentlyEnhancedItems

public java.util.List<DocumentResult> getRecentlyEnhancedItems()
                                                        throws org.apache.clerezza.rdf.core.sparql.ParseException
Throws:
org.apache.clerezza.rdf.core.sparql.ParseException

getMoreRecentItemsUri

public java.net.URI getMoreRecentItemsUri()

getOlderItemsUri

public java.net.URI getOlderItemsUri()

getIndexName

public java.lang.String getIndexName()


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