Search in sources :

Example 1 with RestAssessmentRequest

use of fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssessmentRequest in project muikku by otavanopisto.

the class Evaluation2RESTService method listAssessmentRequests.

@GET
@Path("/compositeAssessmentRequests")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listAssessmentRequests(@QueryParam("workspaceEntityId") Long workspaceEntityId) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.ACCESS_EVALUATION)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    List<RestAssessmentRequest> restAssessmentRequests = new ArrayList<RestAssessmentRequest>();
    if (workspaceEntityId == null) {
        // List assessment requests by staff member
        SchoolDataIdentifier loggedUser = sessionController.getLoggedUser();
        List<CompositeAssessmentRequest> assessmentRequests = gradingController.listAssessmentRequestsByStaffMember(loggedUser);
        for (CompositeAssessmentRequest assessmentRequest : assessmentRequests) {
            restAssessmentRequests.add(toRestAssessmentRequest(assessmentRequest));
        }
    } else {
        // List assessment requests by workspace
        List<String> workspaceStudentIdentifiers = new ArrayList<String>();
        WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
        SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(workspaceEntity.getIdentifier(), workspaceEntity.getDataSource().getIdentifier());
        List<WorkspaceUserEntity> workspaceUserEntities = workspaceUserEntityController.listActiveWorkspaceStudents(workspaceEntity);
        for (WorkspaceUserEntity workspaceUserEntity : workspaceUserEntities) {
            workspaceStudentIdentifiers.add(workspaceUserEntity.getIdentifier());
        }
        List<CompositeAssessmentRequest> assessmentRequests = gradingController.listAssessmentRequestsByWorkspace(workspaceIdentifier, workspaceStudentIdentifiers);
        for (CompositeAssessmentRequest assessmentRequest : assessmentRequests) {
            restAssessmentRequests.add(toRestAssessmentRequest(assessmentRequest));
        }
    }
    return Response.ok(restAssessmentRequests).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) ArrayList(java.util.ArrayList) RestAssessmentRequest(fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssessmentRequest) CompositeAssessmentRequest(fi.otavanopisto.muikku.schooldata.entity.CompositeAssessmentRequest) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 2 with RestAssessmentRequest

use of fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssessmentRequest in project muikku by otavanopisto.

the class Evaluation2RESTService method toRestAssessmentRequest.

private RestAssessmentRequest toRestAssessmentRequest(CompositeAssessmentRequest compositeAssessmentRequest) {
    Long assignmentsDone = 0L;
    Long assignmentsTotal = 0L;
    // Assignments total
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceByIdentifier(compositeAssessmentRequest.getCourseIdentifier());
    if (workspaceEntity == null) {
        logger.severe(String.format("WorkspaceEntity for course %s not found", compositeAssessmentRequest.getCourseIdentifier()));
    } else {
        List<WorkspaceMaterial> evaluatedAssignments = workspaceMaterialController.listVisibleWorkspaceMaterialsByAssignmentType(workspaceEntity, WorkspaceMaterialAssignmentType.EVALUATED);
        assignmentsTotal = new Long(evaluatedAssignments.size());
        // Assignments done by user
        if (assignmentsTotal > 0) {
            UserEntity userEntity = userEntityController.findUserEntityByUserIdentifier(compositeAssessmentRequest.getUserIdentifier());
            if (userEntity == null) {
                logger.severe(String.format("UserEntity not found for AssessmentRequest student %s not found", compositeAssessmentRequest.getUserIdentifier()));
            } else {
                List<WorkspaceMaterialReplyState> replyStates = new ArrayList<WorkspaceMaterialReplyState>();
                replyStates.add(WorkspaceMaterialReplyState.FAILED);
                replyStates.add(WorkspaceMaterialReplyState.PASSED);
                replyStates.add(WorkspaceMaterialReplyState.SUBMITTED);
                replyStates.add(WorkspaceMaterialReplyState.INCOMPLETE);
                assignmentsDone = workspaceMaterialReplyController.getReplyCountByUserEntityAndReplyStatesAndWorkspaceMaterials(userEntity.getId(), replyStates, evaluatedAssignments);
            }
        }
    }
    WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifierIncludeArchived(compositeAssessmentRequest.getCourseStudentIdentifier());
    UserEntity userEntity = userEntityController.findUserEntityByUserIdentifier(compositeAssessmentRequest.getUserIdentifier());
    // An active workspace supplementation request will override graded, passing, and evaluationDate
    Boolean graded = Boolean.TRUE;
    Boolean passing = compositeAssessmentRequest.getPassing();
    Date evaluationDate = compositeAssessmentRequest.getEvaluationDate();
    if (userEntity != null) {
        SupplementationRequest supplementationRequest = evaluationController.findSupplementationRequestByStudentAndWorkspaceAndArchived(userEntity.getId(), workspaceEntity.getId(), Boolean.FALSE);
        if (supplementationRequest != null) {
            graded = Boolean.FALSE;
            passing = Boolean.FALSE;
            evaluationDate = supplementationRequest.getRequestDate();
        }
    }
    RestAssessmentRequest restAssessmentRequest = new RestAssessmentRequest();
    restAssessmentRequest.setWorkspaceUserEntityId(workspaceUserEntity == null ? null : workspaceUserEntity.getId());
    restAssessmentRequest.setWorkspaceUserIdentifier(compositeAssessmentRequest.getCourseStudentIdentifier().toId());
    restAssessmentRequest.setUserEntityId(userEntity == null ? null : userEntity.getId());
    restAssessmentRequest.setAssessmentRequestDate(compositeAssessmentRequest.getAssessmentRequestDate());
    restAssessmentRequest.setEvaluationDate(evaluationDate);
    restAssessmentRequest.setPassing(passing);
    restAssessmentRequest.setGraded(graded);
    restAssessmentRequest.setAssignmentsDone(assignmentsDone);
    restAssessmentRequest.setAssignmentsTotal(assignmentsTotal);
    restAssessmentRequest.setEnrollmentDate(compositeAssessmentRequest.getCourseEnrollmentDate());
    restAssessmentRequest.setFirstName(compositeAssessmentRequest.getFirstName());
    restAssessmentRequest.setLastName(compositeAssessmentRequest.getLastName());
    restAssessmentRequest.setStudyProgramme(compositeAssessmentRequest.getStudyProgramme());
    restAssessmentRequest.setWorkspaceEntityId(workspaceEntity == null ? null : workspaceEntity.getId());
    restAssessmentRequest.setWorkspaceName(compositeAssessmentRequest.getCourseName());
    restAssessmentRequest.setWorkspaceNameExtension(compositeAssessmentRequest.getCourseNameExtension());
    restAssessmentRequest.setWorkspaceUrlName(workspaceEntity == null ? null : workspaceEntity.getUrlName());
    return restAssessmentRequest;
}
Also used : ArrayList(java.util.ArrayList) RestAssessmentRequest(fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssessmentRequest) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) Date(java.util.Date) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) SupplementationRequest(fi.otavanopisto.muikku.plugins.evaluation.model.SupplementationRequest) RestSupplementationRequest(fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestSupplementationRequest) WorkspaceMaterialReplyState(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialReplyState)

Aggregations

WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)2 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)2 RestAssessmentRequest (fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssessmentRequest)2 ArrayList (java.util.ArrayList)2 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)1 SupplementationRequest (fi.otavanopisto.muikku.plugins.evaluation.model.SupplementationRequest)1 RestSupplementationRequest (fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestSupplementationRequest)1 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)1 WorkspaceMaterialReplyState (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialReplyState)1 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)1 CompositeAssessmentRequest (fi.otavanopisto.muikku.schooldata.entity.CompositeAssessmentRequest)1 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)1 Date (java.util.Date)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1