use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class DefaultSchoolDataWorkspaceListener method onSchoolDataWorkspaceUserUpdatedEvent.
public void onSchoolDataWorkspaceUserUpdatedEvent(@Observes SchoolDataWorkspaceUserUpdatedEvent event) {
UserEntity userEntity = userEntityController.findUserEntityByDataSourceAndIdentifier(event.getUserDataSource(), event.getUserIdentifier());
if (userEntity != null) {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceByDataSourceAndIdentifier(event.getWorkspaceDataSource(), event.getWorkspaceIdentifier());
if (workspaceEntity != null) {
SchoolDataIdentifier workspaceUserIdentifier = new SchoolDataIdentifier(event.getIdentifier(), event.getDataSource());
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifierIncludeArchived(workspaceUserIdentifier);
if (workspaceUserEntity != null) {
String currentUserIdentifier = workspaceUserEntity.getUserSchoolDataIdentifier().getIdentifier();
if (!StringUtils.equals(currentUserIdentifier, event.getUserIdentifier())) {
// WorkspaceUserEntity found, but it points to a new study program
UserSchoolDataIdentifier newUserIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierByDataSourceAndIdentifier(event.getUserDataSource(), event.getUserIdentifier());
if (newUserIdentifier == null) {
logger.warning(String.format("Unable to update workspace user. UserSchoolDataIdentifier for %s/%s not found", event.getUserDataSource(), event.getUserIdentifier()));
} else {
WorkspaceUserEntity existingUser = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceAndUserSchoolDataIdentifierIncludeArchived(workspaceEntity, newUserIdentifier);
if (existingUser != null) {
if (!existingUser.getArchived().equals(workspaceUserEntity.getArchived())) {
if (existingUser.getArchived()) {
workspaceUserEntityController.unarchiveWorkspaceUserEntity(existingUser);
} else {
workspaceUserEntityController.archiveWorkspaceUserEntity(existingUser);
}
}
workspaceUserEntityController.updateIdentifier(existingUser, workspaceUserEntity.getIdentifier());
// #3308: If the new study program is active, reactivate the corresponding workspace student in Muikku
if (event.getIsActive() && !existingUser.getActive()) {
workspaceUserEntityController.updateActive(existingUser, event.getIsActive());
}
workspaceUserEntityController.archiveWorkspaceUserEntity(workspaceUserEntity);
} else {
workspaceUserEntityController.updateUserSchoolDataIdentifier(workspaceUserEntity, newUserIdentifier);
// #3308: If the new study program is active, reactivate the corresponding workspace student in Muikku
if (event.getIsActive() && !workspaceUserEntity.getActive()) {
workspaceUserEntityController.updateActive(workspaceUserEntity, event.getIsActive());
}
}
}
} else {
WorkspaceRoleEntity workspaceRoleEntity = workspaceController.findWorkspaceRoleEntityByDataSourceAndIdentifier(event.getRoleDataSource(), event.getRoleIdentifier());
if (workspaceRoleEntity != null && !workspaceRoleEntity.getId().equals(workspaceUserEntity.getWorkspaceUserRole().getId())) {
workspaceUserEntityController.updateWorkspaceUserRole(workspaceUserEntity, workspaceRoleEntity);
}
}
if (!event.getIsActive() && workspaceUserEntity.getActive()) {
workspaceUserEntityController.updateActive(workspaceUserEntity, event.getIsActive());
}
}
} else {
logger.warning("could not update workspace user because workspace entity #" + event.getWorkspaceIdentifier() + '/' + event.getWorkspaceDataSource() + " could not be found");
}
} else {
logger.warning("could not update workspace user because user entity #" + event.getUserIdentifier() + '/' + event.getUserDataSource() + " could not be found");
}
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class DefaultSchoolDataWorkspaceListener method onSchoolDataWorkspaceDiscoveredEvent.
public synchronized void onSchoolDataWorkspaceDiscoveredEvent(@Observes SchoolDataWorkspaceDiscoveredEvent event) {
String discoverId = "WS-" + event.getDataSource() + "/" + event.getIdentifier();
if (discoveredWorkspaces.containsKey(discoverId)) {
event.setDiscoveredWorkspaceEntityId(discoveredWorkspaces.get(discoverId));
return;
}
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceByDataSourceAndIdentifier(event.getDataSource(), event.getIdentifier());
if (workspaceEntity == null) {
// workspace url name
String urlNameBase = generateWorkspaceUrlName(event.getName());
String urlName = urlNameBase;
int urlNameIterator = 1;
while (workspaceEntityController.findWorkspaceByUrlName(urlName) != null) {
urlName = urlNameBase + "-" + ++urlNameIterator;
}
// workspace
workspaceEntity = workspaceEntityController.createWorkspaceEntity(event.getDataSource(), event.getIdentifier(), urlName);
} else {
logger.warning("workspaceEntity #" + event.getDataSource() + '/' + event.getIdentifier() + " already exists");
}
// workspace bookkeeping
discoveredWorkspaces.put(discoverId, workspaceEntity.getId());
event.setDiscoveredWorkspaceEntityId(workspaceEntity.getId());
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class WorkspaceUserEntityController method listWorkspaceEntitiesByUserIdentifier.
public List<WorkspaceEntity> listWorkspaceEntitiesByUserIdentifier(SchoolDataIdentifier userIdentifier) {
List<WorkspaceEntity> result = new ArrayList<>();
List<WorkspaceUserEntity> workspaceUserEntities = listWorkspaceUserEntitiesByUserIdentifier(userIdentifier);
for (WorkspaceUserEntity workspaceUserEntity : workspaceUserEntities) {
result.add(workspaceUserEntity.getWorkspaceEntity());
}
return result;
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class WorkspaceUserEntityController method listActiveWorkspaceEntitiesByUserIdentifier.
public List<WorkspaceEntity> listActiveWorkspaceEntitiesByUserIdentifier(SchoolDataIdentifier userIdentifier) {
List<WorkspaceEntity> result = new ArrayList<>();
List<WorkspaceUserEntity> workspaceUserEntities = listActiveWorkspaceUserEntitiesByUserIdentifier(userIdentifier);
for (WorkspaceUserEntity workspaceUserEntity : workspaceUserEntities) {
result.add(workspaceUserEntity.getWorkspaceEntity());
}
return result;
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class WorkspaceUserEntityController method listWorkspaceEntitiesByUserEntity.
public List<WorkspaceEntity> listWorkspaceEntitiesByUserEntity(UserEntity userEntity) {
SchoolDataIdentifier schoolDataIdentifier = toSchoolDataIdentifier(userEntity);
List<WorkspaceEntity> result = new ArrayList<>();
List<WorkspaceUserEntity> workspaceUserEntities = listWorkspaceUserEntitiesByUserIdentifier(schoolDataIdentifier);
for (WorkspaceUserEntity workspaceUserEntity : workspaceUserEntities) {
result.add(workspaceUserEntity.getWorkspaceEntity());
}
return result;
}
Aggregations