use of org.opencastproject.usertracking.endpoint.FootprintsListImpl 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();
}
}
}
Aggregations