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);
}
}
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;
}
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();
}
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();
}
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());
}
Aggregations