com.canoris.api
Class CanorisResourceManager

java.lang.Object
  extended by com.canoris.api.CanorisResourceManager

public class CanorisResourceManager
extends java.lang.Object

This class is the main communication point with the back-end. Through this class you can perform all the operation the back-end offers.


Constructor Summary
CanorisResourceManager()
           
 
Method Summary
 void addFileToCollection(java.lang.String collectionKey, CanorisFile file)
          Adds a file to the given collection.
 void configProxy(java.lang.String host, int port, java.lang.String protocol)
          Configures the proxy
 java.util.Map<java.lang.String,java.lang.Object> createCollection(java.lang.String name, java.lang.String license, java.lang.String visibility)
           
 CanorisResource createFile(java.lang.String filePath, java.util.Map<java.lang.String,java.lang.String> params)
          Creates a file resource.
 CanorisResource createFileFromURL(java.lang.String url, java.util.Map<java.lang.String,java.lang.String> params)
          Creates a file from the URL parameter.
 java.util.Map<java.lang.String,java.lang.Object> createTask(java.lang.String taskName, java.lang.String taskContent)
          Creates with the give taskName, containing the taskContent.
 org.codehaus.jackson.JsonNode createTemplate(java.lang.String templateName, java.lang.String templateContent)
          Creates a template and returns the response or null TODO: This should return a JsonNode??
 void deleteCollection(java.lang.String collectionKey)
          Deletes the collection.
 void deleteTemplate(java.lang.String templateName)
          Deletes the give template
 java.io.InputStream downloadFile(CanorisFile file)
          Return an InputStream representing the requested file.
 java.io.InputStream downloadFile(java.lang.String fileKey)
          Return an InputStream representing the requested file.
 org.codehaus.jackson.JsonNode getAnalysis(CanorisFile file, java.lang.String filter)
          Returns the analysis of the file as a JsonNode
 org.codehaus.jackson.JsonNode getAnalysisFrames(java.lang.String fileKey)
          Returns the analysis frames
 java.util.Map<java.lang.String,java.lang.Object> getCollection(java.lang.String collectionKey)
           
 java.util.Map<java.lang.String,java.lang.Object> getCollectionFile(java.lang.String collectionKey, CanorisFile file)
           
 Pager getCollectionFiles(java.lang.String collectionKey)
          Returns a Pager.
 Pager getCollections()
           
 java.io.InputStream getConversion(CanorisFile file, java.lang.String conversionName)
          Returns an input stream representing the conversion type requested.
 java.util.Map<java.lang.String,java.lang.Object> getConversions(CanorisFile file)
          Gets the conversions of the file you pass
 CanorisFile getFile(CanorisFile file)
          Returns a Map representing the requested file.
 CanorisFile getFile(java.lang.String fileKey)
          Returns a Map representing the requested file.
 Pager getFiles()
          Returns a Pager object to be used for navigating the pages or accessing a particular element in the page.
 Pager getNextPage(Pager pager)
          Gets the next page.
 Pager getPage(Pager pager)
          Gets the requested page.
 Pager getPage(java.lang.String start, java.lang.String limit)
          Gets the requested page.
 Pager getPreviousPage(Pager pager)
          Gets the previous page.
 java.util.Map<java.lang.String,java.lang.Object> getSimilaritySearch(java.lang.String collectionKey, CanorisFile file, java.lang.String preset, java.lang.String results)
          Performs a similarity search.
 java.util.Map<java.lang.String,java.lang.Object> getTask(java.lang.String taskId)
          Get the task that corresponds to the taskId.
 org.codehaus.jackson.JsonNode getTemplates()
          Gets the list of templates.
 java.util.Map<java.lang.String,java.lang.Object> getText2Phon(java.lang.String text, java.lang.String language)
           
 java.io.InputStream getVisualization(CanorisFile file, java.lang.String name)
          Gets the visualization of the passed file
 java.util.Map<java.lang.String,java.lang.Object> getVisualizations(CanorisFile file)
          Return the visualization of the file
 org.codehaus.jackson.JsonNode updateTemplate(java.lang.String templateContent, java.lang.String templateName)
          Updates the template that matches the templateName.
 void useProxy(boolean useProxy)
          Sets if the communication uses a proxy or not
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CanorisResourceManager

public CanorisResourceManager()
Method Detail

createFile

public CanorisResource createFile(java.lang.String filePath,
                                  java.util.Map<java.lang.String,java.lang.String> params)
                           throws org.apache.http.client.ClientProtocolException,
                                  java.net.URISyntaxException,
                                  java.io.IOException
Creates a file resource. You can pass extra parameters if applicable and the method will use them as required. The params parameter is reserved for later use.

Parameters:
filePath -
params -
Returns:
CanorisResource The created object.
Throws:
org.apache.http.client.ClientProtocolException
java.net.URISyntaxException
java.io.IOException

createFileFromURL

public CanorisResource createFileFromURL(java.lang.String url,
                                         java.util.Map<java.lang.String,java.lang.String> params)
                                  throws org.apache.http.client.ClientProtocolException,
                                         java.net.URISyntaxException,
                                         java.io.IOException,
                                         CanorisException
Creates a file from the URL parameter. Note that creating a file this way will not have a "serve" field so it cannot be retrieved. The file is thrown away after it's being processed.

Parameters:
url -
params -
Returns:
CanorisResource
Throws:
org.apache.http.client.ClientProtocolException
java.net.URISyntaxException
java.io.IOException
CanorisException

getFiles

public Pager getFiles()
               throws org.apache.http.client.ClientProtocolException,
                      java.io.IOException,
                      java.net.URISyntaxException,
                      CanorisException
Returns a Pager object to be used for navigating the pages or accessing a particular element in the page.

Returns:
Pager
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

getFile

public CanorisFile getFile(CanorisFile file)
                    throws org.apache.http.client.ClientProtocolException,
                           java.io.IOException,
                           java.net.URISyntaxException,
                           CanorisException
Returns a Map representing the requested file.

Parameters:
file -
Returns:
CanorisFile
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

getFile

public CanorisFile getFile(java.lang.String fileKey)
                    throws org.apache.http.client.ClientProtocolException,
                           java.io.IOException,
                           java.net.URISyntaxException,
                           CanorisException
Returns a Map representing the requested file.

Parameters:
fileKey -
Returns:
CanorisFile
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

downloadFile

public java.io.InputStream downloadFile(CanorisFile file)
                                 throws org.apache.http.client.ClientProtocolException,
                                        java.io.IOException,
                                        java.net.URISyntaxException,
                                        CanorisException
Return an InputStream representing the requested file. You MUST close the stream manually, if not it will block the operation.

Parameters:
file -
Returns:
InputStream
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

downloadFile

public java.io.InputStream downloadFile(java.lang.String fileKey)
                                 throws org.apache.http.client.ClientProtocolException,
                                        java.io.IOException,
                                        java.net.URISyntaxException,
                                        CanorisException
Return an InputStream representing the requested file. You MUST close the stream manually, if not it will block the operation.

Parameters:
fileKey -
Returns:
InputStream
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

getConversion

public java.io.InputStream getConversion(CanorisFile file,
                                         java.lang.String conversionName)
                                  throws org.apache.http.client.ClientProtocolException,
                                         java.io.IOException,
                                         java.net.URISyntaxException,
                                         CanorisException
Returns an input stream representing the conversion type requested.

Parameters:
file -
conversionName -
Returns:
InputStream
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

getConversions

public java.util.Map<java.lang.String,java.lang.Object> getConversions(CanorisFile file)
                                                                throws org.apache.http.client.ClientProtocolException,
                                                                       java.io.IOException,
                                                                       java.net.URISyntaxException,
                                                                       CanorisException
Gets the conversions of the file you pass

Parameters:
file -
Returns:
Map the conversions
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

getAnalysis

public org.codehaus.jackson.JsonNode getAnalysis(CanorisFile file,
                                                 java.lang.String filter)
                                          throws org.apache.http.client.ClientProtocolException,
                                                 java.io.IOException,
                                                 java.net.URISyntaxException,
                                                 CanorisException
Returns the analysis of the file as a JsonNode

Parameters:
file -
filter -
Returns:
JsonNode
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

getAnalysisFrames

public org.codehaus.jackson.JsonNode getAnalysisFrames(java.lang.String fileKey)
                                                throws org.codehaus.jackson.JsonParseException,
                                                       org.codehaus.jackson.map.JsonMappingException,
                                                       org.apache.http.ParseException,
                                                       java.io.IOException,
                                                       java.net.URISyntaxException,
                                                       CanorisException
Returns the analysis frames

Parameters:
fileKey -
Returns:
JsonNode
Throws:
org.codehaus.jackson.JsonParseException
org.codehaus.jackson.map.JsonMappingException
org.apache.http.ParseException
java.io.IOException
java.net.URISyntaxException
CanorisException

getVisualization

public java.io.InputStream getVisualization(CanorisFile file,
                                            java.lang.String name)
                                     throws org.apache.http.client.ClientProtocolException,
                                            java.io.IOException,
                                            java.net.URISyntaxException,
                                            CanorisException
Gets the visualization of the passed file

Parameters:
file -
name -
Returns:
An InputStream representing the visualization or null
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

getVisualizations

public java.util.Map<java.lang.String,java.lang.Object> getVisualizations(CanorisFile file)
                                                                   throws org.apache.http.client.ClientProtocolException,
                                                                          java.io.IOException,
                                                                          java.net.URISyntaxException,
                                                                          CanorisException
Return the visualization of the file

Parameters:
file -
Returns:
Map
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

getTemplates

public org.codehaus.jackson.JsonNode getTemplates()
                                           throws org.apache.http.client.ClientProtocolException,
                                                  java.io.IOException,
                                                  java.net.URISyntaxException,
                                                  CanorisException
Gets the list of templates.

Returns:
JsonNode
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

createTemplate

public org.codehaus.jackson.JsonNode createTemplate(java.lang.String templateName,
                                                    java.lang.String templateContent)
                                             throws org.apache.http.client.ClientProtocolException,
                                                    java.io.IOException,
                                                    java.net.URISyntaxException,
                                                    CanorisException
Creates a template and returns the response or null TODO: This should return a JsonNode??

Parameters:
templateName -
Returns:
JsonNode
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

updateTemplate

public org.codehaus.jackson.JsonNode updateTemplate(java.lang.String templateContent,
                                                    java.lang.String templateName)
                                             throws org.apache.http.client.ClientProtocolException,
                                                    java.io.IOException,
                                                    java.net.URISyntaxException,
                                                    CanorisException
Updates the template that matches the templateName. Will throw error if template is not found.

Parameters:
templateContent -
templateName -
Returns:
JSonNode
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

deleteTemplate

public void deleteTemplate(java.lang.String templateName)
                    throws org.apache.http.client.ClientProtocolException,
                           java.io.IOException,
                           java.net.URISyntaxException,
                           CanorisException
Deletes the give template

Parameters:
templateName -
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

createTask

public java.util.Map<java.lang.String,java.lang.Object> createTask(java.lang.String taskName,
                                                                   java.lang.String taskContent)
                                                            throws org.apache.http.client.ClientProtocolException,
                                                                   java.io.IOException,
                                                                   java.net.URISyntaxException,
                                                                   CanorisException
Creates with the give taskName, containing the taskContent.

Parameters:
taskName -
taskContent -
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

getTask

public java.util.Map<java.lang.String,java.lang.Object> getTask(java.lang.String taskId)
                                                         throws org.apache.http.client.ClientProtocolException,
                                                                java.io.IOException,
                                                                java.net.URISyntaxException,
                                                                CanorisException
Get the task that corresponds to the taskId. Null if it finds no task with given taskId ?

Parameters:
taskId -
Returns:
Map
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

getText2Phon

public java.util.Map<java.lang.String,java.lang.Object> getText2Phon(java.lang.String text,
                                                                     java.lang.String language)
                                                              throws org.apache.http.client.ClientProtocolException,
                                                                     java.io.IOException,
                                                                     java.net.URISyntaxException,
                                                                     CanorisException
Parameters:
text -
language -
Returns:
Map
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

getCollections

public Pager getCollections()
                     throws org.apache.http.client.ClientProtocolException,
                            java.io.IOException,
                            java.net.URISyntaxException,
                            CanorisException
Throws:
CanorisException
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException

getCollection

public java.util.Map<java.lang.String,java.lang.Object> getCollection(java.lang.String collectionKey)
                                                               throws org.apache.http.client.ClientProtocolException,
                                                                      java.io.IOException,
                                                                      java.net.URISyntaxException,
                                                                      CanorisException
Parameters:
collectionKey -
Returns:
Map
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

createCollection

public java.util.Map<java.lang.String,java.lang.Object> createCollection(java.lang.String name,
                                                                         java.lang.String license,
                                                                         java.lang.String visibility)
                                                                  throws org.apache.http.client.ClientProtocolException,
                                                                         java.io.IOException,
                                                                         java.net.URISyntaxException,
                                                                         CanorisException
Parameters:
name -
license -
visibility -
Returns:
Map
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

deleteCollection

public void deleteCollection(java.lang.String collectionKey)
                      throws org.apache.http.client.ClientProtocolException,
                             java.io.IOException,
                             java.net.URISyntaxException,
                             CanorisException
Deletes the collection. This method does not return a value. If no exception is thrown the operation is considered successful.

Parameters:
collectionKey -
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

getCollectionFiles

public Pager getCollectionFiles(java.lang.String collectionKey)
                         throws org.apache.http.client.ClientProtocolException,
                                java.io.IOException,
                                java.net.URISyntaxException,
                                CanorisException
Returns a Pager. You can use the pager to access the collection or navigate through its pages.

Parameters:
collectionKey - The key used to retrieve the collection.
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

addFileToCollection

public void addFileToCollection(java.lang.String collectionKey,
                                CanorisFile file)
                         throws org.apache.http.client.ClientProtocolException,
                                java.io.IOException,
                                java.net.URISyntaxException,
                                CanorisException
Adds a file to the given collection.

Parameters:
collectionKey -
file -
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

getCollectionFile

public java.util.Map<java.lang.String,java.lang.Object> getCollectionFile(java.lang.String collectionKey,
                                                                          CanorisFile file)
                                                                   throws org.apache.http.client.ClientProtocolException,
                                                                          java.io.IOException,
                                                                          java.net.URISyntaxException,
                                                                          CanorisException
Parameters:
collectionKey -
file -
Returns:
Map
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

getSimilaritySearch

public java.util.Map<java.lang.String,java.lang.Object> getSimilaritySearch(java.lang.String collectionKey,
                                                                            CanorisFile file,
                                                                            java.lang.String preset,
                                                                            java.lang.String results)
                                                                     throws org.apache.http.client.ClientProtocolException,
                                                                            java.io.IOException,
                                                                            java.net.URISyntaxException,
                                                                            CanorisException
Performs a similarity search.

Parameters:
collectionKey -
file -
preset -
results -
Returns:
Map
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

getPage

public Pager getPage(Pager pager)
              throws org.apache.http.client.ClientProtocolException,
                     java.io.IOException,
                     java.net.URISyntaxException,
                     CanorisException
Gets the requested page. Works with old and new paging style depending on parameters passed.

Returns:
Pager
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

getPage

public Pager getPage(java.lang.String start,
                     java.lang.String limit)
              throws org.apache.http.client.ClientProtocolException,
                     java.io.IOException,
                     java.net.URISyntaxException,
                     CanorisException
Gets the requested page. Returns the page corresponding to the start parameter with the page size based on the limit parameter Actually this works like this: page with start=1 limit=2 so next page is 3 using start=1 limit=5 next page will be 6 and so on

Returns:
Pager
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

getNextPage

public Pager getNextPage(Pager pager)
                  throws org.apache.http.client.ClientProtocolException,
                         java.io.IOException,
                         java.net.URISyntaxException,
                         CanorisException
Gets the next page. It extracts the page number by the pager.

Returns:
Pager
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

getPreviousPage

public Pager getPreviousPage(Pager pager)
                      throws org.apache.http.client.ClientProtocolException,
                             java.io.IOException,
                             java.net.URISyntaxException,
                             CanorisException
Gets the previous page. It extracts the page number by the pager.

Parameters:
pager -
Returns:
Pager
Throws:
org.apache.http.client.ClientProtocolException
java.io.IOException
java.net.URISyntaxException
CanorisException

useProxy

public void useProxy(boolean useProxy)
Sets if the communication uses a proxy or not

Parameters:
useProxy -

configProxy

public void configProxy(java.lang.String host,
                        int port,
                        java.lang.String protocol)
Configures the proxy

Parameters:
host -
port -
protocol -