Search in sources :

Example 6 with UserActionList

use of org.opencastproject.usertracking.api.UserActionList 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 7 with UserActionList

use of org.opencastproject.usertracking.api.UserActionList 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 8 with UserActionList

use of org.opencastproject.usertracking.api.UserActionList 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 9 with UserActionList

use of org.opencastproject.usertracking.api.UserActionList 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 10 with UserActionList

use of org.opencastproject.usertracking.api.UserActionList 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

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