Search in sources :

Example 21 with WorkspaceUserEntity

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

the class GuiderRESTService method getWorkspaceAssessmentsStudyProgressAnalysis.

@GET
@Path("/workspaces/{WORKSPACEENTITYID}/activity")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response getWorkspaceAssessmentsStudyProgressAnalysis(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId) {
    SchoolDataIdentifier userIdentifier = sessionController.getLoggedUser();
    if (userIdentifier == null) {
        return Response.status(Status.BAD_REQUEST).entity("Invalid userIdentifier").build();
    }
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).entity("WorkspaceEntity not found").build();
    }
    GuiderStudentWorkspaceActivity activity = guiderController.getStudentWorkspaceActivity(workspaceEntity, userIdentifier);
    if (activity == null) {
        return Response.status(Status.INTERNAL_SERVER_ERROR).entity(String.format("Failed to analyze assignments progress for student %s in workspace %d", userIdentifier, workspaceEntity.getId())).build();
    }
    WorkspaceAssessmentState assessmentState = new WorkspaceAssessmentState(WorkspaceAssessmentState.UNASSESSED);
    WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceAndUserIdentifier(workspaceEntity, userIdentifier);
    if (workspaceUserEntity != null && workspaceUserEntity.getWorkspaceUserRole().getArchetype() == WorkspaceRoleArchetype.STUDENT) {
        assessmentState = assessmentRequestController.getWorkspaceAssessmentState(workspaceUserEntity);
    }
    return Response.ok(toRestModel(activity, assessmentState)).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceAssessmentState(fi.otavanopisto.muikku.plugins.assessmentrequest.WorkspaceAssessmentState) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 22 with WorkspaceUserEntity

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

the class AbstractWorkspaceBackingBean method checkAccess.

@RequestAction
public String checkAccess() {
    String urlName = getWorkspaceUrlName();
    if (StringUtils.isBlank(urlName)) {
        return NavigationRules.NOT_FOUND;
    }
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityByUrlName(urlName);
    if (workspaceEntity == null) {
        return NavigationRules.NOT_FOUND;
    }
    switch(workspaceEntity.getAccess()) {
        case ANYONE:
            break;
        case LOGGED_IN:
            if (!sessionController.isLoggedIn()) {
                return navigationController.requireLogin();
            }
            break;
        case MEMBERS_ONLY:
            if (!sessionController.isLoggedIn()) {
                return navigationController.requireLogin();
            }
            WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findActiveWorkspaceUserByWorkspaceEntityAndUserIdentifier(workspaceEntity, sessionController.getLoggedUser());
            if (workspaceUserEntity == null) {
                if (!sessionController.hasWorkspacePermission(MuikkuPermissions.ACCESS_MEMBERS_ONLY_WORKSPACE, workspaceEntity)) {
                    return NavigationRules.ACCESS_DENIED;
                }
            }
            break;
    }
    return null;
}
Also used : WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction)

Example 23 with WorkspaceUserEntity

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

the class InactiveUserListener method onSchoolDataUserInactiveEvent.

public void onSchoolDataUserInactiveEvent(@Observes SchoolDataUserInactiveEvent event) {
    SchoolDataIdentifier schoolDataIdentifier = new SchoolDataIdentifier(event.getIdentifier(), event.getDataSource());
    // Remove an inactive user from all workspaces in which they are currently active
    List<WorkspaceUserEntity> workspaceUserEntities = workspaceUserEntityController.listActiveWorkspaceUserEntitiesByUserIdentifier(schoolDataIdentifier);
    for (WorkspaceUserEntity workspaceUserEntity : workspaceUserEntities) {
        workspaceUserEntityController.updateActive(workspaceUserEntity, Boolean.FALSE);
    }
    // Update Elastic search index since active workspaces have changed
    UserSchoolDataIdentifier userSchoolDataIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierBySchoolDataIdentifier(schoolDataIdentifier);
    if (userSchoolDataIdentifier != null) {
        userIndexer.indexUser(userSchoolDataIdentifier.getUserEntity());
    }
}
Also used : UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)

Example 24 with WorkspaceUserEntity

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

the class VopsLister method processCourse.

private VopsRESTModel.VopsEntry processCourse(Subject subject, int courseNumber) {
    VopsRESTModel.VopsEntry transferCreditEntry = processTransferCredits(subject, courseNumber);
    if (transferCreditEntry != null) {
        return transferCreditEntry;
    }
    List<VopsWorkspace> workspaces = vopsController.listWorkspaceIdentifiersBySubjectIdentifierAndCourseNumber(subject.getSchoolDataSource(), subject.getIdentifier(), courseNumber);
    List<WorkspaceAssessment> workspaceAssessments = new ArrayList<>();
    if (curriculumIdentifier != null) {
        workspaces.removeIf((VopsWorkspace workspace) -> !workspace.getCurriculumIdentifiers().contains(curriculumIdentifier));
    }
    if (!workspaces.isEmpty()) {
        SchoolDataIdentifier educationSubtypeIdentifier = null;
        boolean workspaceUserExists = false;
        String name = "";
        String description = "";
        boolean canSignUp = false;
        for (VopsWorkspace workspace : workspaces) {
            WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspace.getWorkspaceIdentifier());
            WorkspaceUserEntity workspaceUser = workspaceUserEntityController.findWorkspaceUserByWorkspaceEntityAndUserIdentifier(workspaceEntity, studentIdentifier);
            WorkspaceAssessment workspaceAssesment = studentAssessments.get(workspace.getWorkspaceIdentifier());
            List<UserGroupEntity> userGroupEntities = userGroupEntityController.listUserGroupsByUserIdentifier(studentIdentifier);
            Permission permission = permissionController.findByName(MuikkuPermissions.WORKSPACE_SIGNUP);
            for (UserGroupEntity userGroupEntity : userGroupEntities) {
                if (permissionController.hasWorkspaceGroupPermission(workspaceEntity, userGroupEntity, permission)) {
                    canSignUp = true;
                    break;
                }
            }
            if (workspaceAssesment != null) {
                workspaceAssessments.add(workspaceAssesment);
            }
            if (workspaceUser != null) {
                workspaceUserExists = true;
            }
        }
        for (VopsWorkspace workspace : workspaces) {
            name = workspace.getName();
            if (name != null) {
                break;
            }
        }
        for (VopsWorkspace workspace : workspaces) {
            description = workspace.getDescription();
            if (description != null) {
                break;
            }
        }
        for (VopsWorkspace workspace : workspaces) {
            educationSubtypeIdentifier = workspace.getEducationSubtypeIdentifier();
            if (educationSubtypeIdentifier != null) {
                break;
            }
        }
        Mandatority mandatority = educationTypeMapping.getMandatority(educationSubtypeIdentifier);
        CourseCompletionState state = CourseCompletionState.NOT_ENROLLED;
        String grade = null;
        if (workspaceUserExists) {
            state = CourseCompletionState.ENROLLED;
        }
        for (WorkspaceAssessment workspaceAssessment : workspaceAssessments) {
            if (!Boolean.TRUE.equals(workspaceAssessment.getPassing())) {
                state = CourseCompletionState.FAILED;
                break;
            }
        }
        for (WorkspaceAssessment workspaceAssessment : workspaceAssessments) {
            if (Boolean.TRUE.equals(workspaceAssessment.getPassing())) {
                state = CourseCompletionState.ASSESSED;
                numCourses++;
                if (mandatority == Mandatority.MANDATORY) {
                    numMandatoryCourses++;
                }
                SchoolDataIdentifier gradingScaleIdentifier = workspaceAssessment.getGradingScaleIdentifier();
                if (gradingScaleIdentifier == null) {
                    break;
                }
                SchoolDataIdentifier gradeIdentifier = workspaceAssessment.getGradeIdentifier();
                if (gradeIdentifier == null) {
                    break;
                }
                GradingScaleItem gradingScaleItem = findGradingScaleItemCached(gradingScaleIdentifier, gradeIdentifier);
                String gradeName = gradingScaleItem.getName();
                if (!StringUtils.isBlank(gradeName)) {
                    if (gradeName.length() > 2)
                        grade = gradeName.substring(0, 2);
                    else
                        grade = gradeName;
                }
                break;
            }
        }
        if (state == CourseCompletionState.NOT_ENROLLED && !canSignUp) {
            return new VopsRESTModel.VopsPlaceholder();
        }
        StudiesViewCourseChoice courseChoice = studiesViewCourseChoiceController.find(new SchoolDataIdentifier(subject.getIdentifier(), subject.getSchoolDataSource()).toId(), courseNumber, studentIdentifierString);
        if (state == CourseCompletionState.NOT_ENROLLED && courseChoice != null) {
            state = CourseCompletionState.PLANNED;
        }
        return new VopsRESTModel.VopsItem(courseNumber, state, educationSubtypeIdentifier != null ? educationSubtypeIdentifier.toId() : null, mandatority, grade, workspaceUserExists, clean(name), clean(description));
    }
    return new VopsRESTModel.VopsPlaceholder();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) WorkspaceAssessment(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment) GradingScaleItem(fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem) ArrayList(java.util.ArrayList) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) StudiesViewCourseChoice(fi.otavanopisto.muikku.plugins.transcriptofrecords.model.StudiesViewCourseChoice) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Mandatority(fi.otavanopisto.muikku.plugins.transcriptofrecords.rest.Mandatority) Permission(fi.otavanopisto.muikku.model.security.Permission) VopsRESTModel(fi.otavanopisto.muikku.plugins.transcriptofrecords.rest.VopsRESTModel) CourseCompletionState(fi.otavanopisto.muikku.plugins.transcriptofrecords.rest.CourseCompletionState)

Example 25 with WorkspaceUserEntity

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

the class WorkspaceSystemRESTService method ensureCorrectWorkspaceStudent.

private void ensureCorrectWorkspaceStudent(WorkspaceUserEntity muikkuWorkspaceStudent, SchoolDataIdentifier muikkuStudentIdentifier, SchoolDataIdentifier pyramusStudentIdentifier) {
    if (!pyramusStudentIdentifier.equals(muikkuStudentIdentifier)) {
        logger.warning(String.format("Muikku workspace student points to student %s and Pyramus to student %s", muikkuStudentIdentifier, pyramusStudentIdentifier));
        UserSchoolDataIdentifier userSchoolDataIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierBySchoolDataIdentifier(pyramusStudentIdentifier);
        if (userSchoolDataIdentifier == null) {
            logger.severe(String.format("Unable to fix: UserSchoolDataIdentifier for Pyramus student %s not found", pyramusStudentIdentifier));
        } else if (!userSchoolDataIdentifier.getUserEntity().getId().equals(muikkuWorkspaceStudent.getUserSchoolDataIdentifier().getUserEntity().getId())) {
            logger.severe("Unable to fix: UserSchoolDataIdentifiers in Muikku and Pyramus point to different users");
        } else {
            // Muikku and Pyramus students are not the same. Let's see if we can find a workspace student with workspace + student combo
            WorkspaceUserEntity existingStudent = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceAndUserIdentifierIncludeArchived(muikkuWorkspaceStudent.getWorkspaceEntity(), pyramusStudentIdentifier);
            if (existingStudent != null && !existingStudent.getId().equals(muikkuWorkspaceStudent.getId())) {
                // We can, so delete the workspace student we had and use the one we found instead, unarchiving it if needed
                if (existingStudent.getArchived()) {
                    workspaceUserEntityController.unarchiveWorkspaceUserEntity(existingStudent);
                }
                workspaceUserEntityController.updateIdentifier(existingStudent, muikkuWorkspaceStudent.getIdentifier());
                workspaceUserEntityController.archiveWorkspaceUserEntity(muikkuWorkspaceStudent);
                muikkuWorkspaceStudent = existingStudent;
            }
            // Set workspace student to point at the same student as in Pyramus
            workspaceUserEntityController.updateUserSchoolDataIdentifier(muikkuWorkspaceStudent, userSchoolDataIdentifier);
            logger.info("Muikku workspace student UserSchoolDataIdentifier updated");
        }
    }
}
Also used : UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)

Aggregations

WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)65 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)43 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)33 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)25 Path (javax.ws.rs.Path)20 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)17 ArrayList (java.util.ArrayList)17 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)16 EntityManager (javax.persistence.EntityManager)14 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)14 GET (javax.ws.rs.GET)10 User (fi.otavanopisto.muikku.schooldata.entity.User)9 WorkspaceUser (fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser)7 WorkspaceRoleEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceRoleEntity)6 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)6 RoleSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier)5 Date (java.util.Date)5 UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)4 HashMap (java.util.HashMap)4 DELETE (javax.ws.rs.DELETE)4