use of fi.otavanopisto.muikku.schooldata.entity.GradingScale in project muikku by otavanopisto.
the class EvaluationRESTService method createWorkspaceAssessment.
@POST
@Path("/workspaces/{WORKSPACEENTITYID}/students/{STUDENTID}/assessments")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response createWorkspaceAssessment(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("STUDENTID") String studentId, WorkspaceAssessment payload) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).build();
}
SchoolDataIdentifier studentIdentifier = SchoolDataIdentifier.fromId(studentId);
if (studentIdentifier == null) {
return Response.status(Status.BAD_REQUEST).entity(String.format("Malformed student identifier %s", studentId)).build();
}
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.NOT_FOUND).entity(String.format("Could not find workspace entity %d", workspaceEntityId)).build();
}
WorkspaceUserEntity workspaceStudentEntity = workspaceUserEntityController.findActiveWorkspaceUserByWorkspaceEntityAndUserIdentifier(workspaceEntity, studentIdentifier);
if (workspaceStudentEntity == null) {
return Response.status(Status.NOT_FOUND).entity(String.format("Could not find workspace student entity %s from workspace entity %d", studentIdentifier, workspaceEntityId)).build();
}
if (!sessionController.hasWorkspacePermission(MuikkuPermissions.EVALUATE_USER, workspaceEntity)) {
return Response.status(Status.FORBIDDEN).build();
}
if (payload.getEvaluated() == null) {
return Response.status(Status.BAD_REQUEST).entity("evaluated is missing").build();
}
if (payload.getAssessorEntityId() == null) {
return Response.status(Status.BAD_REQUEST).entity("assessorEntityId is missing").build();
}
if (payload.getGradeSchoolDataSource() == null) {
return Response.status(Status.BAD_REQUEST).entity("gradeSchoolDataSource is missing").build();
}
if (payload.getGradeIdentifier() == null) {
return Response.status(Status.BAD_REQUEST).entity("gradeIdentifier is missing").build();
}
UserEntity assessor = userEntityController.findUserEntityById(payload.getAssessorEntityId());
if (assessor == null) {
return Response.status(Status.BAD_REQUEST).entity("assessor is invalid").build();
}
User assessingUser = userController.findUserByUserEntityDefaults(assessor);
if (assessingUser == null) {
return Response.status(Status.BAD_REQUEST).entity("Could not find assessor from school data source").build();
}
GradingScale gradingScale = gradingController.findGradingScale(payload.getGradingScaleSchoolDataSource(), payload.getGradingScaleIdentifier());
if (gradingScale == null) {
return Response.status(Status.BAD_REQUEST).entity("gradingScale is invalid").build();
}
GradingScaleItem grade = gradingController.findGradingScaleItem(gradingScale, payload.getGradeSchoolDataSource(), payload.getGradeIdentifier());
if (grade == null) {
return Response.status(Status.BAD_REQUEST).entity("grade is invalid").build();
}
fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser workspaceStudent = workspaceController.findWorkspaceUser(workspaceStudentEntity);
if (workspaceStudent == null) {
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(String.format("Failed to get workspace student for workspace student entity %d from school data source", workspaceStudentEntity.getId())).build();
}
Date evaluated = payload.getEvaluated();
UserEntity student = userEntityController.findUserEntityByUserIdentifier(workspaceStudent.getUserIdentifier());
Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment assessment = gradingController.createWorkspaceAssessment(workspaceStudent.getSchoolDataSource(), workspaceStudent, assessingUser, grade, payload.getVerbalAssessment(), evaluated);
if (student != null && workspace != null && assessment != null) {
sendAssessmentNotification(workspaceEntity, payload, assessor, student, workspace, grade.getName());
}
return Response.ok(createRestModel(workspaceEntity, assessment)).build();
}
use of fi.otavanopisto.muikku.schooldata.entity.GradingScale in project muikku by otavanopisto.
the class EvaluationRESTService method updateWorkspaceMaterialEvaluation.
@PUT
@Path("/workspaces/{WORKSPACEENTITYID}/materials/{WORKSPACEMATERIALID}/evaluations/{ID}")
@RESTPermit(handling = Handling.INLINE)
public Response updateWorkspaceMaterialEvaluation(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("WORKSPACEMATERIALID") Long workspaceMaterialId, @PathParam("ID") Long workspaceMaterialEvaluationId, WorkspaceMaterialEvaluation payload) {
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_UPDATEWORKSPACEMATERIALEVALUATION, workspaceEntity)) {
return Response.status(Status.FORBIDDEN).build();
}
WorkspaceMaterial workspaceMaterial = workspaceMaterialController.findWorkspaceMaterialById(workspaceMaterialId);
if (workspaceMaterial == null) {
return Response.status(Status.NOT_FOUND).entity("workspaceMaterial not found").build();
}
WorkspaceRootFolder rootFolder = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceNode(workspaceMaterial);
if (rootFolder == null) {
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}
if (!workspaceEntity.getId().equals(rootFolder.getWorkspaceEntityId())) {
return Response.status(Status.NOT_FOUND).build();
}
fi.otavanopisto.muikku.plugins.evaluation.model.WorkspaceMaterialEvaluation workspaceMaterialEvaluation = evaluationController.findWorkspaceMaterialEvaluation(workspaceMaterialEvaluationId);
if (workspaceMaterialEvaluation == null) {
return Response.status(Status.NOT_FOUND).build();
}
if (!workspaceMaterialEvaluation.getWorkspaceMaterialId().equals(workspaceMaterial.getId())) {
return Response.status(Status.NOT_FOUND).build();
}
if (payload.getEvaluated() == null) {
return Response.status(Status.BAD_REQUEST).entity("evaluated is missing").build();
}
if (payload.getAssessorEntityId() == null) {
return Response.status(Status.BAD_REQUEST).entity("assessorEntityId is missing").build();
}
if (payload.getGradingScaleSchoolDataSource() == null) {
return Response.status(Status.BAD_REQUEST).entity("gradingScaleSchoolDataSource is missing").build();
}
if (payload.getGradingScaleIdentifier() == null) {
return Response.status(Status.BAD_REQUEST).entity("gradingScaleIdentifier is missing").build();
}
if (payload.getGradeSchoolDataSource() == null) {
return Response.status(Status.BAD_REQUEST).entity("gradeSchoolDataSource is missing").build();
}
if (payload.getGradeIdentifier() == null) {
return Response.status(Status.BAD_REQUEST).entity("gradeIdentifier is missing").build();
}
UserEntity assessor = userEntityController.findUserEntityById(payload.getAssessorEntityId());
UserEntity student = userEntityController.findUserEntityById(payload.getStudentEntityId());
GradingScale gradingScale = gradingController.findGradingScale(payload.getGradingScaleSchoolDataSource(), payload.getGradingScaleIdentifier());
GradingScaleItem grade = gradingController.findGradingScaleItem(gradingScale, payload.getGradeSchoolDataSource(), payload.getGradeIdentifier());
if (assessor == null) {
return Response.status(Status.BAD_REQUEST).entity("assessor is invalid").build();
}
if (student == null) {
return Response.status(Status.BAD_REQUEST).entity("student is invalid").build();
}
if (gradingScale == null) {
return Response.status(Status.BAD_REQUEST).entity("gradingScale is invalid").build();
}
if (grade == null) {
return Response.status(Status.BAD_REQUEST).entity("grade is invalid").build();
}
Date evaluated = payload.getEvaluated();
workspaceMaterialEvaluation = evaluationController.updateWorkspaceMaterialEvaluation(workspaceMaterialEvaluation, gradingScale, grade, assessor, evaluated, payload.getVerbalAssessment());
return Response.ok(createRestModel(workspaceMaterialEvaluation)).build();
}
use of fi.otavanopisto.muikku.schooldata.entity.GradingScale in project muikku by otavanopisto.
the class EvaluationRESTService method createOrUpdateWorkspaceMaterialEvaluation.
@POST
@Path("/workspaces/{WORKSPACEENTITYID}/materials/{WORKSPACEMATERIALID}/evaluations/")
@RESTPermit(handling = Handling.INLINE)
public Response createOrUpdateWorkspaceMaterialEvaluation(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("WORKSPACEMATERIALID") Long workspaceMaterialId, WorkspaceMaterialEvaluation payload) {
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_CREATEWORKSPACEMATERIALEVALUATION, workspaceEntity)) {
return Response.status(Status.FORBIDDEN).build();
}
WorkspaceMaterial workspaceMaterial = workspaceMaterialController.findWorkspaceMaterialById(workspaceMaterialId);
if (workspaceMaterial == null) {
return Response.status(Status.NOT_FOUND).entity("workspaceMaterial not found").build();
}
WorkspaceRootFolder rootFolder = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceNode(workspaceMaterial);
if (rootFolder == null) {
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}
if (!workspaceEntity.getId().equals(rootFolder.getWorkspaceEntityId())) {
return Response.status(Status.NOT_FOUND).build();
}
if (payload.getEvaluated() == null) {
return Response.status(Status.BAD_REQUEST).entity("evaluated is missing").build();
}
if (payload.getAssessorEntityId() == null) {
return Response.status(Status.BAD_REQUEST).entity("assessorEntityId is missing").build();
}
if (payload.getStudentEntityId() == null) {
return Response.status(Status.BAD_REQUEST).entity("studentEntityId is missing").build();
}
if (payload.getGradingScaleSchoolDataSource() == null) {
return Response.status(Status.BAD_REQUEST).entity("gradingScaleSchoolDataSource is missing").build();
}
if (payload.getGradingScaleIdentifier() == null) {
return Response.status(Status.BAD_REQUEST).entity("gradingScaleIdentifier is missing").build();
}
if (payload.getGradeSchoolDataSource() == null) {
return Response.status(Status.BAD_REQUEST).entity("gradeSchoolDataSource is missing").build();
}
if (payload.getGradeIdentifier() == null) {
return Response.status(Status.BAD_REQUEST).entity("gradeIdentifier is missing").build();
}
UserEntity assessor = userEntityController.findUserEntityById(payload.getAssessorEntityId());
UserEntity student = userEntityController.findUserEntityById(payload.getStudentEntityId());
GradingScale gradingScale = gradingController.findGradingScale(payload.getGradingScaleSchoolDataSource(), payload.getGradingScaleIdentifier());
GradingScaleItem grade = gradingController.findGradingScaleItem(gradingScale, payload.getGradeSchoolDataSource(), payload.getGradeIdentifier());
if (assessor == null) {
return Response.status(Status.BAD_REQUEST).entity("assessor is invalid").build();
}
if (student == null) {
return Response.status(Status.BAD_REQUEST).entity("student is invalid").build();
}
if (gradingScale == null) {
return Response.status(Status.BAD_REQUEST).entity("gradingScale is invalid").build();
}
if (grade == null) {
return Response.status(Status.BAD_REQUEST).entity("grade is invalid").build();
}
if (evaluationController.findWorkspaceMaterialEvaluationByWorkspaceMaterialAndStudent(workspaceMaterial, student) != null) {
return Response.status(Status.BAD_REQUEST).entity("material already evaluated").build();
}
Date evaluated = payload.getEvaluated();
return Response.ok(createRestModel(evaluationController.createWorkspaceMaterialEvaluation(student, workspaceMaterial, gradingScale, grade, assessor, evaluated, payload.getVerbalAssessment()))).build();
}
use of fi.otavanopisto.muikku.schooldata.entity.GradingScale in project muikku by otavanopisto.
the class Evaluation2RESTService method updateWorkspaceAssessment.
@PUT
@Path("/workspace/{WORKSPACEENTITYID}/user/{USERENTITYID}/assessment")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response updateWorkspaceAssessment(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("USERENTITYID") Long userEntityId, RestAssessment payload) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).build();
}
if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.ACCESS_EVALUATION)) {
return Response.status(Status.FORBIDDEN).build();
}
// Entities and identifiers
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
UserEntity userEntity = userEntityController.findUserEntityById(userEntityId);
Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
if (workspaceEntity == null || userEntity == null || workspace == null) {
return Response.status(Status.BAD_REQUEST).build();
}
SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(workspaceEntity.getIdentifier(), workspaceEntity.getDataSource().getIdentifier());
SchoolDataIdentifier userIdentifier = new SchoolDataIdentifier(userEntity.getDefaultIdentifier(), userEntity.getDefaultSchoolDataSource().getIdentifier());
// TODO listWorkspaceAssessments is incorrect; one student in one workspace should have one assessment at most
List<WorkspaceAssessment> workspaceAssessments = gradingController.listWorkspaceAssessments(workspaceIdentifier, userIdentifier);
WorkspaceAssessment workspaceAssessment = workspaceAssessments.isEmpty() ? null : workspaceAssessments.get(0);
if (workspaceAssessment == null) {
return Response.status(Status.NOT_FOUND).build();
}
// Workspace user
WorkspaceUser workspaceUser = workspaceController.findWorkspaceUserByWorkspaceAndUser(workspaceIdentifier, userIdentifier);
// Assessor
SchoolDataIdentifier assessorIdentifier = SchoolDataIdentifier.fromId(payload.getAssessorIdentifier());
User assessingUser = userController.findUserByIdentifier(assessorIdentifier);
UserEntity assessingUserEntity = userEntityController.findUserEntityByUser(assessingUser);
// Grade
SchoolDataIdentifier gradingScaleIdentifier = SchoolDataIdentifier.fromId(payload.getGradingScaleIdentifier());
GradingScale gradingScale = gradingController.findGradingScale(gradingScaleIdentifier);
SchoolDataIdentifier gradeIdentifier = SchoolDataIdentifier.fromId(payload.getGradeIdentifier());
GradingScaleItem gradingScaleItem = gradingController.findGradingScaleItem(gradingScale, gradeIdentifier);
// Update
workspaceAssessment = gradingController.updateWorkspaceAssessment(workspaceAssessment.getIdentifier(), workspaceUser, assessingUser, gradingScaleItem, payload.getVerbalAssessment(), payload.getAssessmentDate());
// Notification
sendAssessmentNotification(workspaceEntity, workspaceAssessment, assessingUserEntity, userEntity, workspace, gradingScaleItem.getName());
// Back to rest
RestAssessment restAssessment = new RestAssessment(workspaceAssessment.getIdentifier().toId(), workspaceAssessment.getAssessingUserIdentifier().toId(), workspaceAssessment.getGradingScaleIdentifier().toId(), workspaceAssessment.getGradeIdentifier().toId(), workspaceAssessment.getVerbalAssessment(), workspaceAssessment.getDate(), workspaceAssessment.getPassing());
return Response.ok(restAssessment).build();
}
use of fi.otavanopisto.muikku.schooldata.entity.GradingScale in project muikku by otavanopisto.
the class Evaluation2RESTService method createWorkspaceAssessment.
@POST
@Path("/workspace/{WORKSPACEENTITYID}/user/{USERENTITYID}/assessment")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response createWorkspaceAssessment(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("USERENTITYID") Long userEntityId, RestAssessment payload) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).build();
}
if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.ACCESS_EVALUATION)) {
return Response.status(Status.FORBIDDEN).build();
}
// Entities and identifiers
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
UserEntity userEntity = userEntityController.findUserEntityById(userEntityId);
Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
if (workspaceEntity == null || userEntity == null || workspace == null) {
return Response.status(Status.BAD_REQUEST).build();
}
SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(workspaceEntity.getIdentifier(), workspaceEntity.getDataSource().getIdentifier());
SchoolDataIdentifier userIdentifier = new SchoolDataIdentifier(userEntity.getDefaultIdentifier(), userEntity.getDefaultSchoolDataSource().getIdentifier());
// TODO listWorkspaceAssessments is incorrect; one student in one workspace should have one assessment at most
List<WorkspaceAssessment> workspaceAssessments = gradingController.listWorkspaceAssessments(workspaceIdentifier, userIdentifier);
WorkspaceAssessment workspaceAssessment = workspaceAssessments.isEmpty() ? null : workspaceAssessments.get(0);
// Workspace user
WorkspaceUser workspaceUser = workspaceController.findWorkspaceUserByWorkspaceAndUser(workspaceIdentifier, userIdentifier);
// Assessor
SchoolDataIdentifier assessorIdentifier = SchoolDataIdentifier.fromId(payload.getAssessorIdentifier());
User assessingUser = userController.findUserByIdentifier(assessorIdentifier);
UserEntity assessingUserEntity = assessingUser == null ? null : userEntityController.findUserEntityByUser(assessingUser);
// Grade
SchoolDataIdentifier gradingScaleIdentifier = SchoolDataIdentifier.fromId(payload.getGradingScaleIdentifier());
GradingScale gradingScale = gradingController.findGradingScale(gradingScaleIdentifier);
SchoolDataIdentifier gradeIdentifier = SchoolDataIdentifier.fromId(payload.getGradeIdentifier());
GradingScaleItem gradingScaleItem = gradingController.findGradingScaleItem(gradingScale, gradeIdentifier);
if (workspaceAssessment == null) {
workspaceAssessment = gradingController.createWorkspaceAssessment(workspaceIdentifier.getDataSource(), workspaceUser, assessingUser, gradingScaleItem, payload.getVerbalAssessment(), payload.getAssessmentDate());
} else {
workspaceAssessment = gradingController.updateWorkspaceAssessment(workspaceAssessment.getIdentifier(), workspaceUser, assessingUser, gradingScaleItem, payload.getVerbalAssessment(), payload.getAssessmentDate());
}
// Delete workspace supplementation request (if any)
SupplementationRequest supplementationRequest = evaluationController.findSupplementationRequestByStudentAndWorkspace(userEntity.getId(), workspaceEntity.getId());
if (supplementationRequest != null) {
evaluationController.deleteSupplementationRequest(supplementationRequest);
}
// Notification
sendAssessmentNotification(workspaceEntity, workspaceAssessment, assessingUserEntity, userEntity, workspace, gradingScaleItem.getName());
// Back to rest
RestAssessment restAssessment = new RestAssessment(workspaceAssessment.getIdentifier().toId(), workspaceAssessment.getAssessingUserIdentifier().toId(), workspaceAssessment.getGradingScaleIdentifier().toId(), workspaceAssessment.getGradeIdentifier().toId(), workspaceAssessment.getVerbalAssessment(), workspaceAssessment.getDate(), workspaceAssessment.getPassing());
return Response.ok(restAssessment).build();
}
Aggregations