Search in sources :

Example 6 with WorkspaceJournalEntry

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) WorkspaceJournalEntry(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceJournalEntry) EntityManager(javax.persistence.EntityManager)

Example 7 with WorkspaceJournalEntry

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) WorkspaceJournalEntry(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceJournalEntry) EntityManager(javax.persistence.EntityManager)

Example 8 with WorkspaceJournalEntry

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);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) WorkspaceJournalEntry(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceJournalEntry) EntityManager(javax.persistence.EntityManager)

Example 9 with WorkspaceJournalEntry

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;
}
Also used : WorkspaceJournalEntry(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceJournalEntry) WorkspaceMaterialReply(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialReply) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)

Example 10 with WorkspaceJournalEntry

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();
}
Also used : WorkspaceJournalEntry(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceJournalEntry) Path(javax.ws.rs.Path) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) PUT(javax.ws.rs.PUT)

Aggregations

WorkspaceJournalEntry (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceJournalEntry)11 EntityManager (javax.persistence.EntityManager)6 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)6 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)3 Path (javax.ws.rs.Path)3 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)2 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)2 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)1 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)1 CorePluginsDAO (fi.otavanopisto.muikku.plugins.CorePluginsDAO)1 WorkspaceJournalEntry_ (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceJournalEntry_)1 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)1 WorkspaceMaterialReply (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialReply)1 WorkspaceJournalEntryRESTModel (fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceJournalEntryRESTModel)1 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)1 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)1 User (fi.otavanopisto.muikku.schooldata.entity.User)1 WorkspaceUser (fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1