use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceVisit in project muikku by otavanopisto.
the class WorkspaceVisitDAO method lockingFindByUserEntityAndWorkspaceEntity.
public WorkspaceVisit lockingFindByUserEntityAndWorkspaceEntity(UserEntity userEntity, WorkspaceEntity workspaceEntity) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkspaceVisit> criteria = criteriaBuilder.createQuery(WorkspaceVisit.class);
Root<WorkspaceVisit> root = criteria.from(WorkspaceVisit.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(WorkspaceVisit_.userEntityId), userEntity.getId()), criteriaBuilder.equal(root.get(WorkspaceVisit_.workspaceEntityId), workspaceEntity.getId())));
TypedQuery<WorkspaceVisit> query = entityManager.createQuery(criteria);
query.setLockMode(LockModeType.PESSIMISTIC_WRITE);
return getSingleResult(query);
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceVisit in project muikku by otavanopisto.
the class WorkspaceVisitDAO method findByUserEntityAndWorkspaceEntity.
public WorkspaceVisit findByUserEntityAndWorkspaceEntity(UserEntity userEntity, WorkspaceEntity workspaceEntity) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkspaceVisit> criteria = criteriaBuilder.createQuery(WorkspaceVisit.class);
Root<WorkspaceVisit> root = criteria.from(WorkspaceVisit.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(WorkspaceVisit_.userEntityId), userEntity.getId()), criteriaBuilder.equal(root.get(WorkspaceVisit_.workspaceEntityId), workspaceEntity.getId())));
return getSingleResult(entityManager.createQuery(criteria));
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceVisit in project muikku by otavanopisto.
the class WorkspaceVisitController method visit.
public void visit(WorkspaceEntity workspaceEntity) {
UserEntity userEntity = sessionController.getLoggedUserEntity();
if (userEntity == null) {
return;
} else {
synchronized (userEntity) {
WorkspaceVisit workspaceVisit = workspaceVisitDAO.lockingFindByUserEntityAndWorkspaceEntity(userEntity, workspaceEntity);
if (workspaceVisit == null) {
workspaceVisit = workspaceVisitDAO.create(userEntity, workspaceEntity, new Date());
}
workspaceVisitDAO.updateNumVisitsAndLastVisit(workspaceVisit, workspaceVisit.getNumVisits() + 1, new Date());
}
}
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceVisit in project muikku by otavanopisto.
the class WorkspaceVisitController method listEnrolledWorkspaceEntitiesByMinVisitsOrderByLastVisit.
public List<WorkspaceEntity> listEnrolledWorkspaceEntitiesByMinVisitsOrderByLastVisit(UserEntity userEntity, Long numVisits) {
List<WorkspaceEntity> workspaceEntities = workspaceEntityController.listActiveWorkspaceEntitiesByUserEntity(userEntity);
Map<Long, WorkspaceEntity> workspaceEntityMap = new HashMap<>();
for (WorkspaceEntity workspaceEntity : workspaceEntities) {
workspaceEntityMap.put(workspaceEntity.getId(), workspaceEntity);
}
List<WorkspaceVisit> workspaceVisits = workspaceVisitDAO.listByWorkspaceEntityIdsAndUserEntityAndMinVisitsOrderByLastVisit(workspaceEntityMap.keySet(), userEntity, numVisits, null, null);
List<WorkspaceEntity> result = new ArrayList<>(workspaceVisits.size());
for (WorkspaceVisit workspaceVisit : workspaceVisits) {
result.add(workspaceEntityMap.get(workspaceVisit.getWorkspaceEntityId()));
}
return result;
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceVisit in project muikku by otavanopisto.
the class WorkspaceVisitController method listWorkspaceEntitiesByMinVisitsOrderByLastVisit.
public List<WorkspaceEntity> listWorkspaceEntitiesByMinVisitsOrderByLastVisit(UserEntity userEntity, Long numVisits) {
List<WorkspaceVisit> workspaceVisits = workspaceVisitDAO.listByUserEntityAndMinVisitsOrderByLastVisit(userEntity, numVisits, null, null);
List<WorkspaceEntity> result = new ArrayList<>(workspaceVisits.size());
for (WorkspaceVisit workspaceVisit : workspaceVisits) {
result.add(workspaceEntityController.findWorkspaceEntityById(workspaceVisit.getWorkspaceEntityId()));
}
return result;
}
Aggregations