AnnotationServiceJpaImpl implements AnnotationService { public AnnotationList getAnnotationsByMediapackageId(String mediapackageId, int offset, int limit) { AnnotationListImpl result = new AnnotationListImpl(); EntityManager em = null; try { em = emf.createEntityManager(); result.setTotal(getTotalByMediapackageID(mediapackageId, em)); result.setOffset(offset); result.setLimit(limit); Query q = em.createNamedQuery("findAnnotationsByMediapackageId"); q.setParameter("userId", securityService.getUser().getUsername()); q.setParameter("mediapackageId", mediapackageId); q.setFirstResult(offset); q.setMaxResults(limit); @SuppressWarnings("unchecked") Collection<Annotation> annotations = q.getResultList(); for (Annotation a : annotations) { result.add(a); } return result; } finally { em.close(); } }  void setSecurityService(SecurityService securityService); Annotation addAnnotation(Annotation a); boolean removeAnnotation(Annotation a); Annotation changeAnnotation(Annotation a); Annotation getAnnotation(long id); @SuppressWarnings("unchecked") AnnotationList getAnnotations(int offset, int limit); AnnotationList getAnnotationsByTypeAndMediapackageId(String type, String mediapackageId, int offset, int limit); AnnotationList getAnnotationsByMediapackageId(String mediapackageId, int offset, int limit); @SuppressWarnings("unchecked") AnnotationList getAnnotationsByTypeAndDay(String type, String day, int offset, int limit); @SuppressWarnings("unchecked") AnnotationList getAnnotationsByDay(String day, int offset, int limit); @SuppressWarnings("unchecked") AnnotationList getAnnotationsByType(String type, int offset, int limit); static final String PERSISTENCE_UNIT; }
@Test public void testGetAnnotationsByMediapackageId() throws Exception { AnnotationImpl a1 = new AnnotationImpl(); a1.setType("note"); a1.setInpoint(10); a1.setOutpoint(100); a1.setMediapackageId("mp"); a1.setSessionId("session 1"); a1.setValue("This is some user generated content 1"); annotationService.addAnnotation(a1); AnnotationImpl a2 = new AnnotationImpl(); a2.setType("comment"); a2.setInpoint(15); a2.setOutpoint(105); a2.setMediapackageId("mp"); a2.setSessionId("session 2"); a2.setValue("This is some user generated content 2"); annotationService.addAnnotation(a2); AnnotationImpl a3 = new AnnotationImpl(); a3.setType("bookmark"); a3.setInpoint(16); a3.setOutpoint(106); a3.setMediapackageId("a different mediapackage"); a3.setSessionId("a different session"); a3.setValue("More user generated content"); annotationService.addAnnotation(a3); AnnotationList annotationResult = annotationService.getAnnotationsByMediapackageId("mp", 0, 200); Assert.assertEquals(2, annotationResult.getAnnotations().size()); }