use of fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessmentRequest in project muikku by otavanopisto.
the class Evaluation2RESTService method archiveWorkspaceAssessmentRequest.
// TODO update only one, find by id
@PUT
@Path("/workspace/{WORKSPACEENTITYID}/user/{USERENTITYID}/evaluationrequestarchive")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response archiveWorkspaceAssessmentRequest(@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();
}
// Entities and identifiers
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
UserEntity userEntity = userEntityController.findUserEntityById(userEntityId);
SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(workspaceEntity.getIdentifier(), workspaceEntity.getDataSource().getIdentifier());
SchoolDataIdentifier userIdentifier = new SchoolDataIdentifier(userEntity.getDefaultIdentifier(), userEntity.getDefaultSchoolDataSource().getIdentifier());
List<WorkspaceAssessmentRequest> requests = gradingController.listWorkspaceAssessmentRequests(workspaceIdentifier.getDataSource(), workspaceIdentifier.getIdentifier(), userIdentifier.getIdentifier());
if (CollectionUtils.isNotEmpty(requests)) {
for (WorkspaceAssessmentRequest request : requests) {
gradingController.updateWorkspaceAssessmentRequest(request.getSchoolDataSource(), request.getIdentifier(), request.getWorkspaceUserIdentifier(), request.getWorkspaceUserSchoolDataSource(), workspaceIdentifier.getIdentifier(), userIdentifier.getIdentifier(), request.getRequestText(), request.getDate(), // archived
Boolean.TRUE, request.getHandled());
}
return Response.noContent().build();
}
return Response.status(Status.BAD_REQUEST).build();
}
use of fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessmentRequest in project muikku by otavanopisto.
the class AssessmentRequestRESTService method deleteAssessmentRequest.
@DELETE
@Path("/workspace/{WORKSPACEENTITYID}/assessmentRequests/{ID}")
@RESTPermitUnimplemented
public Response deleteAssessmentRequest(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("ID") String assessmentRequestId) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).build();
}
if (assessmentRequestId == null) {
return Response.status(Status.BAD_REQUEST).entity("Invalid assessmentRequestIdentifier").build();
}
SchoolDataIdentifier assessmentRequestIdentifier = SchoolDataIdentifier.fromId(assessmentRequestId);
if (assessmentRequestIdentifier == null) {
return Response.status(Status.BAD_REQUEST).entity("Invalid assessmentRequestIdentifier").build();
}
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.NOT_FOUND).entity("Workspace entity not found").build();
}
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findActiveWorkspaceUserByWorkspaceEntityAndUserIdentifier(workspaceEntity, sessionController.getLoggedUser());
if (workspaceUserEntity == null) {
return Response.status(Status.NOT_FOUND).entity("Workspace user entity not found").build();
}
SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(workspaceEntity.getIdentifier(), workspaceEntity.getDataSource().getIdentifier());
SchoolDataIdentifier studentIdentifier = new SchoolDataIdentifier(workspaceUserEntity.getUserSchoolDataIdentifier().getIdentifier(), workspaceUserEntity.getUserSchoolDataIdentifier().getDataSource().getIdentifier());
if (!sessionController.getLoggedUser().equals(studentIdentifier)) {
return Response.status(Status.FORBIDDEN).build();
}
SchoolDataIdentifier workspaceStudentIdentifier = new SchoolDataIdentifier(workspaceUserEntity.getIdentifier(), workspaceUserEntity.getUserSchoolDataIdentifier().getDataSource().getIdentifier());
WorkspaceAssessmentRequest assessmentRequest = assessmentRequestController.findWorkspaceAssessmentRequest(assessmentRequestIdentifier, workspaceIdentifier, studentIdentifier);
if (assessmentRequest != null) {
SchoolDataIdentifier assessmentRequestWorkspaceUserIdentifier = new SchoolDataIdentifier(assessmentRequest.getWorkspaceUserIdentifier(), assessmentRequest.getSchoolDataSource());
if (assessmentRequestWorkspaceUserIdentifier.equals(workspaceStudentIdentifier)) {
assessmentRequestController.deleteWorkspaceAssessmentRequest(workspaceUserEntity, assessmentRequestIdentifier);
communicatorAssessmentRequestController.sendAssessmentRequestCancelledMessage(workspaceUserEntity);
} else {
return Response.status(Status.FORBIDDEN).build();
}
} else {
return Response.status(Status.NOT_FOUND).entity("Could not find assessment request").build();
}
return Response.noContent().build();
}
use of fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessmentRequest in project muikku by otavanopisto.
the class GradingController method restoreLatestAssessmentRequest.
public void restoreLatestAssessmentRequest(SchoolDataIdentifier workspaceIdentifier, SchoolDataIdentifier studentIdentifier) {
List<WorkspaceAssessmentRequest> requests = listWorkspaceAssessmentRequests(workspaceIdentifier.getDataSource(), workspaceIdentifier.getIdentifier(), studentIdentifier.getIdentifier());
if (CollectionUtils.isNotEmpty(requests)) {
requests.sort(new Comparator<WorkspaceAssessmentRequest>() {
public int compare(WorkspaceAssessmentRequest o1, WorkspaceAssessmentRequest o2) {
// latest request first
return o2.getDate().compareTo(o1.getDate());
}
});
// Mark the latest request as not handled
WorkspaceAssessmentRequest latestRequest = requests.get(0);
updateWorkspaceAssessmentRequest(latestRequest.getSchoolDataSource(), latestRequest.getIdentifier(), latestRequest.getWorkspaceUserIdentifier(), latestRequest.getWorkspaceUserSchoolDataSource(), workspaceIdentifier.getIdentifier(), studentIdentifier.getIdentifier(), latestRequest.getRequestText(), latestRequest.getDate(), latestRequest.getArchived(), // not handled
Boolean.FALSE);
}
}
use of fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessmentRequest in project muikku by otavanopisto.
the class AssessmentRequestNotificationStrategy method getStudentIdentifiersWithoutEvaluationActivity.
private List<SchoolDataIdentifier> getStudentIdentifiersWithoutEvaluationActivity(SearchResult searchResult) {
List<SchoolDataIdentifier> studentIdentifiers = new ArrayList<>();
for (Map<String, Object> result : searchResult.getResults()) {
// Convert the search result id into SchoolDataIdentifier. Skip student if this fails.
String studentId = (String) result.get("id");
if (StringUtils.isBlank(studentId)) {
logger.severe("Could not process user found from search index because it had a null id");
continue;
}
String[] studentIdParts = studentId.split("/", 2);
SchoolDataIdentifier studentIdentifier = studentIdParts.length == 2 ? new SchoolDataIdentifier(studentIdParts[0], studentIdParts[1]) : null;
if (studentIdentifier == null) {
logger.severe(String.format("Could not process user found from search index with id %s", studentId));
continue;
}
// Find the student by SchoolDataIdentifier
User student = userController.findUserByIdentifier(studentIdentifier);
if (student != null) {
if (student.getStudyStartDate() == null || student.getStudyEndDate() != null) {
continue;
}
// Students that have started their studies in the last 60 days should not be notified
// (given searchResult should not even contain these but let's check it once more, just in case)
OffsetDateTime thresholdDateTime = OffsetDateTime.now().minusDays(NOTIFICATION_THRESHOLD_DAYS);
if (student.getStudyStartDate().isAfter(thresholdDateTime)) {
logger.severe(String.format("Skipping student id %s that just started studies", studentId));
continue;
}
// Check if student has made any assessment requests. If they have, they don't need to be notified
WorkspaceAssessmentRequest latestRequest = gradingController.findLatestAssessmentRequestByIdentifier(studentIdentifier);
if (latestRequest != null) {
continue;
}
// Check if student has any workspace assessments. If they have, they don't need to be notified
WorkspaceAssessment latestAssessment = gradingController.findLatestWorkspaceAssessmentByIdentifier(studentIdentifier);
if (latestAssessment != null) {
continue;
}
// By this point, we can be certain that the student has to be notified
studentIdentifiers.add(studentIdentifier);
}
}
return studentIdentifiers;
}
Aggregations