Search in sources :

Example 1 with UserActionList

use of org.opencastproject.usertracking.api.UserActionList in project opencast by opencast.

the class UserTrackingServiceImpl method getUserActionsByType.

@SuppressWarnings("unchecked")
public UserActionList getUserActionsByType(String type, int offset, int limit) {
    UserActionList result = new UserActionListImpl();
    result.setTotal(getTotal(type));
    result.setOffset(offset);
    result.setLimit(limit);
    EntityManager em = null;
    try {
        em = emf.createEntityManager();
        Query q = em.createNamedQuery("findUserActionsByType");
        q.setParameter("type", type);
        q.setFirstResult(offset);
        if (limit > 0)
            q.setMaxResults(limit);
        Collection<UserAction> userActions = q.getResultList();
        for (UserAction a : userActions) {
            result.add(a);
        }
        return result;
    } finally {
        if (em != null && em.isOpen()) {
            em.close();
        }
    }
}
Also used : UserAction(org.opencastproject.usertracking.api.UserAction) UserActionList(org.opencastproject.usertracking.api.UserActionList) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query)

Example 2 with UserActionList

use of org.opencastproject.usertracking.api.UserActionList in project opencast by opencast.

the class UserTrackingServiceImpl method getUserActionsByTypeAndMediapackageIdByDescendingDate.

public UserActionList getUserActionsByTypeAndMediapackageIdByDescendingDate(String type, String mediapackageId, int offset, int limit) {
    UserActionList result = new UserActionListImpl();
    result.setTotal(getTotal(type, mediapackageId));
    result.setOffset(offset);
    result.setLimit(limit);
    EntityManager em = null;
    try {
        em = emf.createEntityManager();
        Query q = em.createNamedQuery("findUserActionsByMediaPackageAndTypeDescendingByDate");
        q.setParameter("type", type);
        q.setParameter("mediapackageId", mediapackageId);
        q.setFirstResult(offset);
        if (limit > 0)
            q.setMaxResults(limit);
        @SuppressWarnings("unchecked") Collection<UserAction> userActions = q.getResultList();
        for (UserAction a : userActions) {
            result.add(a);
        }
        return result;
    } finally {
        if (em != null && em.isOpen()) {
            em.close();
        }
    }
}
Also used : UserAction(org.opencastproject.usertracking.api.UserAction) UserActionList(org.opencastproject.usertracking.api.UserActionList) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query)

Example 3 with UserActionList

use of org.opencastproject.usertracking.api.UserActionList in project opencast by opencast.

the class UserActionListImplTest method testBasicAddition.

/**
 * Tests that adding events to a UserActionList works using the basic .add method
 */
@Test
public void testBasicAddition() {
    UserSession us1 = new UserSessionImpl();
    us1.setSessionId("4");
    us1.setUserId("testing user");
    us1.setUserIp("127.0.0.1");
    UserSession us2 = new UserSessionImpl();
    us2.setSessionId("6");
    us2.setUserId("testing user 2");
    us2.setUserIp("127.0.0.5");
    UserAction ua1 = new UserActionImpl();
    ua1.setId(4L);
    ua1.setInpoint(90);
    ua1.setIsPlaying(true);
    ua1.setMediapackageId("false");
    ua1.setOutpoint(100);
    ua1.setSession(us1);
    ua1.setType("test");
    UserAction ua2 = new UserActionImpl();
    ua2.setId(6L);
    ua2.setInpoint(5);
    ua2.setIsPlaying(false);
    ua2.setMediapackageId("other");
    ua2.setOutpoint(20);
    ua2.setSession(us2);
    ua2.setType("other test");
    UserActionList ual1 = new UserActionListImpl();
    ual1.add(ua1);
    ual1.setTotal(1);
    Assert.assertEquals(1, ual1.getTotal());
    Assert.assertEquals(1, ual1.getUserActions().size());
    Assert.assertEquals(new Long(4), ual1.getUserActions().get(0).getId());
    Assert.assertEquals(90, ual1.getUserActions().get(0).getInpoint());
    Assert.assertEquals(true, ual1.getUserActions().get(0).getIsPlaying());
    Assert.assertEquals("false", ual1.getUserActions().get(0).getMediapackageId());
    Assert.assertEquals(100, ual1.getUserActions().get(0).getOutpoint());
    Assert.assertEquals("4", ual1.getUserActions().get(0).getSession().getSessionId());
    Assert.assertEquals("test", ual1.getUserActions().get(0).getType());
    Assert.assertEquals("testing user", ual1.getUserActions().get(0).getSession().getUserId());
    Assert.assertEquals("127.0.0.1", ual1.getUserActions().get(0).getSession().getUserIp());
    Assert.assertEquals(10, ual1.getUserActions().get(0).getLength());
    UserActionList ual2 = new UserActionListImpl();
    ual2.add(ua2);
    ual2.setTotal(1);
    Assert.assertEquals(1, ual2.getTotal());
    Assert.assertEquals(1, ual2.getUserActions().size());
    Assert.assertEquals(new Long(6), ual2.getUserActions().get(0).getId());
    Assert.assertEquals(5, ual2.getUserActions().get(0).getInpoint());
    Assert.assertEquals(false, ual2.getUserActions().get(0).getIsPlaying());
    Assert.assertEquals("other", ual2.getUserActions().get(0).getMediapackageId());
    Assert.assertEquals(20, ual2.getUserActions().get(0).getOutpoint());
    Assert.assertEquals("6", ual2.getUserActions().get(0).getSession().getSessionId());
    Assert.assertEquals("other test", ual2.getUserActions().get(0).getType());
    Assert.assertEquals("testing user 2", ual2.getUserActions().get(0).getSession().getUserId());
    Assert.assertEquals("127.0.0.5", ual2.getUserActions().get(0).getSession().getUserIp());
    Assert.assertEquals(15, ual2.getUserActions().get(0).getLength());
}
Also used : UserAction(org.opencastproject.usertracking.api.UserAction) UserActionList(org.opencastproject.usertracking.api.UserActionList) UserSession(org.opencastproject.usertracking.api.UserSession) Test(org.junit.Test)

Example 4 with UserActionList

use of org.opencastproject.usertracking.api.UserActionList in project opencast by opencast.

the class UserActionListImplTest method testListAddition.

/**
 * Tests that adding events to a UserActionList works using the list add method
 */
@Test
public void testListAddition() {
    UserSession us1 = new UserSessionImpl();
    us1.setSessionId("4");
    us1.setUserId("testing user");
    us1.setUserIp("127.0.0.1");
    UserSession us2 = new UserSessionImpl();
    us2.setSessionId("6");
    us2.setUserId("testing user 2");
    us2.setUserIp("127.0.0.5");
    UserAction ua1 = new UserActionImpl();
    ua1.setId(4L);
    ua1.setInpoint(90);
    ua1.setIsPlaying(true);
    ua1.setMediapackageId("false");
    ua1.setOutpoint(100);
    ua1.setSession(us1);
    ua1.setType("test");
    UserAction ua2 = new UserActionImpl();
    ua2.setId(6L);
    ua2.setInpoint(5);
    ua2.setIsPlaying(false);
    ua2.setMediapackageId("other");
    ua2.setOutpoint(20);
    ua2.setSession(us2);
    ua2.setType("other test");
    List<UserAction> list = new LinkedList<UserAction>();
    list.add(ua1);
    list.add(ua2);
    UserActionList ual = new UserActionListImpl();
    ual.add(list);
    ual.setTotal(2);
    Assert.assertEquals(2, ual.getTotal());
    Assert.assertEquals(2, ual.getUserActions().size());
    Assert.assertEquals(new Long(4), ual.getUserActions().get(0).getId());
    Assert.assertEquals(90, ual.getUserActions().get(0).getInpoint());
    Assert.assertEquals(true, ual.getUserActions().get(0).getIsPlaying());
    Assert.assertEquals("false", ual.getUserActions().get(0).getMediapackageId());
    Assert.assertEquals(100, ual.getUserActions().get(0).getOutpoint());
    Assert.assertEquals("4", ual.getUserActions().get(0).getSession().getSessionId());
    Assert.assertEquals("test", ual.getUserActions().get(0).getType());
    Assert.assertEquals("testing user", ual.getUserActions().get(0).getSession().getUserId());
    Assert.assertEquals("127.0.0.1", ual.getUserActions().get(0).getSession().getUserIp());
    Assert.assertEquals(new Long(6), ual.getUserActions().get(1).getId());
    Assert.assertEquals(5, ual.getUserActions().get(1).getInpoint());
    Assert.assertEquals(false, ual.getUserActions().get(1).getIsPlaying());
    Assert.assertEquals("other", ual.getUserActions().get(1).getMediapackageId());
    Assert.assertEquals(20, ual.getUserActions().get(1).getOutpoint());
    Assert.assertEquals("6", ual.getUserActions().get(1).getSession().getSessionId());
    Assert.assertEquals("other test", ual.getUserActions().get(1).getType());
    Assert.assertEquals("testing user 2", ual.getUserActions().get(1).getSession().getUserId());
    Assert.assertEquals("127.0.0.5", ual.getUserActions().get(1).getSession().getUserIp());
    Assert.assertEquals(15, ual.getUserActions().get(1).getLength());
}
Also used : UserAction(org.opencastproject.usertracking.api.UserAction) UserActionList(org.opencastproject.usertracking.api.UserActionList) UserSession(org.opencastproject.usertracking.api.UserSession) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 5 with UserActionList

use of org.opencastproject.usertracking.api.UserActionList in project opencast by opencast.

the class UserTrackingServiceImplTest method verifyUserActionListsByType.

/**
 * Gets the user action list based on type, performs some asserts
 * @throws Exception
 */
private void verifyUserActionListsByType(String type, int count, int offset, int limit, int total) {
    UserActionList ual = service.getUserActionsByType(type, offset, limit);
    Assert.assertEquals(limit, ual.getLimit());
    Assert.assertEquals(offset, ual.getOffset());
    Assert.assertEquals(total, ual.getTotal());
    Assert.assertEquals(count, ual.getUserActions().size());
}
Also used : UserActionList(org.opencastproject.usertracking.api.UserActionList)

Aggregations

UserActionList (org.opencastproject.usertracking.api.UserActionList)14 UserAction (org.opencastproject.usertracking.api.UserAction)9 EntityManager (javax.persistence.EntityManager)7 Query (javax.persistence.Query)7 Calendar (java.util.Calendar)2 GregorianCalendar (java.util.GregorianCalendar)2 Test (org.junit.Test)2 Footprint (org.opencastproject.usertracking.api.Footprint)2 UserSession (org.opencastproject.usertracking.api.UserSession)2 LinkedList (java.util.LinkedList)1