Child pages
  • Defining EntityProviders
Skip to end of metadata
Go to start of metadata

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

  1. Implement the EntityProvider interface
  2. Implement any additional capabilities interfaces (optional)
  3. 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

Usage instructions and recommended best practices

example: Thing entity

  1. Create an interface called ThingEntityProvider which extends EntityProvider in api logic (add an entity package for it)
    Example: org.sakaiproject.evaluation.logic.entity.EvaluationEntityProvider.java
  2. Add a public static string which contains the entity prefix (called ENTITY_PREFIX),
    Example:
    public final static String ENTITY_PREFIX = "eval-evaluation";
  3. Implement your ThingEntityProvider in impl logic as ThingEntityProviderImpl (add an entity package for it),
    Example: org.sakaiproject.evaluation.logic.impl.entity.EvaluationEntityProviderImpl.java
  4. Implement CoreEntityProvider in ThingEntityProviderImpl
  5. Implement AutoRegisterEntityProvider in ThingEntityProviderImpl
  6. 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>
    
  7. 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
  1. Create a new class for your entity provider like so:
    • Add in as many capabilities as you like (the RESTful capability is there as an example, AbstractEntityProvider implements EntityProvider already
  2. 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
  • No labels