Search in sources :

Example 1 with GradingScaleItem

use of fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem in project muikku by otavanopisto.

the class AssessmentRequestController method getWorkspaceAssessmentState.

public WorkspaceAssessmentState getWorkspaceAssessmentState(WorkspaceUserEntity workspaceUserEntity) {
    WorkspaceEntity workspaceEntity = workspaceUserEntity.getWorkspaceEntity();
    // List all asssessments
    List<WorkspaceAssessment> workspaceAssessments = gradingController.listWorkspaceAssessments(workspaceEntity.getDataSource().getIdentifier(), workspaceEntity.getIdentifier(), workspaceUserEntity.getUserSchoolDataIdentifier().getIdentifier());
    // Sort latest assessment first
    if (!workspaceAssessments.isEmpty()) {
        workspaceAssessments.sort(new Comparator<WorkspaceAssessment>() {

            public int compare(WorkspaceAssessment o1, WorkspaceAssessment o2) {
                return o2.getDate().compareTo(o1.getDate());
            }
        });
    }
    // List all assessment requests
    List<WorkspaceAssessmentRequest> assessmentRequests = gradingController.listWorkspaceAssessmentRequests(workspaceEntity.getDataSource().getIdentifier(), workspaceEntity.getIdentifier(), workspaceUserEntity.getUserSchoolDataIdentifier().getIdentifier());
    if (!assessmentRequests.isEmpty()) {
        // Strip assessment requests that have been handled (TODO could be handled in Pyramus)
        for (int i = assessmentRequests.size() - 1; i >= 0; i--) {
            if (assessmentRequests.get(i).getHandled()) {
                assessmentRequests.remove(i);
            }
        }
        if (!assessmentRequests.isEmpty()) {
            // Sort latest assessment request first
            assessmentRequests.sort(new Comparator<WorkspaceAssessmentRequest>() {

                public int compare(WorkspaceAssessmentRequest o1, WorkspaceAssessmentRequest o2) {
                    return o2.getDate().compareTo(o1.getDate());
                }
            });
        }
    }
    WorkspaceAssessment latestAssessment = workspaceAssessments.isEmpty() ? null : workspaceAssessments.get(0);
    WorkspaceAssessmentRequest latestRequest = assessmentRequests.isEmpty() ? null : assessmentRequests.get(0);
    if (latestAssessment != null && (latestRequest == null || latestRequest.getDate().before(latestAssessment.getDate()))) {
        // Has assessment and no request, or the request is older
        GradingScale gradingScale = gradingController.findGradingScale(latestAssessment.getGradingScaleIdentifier());
        GradingScaleItem grade = gradingController.findGradingScaleItem(gradingScale, latestAssessment.getGradeIdentifier());
        return grade.isPassingGrade() ? new WorkspaceAssessmentState(WorkspaceAssessmentState.PASS, latestAssessment.getDate()) : new WorkspaceAssessmentState(WorkspaceAssessmentState.FAIL, latestAssessment.getDate());
    } else if (latestRequest != null && (latestAssessment == null || latestAssessment.getDate().before(latestRequest.getDate()))) {
        // Has request and no assessment, or the assessment is older
        if (latestAssessment == null) {
            return new WorkspaceAssessmentState(WorkspaceAssessmentState.PENDING, latestRequest.getDate());
        } else if (Boolean.TRUE.equals(latestAssessment.getPassing())) {
            return new WorkspaceAssessmentState(WorkspaceAssessmentState.PENDING_PASS, latestRequest.getDate());
        } else {
            return new WorkspaceAssessmentState(WorkspaceAssessmentState.PENDING_FAIL, latestRequest.getDate());
        }
    } else {
        // Has neither assessment nor request
        return new WorkspaceAssessmentState(WorkspaceAssessmentState.UNASSESSED);
    }
}
Also used : GradingScale(fi.otavanopisto.muikku.schooldata.entity.GradingScale) WorkspaceAssessment(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceAssessmentRequest(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessmentRequest) GradingScaleItem(fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem)

Example 2 with GradingScaleItem

use of fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem in project muikku by otavanopisto.

the class TranscriptofRecordsBackingBean method init.

@RequestAction
public String init() {
    if (!sessionController.hasEnvironmentPermission(TranscriptofRecordsPermissions.TRANSCRIPT_OF_RECORDS_VIEW)) {
        return NavigationRules.ACCESS_DENIED;
    }
    Map<String, Grade> grades = new HashMap<>();
    List<GradingScale> gradingScales = gradingController.listGradingScales();
    for (GradingScale gradingScale : gradingScales) {
        List<GradingScaleItem> scaleItems = gradingController.listGradingScaleItems(gradingScale);
        for (GradingScaleItem scaleItem : scaleItems) {
            String id = StringUtils.join(new String[] { gradingScale.getSchoolDataSource(), gradingScale.getIdentifier(), scaleItem.getSchoolDataSource(), scaleItem.getIdentifier() }, '-');
            String grade = scaleItem.getName();
            String scale = gradingScale.getName();
            Boolean passing = scaleItem.isPassingGrade();
            grades.put(id, new Grade(grade, scale, passing));
        }
    }
    try {
        this.grades = new ObjectMapper().writeValueAsString(grades);
    } catch (JsonProcessingException e) {
        logger.log(Level.SEVERE, "Failed to serialize grades", e);
        return NavigationRules.INTERNAL_ERROR;
    }
    UserEntity loggedEntity = sessionController.getLoggedUserEntity();
    User user = userController.findUserByDataSourceAndIdentifier(sessionController.getLoggedUserSchoolDataSource(), sessionController.getLoggedUserIdentifier());
    studyStartDate = user.getStudyStartDate();
    studyTimeEnd = user.getStudyTimeEnd();
    studyTimeLeftStr = "";
    if (studyTimeEnd != null) {
        OffsetDateTime now = OffsetDateTime.now();
        Locale locale = sessionController.getLocale();
        if (now.isBefore(studyTimeEnd)) {
            long studyTimeLeftYears = now.until(studyTimeEnd, ChronoUnit.YEARS);
            now = now.plusYears(studyTimeLeftYears);
            if (studyTimeLeftYears > 0) {
                studyTimeLeftStr += studyTimeLeftYears + " " + localeController.getText(locale, "plugin.records.studyTimeEndShort.y");
            }
            long studyTimeLeftMonths = now.until(studyTimeEnd, ChronoUnit.MONTHS);
            now = now.plusMonths(studyTimeLeftMonths);
            if (studyTimeLeftMonths > 0) {
                if (studyTimeLeftStr.length() > 0)
                    studyTimeLeftStr += " ";
                studyTimeLeftStr += studyTimeLeftMonths + " " + localeController.getText(locale, "plugin.records.studyTimeEndShort.m");
            }
            long studyTimeLeftDays = now.until(studyTimeEnd, ChronoUnit.DAYS);
            now = now.plusDays(studyTimeLeftDays);
            if (studyTimeLeftDays > 0) {
                if (studyTimeLeftStr.length() > 0)
                    studyTimeLeftStr += " ";
                studyTimeLeftStr += studyTimeLeftDays + " " + localeController.getText(locale, "plugin.records.studyTimeEndShort.d");
            }
        }
    }
    List<TranscriptOfRecordsFile> transcriptOfRecordsFiles;
    if (loggedEntity != null) {
        transcriptOfRecordsFiles = transcriptOfRecordsFileController.listFiles(loggedEntity);
    } else {
        transcriptOfRecordsFiles = Collections.emptyList();
    }
    try {
        files = new ObjectMapper().writeValueAsString(transcriptOfRecordsFiles);
    } catch (JsonProcessingException e) {
        logger.log(Level.SEVERE, "Failed to serialize files", e);
        return NavigationRules.INTERNAL_ERROR;
    }
    return null;
}
Also used : Locale(java.util.Locale) GradingScale(fi.otavanopisto.muikku.schooldata.entity.GradingScale) User(fi.otavanopisto.muikku.schooldata.entity.User) HashMap(java.util.HashMap) GradingScaleItem(fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) OffsetDateTime(java.time.OffsetDateTime) TranscriptOfRecordsFile(fi.otavanopisto.muikku.plugins.transcriptofrecords.model.TranscriptOfRecordsFile) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction)

Example 3 with GradingScaleItem

use of fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem in project muikku by otavanopisto.

the class Evaluation2RESTService method createWorkspaceMaterialAssessment.

@POST
@Path("/workspace/{WORKSPACEENTITYID}/user/{USERENTITYID}/workspacematerial/{WORKSPACEMATERIALID}/assessment")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response createWorkspaceMaterialAssessment(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("USERENTITYID") Long userEntityId, @PathParam("WORKSPACEMATERIALID") Long workspaceMaterialId, RestAssessment payload) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.ACCESS_EVALUATION)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    // User entity
    UserEntity userEntity = userEntityController.findUserEntityById(userEntityId);
    if (userEntity == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    // Workspace material
    WorkspaceMaterial workspaceMaterial = workspaceMaterialController.findWorkspaceMaterialById(workspaceMaterialId);
    if (workspaceMaterial == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    // Workspace material evaluation
    WorkspaceMaterialEvaluation workspaceMaterialEvaluation = evaluationController.findWorkspaceMaterialEvaluationByWorkspaceMaterialAndStudent(workspaceMaterial, userEntity);
    // Grade
    SchoolDataIdentifier gradingScaleIdentifier = SchoolDataIdentifier.fromId(payload.getGradingScaleIdentifier());
    GradingScale gradingScale = gradingController.findGradingScale(gradingScaleIdentifier);
    SchoolDataIdentifier gradeIdentifier = SchoolDataIdentifier.fromId(payload.getGradeIdentifier());
    GradingScaleItem gradingScaleItem = gradingController.findGradingScaleItem(gradingScale, gradeIdentifier);
    // Assessor
    SchoolDataIdentifier assessorIdentifier = SchoolDataIdentifier.fromId(payload.getAssessorIdentifier());
    User assessingUser = userController.findUserByIdentifier(assessorIdentifier);
    UserEntity assessor = userEntityController.findUserEntityByUser(assessingUser);
    if (workspaceMaterialEvaluation == null) {
        workspaceMaterialEvaluation = evaluationController.createWorkspaceMaterialEvaluation(userEntity, workspaceMaterial, gradingScale, gradingScaleItem, assessor, payload.getAssessmentDate(), payload.getVerbalAssessment());
    } else {
        workspaceMaterialEvaluation = evaluationController.updateWorkspaceMaterialEvaluation(workspaceMaterialEvaluation, gradingScale, gradingScaleItem, assessor, payload.getAssessmentDate(), payload.getVerbalAssessment());
    }
    // Remove possible workspace assignment supplementation request
    SupplementationRequest supplementationRequest = evaluationController.findSupplementationRequestByStudentAndWorkspaceMaterialAndArchived(userEntityId, workspaceMaterialId, Boolean.FALSE);
    if (supplementationRequest != null) {
        evaluationController.deleteSupplementationRequest(supplementationRequest);
    }
    // WorkspaceMaterialEvaluation to RestAssessment
    RestAssessment restAssessment = new RestAssessment(workspaceMaterialEvaluation.getId().toString(), assessorIdentifier.toId(), gradingScaleIdentifier.toId(), gradeIdentifier.toId(), workspaceMaterialEvaluation.getVerbalAssessment(), workspaceMaterialEvaluation.getEvaluated(), gradingScaleItem.isPassingGrade());
    return Response.ok(restAssessment).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) CompositeGradingScale(fi.otavanopisto.muikku.schooldata.entity.CompositeGradingScale) GradingScale(fi.otavanopisto.muikku.schooldata.entity.GradingScale) WorkspaceGradingScale(fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGradingScale) User(fi.otavanopisto.muikku.schooldata.entity.User) WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) WorkspaceMaterialEvaluation(fi.otavanopisto.muikku.plugins.evaluation.model.WorkspaceMaterialEvaluation) GradingScaleItem(fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem) RestAssessment(fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssessment) SupplementationRequest(fi.otavanopisto.muikku.plugins.evaluation.model.SupplementationRequest) RestSupplementationRequest(fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestSupplementationRequest) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Example 4 with GradingScaleItem

use of fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem in project muikku by otavanopisto.

the class EvaluationRESTService method listWorkspaceGrades.

@GET
@Path("/workspaces/{WORKSPACEENTITYID}/gradingScales")
@RESTPermit(handling = Handling.INLINE)
public Response listWorkspaceGrades(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!sessionController.hasWorkspacePermission(EvaluationResourcePermissionCollection.EVALUATION_LISTGRADINGSCALES, workspaceEntity)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    List<WorkspaceGradingScale> result = new ArrayList<>();
    List<GradingScale> gradingScales = gradingController.listGradingScales();
    for (GradingScale gradingScale : gradingScales) {
        List<GradingScaleItem> gradingScaleItems = gradingController.listGradingScaleItems(gradingScale);
        List<WorkspaceGrade> workspaceGrades = new ArrayList<>();
        for (GradingScaleItem gradingScaleItem : gradingScaleItems) {
            workspaceGrades.add(new WorkspaceGrade(gradingScaleItem.getName(), gradingScaleItem.getIdentifier(), gradingScaleItem.getSchoolDataSource()));
        }
        result.add(new WorkspaceGradingScale(gradingScale.getName(), gradingScale.getIdentifier(), gradingScale.getSchoolDataSource(), workspaceGrades));
    }
    return Response.ok(result).build();
}
Also used : WorkspaceGrade(fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGrade) GradingScale(fi.otavanopisto.muikku.schooldata.entity.GradingScale) WorkspaceGradingScale(fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGradingScale) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) GradingScaleItem(fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem) ArrayList(java.util.ArrayList) WorkspaceGradingScale(fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGradingScale) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 5 with GradingScaleItem

use of fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem in project muikku by otavanopisto.

the class EvaluationRESTService method createRestModel.

private fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceAssessment createRestModel(WorkspaceEntity workspaceEntity, fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment entry) {
    UserEntity assessor = null;
    if (entry.getAssessingUserIdentifier() != null) {
        assessor = userEntityController.findUserEntityByUserIdentifier(entry.getAssessingUserIdentifier());
    }
    GradingScale gradingScale = null;
    SchoolDataIdentifier identifier = entry.getGradingScaleIdentifier();
    if (identifier != null && !StringUtils.isBlank(identifier.getDataSource()) && !StringUtils.isBlank(identifier.getIdentifier())) {
        gradingScale = gradingController.findGradingScale(identifier);
    }
    GradingScaleItem grade = null;
    if (gradingScale != null) {
        identifier = entry.getGradeIdentifier();
        if (identifier != null && !StringUtils.isBlank(identifier.getDataSource()) && !StringUtils.isBlank(identifier.getIdentifier())) {
            grade = gradingController.findGradingScaleItem(gradingScale, identifier);
        }
    }
    return new fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceAssessment(entry.getIdentifier().toId(), entry.getDate(), assessor != null ? assessor.getId() : null, entry.getWorkspaceUserIdentifier().toId(), entry.getGradingScaleIdentifier() == null ? null : entry.getGradingScaleIdentifier().getIdentifier(), entry.getGradingScaleIdentifier() == null ? null : entry.getGradingScaleIdentifier().getDataSource(), entry.getGradeIdentifier() == null ? null : entry.getGradeIdentifier().getIdentifier(), entry.getGradeIdentifier() == null ? null : entry.getGradeIdentifier().getDataSource(), entry.getVerbalAssessment(), grade == null ? Boolean.FALSE : grade.isPassingGrade());
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) GradingScale(fi.otavanopisto.muikku.schooldata.entity.GradingScale) WorkspaceGradingScale(fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGradingScale) WorkspaceAssessment(fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceAssessment) GradingScaleItem(fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)

Aggregations

GradingScaleItem (fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem)17 GradingScale (fi.otavanopisto.muikku.schooldata.entity.GradingScale)15 WorkspaceGradingScale (fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGradingScale)12 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)11 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)11 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)10 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)10 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)10 Path (javax.ws.rs.Path)10 User (fi.otavanopisto.muikku.schooldata.entity.User)7 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)5 CompositeGradingScale (fi.otavanopisto.muikku.schooldata.entity.CompositeGradingScale)5 Date (java.util.Date)5 RestAssessment (fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssessment)4 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)4 WorkspaceAssessment (fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment)4 WorkspaceUser (fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser)4 PUT (javax.ws.rs.PUT)4 SupplementationRequest (fi.otavanopisto.muikku.plugins.evaluation.model.SupplementationRequest)3 WorkspaceMaterialEvaluation (fi.otavanopisto.muikku.plugins.evaluation.model.WorkspaceMaterialEvaluation)3