Search in sources :

Example 6 with WorkspaceAssessmentRequest

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();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceAssessmentRequest(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessmentRequest) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) PUT(javax.ws.rs.PUT)

Example 7 with WorkspaceAssessmentRequest

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();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceAssessmentRequest(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessmentRequest) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)

Example 8 with WorkspaceAssessmentRequest

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);
    }
}
Also used : WorkspaceAssessmentRequest(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessmentRequest)

Example 9 with WorkspaceAssessmentRequest

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;
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) WorkspaceAssessment(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment) User(fi.otavanopisto.muikku.schooldata.entity.User) OffsetDateTime(java.time.OffsetDateTime) WorkspaceAssessmentRequest(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessmentRequest) ArrayList(java.util.ArrayList)

Aggregations

WorkspaceAssessmentRequest (fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessmentRequest)9 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)7 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)5 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)4 Path (javax.ws.rs.Path)4 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)3 WorkspaceAssessment (fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment)3 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)2 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)2 SupplementationRequest (fi.otavanopisto.muikku.plugins.evaluation.model.SupplementationRequest)1 GradingScale (fi.otavanopisto.muikku.schooldata.entity.GradingScale)1 GradingScaleItem (fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem)1 User (fi.otavanopisto.muikku.schooldata.entity.User)1 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)1 SearchResult (fi.otavanopisto.muikku.search.SearchResult)1 OffsetDateTime (java.time.OffsetDateTime)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1