Search in sources :

Example 6 with RoleSchoolDataIdentifier

use of fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier 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 7 with RoleSchoolDataIdentifier

use of fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier in project muikku by otavanopisto.

the class WorkspaceController method findWorkspaceRoleEntityByDataSourceAndIdentifier.

/* WorkspaceRoleEntity */
public WorkspaceRoleEntity findWorkspaceRoleEntityByDataSourceAndIdentifier(String schoolDataSource, String roleIdentifier) {
    SchoolDataSource dataSource = schoolDataSourceDAO.findByIdentifier(schoolDataSource);
    if (dataSource == null) {
        logger.log(Level.SEVERE, "Could not find school data source '" + schoolDataSource + "'");
        return null;
    }
    RoleSchoolDataIdentifier roleSchoolDataIdentifier = roleSchoolDataIdentifierDAO.findByDataSourceAndIdentifier(dataSource, roleIdentifier);
    if (roleSchoolDataIdentifier != null) {
        RoleEntity roleEntity = roleSchoolDataIdentifier.getRoleEntity();
        if (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 8 with RoleSchoolDataIdentifier

use of fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier in project muikku by otavanopisto.

the class RoleController method findRoleByDataSourceAndRoleEntity.

public Role findRoleByDataSourceAndRoleEntity(String schoolDataSource, RoleEntity roleEntity) {
    SchoolDataSource dataSource = schoolDataSourceDAO.findByIdentifier(schoolDataSource);
    if (dataSource == null) {
        logger.severe("Could not find school data source " + schoolDataSource);
        return null;
    }
    RoleSchoolDataIdentifier schoolDataIdentifier = roleSchoolDataIdentifierDAO.findByDataSourceAndRoleEntity(dataSource, roleEntity);
    if (schoolDataIdentifier != null) {
        return findRole(dataSource, schoolDataIdentifier.getIdentifier());
    }
    return null;
}
Also used : RoleSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier) SchoolDataSource(fi.otavanopisto.muikku.model.base.SchoolDataSource)

Example 9 with RoleSchoolDataIdentifier

use of fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier in project muikku by otavanopisto.

the class RoleSchoolDataIdentifierDAO method create.

public RoleSchoolDataIdentifier create(SchoolDataSource dataSource, String identifier, RoleEntity roleEntity) {
    RoleSchoolDataIdentifier roleSchoolDataIdentifier = new RoleSchoolDataIdentifier();
    roleSchoolDataIdentifier.setDataSource(dataSource);
    roleSchoolDataIdentifier.setIdentifier(identifier);
    roleSchoolDataIdentifier.setRoleEntity(roleEntity);
    return persist(roleSchoolDataIdentifier);
}
Also used : RoleSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier)

Example 10 with RoleSchoolDataIdentifier

use of fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier in project muikku by otavanopisto.

the class RoleSchoolDataIdentifierDAO method listByRoleEntity.

public List<RoleSchoolDataIdentifier> listByRoleEntity(RoleEntity roleEntity) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<RoleSchoolDataIdentifier> criteria = criteriaBuilder.createQuery(RoleSchoolDataIdentifier.class);
    Root<RoleSchoolDataIdentifier> root = criteria.from(RoleSchoolDataIdentifier.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.equal(root.get(RoleSchoolDataIdentifier_.roleEntity), roleEntity));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) RoleSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier) EntityManager(javax.persistence.EntityManager)

Aggregations

RoleSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier)10 SchoolDataSource (fi.otavanopisto.muikku.model.base.SchoolDataSource)4 EntityManager (javax.persistence.EntityManager)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 RoleEntity (fi.otavanopisto.muikku.model.users.RoleEntity)3 WorkspaceRoleEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceRoleEntity)3 EnvironmentRoleEntity (fi.otavanopisto.muikku.model.users.EnvironmentRoleEntity)1 EnvironmentRole (fi.otavanopisto.muikku.schooldata.entity.EnvironmentRole)1 WorkspaceRole (fi.otavanopisto.muikku.schooldata.entity.WorkspaceRole)1 SchoolDataEnvironmentRoleDiscoveredEvent (fi.otavanopisto.muikku.schooldata.events.SchoolDataEnvironmentRoleDiscoveredEvent)1 SchoolDataEnvironmentRoleRemovedEvent (fi.otavanopisto.muikku.schooldata.events.SchoolDataEnvironmentRoleRemovedEvent)1 SchoolDataWorkspaceRoleDiscoveredEvent (fi.otavanopisto.muikku.schooldata.events.SchoolDataWorkspaceRoleDiscoveredEvent)1 SchoolDataWorkspaceRoleRemovedEvent (fi.otavanopisto.muikku.schooldata.events.SchoolDataWorkspaceRoleRemovedEvent)1 CourseStaffMemberRole (fi.otavanopisto.pyramus.rest.model.CourseStaffMemberRole)1 UserRole (fi.otavanopisto.pyramus.rest.model.UserRole)1 HashMap (java.util.HashMap)1