use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class WorkspaceRESTService method listJournalEntries.
@GET
@Path("/workspaces/{WORKSPACEID}/journal")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listJournalEntries(@PathParam("WORKSPACEID") Long workspaceEntityId, @QueryParam("userEntityId") Long userEntityId, @QueryParam("workspaceStudentId") String workspaceStudentId, @QueryParam("firstResult") @DefaultValue("0") Integer firstResult, @QueryParam("maxResults") @DefaultValue("25") Integer maxResults) {
List<WorkspaceJournalEntry> entries = new ArrayList<>();
List<WorkspaceJournalEntryRESTModel> result = new ArrayList<>();
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.NOT_FOUND).build();
}
UserEntity userEntity = sessionController.getLoggedUserEntity();
boolean canListAllEntries = sessionController.hasWorkspacePermission(MuikkuPermissions.LIST_ALL_JOURNAL_ENTRIES, workspaceEntity);
if (workspaceStudentId == null && userEntityId == null && canListAllEntries) {
List<WorkspaceUserEntity> workspaceUserEntities = workspaceUserEntityController.listActiveWorkspaceStudents(workspaceEntity);
Set<UserEntity> userEntities = new HashSet<>();
for (WorkspaceUserEntity workspaceUserEntity : workspaceUserEntities) {
userEntities.add(workspaceUserEntity.getUserSchoolDataIdentifier().getUserEntity());
}
entries = workspaceJournalController.listEntriesForStudents(workspaceEntity, userEntities, firstResult, maxResults);
} else {
if (userEntityId != null) {
// List by user entity (Muikku)
if (!userEntityId.equals(userEntity.getId())) {
if (canListAllEntries) {
userEntity = userEntityController.findUserEntityById(userEntityId);
if (userEntity == null) {
return Response.status(Status.NOT_FOUND).build();
}
} else {
return Response.status(Status.FORBIDDEN).build();
}
}
} else if (workspaceStudentId != null) {
// List by workspace student (school data)
SchoolDataIdentifier workspaceUserIdentifier = SchoolDataIdentifier.fromId(workspaceStudentId);
if (workspaceUserIdentifier == null) {
return Response.status(Status.BAD_REQUEST).entity("Invalid workspaceStudentId").build();
}
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifierIncludeArchived(workspaceUserIdentifier);
if (workspaceUserEntity == null) {
return Response.status(Status.NOT_FOUND).build();
}
UserEntity userEntityFromWorkspaceUser = workspaceUserEntity.getUserSchoolDataIdentifier().getUserEntity();
if (userEntityFromWorkspaceUser == null) {
return Response.status(Status.NOT_FOUND).build();
}
if (!canListAllEntries) {
if (!userEntity.getId().equals(userEntityFromWorkspaceUser.getId())) {
return Response.status(Status.FORBIDDEN).build();
}
} else {
userEntity = userEntityFromWorkspaceUser;
}
}
entries = workspaceJournalController.listEntriesByWorkspaceEntityAndUserEntity(workspaceEntity, userEntity, firstResult, maxResults);
}
for (WorkspaceJournalEntry entry : entries) {
UserEntity entryUserEntity = userEntityController.findUserEntityById(entry.getUserEntityId());
if (entryUserEntity != null) {
User user = userController.findUserByUserEntityDefaults(entryUserEntity);
if (user != null) {
result.add(new WorkspaceJournalEntryRESTModel(entry.getId(), entry.getWorkspaceEntityId(), entry.getUserEntityId(), user.getFirstName(), user.getLastName(), entry.getHtml(), entry.getTitle(), entry.getCreated()));
}
}
}
return Response.ok(result).build();
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class WorkspaceRESTService method updateWorkspaceStudent.
@PUT
@Path("/workspaces/{WORKSPACEENTITYID}/students/{ID}")
@RESTPermit(handling = Handling.INLINE)
public Response updateWorkspaceStudent(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("ID") String workspaceStudentId, WorkspaceStudent workspaceStudent) {
// Workspace
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.BAD_REQUEST).build();
}
// Access check
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).entity("Not logged in").build();
}
if (!sessionController.hasWorkspacePermission(MuikkuPermissions.MANAGE_WORKSPACE_MEMBERS, workspaceEntity)) {
return Response.status(Status.FORBIDDEN).build();
}
// Workspace student and school data user
SchoolDataIdentifier workspaceUserIdentifier = SchoolDataIdentifier.fromId(workspaceStudentId);
if (workspaceUserIdentifier == null) {
return Response.status(Status.BAD_REQUEST).entity("Invalid workspace user id").build();
}
SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(workspaceEntity.getIdentifier(), workspaceEntity.getDataSource().getIdentifier());
fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser bridgeUser = workspaceController.findWorkspaceUser(workspaceIdentifier, workspaceUserIdentifier);
if (bridgeUser == null) {
return Response.status(Status.NOT_FOUND).entity("School data user not found").build();
}
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifier(workspaceUserIdentifier);
// Reindex user when switching between active and inactive
if (workspaceStudent.getActive() != null && !workspaceStudent.getActive().equals(workspaceUserEntity.getActive())) {
workspaceController.updateWorkspaceStudentActivity(bridgeUser, workspaceStudent.getActive());
workspaceUserEntityController.updateActive(workspaceUserEntity, workspaceStudent.getActive());
UserSchoolDataIdentifier userSchoolDataIdentifier = workspaceUserEntity.getUserSchoolDataIdentifier();
userIndexer.indexUser(userSchoolDataIdentifier.getDataSource().getIdentifier(), userSchoolDataIdentifier.getIdentifier());
}
return Response.ok(workspaceStudent).build();
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class Evaluation2RESTService method listAssessmentRequests.
@GET
@Path("/compositeAssessmentRequests")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listAssessmentRequests(@QueryParam("workspaceEntityId") Long workspaceEntityId) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).build();
}
if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.ACCESS_EVALUATION)) {
return Response.status(Status.FORBIDDEN).build();
}
List<RestAssessmentRequest> restAssessmentRequests = new ArrayList<RestAssessmentRequest>();
if (workspaceEntityId == null) {
// List assessment requests by staff member
SchoolDataIdentifier loggedUser = sessionController.getLoggedUser();
List<CompositeAssessmentRequest> assessmentRequests = gradingController.listAssessmentRequestsByStaffMember(loggedUser);
for (CompositeAssessmentRequest assessmentRequest : assessmentRequests) {
restAssessmentRequests.add(toRestAssessmentRequest(assessmentRequest));
}
} else {
// List assessment requests by workspace
List<String> workspaceStudentIdentifiers = new ArrayList<String>();
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(workspaceEntity.getIdentifier(), workspaceEntity.getDataSource().getIdentifier());
List<WorkspaceUserEntity> workspaceUserEntities = workspaceUserEntityController.listActiveWorkspaceStudents(workspaceEntity);
for (WorkspaceUserEntity workspaceUserEntity : workspaceUserEntities) {
workspaceStudentIdentifiers.add(workspaceUserEntity.getIdentifier());
}
List<CompositeAssessmentRequest> assessmentRequests = gradingController.listAssessmentRequestsByWorkspace(workspaceIdentifier, workspaceStudentIdentifiers);
for (CompositeAssessmentRequest assessmentRequest : assessmentRequests) {
restAssessmentRequests.add(toRestAssessmentRequest(assessmentRequest));
}
}
return Response.ok(restAssessmentRequests).build();
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity 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.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class Evaluation2RESTService method toRestAssessmentRequest.
private RestAssessmentRequest toRestAssessmentRequest(CompositeAssessmentRequest compositeAssessmentRequest) {
Long assignmentsDone = 0L;
Long assignmentsTotal = 0L;
// Assignments total
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceByIdentifier(compositeAssessmentRequest.getCourseIdentifier());
if (workspaceEntity == null) {
logger.severe(String.format("WorkspaceEntity for course %s not found", compositeAssessmentRequest.getCourseIdentifier()));
} else {
List<WorkspaceMaterial> evaluatedAssignments = workspaceMaterialController.listVisibleWorkspaceMaterialsByAssignmentType(workspaceEntity, WorkspaceMaterialAssignmentType.EVALUATED);
assignmentsTotal = new Long(evaluatedAssignments.size());
// Assignments done by user
if (assignmentsTotal > 0) {
UserEntity userEntity = userEntityController.findUserEntityByUserIdentifier(compositeAssessmentRequest.getUserIdentifier());
if (userEntity == null) {
logger.severe(String.format("UserEntity not found for AssessmentRequest student %s not found", compositeAssessmentRequest.getUserIdentifier()));
} else {
List<WorkspaceMaterialReplyState> replyStates = new ArrayList<WorkspaceMaterialReplyState>();
replyStates.add(WorkspaceMaterialReplyState.FAILED);
replyStates.add(WorkspaceMaterialReplyState.PASSED);
replyStates.add(WorkspaceMaterialReplyState.SUBMITTED);
replyStates.add(WorkspaceMaterialReplyState.INCOMPLETE);
assignmentsDone = workspaceMaterialReplyController.getReplyCountByUserEntityAndReplyStatesAndWorkspaceMaterials(userEntity.getId(), replyStates, evaluatedAssignments);
}
}
}
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifierIncludeArchived(compositeAssessmentRequest.getCourseStudentIdentifier());
UserEntity userEntity = userEntityController.findUserEntityByUserIdentifier(compositeAssessmentRequest.getUserIdentifier());
// An active workspace supplementation request will override graded, passing, and evaluationDate
Boolean graded = Boolean.TRUE;
Boolean passing = compositeAssessmentRequest.getPassing();
Date evaluationDate = compositeAssessmentRequest.getEvaluationDate();
if (userEntity != null) {
SupplementationRequest supplementationRequest = evaluationController.findSupplementationRequestByStudentAndWorkspaceAndArchived(userEntity.getId(), workspaceEntity.getId(), Boolean.FALSE);
if (supplementationRequest != null) {
graded = Boolean.FALSE;
passing = Boolean.FALSE;
evaluationDate = supplementationRequest.getRequestDate();
}
}
RestAssessmentRequest restAssessmentRequest = new RestAssessmentRequest();
restAssessmentRequest.setWorkspaceUserEntityId(workspaceUserEntity == null ? null : workspaceUserEntity.getId());
restAssessmentRequest.setWorkspaceUserIdentifier(compositeAssessmentRequest.getCourseStudentIdentifier().toId());
restAssessmentRequest.setUserEntityId(userEntity == null ? null : userEntity.getId());
restAssessmentRequest.setAssessmentRequestDate(compositeAssessmentRequest.getAssessmentRequestDate());
restAssessmentRequest.setEvaluationDate(evaluationDate);
restAssessmentRequest.setPassing(passing);
restAssessmentRequest.setGraded(graded);
restAssessmentRequest.setAssignmentsDone(assignmentsDone);
restAssessmentRequest.setAssignmentsTotal(assignmentsTotal);
restAssessmentRequest.setEnrollmentDate(compositeAssessmentRequest.getCourseEnrollmentDate());
restAssessmentRequest.setFirstName(compositeAssessmentRequest.getFirstName());
restAssessmentRequest.setLastName(compositeAssessmentRequest.getLastName());
restAssessmentRequest.setStudyProgramme(compositeAssessmentRequest.getStudyProgramme());
restAssessmentRequest.setWorkspaceEntityId(workspaceEntity == null ? null : workspaceEntity.getId());
restAssessmentRequest.setWorkspaceName(compositeAssessmentRequest.getCourseName());
restAssessmentRequest.setWorkspaceNameExtension(compositeAssessmentRequest.getCourseNameExtension());
restAssessmentRequest.setWorkspaceUrlName(workspaceEntity == null ? null : workspaceEntity.getUrlName());
return restAssessmentRequest;
}
Aggregations