Search in sources :

Example 26 with WorkspaceUserEntity

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

the class DefaultPermissionResolver method hasWorkspaceAccess.

private boolean hasWorkspaceAccess(WorkspaceEntity workspaceEntity, UserEntity userEntity, Permission permission) {
    // Workspace access as an individual
    WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findActiveWorkspaceUserByWorkspaceEntityAndUserEntity(workspaceEntity, userEntity);
    if (workspaceUserEntity != null) {
        if (permissionController.hasPermission(workspaceUserEntity.getWorkspaceUserRole(), permission)) {
            // TODO Override rules for workspace users
            return true;
        }
    }
    // Workspace access as a group member
    List<UserGroupEntity> userGroups = userGroupEntityController.listUserGroupsByUserEntity(userEntity);
    for (UserGroupEntity userGroup : userGroups) {
        // TODO Override rules for user groups
        if (permissionController.hasPermission(workspaceEntity, userGroup, permission)) {
            return true;
        }
    }
    return false;
}
Also used : WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity)

Example 27 with WorkspaceUserEntity

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

the class PyramusUpdater method updateInactiveWorkspaceStudents.

/**
 * Updates inactive course students from Pyramus
 *
 * @param courseId id of course in Pyramus
 * @return count of updated course students
 */
public int updateInactiveWorkspaceStudents(WorkspaceEntity workspaceEntity) {
    int count = 0;
    Long courseId = identifierMapper.getPyramusCourseId(workspaceEntity.getIdentifier());
    CourseStudent[] nonActiveCourseStudents = pyramusClient.get().get("/courses/courses/" + courseId + "/students?filterArchived=false&activeStudents=false", CourseStudent[].class);
    if (nonActiveCourseStudents != null) {
        for (CourseStudent nonActiveCourseStudent : nonActiveCourseStudents) {
            SchoolDataIdentifier workspaceUserIdentifier = toIdentifier(identifierMapper.getWorkspaceStudentIdentifier(nonActiveCourseStudent.getId()));
            WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifierIncludeArchived(workspaceUserIdentifier);
            if (workspaceUserEntity != null) {
                if (nonActiveCourseStudent.getArchived()) {
                    fireCourseStudentRemoved(nonActiveCourseStudent.getId(), nonActiveCourseStudent.getStudentId(), nonActiveCourseStudent.getCourseId());
                    count++;
                } else {
                    fireCourseStudentUpdated(nonActiveCourseStudent, false);
                    count++;
                }
            } else {
                fireCourseStudentDiscovered(nonActiveCourseStudent, false);
                count++;
            }
        }
    }
    return count;
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) RoleSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) CourseStudent(fi.otavanopisto.pyramus.rest.model.CourseStudent)

Example 28 with WorkspaceUserEntity

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

the class PyramusUpdater method updateCourseStudent.

/**
 * Updates course student from Pyramus
 *
 * @param courseStudentId id of course student in Pyramus
 * @param courseId id of course in Pyramus
 * @param studentId id of student in Pyramus
 * @return returns whether new course student was created or not
 */
public boolean updateCourseStudent(Long courseStudentId, Long courseId, Long studentId) {
    String workspaceIdentifier = identifierMapper.getWorkspaceIdentifier(courseId);
    String identifier = identifierMapper.getWorkspaceStudentIdentifier(courseStudentId);
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, workspaceIdentifier);
    if (workspaceEntity == null) {
        updateCourse(courseId);
        workspaceEntity = workspaceController.findWorkspaceEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, workspaceIdentifier);
    }
    if (workspaceEntity != null) {
        SchoolDataIdentifier workspaceUserIdentifier = new SchoolDataIdentifier(identifier, SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE);
        WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifierIncludeArchived(workspaceUserIdentifier);
        CourseStudent courseStudent = pyramusClient.get().get("/courses/courses/" + courseId + "/students/" + courseStudentId, CourseStudent.class);
        if (courseStudent != null && !courseStudent.getArchived()) {
            boolean studentActive = isStudentActive(courseStudent.getStudentId());
            if (workspaceUserEntity == null) {
                fireCourseStudentDiscovered(courseStudent, studentActive);
                return true;
            } else {
                fireCourseStudentUpdated(courseStudent, studentActive);
            }
        } else {
            if (workspaceUserEntity != null) {
                fireCourseStudentRemoved(courseStudentId, studentId, courseId);
            }
        }
    }
    return false;
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) RoleSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) CourseStudent(fi.otavanopisto.pyramus.rest.model.CourseStudent)

Example 29 with WorkspaceUserEntity

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

the class PyramusUpdater method updateActiveWorkspaceStudents.

/**
 * Updates active course students from Pyramus
 *
 * @param courseId id of course in Pyramus
 * @return count of updated course students
 */
public int updateActiveWorkspaceStudents(WorkspaceEntity workspaceEntity) {
    int count = 0;
    Long courseId = identifierMapper.getPyramusCourseId(workspaceEntity.getIdentifier());
    CourseStudent[] courseStudents = pyramusClient.get().get("/courses/courses/" + courseId + "/students?filterArchived=false&activeStudents=true", CourseStudent[].class);
    if (courseStudents != null) {
        for (CourseStudent courseStudent : courseStudents) {
            SchoolDataIdentifier workspaceUserIdentifier = toIdentifier(identifierMapper.getWorkspaceStudentIdentifier(courseStudent.getId()));
            WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifierIncludeArchived(workspaceUserIdentifier);
            if (courseStudent.getArchived()) {
                if (workspaceUserEntity != null) {
                    fireCourseStudentRemoved(courseStudent.getId(), courseStudent.getStudentId(), courseStudent.getCourseId());
                    count++;
                }
            } else {
                if (workspaceUserEntity == null) {
                    fireCourseStudentDiscovered(courseStudent, true);
                    count++;
                } else {
                    fireCourseStudentUpdated(courseStudent, true);
                }
            }
        }
    }
    return count;
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) RoleSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) CourseStudent(fi.otavanopisto.pyramus.rest.model.CourseStudent)

Example 30 with WorkspaceUserEntity

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

the class DefaultSchoolDataWorkspaceListener method onSchoolDataWorkspaceUserRemovedEvent.

public void onSchoolDataWorkspaceUserRemovedEvent(@Observes SchoolDataWorkspaceUserRemovedEvent event) {
    UserEntity userEntity = userEntityController.findUserEntityByDataSourceAndIdentifier(event.getUserDataSource(), event.getUserIdentifier());
    if (userEntity != null) {
        WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceByDataSourceAndIdentifier(event.getWorkspaceDataSource(), event.getWorkspaceIdentifier());
        if (workspaceEntity != null) {
            SchoolDataIdentifier workspaceUserIdentifier = new SchoolDataIdentifier(event.getIdentifier(), event.getDataSource());
            WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifier(workspaceUserIdentifier);
            if (workspaceUserEntity != null) {
                workspaceUserEntityController.archiveWorkspaceUserEntity(workspaceUserEntity);
            }
        } else {
            logger.warning("could not remove workspace user because workspace entity #" + event.getWorkspaceIdentifier() + '/' + event.getWorkspaceDataSource() + " could not be found");
        }
    } else {
        logger.warning("could not remove workspace user because user entity #" + event.getUserIdentifier() + '/' + event.getUserDataSource() + " could not be found");
    }
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity)

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