Search in sources :

Example 11 with UserSchoolDataIdentifier

use of fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier in project muikku by otavanopisto.

the class WorkspaceSystemRESTService method ensureCorrectWorkspaceStudent.

private void ensureCorrectWorkspaceStudent(WorkspaceUserEntity muikkuWorkspaceStudent, SchoolDataIdentifier muikkuStudentIdentifier, SchoolDataIdentifier pyramusStudentIdentifier) {
    if (!pyramusStudentIdentifier.equals(muikkuStudentIdentifier)) {
        logger.warning(String.format("Muikku workspace student points to student %s and Pyramus to student %s", muikkuStudentIdentifier, pyramusStudentIdentifier));
        UserSchoolDataIdentifier userSchoolDataIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierBySchoolDataIdentifier(pyramusStudentIdentifier);
        if (userSchoolDataIdentifier == null) {
            logger.severe(String.format("Unable to fix: UserSchoolDataIdentifier for Pyramus student %s not found", pyramusStudentIdentifier));
        } else if (!userSchoolDataIdentifier.getUserEntity().getId().equals(muikkuWorkspaceStudent.getUserSchoolDataIdentifier().getUserEntity().getId())) {
            logger.severe("Unable to fix: UserSchoolDataIdentifiers in Muikku and Pyramus point to different users");
        } else {
            // Muikku and Pyramus students are not the same. Let's see if we can find a workspace student with workspace + student combo
            WorkspaceUserEntity existingStudent = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceAndUserIdentifierIncludeArchived(muikkuWorkspaceStudent.getWorkspaceEntity(), pyramusStudentIdentifier);
            if (existingStudent != null && !existingStudent.getId().equals(muikkuWorkspaceStudent.getId())) {
                // We can, so delete the workspace student we had and use the one we found instead, unarchiving it if needed
                if (existingStudent.getArchived()) {
                    workspaceUserEntityController.unarchiveWorkspaceUserEntity(existingStudent);
                }
                workspaceUserEntityController.updateIdentifier(existingStudent, muikkuWorkspaceStudent.getIdentifier());
                workspaceUserEntityController.archiveWorkspaceUserEntity(muikkuWorkspaceStudent);
                muikkuWorkspaceStudent = existingStudent;
            }
            // Set workspace student to point at the same student as in Pyramus
            workspaceUserEntityController.updateUserSchoolDataIdentifier(muikkuWorkspaceStudent, userSchoolDataIdentifier);
            logger.info("Muikku workspace student UserSchoolDataIdentifier updated");
        }
    }
}
Also used : UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)

Example 12 with UserSchoolDataIdentifier

use of fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier in project muikku by otavanopisto.

the class UserSchoolDataController method findUserEntity.

/* User Entity */
public UserEntity findUserEntity(User user) {
    SchoolDataSource schoolDataSource = schoolDataSourceDAO.findByIdentifier(user.getSchoolDataSource());
    UserSchoolDataIdentifier userSchoolDataIdentifier = userSchoolDataIdentifierDAO.findByDataSourceAndIdentifierAndArchived(schoolDataSource, user.getIdentifier(), Boolean.FALSE);
    return userSchoolDataIdentifier == null ? null : userSchoolDataIdentifier.getUserEntity();
}
Also used : UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) SchoolDataSource(fi.otavanopisto.muikku.model.base.SchoolDataSource)

Example 13 with UserSchoolDataIdentifier

use of fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier in project muikku by otavanopisto.

the class PyramusSchoolDataUserListener method handlePyramusUserUpdated.

private void handlePyramusUserUpdated(SchoolDataIdentifier identifier) {
    Long pyramusStudentId = identifierMapper.getPyramusStudentId(identifier.getIdentifier());
    if (pyramusStudentId != null) {
        Student student = pyramusClient.get().get(String.format("/students/students/%d", pyramusStudentId), Student.class);
        if (student != null) {
            Long pyramusStudyProgrammeId = student.getStudyProgrammeId();
            if (pyramusStudyProgrammeId != null) {
                String userGroupIdentifier = identifierMapper.getStudyProgrammeIdentifier(pyramusStudyProgrammeId);
                boolean found = false;
                boolean isActive = !student.getArchived() && (student.getStudyEndDate() == null || student.getStudyEndDate().isAfter(OffsetDateTime.now()));
                if (!isActive) {
                    schoolDataUserInactiveEvent.fire(new SchoolDataUserInactiveEvent(identifier.getDataSource(), identifier.getIdentifier()));
                }
                // Remove StudyProgrammeGroups
                UserSchoolDataIdentifier userSchoolDataIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierByDataSourceAndIdentifier(identifier.getDataSource(), identifier.getIdentifier());
                List<UserGroupUserEntity> userGroupUsers = userGroupEntityController.listUserGroupUsersByUserSchoolDataIdentifier(userSchoolDataIdentifier);
                for (UserGroupUserEntity userGroupUser : userGroupUsers) {
                    UserGroupEntity userGroup = userGroupUser.getUserGroupEntity();
                    StudentGroupType studentGroupType = identifierMapper.getStudentGroupType(userGroup.getIdentifier());
                    if (studentGroupType == StudentGroupType.STUDYPROGRAMME) {
                        boolean archived = Boolean.TRUE.equals(userGroupUser.getArchived());
                        if (!archived && !isActive) {
                            fireUserGroupUserRemoved(userGroupUser.getIdentifier(), userGroup.getIdentifier(), identifier.getIdentifier());
                        } else {
                            found = !archived;
                        }
                    }
                }
                if (!found && isActive) {
                    String userGroupUserIdentifier = identifierMapper.getStudyProgrammeStudentIdentifier(pyramusStudentId);
                    fireUserGroupUserDiscovered(userGroupUserIdentifier, userGroupIdentifier, identifier.getIdentifier());
                }
            }
        }
    }
}
Also used : SchoolDataUserInactiveEvent(fi.otavanopisto.muikku.schooldata.events.SchoolDataUserInactiveEvent) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) Student(fi.otavanopisto.pyramus.rest.model.Student) StudentGroupType(fi.otavanopisto.muikku.plugins.schooldatapyramus.PyramusIdentifierMapper.StudentGroupType)

Example 14 with UserSchoolDataIdentifier

use of fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier in project muikku by otavanopisto.

the class DefaultSchoolDataUserGroupListener method onSchoolDataUserGroupUserUpdatedEvent.

public void onSchoolDataUserGroupUserUpdatedEvent(@Observes SchoolDataUserGroupUserUpdatedEvent event) {
    UserGroupUserEntity userGroupUserEntity = userGroupEntityController.findUserGroupUserEntityByDataSourceAndIdentifier(event.getDataSource(), event.getIdentifier());
    UserGroupEntity userGroupEntity = userGroupEntityController.findUserGroupEntityByDataSourceAndIdentifier(event.getUserGroupDataSource(), event.getUserGroupIdentifier());
    UserSchoolDataIdentifier userSchoolDataIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierByDataSourceAndIdentifier(event.getUserDataSource(), event.getUserIdentifier());
    if ((userGroupUserEntity != null) && (userGroupEntity != null) && (userSchoolDataIdentifier != null)) {
        userGroupEntityController.updateUserGroupEntity(userGroupUserEntity, userGroupEntity);
        userGroupEntityController.updateUserSchoolDataIdentifier(userGroupUserEntity, userSchoolDataIdentifier);
    } else
        logger.warning(String.format("Couldn't find userGroupUserEntity (%s) or userGroupEntity (%s)", event.getIdentifier(), event.getUserGroupIdentifier()));
}
Also used : UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity)

Example 15 with UserSchoolDataIdentifier

use of fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier in project muikku by otavanopisto.

the class DefaultSchoolDataUserGroupListener method onSchoolDataUserGroupUserDiscoveredEvent.

public void onSchoolDataUserGroupUserDiscoveredEvent(@Observes SchoolDataUserGroupUserDiscoveredEvent event) {
    String discoverId = getUserGroupUserDiscoveryId(event.getDataSource(), event.getIdentifier());
    if (discoveredUserGroupUsers.containsKey(discoverId)) {
        event.setDiscoveredUserGroupUserEntityId(discoveredUserGroupUsers.get(discoverId));
        return;
    }
    UserGroupEntity userGroupEntity = userGroupEntityController.findUserGroupEntityByDataSourceAndIdentifier(event.getUserGroupDataSource(), event.getUserGroupIdentifier(), true);
    if (userGroupEntity != null) {
        if (!userGroupEntity.getArchived()) {
            UserGroupUserEntity userGroupUserEntity = userGroupEntityController.findUserGroupUserEntityByDataSourceAndIdentifier(event.getDataSource(), event.getIdentifier(), true);
            if ((userGroupUserEntity == null) || (userGroupUserEntity.getArchived())) {
                UserSchoolDataIdentifier userSchoolDataIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierByDataSourceAndIdentifier(event.getUserDataSource(), event.getUserIdentifier());
                if (userSchoolDataIdentifier != null) {
                    if (userGroupUserEntity == null) {
                        userGroupUserEntity = userGroupEntityController.createUserGroupUserEntity(userGroupEntity, event.getDataSource(), event.getIdentifier(), userSchoolDataIdentifier);
                    } else {
                        userGroupEntityController.unarchiveUserGroupUserEntity(userGroupUserEntity);
                        userGroupEntityController.updateUserSchoolDataIdentifier(userGroupUserEntity, userSchoolDataIdentifier);
                    }
                    discoveredUserGroupUsers.put(discoverId, userGroupUserEntity.getId());
                    event.setDiscoveredUserGroupUserEntityId(userGroupUserEntity.getId());
                } else {
                    logger.warning("could not add group user because UserSchoolDataIdentifier for " + event.getUserIdentifier() + "/" + event.getUserDataSource() + " wasn't found");
                }
            } else {
                logger.warning("UserGroupUserEntity for " + event.getIdentifier() + "/" + event.getDataSource() + " already exists");
            }
        }
    } else {
        logger.warning("could not init user group user because usergroup #" + event.getUserGroupIdentifier() + '/' + event.getUserGroupDataSource() + " could not be found");
    }
}
Also used : UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity)

Aggregations

UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)37 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)14 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)14 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)11 UserGroupUserEntity (fi.otavanopisto.muikku.model.users.UserGroupUserEntity)10 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)10 ArrayList (java.util.ArrayList)10 UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)9 EntityManager (javax.persistence.EntityManager)7 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)7 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)6 Path (javax.ws.rs.Path)6 FlagStudent (fi.otavanopisto.muikku.model.users.FlagStudent)5 User (fi.otavanopisto.muikku.schooldata.entity.User)5 WorkspaceRoleEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceRoleEntity)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 CommunicatorMessageId (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId)3 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)3 Flag (fi.otavanopisto.muikku.model.users.Flag)2