use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class CommunicatorController method createMessage.
public CommunicatorMessage createMessage(CommunicatorMessageId communicatorMessageId, UserEntity sender, List<UserEntity> userRecipients, List<UserGroupEntity> userGroupRecipients, List<WorkspaceEntity> workspaceStudentRecipients, List<WorkspaceEntity> workspaceTeacherRecipients, CommunicatorMessageCategory category, String caption, String content, Set<Tag> tags) {
CommunicatorMessage message = communicatorMessageDAO.create(communicatorMessageId, sender.getId(), category, caption, clean(content), new Date(), tags);
// Clean duplicates from recipient list
cleanDuplicateRecipients(userRecipients);
Set<Long> recipientIds = new HashSet<Long>();
for (UserEntity recipient : userRecipients) {
// #3758: Only send messages to active users
if (!isActiveUser(recipient)) {
continue;
}
if (!recipientIds.contains(recipient.getId())) {
recipientIds.add(recipient.getId());
communicatorMessageRecipientDAO.create(message, recipient, null);
}
}
if (!CollectionUtils.isEmpty(userGroupRecipients)) {
for (UserGroupEntity userGroup : userGroupRecipients) {
List<UserGroupUserEntity> groupUsers = userGroupEntityController.listUserGroupUserEntitiesByUserGroupEntity(userGroup);
if (!CollectionUtils.isEmpty(groupUsers)) {
CommunicatorMessageRecipientUserGroup groupRecipient = createUserGroupRecipient(userGroup);
for (UserGroupUserEntity groupUser : groupUsers) {
UserSchoolDataIdentifier userSchoolDataIdentifier = groupUser.getUserSchoolDataIdentifier();
UserEntity recipient = userSchoolDataIdentifier.getUserEntity();
// #3758: Only send messages to active users
if (!isActiveUser(recipient)) {
continue;
}
if ((recipient != null) && !Objects.equals(sender.getId(), recipient.getId())) {
if (!recipientIds.contains(recipient.getId())) {
recipientIds.add(recipient.getId());
communicatorMessageRecipientDAO.create(message, recipient, groupRecipient);
}
}
}
}
}
}
if (!CollectionUtils.isEmpty(workspaceStudentRecipients)) {
for (WorkspaceEntity workspaceEntity : workspaceStudentRecipients) {
List<WorkspaceUserEntity> workspaceUsers = workspaceUserEntityController.listActiveWorkspaceStudents(workspaceEntity);
if (!CollectionUtils.isEmpty(workspaceUsers)) {
CommunicatorMessageRecipientWorkspaceGroup groupRecipient = createWorkspaceGroupRecipient(workspaceEntity, WorkspaceRoleArchetype.STUDENT);
for (WorkspaceUserEntity workspaceUserEntity : workspaceUsers) {
UserEntity recipient = workspaceUserEntity.getUserSchoolDataIdentifier().getUserEntity();
// #3758: Only send messages to active users
if (!isActiveUser(recipient)) {
continue;
}
if ((recipient != null) && !Objects.equals(sender.getId(), recipient.getId())) {
if (!recipientIds.contains(recipient.getId())) {
recipientIds.add(recipient.getId());
communicatorMessageRecipientDAO.create(message, recipient, groupRecipient);
}
}
}
}
}
}
if (!CollectionUtils.isEmpty(workspaceTeacherRecipients)) {
for (WorkspaceEntity workspaceEntity : workspaceTeacherRecipients) {
List<WorkspaceUserEntity> workspaceUsers = workspaceUserEntityController.listActiveWorkspaceStaffMembers(workspaceEntity);
if (!CollectionUtils.isEmpty(workspaceUsers)) {
CommunicatorMessageRecipientWorkspaceGroup groupRecipient = createWorkspaceGroupRecipient(workspaceEntity, WorkspaceRoleArchetype.TEACHER);
for (WorkspaceUserEntity wosu : workspaceUsers) {
UserEntity recipient = wosu.getUserSchoolDataIdentifier().getUserEntity();
// #3758: Workspace teachers are considered active, no need to check
if ((recipient != null) && !Objects.equals(sender.getId(), recipient.getId())) {
if (!recipientIds.contains(recipient.getId())) {
recipientIds.add(recipient.getId());
communicatorMessageRecipientDAO.create(message, recipient, groupRecipient);
}
}
}
}
}
}
return message;
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity 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");
}
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity 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.WorkspaceUserEntity 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.WorkspaceUserEntity 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;
}
Aggregations