Search in sources :

Example 1 with FootprintImpl

use of org.opencastproject.usertracking.endpoint.FootprintImpl in project opencast by opencast.

the class UserTrackingServiceImpl method getFootprints.

public FootprintList getFootprints(String mediapackageId, String userId) {
    EntityManager em = null;
    if (!logUser)
        userId = null;
    try {
        em = emf.createEntityManager();
        Query q = null;
        if (StringUtils.trimToNull(userId) == null) {
            q = em.createNamedQuery("findUserActionsByTypeAndMediapackageIdOrderByOutpointDESC");
        } else {
            q = em.createNamedQuery("findUserActionsByTypeAndMediapackageIdByUserOrderByOutpointDESC");
            q.setParameter("userid", userId);
        }
        q.setParameter("type", FOOTPRINT_KEY);
        q.setParameter("mediapackageId", mediapackageId);
        @SuppressWarnings("unchecked") Collection<UserAction> userActions = q.getResultList();
        int[] resultArray = new int[1];
        boolean first = true;
        for (UserAction a : userActions) {
            if (first) {
                // Get one more item than the known outpoint to append a footprint of 0 views at the end of the result set
                resultArray = new int[a.getOutpoint() + 1];
                first = false;
            }
            for (int i = a.getInpoint(); i < a.getOutpoint(); i++) {
                resultArray[i]++;
            }
        }
        FootprintList list = new FootprintsListImpl();
        int current = -1;
        int last = -1;
        for (int i = 0; i < resultArray.length; i++) {
            current = resultArray[i];
            if (last != current) {
                Footprint footprint = new FootprintImpl();
                footprint.setPosition(i);
                footprint.setViews(current);
                list.add(footprint);
            }
            last = current;
        }
        return list;
    } finally {
        if (em != null && em.isOpen()) {
            em.close();
        }
    }
}
Also used : UserAction(org.opencastproject.usertracking.api.UserAction) Footprint(org.opencastproject.usertracking.api.Footprint) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) FootprintImpl(org.opencastproject.usertracking.endpoint.FootprintImpl) FootprintList(org.opencastproject.usertracking.api.FootprintList) FootprintsListImpl(org.opencastproject.usertracking.endpoint.FootprintsListImpl) Footprint(org.opencastproject.usertracking.api.Footprint)

Aggregations

EntityManager (javax.persistence.EntityManager)1 Query (javax.persistence.Query)1 Footprint (org.opencastproject.usertracking.api.Footprint)1 FootprintList (org.opencastproject.usertracking.api.FootprintList)1 UserAction (org.opencastproject.usertracking.api.UserAction)1 FootprintImpl (org.opencastproject.usertracking.endpoint.FootprintImpl)1 FootprintsListImpl (org.opencastproject.usertracking.endpoint.FootprintsListImpl)1