Package org.sakaiproject.entitybroker
Interface EntityBroker
-
- All Superinterfaces:
LearningTrackingProvider,PropertiesProvider,SearchProvider,TagProvider
public interface EntityBroker extends PropertiesProvider, TagProvider, SearchProvider, LearningTrackingProvider
This service interface defines the capabilities of the entity broker system
It allows Sakai system methods, developers, etc. to access Sakai entity information (new and old)- Author:
- Aaron Zeckoski (azeckoski @ unicon.net) (azeckoski @ vt.edu), Antranig Basman (antranig@caret.cam.ac.uk)
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description List<EntityData>browseEntities(String prefix, Search search, String userReference, String associatedReference, String parentReference, Map<String,Object> params)Returns the list of entity information (and possibly entities) for a user to view while browsing an entity space, this is specially designed to support browsing and picking entities, not all entities support browsing
If the entity type indicated by the prefix does not support browsing then this will return an empty listbooleanentityExists(String reference)Check if an entity exists by the globally unique reference string, (the global reference string will consist of the entity prefix and any local ID).ActionReturnexecuteCustomAction(String reference, String action, Map<String,Object> params, OutputStream outputStream)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 onlyList<?>fetchEntities(String prefix, Search search, Map<String,Object> params)Allows these entities to be fetched based on search parameters, this should never return null and if there are no entities then the list should be empty
Note: The entity class types in the list need to be able to be resolved from the ClassLoader of the EntityBrokerManager (currently this means deployed into shared)
These do not have to be model objects and may simply be something created (e.g.ObjectfetchEntity(String reference)Fetches a concrete object representing this entity reference; either one from theResolvablecapability if implemented by the responsibleEntityProvider, or else from the underlying legacy Sakai entity system
Note that this may be aStringorMapand does not have to be a POJO, the type of object should be determined out of band
This will return null if the entity exists but is notResolvableor available in the legacy entity systemList<EntityData>findEntitesByTags(String[] tags, String[] prefixes, boolean matchAll, Search search, Map<String,Object> params)Search for all entities which have the given tags, can limit the return using the search objectEntityResponsefireEntityRequest(String reference, String viewKey, String format, Map<String,String> params, Object entity)voidfireEvent(String eventName, String reference)Fire an event to Sakai with the specified name, targeted at the supplied reference, which should be a reference to an existing entity managed by this broker
NOTE: This will allow events to be fired for references without a broker or invalid referencesvoidformatAndOutputEntity(String reference, String format, List<?> entities, OutputStream output, 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 themList<BrowseEntity>getBrowseableEntities(String parentPrefix)For authors of entity browsing systems, this provides a list of all the meta data related to the entities in the system which areBrowseable, this provides the root entities when there is no parent prefix providedList<EntityData>getEntities(String prefix, Search search, Map<String,Object> params)Gets entity data (and possibly entities) for a specific entity prefix, entity data contains the reference, URL, display title and optionally the concrete entity and properties
If the entity type indicated by the prefix does not support collections then this will return an empty listEntityDatagetEntity(String reference)Gets the data related to an entity as long as it exists, always includes at least the entity reference information and the URL, may also include a concrete entity object and entity propertiesStringgetEntityURL(String reference)Get the full absolute URL to the entity defined by this entity reference, this will fail-safe to a direct URL to an entity space URL if that is all that is availableStringgetEntityURL(String reference, String viewKey, String extension)Get the full absolute URL to the entity view defined by these params, this will fail-safe to a direct URL to an entity space URL if that is all that is available, this will use the default entity URL template associated with the viewKey and include an optional extension if specified (these will be inferred if they are missing)EntityViewgetEntityView(String reference, String viewKey, String extension)Get theEntityViewobject which represents a specific view of an entity or entity collection, this is similar togetEntityURL(String, String, String)but allows the developer to deal with theEntityViewobject if desiredSet<String>getRegisteredPrefixes()Retrieve a complete set of all currently registeredEntityProviderprefixesSet<String>getTags(String reference)Deprecated.booleanisPrefixRegistered(String prefix)Check if a prefix is currently registeredEntityReferenceparseReference(String reference)Parses an entity reference into a concrete object, of typeEntityReference, or some class derived from it, for exampleIdEntityReferenceor some other class of object which is returned fromParseSpecParseable.voidsetTags(String reference, String[] tags)Deprecated.ObjecttranslateInputToEntity(String reference, String format, InputStream input, Map<String,Object> params)Translates the input data stream in the supplied format into an entity object for this reference-
Methods inherited from interface org.sakaiproject.entitybroker.entityprovider.extension.LearningTrackingProvider
registerStatement
-
Methods inherited from interface org.sakaiproject.entitybroker.entityprovider.extension.PropertiesProvider
findEntityRefs, getProperties, getPropertyValue, setPropertyValue
-
Methods inherited from interface org.sakaiproject.entitybroker.entityprovider.extension.SearchProvider
add, remove, resetSearchIndexes, search
-
Methods inherited from interface org.sakaiproject.entitybroker.entityprovider.extension.TagProvider
addTagsToEntity, getTagsForEntity, removeTagsFromEntity, setTagsForEntity
-
-
-
-
Method Detail
-
entityExists
boolean entityExists(String reference)
Check if an entity exists by the globally unique reference string, (the global reference string will consist of the entity prefix and any local ID). If noEntityProviderfor the reference is found which implementsCoreEntityProvider, this method will returntrueby default, in other words, this cannot determine if a legacy entity exists, only a new entity- Parameters:
reference- a globally unique reference to an entity (e.g. /myprefix/myid), consists of the entity prefix and optional segments (normally the id at least)- Returns:
- true if the entity exists, false otherwise
- Throws:
IllegalArgumentException- if the reference is invalid
-
isPrefixRegistered
boolean isPrefixRegistered(String prefix)
Check if a prefix is currently registered- Parameters:
prefix- the string which represents a type of entity handled by an entity provider- Returns:
- true if the prefix is registered OR false if not
-
getRegisteredPrefixes
Set<String> getRegisteredPrefixes()
Retrieve a complete set of all currently registeredEntityProviderprefixes- Returns:
- all currently registered entity prefixes
-
getEntityURL
String getEntityURL(String reference)
Get the full absolute URL to the entity defined by this entity reference, this will fail-safe to a direct URL to an entity space URL if that is all that is available- Parameters:
reference- a globally unique reference to an entity, consists of the entity prefix and optional segments- Returns:
- a full URL string (e.g. http://server/direct/prefix/id)
- Throws:
IllegalArgumentException- if the reference or other inputs are invalid
-
getEntityURL
String getEntityURL(String reference, String viewKey, String extension)
Get the full absolute URL to the entity view defined by these params, this will fail-safe to a direct URL to an entity space URL if that is all that is available, this will use the default entity URL template associated with the viewKey and include an optional extension if specified (these will be inferred if they are missing)- Parameters:
reference- a globally unique reference to an entity, consists of the entity prefix and optionally the local idviewKey- the specific view type to get the URL for, use the VIEW_* constants fromEntityView(e.g.EntityView.VIEW_LIST), can be null to determine the key automaticallyextension- the optional extension to add to the end which defines the expected data which is returned, use constants inFormats(e.g.Formats.XML), can be null to use no extension, default is assumed to be html if none is set- Returns:
- the full URL string to a specific entity or space, (e.g. http://server/direct/prefix/id)
- Throws:
IllegalArgumentException- if the reference or other inputs are invalid
-
getEntityView
EntityView getEntityView(String reference, String viewKey, String extension)
Get theEntityViewobject which represents a specific view of an entity or entity collection, this is similar togetEntityURL(String, String, String)but allows the developer to deal with theEntityViewobject if desired- Parameters:
reference- a globally unique reference to an entity, consists of the entity prefix and optionally the local idviewKey- the specific view type to get the URL for, use the VIEW_* constants fromEntityView(e.g.EntityView.VIEW_LIST), can be null to determine the key automaticallyextension- the optional extension to add to the end which defines the expected data which is returned, use constants inFormats(e.g.Formats.XML), can be null to use no extension, default is assumed to be html if none is set- Returns:
- an EntityView object if one can be formed
- Throws:
IllegalArgumentException- if the params cannot be made into an EntityView
-
fireEvent
void fireEvent(String eventName, String reference)
Fire an event to Sakai with the specified name, targeted at the supplied reference, which should be a reference to an existing entity managed by this broker
NOTE: This will allow events to be fired for references without a broker or invalid references- Parameters:
eventName- a string which represents the name of the event (e.g. announcement.create), cannot be null or emptyreference- a globally unique reference to an entity, consists of the entity prefix and optionally the local id, cannot be null or empty
-
fireEntityRequest
EntityResponse fireEntityRequest(String reference, String viewKey, String format, Map<String,String> params, Object entity)
- 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
-
parseReference
EntityReference parseReference(String reference)
Parses an entity reference into a concrete object, of typeEntityReference, or some class derived from it, for exampleIdEntityReferenceor some other class of object which is returned fromParseSpecParseable.- Parameters:
reference- a globally unique reference to an entity, consists of the entity prefix and optional segments- Returns:
- an entity reference object which will contain the entity prefix and any optional
segments, or
nullif the reference was not recognized as a valid entity handled by the broker (will be anIdEntityReferenceif there is an id set) - Throws:
IllegalArgumentException- if the reference is invalid and cannot be parsed
-
fetchEntity
Object fetchEntity(String reference)
Fetches a concrete object representing this entity reference; either one from theResolvablecapability if implemented by the responsibleEntityProvider, or else from the underlying legacy Sakai entity system
Note that this may be aStringorMapand does not have to be a POJO, the type of object should be determined out of band
This will return null if the entity exists but is notResolvableor available in the legacy entity system- Parameters:
reference- a globally unique reference to an entity, consists of the entity prefix and local id- Returns:
- an object which represents the entity OR null if none can be found or this type does not support fetching
- Throws:
SecurityException- if the entity cannot be accessed by the current user or is not publicly accessibleIllegalArgumentException- if the reference is invalidIllegalStateException- if any other error occurs
-
fetchEntities
List<?> fetchEntities(String prefix, Search search, Map<String,Object> params)
Allows these entities to be fetched based on search parameters, this should never return null and if there are no entities then the list should be empty
Note: The entity class types in the list need to be able to be resolved from the ClassLoader of the EntityBrokerManager (currently this means deployed into shared)
These do not have to be model objects and may simply be something created (e.g. String, Map, etc.) to give to anyone calling this method- Parameters:
prefix- the string which represents a type of entity handled by an entity provider, if the prefix does not support fetching collections then no entities will be returnedsearch- a search object which can define the order to return entities, search filters, and total number of entities returned,
NOTE: There are some predefined search keys which you may optionally use, provider are encourage to support the SEARCH_* search keys listed in this interface- Returns:
- a list of entity objects (POJOs,
Map, etc.) of the type handled by this provider OR empty if none found, will not return null - Throws:
SecurityException- if the data cannot be accessed by the current user or is not publicly accessibleIllegalArgumentException- if the reference is invalid or the search is invalidIllegalStateException- if any other error occurs
-
getEntity
EntityData getEntity(String reference)
Gets the data related to an entity as long as it exists, always includes at least the entity reference information and the URL, may also include a concrete entity object and entity properties- Parameters:
reference- a globally unique reference to an entity, consists of the entity prefix and local id- Returns:
- an entity data object which contains data about the entity OR null if the entity does not exist
- Throws:
SecurityException- if the entity cannot be accessed by the current user or is not publicly accessibleIllegalArgumentException- if the reference is invalidIllegalStateException- if any other error occurs
-
getEntities
List<EntityData> getEntities(String prefix, Search search, Map<String,Object> params)
Gets entity data (and possibly entities) for a specific entity prefix, entity data contains the reference, URL, display title and optionally the concrete entity and properties
If the entity type indicated by the prefix does not support collections then this will return an empty list- Parameters:
prefix- the string which represents a type of entity handled by an entity provider, the entity prefix to search for the collection of entities in, if the prefix does not support browsing then no entities will be returnedsearch- a search object which can define the order to return entities, search filters, and total number of entities returned, may be left emptyparams- (optional) incoming set of parameters which may be used to send data specific to this request, may be null- Returns:
- a list of entity data objects OR an empty list if none found
- Throws:
SecurityException- if the data cannot be accessed by the current user or is not publicly accessibleIllegalArgumentException- if the prefix is invalid or the search is invalidIllegalStateException- if any other error occurs
-
formatAndOutputEntity
void formatAndOutputEntity(String reference, String format, List<?> entities, OutputStream output, 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- Parameters:
reference- 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 orEntityDataobjects to create formatted output for, if this is null then the entities will be retrieved based on the reference, if this contains only a single item AND the ref refers to a single entity then the entity will be extracted from the list and encoded without the indication that it is a collection, for all other cases the encoding will include an indication that this is a list of entitiesoutput- the output stream to place the formatted data in, should be UTF-8 encoded if there is char dataparams- (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 needed- Throws:
FormatUnsupportedException- if entity cannot handle this format typeIllegalArgumentException- if any of the arguments are invalidEntityEncodingException- is there is failure encoding the outputIllegalStateException- for all other failures
-
translateInputToEntity
Object translateInputToEntity(String reference, String format, InputStream input, Map<String,Object> params)
Translates the input data stream in the supplied format into an entity object for this reference- Parameters:
reference- 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 itparams- (optional) set of parameters which may be used to control this request, may be left null if not needed- Returns:
- an entity object of the type used for the given reference
- Throws:
FormatUnsupportedException- if entity cannot handle this format typeIllegalArgumentException- if any of the arguments are invalidEntityEncodingException- is there is failure translating the inputIllegalStateException- for all other failures
-
executeCustomAction
ActionReturn executeCustomAction(String reference, String action, Map<String,Object> params, OutputStream outputStream)
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:
reference- 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/promoteparams- (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 streams- 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
-
findEntitesByTags
List<EntityData> findEntitesByTags(String[] tags, String[] prefixes, boolean matchAll, Search search, Map<String,Object> params)
Search for all entities which have the given tags, can limit the return using the search object- Parameters:
tags- a set of tags associated with entitiesprefixes- (optional) a set of unique entity prefixes, limits the search to only include entities in these prefixes, if this is null then all entities and prefixes are searched
NOTE: It is much more efficient to specify prefixesmatchAll- if true then all tags must exist on the entity for it to be matched, if false then the entity just has to have one or more of the given tagssearch- (optional) a search object, used to order or limit the number of returned results, restrictions will be typically ignoredparams- (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 needed- Returns:
- a list of entity search results (contains the ref, url, displayname of the matching entities)
- Throws:
IllegalArgumentException- if the tags set is empty or null
-
browseEntities
List<EntityData> browseEntities(String prefix, Search search, String userReference, String associatedReference, String parentReference, Map<String,Object> params)
Returns the list of entity information (and possibly entities) for a user to view while browsing an entity space, this is specially designed to support browsing and picking entities, not all entities support browsing
If the entity type indicated by the prefix does not support browsing then this will return an empty list- Parameters:
prefix- the string which represents a type of entity handled by an entity provider, the entity prefix to search for browseable entities in, if the prefix does not support browsing then no entities will be returnedsearch- a search object which can define the order to return entities, search filters, and total number of entities returned, may be left emptyuserReference- (optional) the unique entity reference for a user which is browsing the results, this may be null to indicate that only items which are visible to all users should be shownassociatedReference- (optional) a globally unique reference to an entity, this is the entity that the returned browseable data must be associated with (e.g. limited by reference to a location or associated entity), this may be null to indicate there is no association limitparentReference- (optional) if not null then only the entities which have the referenced entity as a parent will be searched, if null then the parent/child relationship would be ignored when searching browseable entitiesparams- (optional) incoming set of parameters which may be used to send data specific to this request, may be null- Returns:
- a list of entity data objects which contain the reference, URL, display title and optionally other entity data
- Throws:
SecurityException- if the data cannot be accessed by the current user or is not publicly accessibleIllegalArgumentException- if the prefix is invalid or the search is invalidIllegalStateException- if any other error occurs
-
getBrowseableEntities
List<BrowseEntity> getBrowseableEntities(String parentPrefix)
For authors of entity browsing systems, this provides a list of all the meta data related to the entities in the system which areBrowseable, this provides the root entities when there is no parent prefix provided- Parameters:
parentPrefix- (optional) the parent prefix to get the browseable entities for, if this is null then all the root browseable entities are returned- Returns:
- the list of meta data for all entity prefixes that are
Browseable
-
-