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;
}
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;
}
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;
}
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);
}
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();
}
Aggregations