Interface EntityRESTProvider
-
public interface EntityRESTProviderHandles anything REST based that is not part of the core EB registration piece- Author:
- Aaron Zeckoski (azeckoski @ gmail.com)
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Map<String,Object>decodeData(String data, String format)Decode a string of a specified format into a java map of simple objects
Returned map can be fed into#populate(Object, Map)if you want to convert it into a known object type
Types are likely to require conversion as guesses are made about the right formats, use of the#convert(Object, Class)method is recommendedStringencodeData(Object data, String format, String name, Map<String,Object> properties)Encode data into a given format, can handle any java object, note that unsupported formats and invalid data will result in an exceptionvoidformatAndOutputEntity(EntityReference ref, String format, List<EntityData> entities, OutputStream outputStream, Map<String,Object> params)Format and output an entity or collection included or referred to by this entity ref object into output according to the format string provided, Should take into account the reference when determining what the entities are and how to encode them (This is basically a copy of the code in EntityHandlerImpl with stuff removed)ActionReturnhandleCustomActionExecution(ActionsExecutable actionProvider, EntityReference ref, String action, Map<String,Object> actionParams, OutputStream outputStream, EntityView view, Map<String,Object> searchParams)This will execute a custom action for an entity or space/collection of entities
This is meant for specialized usage as custom actions are typically meant to be executed by REST calls onlyEntityResponsehandleEntityRequest(String reference, String viewKey, String format, Map<String,String> params, Object entity)Processes and handles an entity request without requiring servlet processing and a request/response round tripObjecttranslateInputToEntity(EntityReference ref, String format, InputStream inputStream, Map<String,Object> params)Translates the input data stream in the supplied format into an entity object for this reference
-
-
-
Method Detail
-
handleEntityRequest
EntityResponse handleEntityRequest(String reference, String viewKey, String format, Map<String,String> params, Object entity)
Processes and handles an entity request without requiring servlet processing and a request/response round trip- Parameters:
reference- a globally unique reference to an entity, consists of the entity prefix and optionally the local id, cannot be null or emptyviewKey- specifies what kind of request this is (create, read/show, etc.), must correspond to the VIEW constants inEntityView, example:EntityView.VIEW_SHOWformat- (optional) this is the format for this request (fromFormats, e.g. XML), if nothing is specified then the default will be used:Formats.HTMLparams- (optional) any params you want to send along with the request should be included here, they will be placed into the query string or the request body depending on the type of request this isentity- (optional) leave this null in most cases, if you supply an entity object here it will be encoded based on the supplied format (only if the entity supports output formatting) and then decoded on the other end (only if the entity supports input translation), in most cases it is better to supply the entity values in the params- Returns:
- the response information encoded in an object, you must check this to see what the results of the request were (getting a response back does not mean the request succeeded)
- Throws:
IllegalArgumentException- if the inputs are invalidRuntimeException- if the http request has an unrecoverable failure or an encoding failure occurs
-
formatAndOutputEntity
void formatAndOutputEntity(EntityReference ref, String format, List<EntityData> entities, OutputStream outputStream, Map<String,Object> params)
Format and output an entity or collection included or referred to by this entity ref object into output according to the format string provided, Should take into account the reference when determining what the entities are and how to encode them (This is basically a copy of the code in EntityHandlerImpl with stuff removed)- Parameters:
ref- a globally unique reference to an entity, consists of the entity prefix and optional segmentsformat- a string constant indicating the format (fromFormats) for output, (example:#XML)entities- (optional) a list of entities to create formatted output for, if this is null then the entities should be retrieved based on the reference, if this contains only a single item AND the ref refers to a single entity then the entity should be extracted from the list and encoded without the indication that it is a collection, for all other cases the encoding should include an indication that this is a list of entitiesoutputStream- the output stream to place the formatted data in, should be UTF-8 encoded if there is char data- Throws:
FormatUnsupportedException- if you do not handle this format type (passes control to the internal handlers)EntityEncodingException- if you cannot encode the received data into an entityIllegalArgumentException- if any of the arguments are invalidIllegalStateException- for all other failures
-
translateInputToEntity
Object translateInputToEntity(EntityReference ref, String format, InputStream inputStream, Map<String,Object> params)
Translates the input data stream in the supplied format into an entity object for this reference- Parameters:
ref- a globally unique reference to an entity, consists of the entity prefix and optional segmentsformat- a string constant indicating the format (fromFormats) of the input, (example:#XML)input- a stream which contains the data to make up this entity, you may assume this is UTF-8 encoded if you don't know anything else about it- Returns:
- an entity object of the type used for the given reference
- Throws:
FormatUnsupportedException- if you do not handle this format type (passes control to the internal handlers)EntityEncodingException- if you cannot encode the received data into an entityIllegalArgumentException- if any of the arguments are invalidIllegalStateException- for all other failures
-
handleCustomActionExecution
ActionReturn handleCustomActionExecution(ActionsExecutable actionProvider, EntityReference ref, String action, Map<String,Object> actionParams, OutputStream outputStream, EntityView view, Map<String,Object> searchParams)
This will execute a custom action for an entity or space/collection of entities
This is meant for specialized usage as custom actions are typically meant to be executed by REST calls only- Parameters:
actionProvider- the action provider which has declared itself as the handler for this action and prefixref- a globally unique reference to an entity, consists of the entity prefix and optional segmentsaction- key which will be used to trigger the action (e.g. promote, double, photo), can be triggered by a URL like so: /user/aaronz/promoteactionParams- (optional) an optional set of params to pass along with this custom action request, typically used to provide information about the request, may be left null if not neededoutputStream- (optional) an OutputStream to place binary or long text data into, if this is used for binary data then theActionReturnshould be returned with the correct encoding information and the output variable set to the OutputStream, may be left null if this custom action does not deal with binary streamsview- the entity view corresponding to all data sent in the URL for this action viewsearchParams- any search params which were included in the request- Returns:
- an
ActionReturnwhich contains entity data or binary/string data OR null if there is no return for this action - Throws:
UnsupportedOperationException- if there is no action with this key for this entityIllegalArgumentException- if there are required params that are missing or invalidIllegalStateException- if the action cannot be performed for some reason
-
encodeData
String encodeData(Object data, String format, String name, Map<String,Object> properties)
Encode data into a given format, can handle any java object, note that unsupported formats and invalid data will result in an exception- Parameters:
data- the data to encodeformat- the format to use for output (fromFormats)name- (optional) the name to use for the encoded data (e.g. root node for XML)properties- (optional) extra properties to add into the encoding, ignored if encoded object is not a map or bean- Returns:
- the encoded string in the requested format
- Throws:
UnsupportedOperationException- if the data cannot be encodedIllegalArgumentException- if the format requested cannot be encoded because there is no encoder
-
decodeData
Map<String,Object> decodeData(String data, String format)
Decode a string of a specified format into a java map of simple objects
Returned map can be fed into#populate(Object, Map)if you want to convert it into a known object type
Types are likely to require conversion as guesses are made about the right formats, use of the#convert(Object, Class)method is recommended- Parameters:
data- encoded dataformat- the format of the encoded data (fromFormats)- Returns:
- a map containing all the data derived from the encoded data
- Throws:
UnsupportedOperationException- if the data cannot be decodedIllegalArgumentException- if the data cannot be decoded because there is no decoder for that format
-
-