Defining EntityProviders
Information
This explains how to define your own entity provider for your entities. Remember that entities can be anything and do not have be persistent objects, rows in a table, etc.
Overview of defining an EntityProvider
Implement the EntityProvider interface
Implement any additional capabilities interfaces (optional)
Create a spring bean definition in the Sakai application context (components.xml) OR your tool application context OR register the entity provider manually using the EntityProviderManager
Autoregistration: Implement AutoRegisterEntityProvider interface in your EntityProvider
Usage instructions and recommended best practices
example: Thing entity
Create an interface called ThingEntityProvider which extends EntityProvider in api logic (add an entity package for it)
Example: org.sakaiproject.evaluation.logic.entity.EvaluationEntityProvider.javaAdd a public static string which contains the entity prefix (called ENTITY_PREFIX),
Example:public final static String ENTITY_PREFIX = "eval-evaluation";Implement your ThingEntityProvider in impl logic as ThingEntityProviderImpl (add an entity package for it),
Example: org.sakaiproject.evaluation.logic.impl.entity.EvaluationEntityProviderImpl.javaImplement CoreEntityProvider in ThingEntityProviderImpl
Implement AutoRegisterEntityProvider in ThingEntityProviderImpl
Add a spring bean definition in the Sakai application context (components.xml), use the api name as the id
Example:<bean id="org.sakaiproject.evaluation.logic.entity.EvaluationEntityProvider" class="org.sakaiproject.evaluation.logic.impl.entity.EvaluationEntityProviderImpl"> </bean>Add the needed maven dependendencies to the tool maven files
Maven 1 users will need soemthing like this in the project.xml:
<dependency> <groupId>sakaiproject</groupId> <artifactId>sakai-entitybroker-api</artifactId> <version>${sakai.version}</version> </dependency>Maven 2 users will need something like this in the pom.xml:
<dependency> <groupId>org.sakaiproject.entitybroker</groupId> <artifactId>entitybroker-api</artifactId> <version>1.3.3</version> <scope>provided</scope> </dependency>That should do it. You should now be able to use the Entity Broker to access information about your entities and register events for your entities (among other things).
Implementing EntityProviders in webapps/tools
EntityProviders can be defined in webapps and tools exactly the same way they are defined in a Sakai component, the only trick is that AutoRegisterEntityProvider no longer works so you have to handle the registration yourself OR you can use AbstractEntityProvider
Create a new class for your entity provider like so:
public class WebappEntityProvider extends AbstractEntityProvider implements RESTful { ... }Add in as many capabilities as you like (the RESTful capability is there as an example, AbstractEntityProvider implements EntityProvider already
Create a spring bean definition in your webapp application context using the special parent bean like so:
<!-- entity provider --> <bean parent="org.sakaiproject.entitybroker.entityprovider.AbstractEntityProvider" class="org.sakaiproject.entitybroker.entitywebapp.WebappEntityProvider"> <property name="dao" ref="MemoryDao" /> </bean>There is not much point in defining an interface for your EntityProvider when you are using it in a webapp
Inject any needed dependencies, the DeveloperHelperService is already injected and the provider will be registered and unregistered on webapp startup and shutdown
NOTE: You can always handle this manually if you like but it tends to be a lot easier to just use the AbstractEntityProvider