Search in sources :

Example 6 with WorkspaceRoleEntity

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

the class WorkspaceRoleEntityController method findWorkspaceRoleEntityByDataSourceAndIdentifier.

public WorkspaceRoleEntity findWorkspaceRoleEntityByDataSourceAndIdentifier(String dataSource, String identifier) {
    SchoolDataSource schoolDataSource = schoolDataSourceDAO.findByIdentifier(dataSource);
    if (schoolDataSource == null) {
        logger.severe("Could not find datasource " + dataSource);
        return null;
    }
    RoleSchoolDataIdentifier roleIdentifier = roleSchoolDataIdentifierDAO.findByDataSourceAndIdentifier(schoolDataSource, identifier);
    if (roleIdentifier != null) {
        RoleEntity roleEntity = roleIdentifier.getRoleEntity();
        if (roleEntity != null && roleEntity.getType() == UserRoleType.WORKSPACE) {
            return (WorkspaceRoleEntity) roleEntity;
        }
    }
    return null;
}
Also used : WorkspaceRoleEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceRoleEntity) RoleEntity(fi.otavanopisto.muikku.model.users.RoleEntity) RoleSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier) SchoolDataSource(fi.otavanopisto.muikku.model.base.SchoolDataSource) WorkspaceRoleEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceRoleEntity)

Example 7 with WorkspaceRoleEntity

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

the class WorkspaceRoleEntityController method createWorkspaceRoleEntity.

public WorkspaceRoleEntity createWorkspaceRoleEntity(String dataSource, String identifier, WorkspaceRoleArchetype archetype, String name) {
    SchoolDataSource schoolDataSource = schoolDataSourceDAO.findByIdentifier(dataSource);
    if (schoolDataSource == null) {
        logger.severe("Could not find datasource " + dataSource);
        return null;
    }
    WorkspaceRoleEntity workspaceRoleEntity = workspaceRoleEntityDAO.create(archetype, name);
    roleSchoolDataIdentifierDAO.create(schoolDataSource, identifier, workspaceRoleEntity);
    return workspaceRoleEntity;
}
Also used : SchoolDataSource(fi.otavanopisto.muikku.model.base.SchoolDataSource) WorkspaceRoleEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceRoleEntity)

Example 8 with WorkspaceRoleEntity

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

the class PyramusUpdater method updateUserRoles.

/**
 * Updates user roles from Pyramus
 *
 * @return count of updates roles
 */
public int updateUserRoles() {
    int count = 0;
    List<RoleSchoolDataIdentifier> existingRoleIdentifiers = roleSchoolDataIdentifierController.listRoleSchoolDataIdentifiersByDataSource(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE);
    Map<String, RoleSchoolDataIdentifier> removedIdentifiers = new HashMap<>();
    for (RoleSchoolDataIdentifier existingRoleIdentifier : existingRoleIdentifiers) {
        removedIdentifiers.put(existingRoleIdentifier.getIdentifier(), existingRoleIdentifier);
    }
    for (fi.otavanopisto.pyramus.rest.model.UserRole userRole : fi.otavanopisto.pyramus.rest.model.UserRole.values()) {
        String roleIdentifier = identifierMapper.getEnvironmentRoleIdentifier(userRole);
        removedIdentifiers.remove(roleIdentifier);
        if (environmentRoleEntityController.findEnvironmentRoleEntity(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, roleIdentifier) == null) {
            EnvironmentRole environmentRole = entityFactory.createEntity(userRole);
            schoolDataEnvironmentRoleDiscoveredEvent.fire(new SchoolDataEnvironmentRoleDiscoveredEvent(environmentRole.getSchoolDataSource(), environmentRole.getIdentifier(), environmentRole.getArchetype(), environmentRole.getName()));
            count++;
        }
    }
    CourseStaffMemberRole[] staffMemberRoles = pyramusClient.get().get("/courses/staffMemberRoles", CourseStaffMemberRole[].class);
    if (staffMemberRoles == null || staffMemberRoles.length == 0) {
        logger.warning("Aborting role synchronization because Pyramus has no course staff member roles");
        return count;
    }
    for (CourseStaffMemberRole staffMemberRole : staffMemberRoles) {
        String identifier = identifierMapper.getWorkspaceStaffRoleIdentifier(staffMemberRole.getId());
        removedIdentifiers.remove(identifier);
        WorkspaceRoleEntity workspaceRoleEntity = workspaceRoleEntityController.findWorkspaceRoleEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, identifier);
        if (workspaceRoleEntity == null) {
            WorkspaceRole workspaceRole = entityFactory.createEntity(staffMemberRole);
            schoolDataWorkspaceRoleDiscoveredEvent.fire(new SchoolDataWorkspaceRoleDiscoveredEvent(workspaceRole.getSchoolDataSource(), workspaceRole.getIdentifier(), workspaceRole.getArchetype(), workspaceRole.getName()));
            count++;
        }
    }
    WorkspaceRole studentRole = entityFactory.createCourseStudentRoleEntity();
    removedIdentifiers.remove(studentRole.getIdentifier());
    WorkspaceRoleEntity studentWorkspaceRoleEntity = workspaceRoleEntityController.findWorkspaceRoleEntityByDataSourceAndIdentifier(studentRole.getSchoolDataSource(), studentRole.getIdentifier());
    if (studentWorkspaceRoleEntity == null) {
        schoolDataWorkspaceRoleDiscoveredEvent.fire(new SchoolDataWorkspaceRoleDiscoveredEvent(studentRole.getSchoolDataSource(), studentRole.getIdentifier(), studentRole.getArchetype(), studentRole.getName()));
        count++;
    }
    Set<String> removedIdentifierIds = removedIdentifiers.keySet();
    for (String removedIdentifierId : removedIdentifierIds) {
        RoleSchoolDataIdentifier removedIdentifier = removedIdentifiers.get(removedIdentifierId);
        if (removedIdentifier.getRoleEntity().getType() == UserRoleType.ENVIRONMENT) {
            schoolDataEnvironmentRoleRemovedEvent.fire(new SchoolDataEnvironmentRoleRemovedEvent(removedIdentifier.getDataSource().getIdentifier(), removedIdentifier.getIdentifier()));
        } else if (removedIdentifier.getRoleEntity().getType() == UserRoleType.WORKSPACE) {
            schoolDataWorkspaceRoleRemovedEvent.fire(new SchoolDataWorkspaceRoleRemovedEvent(removedIdentifier.getDataSource().getIdentifier(), removedIdentifier.getIdentifier()));
        }
    }
    return count;
}
Also used : CourseStaffMemberRole(fi.otavanopisto.pyramus.rest.model.CourseStaffMemberRole) SchoolDataWorkspaceRoleDiscoveredEvent(fi.otavanopisto.muikku.schooldata.events.SchoolDataWorkspaceRoleDiscoveredEvent) UserRole(fi.otavanopisto.pyramus.rest.model.UserRole) HashMap(java.util.HashMap) SchoolDataEnvironmentRoleDiscoveredEvent(fi.otavanopisto.muikku.schooldata.events.SchoolDataEnvironmentRoleDiscoveredEvent) SchoolDataEnvironmentRoleRemovedEvent(fi.otavanopisto.muikku.schooldata.events.SchoolDataEnvironmentRoleRemovedEvent) WorkspaceRole(fi.otavanopisto.muikku.schooldata.entity.WorkspaceRole) RoleSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier) SchoolDataWorkspaceRoleRemovedEvent(fi.otavanopisto.muikku.schooldata.events.SchoolDataWorkspaceRoleRemovedEvent) EnvironmentRole(fi.otavanopisto.muikku.schooldata.entity.EnvironmentRole) WorkspaceRoleEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceRoleEntity)

Example 9 with WorkspaceRoleEntity

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

the class DefaultSchoolDataRoleListener method onSchoolDataWorkspaceRoleDiscoveredEvent.

public void onSchoolDataWorkspaceRoleDiscoveredEvent(@Observes SchoolDataWorkspaceRoleDiscoveredEvent event) {
    String discoverId = "WSR-" + event.getDataSource() + "/" + event.getIdentifier();
    if (discoveredWorkspaceRoles.containsKey(discoverId)) {
        event.setDiscoveredWorkspaceRoleEntityId(discoveredWorkspaceRoles.get(discoverId));
        return;
    }
    WorkspaceRoleEntity workspaceRoleEntity = workspaceRoleEntityController.findWorkspaceRoleEntityByDataSourceAndIdentifier(event.getDataSource(), event.getIdentifier());
    if (workspaceRoleEntity == null) {
        WorkspaceRoleArchetype roleArchetype = WorkspaceRoleArchetype.valueOf(event.getArchetype().name());
        workspaceRoleEntity = workspaceRoleEntityController.createWorkspaceRoleEntity(event.getDataSource(), event.getIdentifier(), roleArchetype, event.getName());
        discoveredWorkspaceRoles.put(discoverId, workspaceRoleEntity.getId());
        event.setDiscoveredWorkspaceRoleEntityId(workspaceRoleEntity.getId());
    } else {
        logger.warning("WorkspaceRoleEntity for " + event.getIdentifier() + "/" + event.getDataSource() + " already exists");
    }
}
Also used : WorkspaceRoleEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceRoleEntity) WorkspaceRoleArchetype(fi.otavanopisto.muikku.model.workspace.WorkspaceRoleArchetype)

Example 10 with WorkspaceRoleEntity

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

the class DefaultSchoolDataWorkspaceListener method onSchoolDataWorkspaceUserDiscoveredEvent.

public synchronized void onSchoolDataWorkspaceUserDiscoveredEvent(@Observes SchoolDataWorkspaceUserDiscoveredEvent event) {
    String discoverId = "WSU-" + event.getDataSource() + "/" + event.getIdentifier();
    if (discoveredWorkspaceUsers.containsKey(discoverId)) {
        event.setDiscoveredWorkspaceUserEntityId(discoveredWorkspaceUsers.get(discoverId));
        return;
    }
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceByDataSourceAndIdentifier(event.getWorkspaceDataSource(), event.getWorkspaceIdentifier());
    if (workspaceEntity != null) {
        WorkspaceRoleEntity workspaceUserRole = workspaceController.findWorkspaceRoleEntityByDataSourceAndIdentifier(event.getRoleDataSource(), event.getRoleIdentifier());
        if (workspaceUserRole != null) {
            UserSchoolDataIdentifier userSchoolDataIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierByDataSourceAndIdentifier(event.getUserDataSource(), event.getUserIdentifier());
            if (userSchoolDataIdentifier != null) {
                WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceAndUserSchoolDataIdentifierIncludeArchived(workspaceEntity, userSchoolDataIdentifier);
                if (workspaceUserEntity == null) {
                    workspaceUserEntity = workspaceUserEntityController.createWorkspaceUserEntity(userSchoolDataIdentifier, workspaceEntity, event.getIdentifier(), workspaceUserRole);
                    discoveredWorkspaceUsers.put(discoverId, workspaceUserEntity.getId());
                    event.setDiscoveredWorkspaceUserEntityId(workspaceUserEntity.getId());
                } else {
                    if (!workspaceUserEntity.getIdentifier().equals(event.getIdentifier())) {
                        workspaceUserEntityController.updateIdentifier(workspaceUserEntity, event.getIdentifier());
                    }
                    // #3806: WorkspaceUserEntity exists; check if role has changed
                    if (workspaceUserEntity.getWorkspaceUserRole() == null || !workspaceUserRole.getId().equals(workspaceUserEntity.getWorkspaceUserRole().getId())) {
                        workspaceUserEntityController.updateWorkspaceUserRole(workspaceUserEntity, workspaceUserRole);
                    }
                    workspaceUserEntityController.unarchiveWorkspaceUserEntity(workspaceUserEntity);
                }
                if (!workspaceUserEntity.getActive().equals(event.getIsActive())) {
                    workspaceUserEntityController.updateActive(workspaceUserEntity, event.getIsActive());
                }
            } else {
                logger.warning("could not add workspace user because userSchoolDataIdentifier #" + event.getUserIdentifier() + '/' + event.getUserDataSource() + " could not be found");
            }
        } else {
            logger.warning("could not init workspace user because workspace role #" + event.getRoleIdentifier() + '/' + event.getRoleDataSource() + " could not be found");
        }
    } else {
        logger.warning("could not init workspace user because workspace entity #" + event.getWorkspaceIdentifier() + '/' + event.getWorkspaceDataSource() + " could not be found");
    }
}
Also used : UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceRoleEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceRoleEntity)

Aggregations

WorkspaceRoleEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceRoleEntity)17 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)6 RoleEntity (fi.otavanopisto.muikku.model.users.RoleEntity)5 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)5 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)4 EntityManager (javax.persistence.EntityManager)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 SchoolDataSource (fi.otavanopisto.muikku.model.base.SchoolDataSource)3 Permission (fi.otavanopisto.muikku.model.security.Permission)3 EnvironmentRoleEntity (fi.otavanopisto.muikku.model.users.EnvironmentRoleEntity)3 RoleSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier)3 WorkspaceRoleArchetype (fi.otavanopisto.muikku.model.workspace.WorkspaceRoleArchetype)3 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)3 ArrayList (java.util.ArrayList)3 RolePermission (fi.otavanopisto.muikku.model.security.RolePermission)2 EnvironmentRoleArchetype (fi.otavanopisto.muikku.model.users.EnvironmentRoleArchetype)2 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)2 MuikkuPermissionCollection (fi.otavanopisto.muikku.security.MuikkuPermissionCollection)2 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)2 Path (javax.ws.rs.Path)2