use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceJournalEntry in project muikku by otavanopisto.
the class WorkspaceJournalEntryDAO method listByWorkspaceEntityId.
public List<WorkspaceJournalEntry> listByWorkspaceEntityId(WorkspaceEntity workspaceEntity, int firstResult, int maxResults) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkspaceJournalEntry> criteria = criteriaBuilder.createQuery(WorkspaceJournalEntry.class);
Root<WorkspaceJournalEntry> root = criteria.from(WorkspaceJournalEntry.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(WorkspaceJournalEntry_.workspaceEntityId), workspaceEntity.getId()), criteriaBuilder.equal(root.get(WorkspaceJournalEntry_.archived), Boolean.FALSE)));
criteria.orderBy(criteriaBuilder.desc(root.get(WorkspaceJournalEntry_.created)));
TypedQuery<WorkspaceJournalEntry> query = entityManager.createQuery(criteria);
query.setFirstResult(firstResult);
query.setMaxResults(maxResults);
return query.getResultList();
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceJournalEntry in project muikku by otavanopisto.
the class WorkspaceJournalEntryDAO method listByWorkspaceEntityIdAndUserEntityId.
public List<WorkspaceJournalEntry> listByWorkspaceEntityIdAndUserEntityId(WorkspaceEntity workspaceEntity, UserEntity userEntity, int firstResult, int maxResults) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkspaceJournalEntry> criteria = criteriaBuilder.createQuery(WorkspaceJournalEntry.class);
Root<WorkspaceJournalEntry> root = criteria.from(WorkspaceJournalEntry.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(WorkspaceJournalEntry_.workspaceEntityId), workspaceEntity.getId()), criteriaBuilder.equal(root.get(WorkspaceJournalEntry_.userEntityId), userEntity.getId()), criteriaBuilder.equal(root.get(WorkspaceJournalEntry_.archived), Boolean.FALSE)));
criteria.orderBy(criteriaBuilder.desc(root.get(WorkspaceJournalEntry_.created)));
TypedQuery<WorkspaceJournalEntry> query = entityManager.createQuery(criteria);
query.setFirstResult(firstResult);
query.setMaxResults(maxResults);
return query.getResultList();
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceJournalEntry in project muikku by otavanopisto.
the class WorkspaceJournalEntryDAO method findLatestByWorkspaceEntityIdAndUserEntityId.
public WorkspaceJournalEntry findLatestByWorkspaceEntityIdAndUserEntityId(Long workspaceEntityId, Long userEntityId) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkspaceJournalEntry> criteria = criteriaBuilder.createQuery(WorkspaceJournalEntry.class);
Root<WorkspaceJournalEntry> root = criteria.from(WorkspaceJournalEntry.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(WorkspaceJournalEntry_.workspaceEntityId), workspaceEntityId), criteriaBuilder.equal(root.get(WorkspaceJournalEntry_.userEntityId), userEntityId), criteriaBuilder.equal(root.get(WorkspaceJournalEntry_.archived), Boolean.FALSE)));
criteria.orderBy(criteriaBuilder.desc(root.get(WorkspaceJournalEntry_.created)));
TypedQuery<WorkspaceJournalEntry> query = entityManager.createQuery(criteria);
query.setMaxResults(1);
return getSingleResult(query);
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceJournalEntry in project muikku by otavanopisto.
the class GuiderController method getStudentWorkspaceActivity.
public GuiderStudentWorkspaceActivity getStudentWorkspaceActivity(WorkspaceEntity workspaceEntity, SchoolDataIdentifier userIdentifier) {
UserEntity userEntity = userEntityController.findUserEntityByUserIdentifier(userIdentifier);
if (userEntity == null) {
return null;
}
GuiderStudentWorkspaceActivity activity = new GuiderStudentWorkspaceActivity();
activity.setLastVisit(workspaceVisitController.getLastVisit(workspaceEntity, userEntity));
activity.setNumVisits(workspaceVisitController.getNumVisits(workspaceEntity, userEntity));
WorkspaceJournalEntry workspaceJournalEntry = workspaceJournalController.findLatestsEntryByWorkspaceEntityAndUserEntity(workspaceEntity, userEntity);
if (workspaceJournalEntry != null) {
activity.setJournalEntryCount(workspaceJournalController.countEntriesByWorkspaceEntityAndUserEntity(workspaceEntity, userEntity));
activity.setLastJournalEntry(workspaceJournalEntry.getCreated());
}
List<WorkspaceMaterial> evaluatedAssignments = workspaceMaterialController.listVisibleWorkspaceMaterialsByAssignmentType(workspaceEntity, WorkspaceMaterialAssignmentType.EVALUATED);
for (WorkspaceMaterial evaluatedAssignment : evaluatedAssignments) {
WorkspaceMaterialReply workspaceMaterialReply = workspaceMaterialReplyController.findWorkspaceMaterialReplyByWorkspaceMaterialAndUserEntity(evaluatedAssignment, userEntity);
if (workspaceMaterialReply == null) {
activity.getEvaluables().addUnanswered();
} else {
switch(workspaceMaterialReply.getState()) {
case WITHDRAWN:
activity.getEvaluables().addAnswered(workspaceMaterialReply.getWithdrawn());
break;
case ANSWERED:
activity.getEvaluables().addAnswered(workspaceMaterialReply.getLastModified());
break;
case FAILED:
activity.getEvaluables().addFailed(workspaceMaterialReply.getSubmitted());
break;
case PASSED:
activity.getEvaluables().addPassed(workspaceMaterialReply.getSubmitted());
break;
case SUBMITTED:
activity.getEvaluables().addSubmitted(workspaceMaterialReply.getSubmitted());
break;
case UNANSWERED:
activity.getEvaluables().addUnanswered();
break;
case INCOMPLETE:
activity.getEvaluables().addIncomplete(workspaceMaterialReply.getLastModified());
break;
}
}
}
List<WorkspaceMaterial> exerciseAssignments = workspaceMaterialController.listVisibleWorkspaceMaterialsByAssignmentType(workspaceEntity, WorkspaceMaterialAssignmentType.EXERCISE);
for (WorkspaceMaterial exerciseAssignment : exerciseAssignments) {
WorkspaceMaterialReply workspaceMaterialReply = workspaceMaterialReplyController.findWorkspaceMaterialReplyByWorkspaceMaterialAndUserEntity(exerciseAssignment, userEntity);
if (workspaceMaterialReply == null) {
activity.getExercises().addUnanswered();
} else {
switch(workspaceMaterialReply.getState()) {
case UNANSWERED:
case ANSWERED:
case WITHDRAWN:
activity.getExercises().addUnanswered();
break;
case PASSED:
case FAILED:
case SUBMITTED:
case INCOMPLETE:
activity.getExercises().addAnswered(workspaceMaterialReply.getSubmitted());
break;
}
}
}
return activity;
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceJournalEntry in project muikku by otavanopisto.
the class WorkspaceRESTService method updateJournalEntry.
@PUT
@Path("/journal/{JOURNALENTRYID}")
@RESTPermitUnimplemented
public Response updateJournalEntry(@PathParam("JOURNALENTRYID") Long journalEntryId, WorkspaceJournalEntryRESTModel restModel) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).build();
}
WorkspaceJournalEntry workspaceJournalEntry = workspaceJournalController.findJournalEntry(journalEntryId);
if (workspaceJournalEntry == null) {
return Response.status(Status.NOT_FOUND).build();
}
workspaceJournalController.updateJournalEntry(journalEntryId, restModel.getTitle(), restModel.getContent());
return Response.noContent().build();
}
Aggregations