@Test public void testGetAnnotationsByTypeAndMediapackageId() throws Exception { String type = "a type of annotation, such as 'bookmark' or 'note'"; AnnotationImpl a1 = new AnnotationImpl(); a1.setType(type); a1.setInpoint(10); a1.setOutpoint(100); a1.setMediapackageId("mp"); a1.setSessionId("session"); a1.setValue("This is some user generated content"); annotationService.addAnnotation(a1); AnnotationImpl a2 = new AnnotationImpl(); a2.setType(type); a2.setInpoint(10); a2.setOutpoint(100); a2.setMediapackageId("a different mediapackage"); a2.setSessionId("a different session"); a2.setValue("More user generated content"); annotationService.addAnnotation(a2); AnnotationList annotations = annotationService.getAnnotationsByTypeAndMediapackageId(type, "mp", 0, 100); Assert.assertEquals(1, annotations.getAnnotations().size()); }
public AnnotationList getAnnotationsByTypeAndMediapackageId(String type, String mediapackageId, int offset, int limit) { AnnotationListImpl result = new AnnotationListImpl(); EntityManager em = null; try { em = emf.createEntityManager(); result.setTotal(getTotal(type, mediapackageId, em)); result.setOffset(offset); result.setLimit(limit); Query q = em.createNamedQuery("findAnnotationsByTypeAndMediapackageId"); q.setParameter("userId", securityService.getUser().getUsername()); q.setParameter("type", type); 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 { if (em != null) em.close(); } }
AnnotationServiceJpaImpl implements AnnotationService { public AnnotationList getAnnotationsByTypeAndMediapackageId(String type, String mediapackageId, int offset, int limit) { AnnotationListImpl result = new AnnotationListImpl(); EntityManager em = null; try { em = emf.createEntityManager(); result.setTotal(getTotal(type, mediapackageId, em)); result.setOffset(offset); result.setLimit(limit); Query q = em.createNamedQuery("findAnnotationsByTypeAndMediapackageId"); q.setParameter("userId", securityService.getUser().getUsername()); q.setParameter("type", type); 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 { if (em != null) em.close(); } } }
AnnotationServiceJpaImpl implements AnnotationService { public AnnotationList getAnnotationsByTypeAndMediapackageId(String type, String mediapackageId, int offset, int limit) { AnnotationListImpl result = new AnnotationListImpl(); EntityManager em = null; try { em = emf.createEntityManager(); result.setTotal(getTotal(type, mediapackageId, em)); result.setOffset(offset); result.setLimit(limit); Query q = em.createNamedQuery("findAnnotationsByTypeAndMediapackageId"); q.setParameter("userId", securityService.getUser().getUsername()); q.setParameter("type", type); 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 { if (em != null) em.close(); } }  }
AnnotationServiceJpaImpl implements AnnotationService { public AnnotationList getAnnotationsByTypeAndMediapackageId(String type, String mediapackageId, int offset, int limit) { AnnotationListImpl result = new AnnotationListImpl(); EntityManager em = null; try { em = emf.createEntityManager(); result.setTotal(getTotal(type, mediapackageId, em)); result.setOffset(offset); result.setLimit(limit); Query q = em.createNamedQuery("findAnnotationsByTypeAndMediapackageId"); q.setParameter("userId", securityService.getUser().getUsername()); q.setParameter("type", type); 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 { if (em != null) 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); }
AnnotationServiceJpaImpl implements AnnotationService { public AnnotationList getAnnotationsByTypeAndMediapackageId(String type, String mediapackageId, int offset, int limit) { AnnotationListImpl result = new AnnotationListImpl(); EntityManager em = null; try { em = emf.createEntityManager(); result.setTotal(getTotal(type, mediapackageId, em)); result.setOffset(offset); result.setLimit(limit); Query q = em.createNamedQuery("findAnnotationsByTypeAndMediapackageId"); q.setParameter("userId", securityService.getUser().getUsername()); q.setParameter("type", type); 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 { if (em != null) 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; }