Search in sources :

Example 11 with UserAction

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

the class UserTrackingServiceImpl method getUserActionsByTypeAndMediapackageId.

public UserActionList getUserActionsByTypeAndMediapackageId(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("findUserActionsByTypeAndMediapackageId");
        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 12 with UserAction

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

the class UserTrackingServiceImpl method getUserActionsByTypeAndMediapackageIdByDate.

public UserActionList getUserActionsByTypeAndMediapackageIdByDate(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("findUserActionsByMediaPackageAndTypeAscendingByDate");
        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 13 with UserAction

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

the class UserTrackingServiceImpl method getUserActionsByDay.

@SuppressWarnings("unchecked")
public UserActionList getUserActionsByDay(String day, int offset, int limit) {
    UserActionList result = new UserActionListImpl();
    int year = Integer.parseInt(day.substring(0, 4));
    int month = Integer.parseInt(day.substring(4, 6)) - 1;
    int date = Integer.parseInt(day.substring(6, 8));
    Calendar calBegin = new GregorianCalendar();
    calBegin.set(year, month, date, 0, 0);
    Calendar calEnd = new GregorianCalendar();
    calEnd.set(year, month, date, 23, 59);
    result.setTotal(getTotal(calBegin, calEnd));
    result.setOffset(offset);
    result.setLimit(limit);
    EntityManager em = null;
    try {
        em = emf.createEntityManager();
        Query q = em.createNamedQuery("findUserActionsByIntervall");
        q.setParameter("begin", calBegin, TemporalType.TIMESTAMP);
        q.setParameter("end", calEnd, TemporalType.TIMESTAMP);
        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) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) Footprint(org.opencastproject.usertracking.api.Footprint)

Example 14 with UserAction

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

the class UserTrackingServiceImpl method getUserActionsByTypeAndDay.

@SuppressWarnings("unchecked")
public UserActionList getUserActionsByTypeAndDay(String type, String day, int offset, int limit) {
    UserActionList result = new UserActionListImpl();
    int year = Integer.parseInt(day.substring(0, 4));
    int month = Integer.parseInt(day.substring(4, 6)) - 1;
    int date = Integer.parseInt(day.substring(6, 8));
    Calendar calBegin = new GregorianCalendar();
    calBegin.set(year, month, date, 0, 0);
    Calendar calEnd = new GregorianCalendar();
    calEnd.set(year, month, date, 23, 59);
    result.setTotal(getTotal(type, calBegin, calEnd));
    result.setOffset(offset);
    result.setLimit(limit);
    EntityManager em = null;
    try {
        em = emf.createEntityManager();
        Query q = em.createNamedQuery("findUserActionsByTypeAndIntervall");
        q.setParameter("type", type);
        q.setParameter("begin", calBegin, TemporalType.TIMESTAMP);
        q.setParameter("end", calEnd, TemporalType.TIMESTAMP);
        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) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) Footprint(org.opencastproject.usertracking.api.Footprint)

Example 15 with UserAction

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

the class UserTrackingServiceImpl method getUserActions.

@SuppressWarnings("unchecked")
public UserActionList getUserActions(int offset, int limit) {
    UserActionList result = new UserActionListImpl();
    result.setTotal(getTotal());
    result.setOffset(offset);
    result.setLimit(limit);
    EntityManager em = null;
    try {
        em = emf.createEntityManager();
        Query q = em.createNamedQuery("findUserActions");
        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)

Aggregations

UserAction (org.opencastproject.usertracking.api.UserAction)16 EntityManager (javax.persistence.EntityManager)9 Query (javax.persistence.Query)9 UserActionList (org.opencastproject.usertracking.api.UserActionList)9 UserSession (org.opencastproject.usertracking.api.UserSession)6 Test (org.junit.Test)5 Footprint (org.opencastproject.usertracking.api.Footprint)3 Calendar (java.util.Calendar)2 GregorianCalendar (java.util.GregorianCalendar)2 ParseException (java.text.ParseException)1 LinkedList (java.util.LinkedList)1 EntityTransaction (javax.persistence.EntityTransaction)1 NoResultException (javax.persistence.NoResultException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Response (javax.ws.rs.core.Response)1 Ignore (org.junit.Ignore)1 FootprintList (org.opencastproject.usertracking.api.FootprintList)1 UserTrackingException (org.opencastproject.usertracking.api.UserTrackingException)1 FootprintImpl (org.opencastproject.usertracking.endpoint.FootprintImpl)1 FootprintsListImpl (org.opencastproject.usertracking.endpoint.FootprintsListImpl)1