use of fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessmentRequest in project muikku by otavanopisto.
the class AssessmentRequestController method getWorkspaceAssessmentState.
public WorkspaceAssessmentState getWorkspaceAssessmentState(WorkspaceUserEntity workspaceUserEntity) {
WorkspaceEntity workspaceEntity = workspaceUserEntity.getWorkspaceEntity();
// List all asssessments
List<WorkspaceAssessment> workspaceAssessments = gradingController.listWorkspaceAssessments(workspaceEntity.getDataSource().getIdentifier(), workspaceEntity.getIdentifier(), workspaceUserEntity.getUserSchoolDataIdentifier().getIdentifier());
// Sort latest assessment first
if (!workspaceAssessments.isEmpty()) {
workspaceAssessments.sort(new Comparator<WorkspaceAssessment>() {
public int compare(WorkspaceAssessment o1, WorkspaceAssessment o2) {
return o2.getDate().compareTo(o1.getDate());
}
});
}
// List all assessment requests
List<WorkspaceAssessmentRequest> assessmentRequests = gradingController.listWorkspaceAssessmentRequests(workspaceEntity.getDataSource().getIdentifier(), workspaceEntity.getIdentifier(), workspaceUserEntity.getUserSchoolDataIdentifier().getIdentifier());
if (!assessmentRequests.isEmpty()) {
// Strip assessment requests that have been handled (TODO could be handled in Pyramus)
for (int i = assessmentRequests.size() - 1; i >= 0; i--) {
if (assessmentRequests.get(i).getHandled()) {
assessmentRequests.remove(i);
}
}
if (!assessmentRequests.isEmpty()) {
// Sort latest assessment request first
assessmentRequests.sort(new Comparator<WorkspaceAssessmentRequest>() {
public int compare(WorkspaceAssessmentRequest o1, WorkspaceAssessmentRequest o2) {
return o2.getDate().compareTo(o1.getDate());
}
});
}
}
WorkspaceAssessment latestAssessment = workspaceAssessments.isEmpty() ? null : workspaceAssessments.get(0);
WorkspaceAssessmentRequest latestRequest = assessmentRequests.isEmpty() ? null : assessmentRequests.get(0);
if (latestAssessment != null && (latestRequest == null || latestRequest.getDate().before(latestAssessment.getDate()))) {
// Has assessment and no request, or the request is older
GradingScale gradingScale = gradingController.findGradingScale(latestAssessment.getGradingScaleIdentifier());
GradingScaleItem grade = gradingController.findGradingScaleItem(gradingScale, latestAssessment.getGradeIdentifier());
return grade.isPassingGrade() ? new WorkspaceAssessmentState(WorkspaceAssessmentState.PASS, latestAssessment.getDate()) : new WorkspaceAssessmentState(WorkspaceAssessmentState.FAIL, latestAssessment.getDate());
} else if (latestRequest != null && (latestAssessment == null || latestAssessment.getDate().before(latestRequest.getDate()))) {
// Has request and no assessment, or the assessment is older
if (latestAssessment == null) {
return new WorkspaceAssessmentState(WorkspaceAssessmentState.PENDING, latestRequest.getDate());
} else if (Boolean.TRUE.equals(latestAssessment.getPassing())) {
return new WorkspaceAssessmentState(WorkspaceAssessmentState.PENDING_PASS, latestRequest.getDate());
} else {
return new WorkspaceAssessmentState(WorkspaceAssessmentState.PENDING_FAIL, latestRequest.getDate());
}
} else {
// Has neither assessment nor request
return new WorkspaceAssessmentState(WorkspaceAssessmentState.UNASSESSED);
}
}
use of fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessmentRequest in project muikku by otavanopisto.
the class AssessmentRequestRESTService method createAssessmentRequest.
@POST
@Path("/workspace/{WORKSPACEENTITYID}/assessmentRequests")
@RESTPermitUnimplemented
public Response createAssessmentRequest(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, AssessmentRequestRESTModel newAssessmentRequest) {
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.BAD_REQUEST).build();
}
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).build();
}
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findActiveWorkspaceUserByWorkspaceEntityAndUserIdentifier(workspaceEntity, sessionController.getLoggedUser());
try {
WorkspaceAssessmentRequest assessmentRequest = assessmentRequestController.createWorkspaceAssessmentRequest(workspaceUserEntity, newAssessmentRequest.getRequestText());
communicatorAssessmentRequestController.sendAssessmentRequestMessage(assessmentRequest);
return Response.ok(restModel(assessmentRequest)).build();
} catch (Exception e) {
logger.log(Level.SEVERE, "Couldn't create workspace assessment request.", e);
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}
}
use of fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessmentRequest in project muikku by otavanopisto.
the class AssessmentRequestRESTService method listAssessmentRequestsByWorkspaceId.
@GET
@Path("/workspace/{WORKSPACEENTITYID}/assessmentRequests")
@RESTPermit(handling = Handling.INLINE)
public Response listAssessmentRequestsByWorkspaceId(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @QueryParam("studentIdentifier") String studentId) {
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.NOT_FOUND).entity("Workspace not found").build();
}
SchoolDataIdentifier studentIdentifier = SchoolDataIdentifier.fromId(studentId);
if (studentIdentifier != null) {
if (!studentIdentifier.equals(sessionController.getLoggedUser())) {
if (!sessionController.hasPermission(AssessmentRequestPermissions.LIST_WORKSPACE_ASSESSMENTREQUESTS, workspaceEntity)) {
return Response.status(Status.FORBIDDEN).build();
}
}
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceAndUserIdentifier(workspaceEntity, studentIdentifier);
if (workspaceUserEntity == null) {
return Response.status(Status.BAD_REQUEST).entity("WorkspaceUserEntity could not find").build();
}
return Response.ok(restModel(assessmentRequestController.listByWorkspaceUser(workspaceUserEntity))).build();
} else {
if (!sessionController.hasPermission(AssessmentRequestPermissions.LIST_WORKSPACE_ASSESSMENTREQUESTS, workspaceEntity)) {
return Response.status(Status.FORBIDDEN).build();
}
List<WorkspaceAssessmentRequest> assessmentRequests = assessmentRequestController.listByWorkspace(workspaceEntity);
return Response.ok(restModel(assessmentRequests)).build();
}
}
use of fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessmentRequest in project muikku by otavanopisto.
the class RequestedAssessmentSupplementationsNotificationStrategy method sendNotifications.
@Override
public void sendNotifications() {
Collection<Long> groups = getGroups();
if (groups.isEmpty()) {
return;
}
// Iterate through active students who belong to pre-configured groups (read: study programs)
SearchResult searchResult = requestedAssessmentSupplementationsNotificationController.searchActiveStudentIds(groups, FIRST_RESULT + offset, MAX_RESULTS);
logger.log(Level.INFO, String.format("%s processing %d/%d", getClass().getSimpleName(), offset, searchResult.getTotalHitCount()));
if ((offset + MAX_RESULTS) > searchResult.getTotalHitCount()) {
offset = 0;
} else {
offset += MAX_RESULTS;
}
for (Map<String, Object> result : searchResult.getResults()) {
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;
}
UserEntity studentEntity = userEntityController.findUserEntityByUserIdentifier(studentIdentifier);
if (studentEntity == null) {
logger.severe(String.format("UserEntity with identifier %s not found", studentIdentifier));
continue;
}
// Iterate through the workspaces in which the student is currently active
List<WorkspaceEntity> workspaceEntities = workspaceUserEntityController.listActiveWorkspaceEntitiesByUserIdentifier(studentIdentifier);
for (WorkspaceEntity workspaceEntity : workspaceEntities) {
SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(workspaceEntity.getIdentifier(), workspaceEntity.getDataSource().getIdentifier());
if (requestedAssessmentSupplementationsNotificationController.countByStudentIdentifierAndWorkspaceIdentifier(studentIdentifier, workspaceIdentifier) == 0) {
// Skip if workspace doesn't have a supplementation request
SupplementationRequest supplementationRequest = supplementationRequestDAO.findByStudentAndWorkspace(studentEntity.getId(), workspaceEntity.getId());
if (supplementationRequest == null) {
continue;
}
// Skip if workspace assessment is newer than supplementation request
WorkspaceAssessment workspaceAssessment = gradingController.findLatestWorkspaceAssessment(workspaceIdentifier, studentIdentifier);
if (workspaceAssessment != null && workspaceAssessment.getDate().getTime() >= supplementationRequest.getRequestDate().getTime()) {
continue;
}
// Skip if assessment request is newer than supplementation request
// TODO: At some point, refactor to simply fetch latest request by student + workspace
WorkspaceAssessmentRequest latestAssesmentRequest = null;
List<WorkspaceAssessmentRequest> studentAssesmentRequests = gradingController.listWorkspaceAssessmentRequests(workspaceIdentifier.getDataSource(), workspaceIdentifier.getIdentifier(), studentIdentifier.getIdentifier());
for (WorkspaceAssessmentRequest assessmentRequest : studentAssesmentRequests) {
Date assessmentRequestDate = assessmentRequest.getDate();
if (assessmentRequestDate != null) {
if (latestAssesmentRequest == null || latestAssesmentRequest.getDate().before(assessmentRequestDate)) {
latestAssesmentRequest = assessmentRequest;
}
}
}
if (latestAssesmentRequest != null && latestAssesmentRequest.getDate().getTime() >= supplementationRequest.getRequestDate().getTime()) {
continue;
}
if (!supplementationRequest.getRequestDate().before(Date.from(OffsetDateTime.now().minusDays(NOTIFICATION_THRESHOLD_DAYS).toInstant()))) {
continue;
}
// If we haven't skipped so far, student needs to be notified
Workspace workspace = workspaceController.findWorkspace(workspaceIdentifier);
if (workspace != null) {
String workspaceName = StringUtils.isBlank(workspace.getNameExtension()) ? workspace.getName() : String.format("%s (%s)", workspace.getName(), workspace.getNameExtension());
Locale studentLocale = localeController.resolveLocale(LocaleUtils.toLocale(studentEntity.getLocale()));
Map<String, Object> templateModel = new HashMap<>();
templateModel.put("workspaceName", workspaceName);
templateModel.put("locale", studentLocale);
templateModel.put("localeHelper", jadeLocaleHelper);
String notificationContent = renderNotificationTemplate("requested-assessment-supplementation-notification", templateModel);
notificationController.sendNotification(localeController.getText(studentLocale, "plugin.timednotifications.notification.category"), localeController.getText(studentLocale, "plugin.timednotifications.notification.requestedassessmentsupplementation.subject"), notificationContent, studentEntity, studentIdentifier, "requestedassessmentsupplementation");
// Store notification to avoid duplicates in the future
requestedAssessmentSupplementationsNotificationController.createRequestedAssessmentSupplementationNotification(studentIdentifier, workspaceIdentifier);
} else {
logger.log(Level.SEVERE, String.format("Cannot send notification to student with identifier %s because UserEntity or workspace was not found", studentIdentifier.toId()));
}
}
}
}
}
use of fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessmentRequest in project muikku by otavanopisto.
the class EvaluationController method markWorkspaceAssessmentRequestsAsHandled.
/**
* Marks the assessment requests of student <code>userEntityId</code> in workspace
* <code>workspaceEntityId</code> as handled.
*
* @param userEntityId Student id (in Muikku)
* @param workspaceEntityId Workspace id (in Muikku)
*/
private void markWorkspaceAssessmentRequestsAsHandled(Long userEntityId, Long workspaceEntityId) {
// TODO Performance bottleneck?
UserEntity userEntity = userEntityController.findUserEntityById(userEntityId);
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
// List assessment requests (from Pyramus)
List<WorkspaceAssessmentRequest> assessmentRequests = gradingController.listWorkspaceAssessmentRequests(workspaceEntity.getDataSource().getIdentifier(), workspaceEntity.getIdentifier(), userEntity.getDefaultIdentifier());
for (WorkspaceAssessmentRequest assessmentRequest : assessmentRequests) {
gradingController.updateWorkspaceAssessmentRequest(assessmentRequest.getSchoolDataSource(), assessmentRequest.getIdentifier(), assessmentRequest.getWorkspaceUserIdentifier(), assessmentRequest.getWorkspaceUserSchoolDataSource(), workspaceEntity.getIdentifier(), userEntity.getDefaultIdentifier(), assessmentRequest.getRequestText(), assessmentRequest.getDate(), assessmentRequest.getArchived(), // handled
Boolean.TRUE);
}
}
Aggregations