use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class Evaluation2RESTService method findWorkspaceSupplementationRequest.
@GET
@Path("/workspace/{WORKSPACEENTITYID}/user/{USERENTITYID}/supplementationrequest")
@RESTPermit(handling = Handling.INLINE)
public Response findWorkspaceSupplementationRequest(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("USERENTITYID") Long userEntityId) {
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 entity
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.NOT_FOUND).entity("workspaceEntity not found").build();
}
// Workspace supplementation request
SupplementationRequest supplementationRequest = evaluationController.findSupplementationRequestByStudentAndWorkspace(userEntityId, workspaceEntityId);
if (supplementationRequest == null) {
return Response.status(Status.NOT_FOUND).build();
}
// SupplementationRequest to RestSupplementationRequest
RestSupplementationRequest restSupplementationRequest = new RestSupplementationRequest(supplementationRequest.getId(), supplementationRequest.getUserEntityId(), supplementationRequest.getStudentEntityId(), supplementationRequest.getWorkspaceEntityId(), supplementationRequest.getWorkspaceMaterialId(), supplementationRequest.getRequestDate(), supplementationRequest.getRequestText());
return Response.ok(restSupplementationRequest).build();
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class EvaluationController method handleSupplementationNotifications.
/**
* Handles all notification messages related to the given supplementation request.
*
* @param supplementationRequest Supplementation request
*/
private void handleSupplementationNotifications(SupplementationRequest supplementationRequest) {
Long teacherEntityId = supplementationRequest.getUserEntityId();
Long studentEntityId = supplementationRequest.getStudentEntityId();
Long workspaceEntityId = supplementationRequest.getWorkspaceEntityId();
Long workspaceMaterialId = supplementationRequest.getWorkspaceMaterialId();
String requestText = supplementationRequest.getRequestText();
if (studentEntityId != null && workspaceMaterialId != null) {
UserEntity student = userEntityController.findUserEntityById(studentEntityId);
WorkspaceMaterial workspaceMaterial = workspaceMaterialController.findWorkspaceMaterialById(workspaceMaterialId);
if (student != null && workspaceMaterial != null) {
WorkspaceMaterialReply reply = workspaceMaterialReplyController.findWorkspaceMaterialReplyByWorkspaceMaterialAndUserEntity(workspaceMaterial, student);
if (reply == null) {
workspaceMaterialReplyController.createWorkspaceMaterialReply(workspaceMaterial, WorkspaceMaterialReplyState.INCOMPLETE, student);
} else {
workspaceMaterialReplyController.updateWorkspaceMaterialReply(reply, WorkspaceMaterialReplyState.INCOMPLETE);
}
}
} else if (studentEntityId != null && workspaceEntityId != null) {
// Send notification of an incomplete workspace
UserEntity teacher = userEntityController.findUserEntityById(teacherEntityId);
UserEntity student = userEntityController.findUserEntityById(studentEntityId);
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
notifyOfIncompleteWorkspace(teacher, student, workspaceEntity, requestText);
}
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class EvaluationMainViewBackingBean method init.
@RequestAction
public String init() {
UserEntity userEntity = sessionController.getLoggedUserEntity();
if (userEntity == null) {
return NavigationRules.ACCESS_DENIED;
}
WorkspaceEntity workspaceEntity = null;
if (workspaceEntityId != null) {
workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return NavigationRules.NOT_FOUND;
}
Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
if (workspace == null) {
return NavigationRules.NOT_FOUND;
}
setWorkspaceName(workspace.getName());
if (!StringUtils.isEmpty(workspace.getNameExtension())) {
setWorkspaceName(getWorkspaceName() + String.format(" (%s)", workspace.getNameExtension()));
}
}
if (workspaceEntity == null) {
if (!sessionController.hasEnvironmentPermission(EvaluationResourcePermissionCollection.EVALUATION_VIEW_INDEX)) {
return NavigationRules.ACCESS_DENIED;
}
} else {
if (!sessionController.hasWorkspacePermission(EvaluationResourcePermissionCollection.EVALUATION_VIEW_INDEX, workspaceEntity)) {
return NavigationRules.ACCESS_DENIED;
}
}
return null;
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity 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.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class EvaluationRESTService method updateWorkspaceAssessment.
@PUT
@Path("/workspaces/{WORKSPACEENTITYID}/students/{STUDENTID}/assessments/{EVALUATIONID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response updateWorkspaceAssessment(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("STUDENTID") String studentId, @PathParam("EVALUATIONID") String workspaceAssesmentId, 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();
}
SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(workspaceEntity.getIdentifier(), workspaceEntity.getDataSource().getIdentifier());
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();
}
SchoolDataIdentifier workspaceAssesmentIdentifier = SchoolDataIdentifier.fromId(workspaceAssesmentId);
if (workspaceAssesmentIdentifier == null) {
return Response.status(Status.BAD_REQUEST).entity(String.format("Malformed workspace assessment identifier %s", workspaceAssesmentIdentifier)).build();
}
fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment workspaceAssessment = gradingController.findWorkspaceAssessment(workspaceIdentifier, studentIdentifier, workspaceAssesmentIdentifier);
if (workspaceAssessment == null) {
return Response.status(Status.NOT_FOUND).entity(String.format("Could not find workspace assessment %s from workspace entity %d, student identifer %s", workspaceAssesmentId, workspaceEntityId, studentIdentifier)).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();
}
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();
}
if (payload.getGradeSchoolDataSource() == null) {
return Response.status(Status.BAD_REQUEST).entity("gradeSchoolDataSource is missing").build();
}
GradingScale gradingScale = gradingController.findGradingScale(payload.getGradingScaleSchoolDataSource(), payload.getGradingScaleIdentifier());
if (gradingScale == null) {
return Response.status(Status.BAD_REQUEST).entity("gradingScale is invalid").build();
}
if (payload.getGradeIdentifier() == null) {
return Response.status(Status.BAD_REQUEST).entity("gradeIdentifier is missing").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.updateWorkspaceAssessment(workspaceAssesmentIdentifier, 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();
}
Aggregations