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