use of fi.otavanopisto.muikku.schooldata.entity.WorkspaceRole 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;
}
Aggregations