Search in sources :

Example 76 with WorkspaceEntity

use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity 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);
    }
}
Also used : GradingScale(fi.otavanopisto.muikku.schooldata.entity.GradingScale) WorkspaceAssessment(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceAssessmentRequest(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessmentRequest) GradingScaleItem(fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem)

Example 77 with WorkspaceEntity

use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity 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();
    }
}
Also used : 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) POST(javax.ws.rs.POST) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)

Example 78 with WorkspaceEntity

use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.

the class AssessmentRequestRESTService method restModel.

private AssessmentRequestRESTModel restModel(WorkspaceAssessmentRequest workspaceAssessmentRequest) {
    SchoolDataIdentifier workspaceUserIdentifier = new SchoolDataIdentifier(workspaceAssessmentRequest.getWorkspaceUserIdentifier(), workspaceAssessmentRequest.getWorkspaceUserSchoolDataSource());
    WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifier(workspaceUserIdentifier);
    if (workspaceUserEntity != null) {
        SchoolDataIdentifier userIdentifier = new SchoolDataIdentifier(workspaceUserEntity.getUserSchoolDataIdentifier().getIdentifier(), workspaceUserEntity.getUserSchoolDataIdentifier().getDataSource().getIdentifier());
        SchoolDataIdentifier workspaceAssessmentRequestIdentifier = new SchoolDataIdentifier(workspaceAssessmentRequest.getIdentifier(), workspaceAssessmentRequest.getSchoolDataSource());
        WorkspaceEntity workspaceEntity = workspaceUserEntity.getWorkspaceEntity();
        UserEntity userEntity = workspaceUserEntity.getUserSchoolDataIdentifier().getUserEntity();
        AssessmentRequestRESTModel restAssessmentRequest = new AssessmentRequestRESTModel(workspaceAssessmentRequestIdentifier.toId(), userIdentifier.toId(), workspaceUserIdentifier.toId(), workspaceEntity.getId(), userEntity.getId(), workspaceAssessmentRequest.getRequestText(), workspaceAssessmentRequest.getDate());
        return restAssessmentRequest;
    }
    return null;
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) AssessmentRequestRESTModel(fi.otavanopisto.muikku.plugins.assessmentrequest.rest.model.AssessmentRequestRESTModel) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity)

Example 79 with WorkspaceEntity

use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity 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();
    }
}
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) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 80 with WorkspaceEntity

use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.

the class WorkspaceAnnouncementsViewBackingBean method init.

@RequestAction
public String init() {
    String urlName = getWorkspaceUrlName();
    if (StringUtils.isBlank(urlName)) {
        return NavigationRules.NOT_FOUND;
    }
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityByUrlName(urlName);
    if (workspaceEntity == null) {
        return NavigationRules.NOT_FOUND;
    }
    if (!workspaceEntity.getPublished()) {
        if (!sessionController.hasWorkspacePermission(MuikkuPermissions.ACCESS_UNPUBLISHED_WORKSPACE, workspaceEntity)) {
            return NavigationRules.NOT_FOUND;
        }
    }
    if (workspaceEntity.getAccess() != WorkspaceAccess.ANYONE) {
        if (!sessionController.hasWorkspacePermission(AnnouncerPermissions.LIST_WORKSPACE_ANNOUNCEMENTS, workspaceEntity)) {
            if (!sessionController.isLoggedIn()) {
                return navigationController.requireLogin();
            } else {
                return NavigationRules.ACCESS_DENIED;
            }
        }
    }
    workspaceEntityId = workspaceEntity.getId();
    workspaceBackingBean.setWorkspaceUrlName(urlName);
    workspaceName = workspaceBackingBean.getWorkspaceName();
    workspaceNameExtension = workspaceBackingBean.getWorkspaceNameExtension();
    if (announcementId != null) {
        currentAnnouncement = announcementController.findById(announcementId);
    }
    activeAnnouncements = announcementController.listActiveByWorkspaceEntities(Collections.singletonList(workspaceEntity));
    return null;
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction)

Aggregations

WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)190 Path (javax.ws.rs.Path)102 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)82 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)65 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)51 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)49 GET (javax.ws.rs.GET)46 ArrayList (java.util.ArrayList)38 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)29 POST (javax.ws.rs.POST)26 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)25 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)21 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)21 WorkspaceForumArea (fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea)20 RequestAction (org.ocpsoft.rewrite.annotation.RequestAction)19 ForumArea (fi.otavanopisto.muikku.plugins.forum.model.ForumArea)17 Date (java.util.Date)17 DELETE (javax.ws.rs.DELETE)17 PUT (javax.ws.rs.PUT)16 WorkspaceRootFolder (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder)15