Information
This explains basic usage of the Sakai EntityManager Service. This service is used to find out things about Sakai Sites and look them up by references or contexts.
- Trunk javadocs:
- Trunk source location: https://source.sakaiproject.org/svn/entity/trunk/
Accessing the EntityManager
- You can use Spring Framework to inject the service or use the cover
- Using Spring to get the service for your class (e.g. YourAppClass) (recommended)
- Add the EntityManager bean to the bean for YourAppClass
<bean id="org.sakaiproject.yourapp.logic.YourAppClass" class="org.sakaiproject.yourapp.logic.impl.YourAppClassImpl"> <property name="entityManager" ref="org.sakaiproject.entity.api.EntityManager" /> </bean>
- Add a variable and setter to YourAppClass to use the service in like so:
private EntityManager entityManager; public void setEntityManager(EntityManager entityManager) { this.entityManager = entityManager; }
- Add the EntityManager bean to the bean for YourAppClass
- Using the cover to get the service
- Note: This is not the recommended method, you should be using Spring to inject the service
- Setup a variable to hold the instance from the cover
private EntityManager entityManager; - Get access to the service using the cover
entityManager = org.sakaiproject.entity.cover.EntityManager.getInstance();
Getting the Reference for an Entity
- Get the id of any Entity in Sakai
- Use the EntityManager service to get the Reference
- Check if the type of the reference is known
- Use a service (e.g. SiteService) to compare the type
String entityId = entity.getId(); // (1) Reference r = entityManager.newReference(entityId); // (2) if(r.isKnownType()) { // (3) if(r.getType().equals(SiteService.APPLICATION_ID)) { // (4) // do something since this is a site } }
Comments (2)
Nov 05, 2007
James Marca says:
possible typo in the code block. Should be entityId, not authzGroupId, as in: ...possible typo in the code block. Should be entityId, not authzGroupId, as in:
Nov 06, 2007
Aaron Zeckoski says:
Good point. Example updated.Good point. Example updated.