use of fi.otavanopisto.muikku.model.users.UserEntity 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.users.UserEntity 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.users.UserEntity 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());
}
use of fi.otavanopisto.muikku.model.users.UserEntity 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();
}
use of fi.otavanopisto.muikku.model.users.UserEntity 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();
}
Aggregations