Search in sources :

Example 1 with RestAssignment

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

the class Evaluation2RESTService method listWorkspaceAssignments.

@GET
@Path("/workspace/{WORKSPACEENTITYID}/assignments")
@RESTPermit(handling = Handling.INLINE)
public Response listWorkspaceAssignments(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @QueryParam("userEntityId") Long userEntityId) {
    // Workspace entity
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    // User entity (optional)
    UserEntity userEntity = null;
    if (userEntityId != null) {
        userEntity = userEntityController.findUserEntityById(userEntityId);
        if (userEntity == null) {
            return Response.status(Status.NOT_FOUND).build();
        }
    }
    // Workspace materials...
    List<WorkspaceMaterial> workspaceMaterials = workspaceMaterialController.listWorkspaceMaterialsByAssignmentType(workspaceEntity, WorkspaceMaterialAssignmentType.EVALUATED, BooleanPredicate.IGNORE);
    workspaceMaterials.addAll(workspaceMaterialController.listWorkspaceMaterialsByAssignmentType(workspaceEntity, WorkspaceMaterialAssignmentType.EXERCISE, BooleanPredicate.IGNORE));
    // ...to RestAssignments
    List<RestAssignment> assignments = new ArrayList<RestAssignment>();
    for (WorkspaceMaterial workspaceMaterial : workspaceMaterials) {
        Long workspaceMaterialEvaluationId = null;
        Long workspaceMaterialId = workspaceMaterial.getId();
        Long materialId = workspaceMaterial.getMaterialId();
        String path = workspaceMaterial.getPath();
        String title = workspaceMaterial.getTitle();
        Boolean evaluable = workspaceMaterial.getAssignmentType() == WorkspaceMaterialAssignmentType.EVALUATED;
        Date submitted = null;
        Date evaluated = null;
        String grade = null;
        String literalEvaluation = null;
        if (userEntity != null) {
            WorkspaceMaterialReply workspaceMaterialReply = workspaceMaterialReplyController.findWorkspaceMaterialReplyByWorkspaceMaterialAndUserEntity(workspaceMaterial, userEntity);
            if (workspaceMaterialReply != null) {
                WorkspaceMaterialReplyState replyState = workspaceMaterialReply.getState();
                if (replyState == WorkspaceMaterialReplyState.SUBMITTED || replyState == WorkspaceMaterialReplyState.PASSED || replyState == WorkspaceMaterialReplyState.FAILED || replyState == WorkspaceMaterialReplyState.INCOMPLETE) {
                    submitted = workspaceMaterialReply.getLastModified();
                }
            } else if (workspaceMaterial.getHidden()) {
                // Skip hidden material which has no reply
                continue;
            }
            WorkspaceMaterialEvaluation workspaceMaterialEvaluation = evaluationController.findWorkspaceMaterialEvaluationByWorkspaceMaterialAndStudent(workspaceMaterial, userEntity);
            if (workspaceMaterialEvaluation != null) {
                workspaceMaterialEvaluationId = workspaceMaterialEvaluation.getId();
                evaluated = workspaceMaterialEvaluation.getEvaluated();
                GradingScale gradingScale = gradingController.findGradingScale(workspaceMaterialEvaluation.getGradingScaleSchoolDataSource(), workspaceMaterialEvaluation.getGradingScaleIdentifier());
                if (gradingScale != null) {
                    GradingScaleItem gradingScaleItem = gradingController.findGradingScaleItem(gradingScale, workspaceMaterialEvaluation.getGradeSchoolDataSource(), workspaceMaterialEvaluation.getGradeIdentifier());
                    if (gradingScaleItem != null) {
                        grade = gradingScaleItem.getName();
                    }
                }
                literalEvaluation = workspaceMaterialEvaluation.getVerbalAssessment();
            } else {
                SupplementationRequest supplementationRequest = evaluationController.findSupplementationRequestByStudentAndWorkspaceMaterialAndArchived(userEntity.getId(), workspaceMaterial.getId(), Boolean.FALSE);
                if (supplementationRequest != null) {
                    evaluated = supplementationRequest.getRequestDate();
                    literalEvaluation = supplementationRequest.getRequestText();
                }
            }
        }
        if (!(workspaceMaterial.getHidden() && submitted == null)) {
            assignments.add(new RestAssignment(workspaceMaterialEvaluationId, workspaceMaterialId, materialId, path, title, evaluable, submitted, evaluated, grade, literalEvaluation));
        }
    }
    return Response.ok(assignments).build();
}
Also used : CompositeGradingScale(fi.otavanopisto.muikku.schooldata.entity.CompositeGradingScale) GradingScale(fi.otavanopisto.muikku.schooldata.entity.GradingScale) WorkspaceGradingScale(fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGradingScale) RestAssignment(fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssignment) WorkspaceMaterialReply(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialReply) GradingScaleItem(fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem) ArrayList(java.util.ArrayList) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) Date(java.util.Date) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceMaterialEvaluation(fi.otavanopisto.muikku.plugins.evaluation.model.WorkspaceMaterialEvaluation) 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) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Aggregations

UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)1 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)1 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)1 SupplementationRequest (fi.otavanopisto.muikku.plugins.evaluation.model.SupplementationRequest)1 WorkspaceMaterialEvaluation (fi.otavanopisto.muikku.plugins.evaluation.model.WorkspaceMaterialEvaluation)1 RestAssignment (fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssignment)1 RestSupplementationRequest (fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestSupplementationRequest)1 WorkspaceGradingScale (fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGradingScale)1 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)1 WorkspaceMaterialReply (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialReply)1 WorkspaceMaterialReplyState (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialReplyState)1 CompositeGradingScale (fi.otavanopisto.muikku.schooldata.entity.CompositeGradingScale)1 GradingScale (fi.otavanopisto.muikku.schooldata.entity.GradingScale)1 GradingScaleItem (fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem)1 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1