Search in sources :

Example 11 with UserGroupUserEntity

use of fi.otavanopisto.muikku.model.users.UserGroupUserEntity 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)

Example 12 with UserGroupUserEntity

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

the class PyramusSchoolDataUserListener method handlePyramusUserRemoved.

private void handlePyramusUserRemoved(SchoolDataIdentifier identifier) {
    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) {
            fireUserGroupUserRemoved(userGroupUser.getIdentifier(), userGroup.getIdentifier(), identifier.getIdentifier());
        }
    }
}
Also used : UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) StudentGroupType(fi.otavanopisto.muikku.plugins.schooldatapyramus.PyramusIdentifierMapper.StudentGroupType)

Example 13 with UserGroupUserEntity

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

the class PyramusUpdater method updateStudyProgrammeMember.

public void updateStudyProgrammeMember(Student student) {
    if (student.getStudyProgrammeId() != null) {
        String studyProgrammeIdentifier = identifierMapper.getStudyProgrammeIdentifier(student.getStudyProgrammeId());
        String studyProgrammeStudentIdentifier = identifierMapper.getStudyProgrammeStudentIdentifier(student.getId());
        UserGroupUserEntity userGroupUserEntity = userGroupEntityController.findUserGroupUserEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, studyProgrammeStudentIdentifier);
        boolean isActive = !student.getArchived() && (student.getStudyEndDate() == null || student.getStudyEndDate().isAfter(OffsetDateTime.now()));
        if (isActive) {
            if (userGroupUserEntity == null) {
                String userEntityIdentifier = identifierMapper.getStudentIdentifier(student.getId());
                fireUserGroupUserDiscovered(studyProgrammeStudentIdentifier, studyProgrammeIdentifier, userEntityIdentifier);
            } else
                fireUserGroupUserUpdated(studyProgrammeStudentIdentifier, studyProgrammeIdentifier, userGroupUserEntity.getUserSchoolDataIdentifier().getIdentifier());
        } else {
            if (userGroupUserEntity != null)
                fireUserGroupUserRemoved(studyProgrammeStudentIdentifier, studyProgrammeIdentifier, userGroupUserEntity.getUserSchoolDataIdentifier().getIdentifier());
        }
    }
}
Also used : UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity)

Example 14 with UserGroupUserEntity

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

the class PyramusUpdater method updateStudentGroupUsers.

public int updateStudentGroupUsers(Long studentGroupId) {
    String userGroupIdentifier = identifierMapper.getStudentGroupIdentifier(studentGroupId);
    UserGroupEntity userGroupEntity = userGroupEntityController.findUserGroupEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, userGroupIdentifier, true);
    if (userGroupEntity != null) {
        if (userGroupEntity.getArchived()) {
            // Just skip archived user groups
            return 0;
        }
        List<UserGroupUserEntity> existingUsers = userGroupEntityController.listUserGroupUserEntitiesByUserGroupEntity(userGroupEntity);
        List<String> existingGroupUserIds = new ArrayList<String>();
        for (UserGroupUserEntity existingUser : existingUsers) {
            existingGroupUserIds.add(existingUser.getIdentifier());
        }
        List<String> foundGroupUserIds = new ArrayList<String>();
        int count = 0;
        StudentGroupUser[] userGroupStaffMembers = pyramusClient.get().get(String.format("/students/studentGroups/%d/staffmembers", studentGroupId), StudentGroupUser[].class);
        if (userGroupStaffMembers != null) {
            for (StudentGroupUser sgStaffMember : userGroupStaffMembers) {
                String identifier = identifierMapper.getStudentGroupStaffMemberIdentifier(sgStaffMember.getId());
                foundGroupUserIds.add(identifier);
                // If not existing, then it's a new one
                if (!existingGroupUserIds.contains(identifier)) {
                    String staffMemberIdentifier = identifierMapper.getStaffIdentifier(sgStaffMember.getStaffMemberId());
                    fireUserGroupUserDiscovered(identifier, userGroupIdentifier, staffMemberIdentifier);
                }
            }
            count += userGroupStaffMembers.length;
        }
        StudentGroupStudent[] userGroupStudents = pyramusClient.get().get(String.format("/students/studentGroups/%d/students", studentGroupId), StudentGroupStudent[].class);
        if (userGroupStudents != null) {
            for (StudentGroupStudent sgs : userGroupStudents) {
                String identifier = identifierMapper.getStudentGroupStudentIdentifier(sgs.getId());
                foundGroupUserIds.add(identifier);
                // If not existing, then it's a new one
                if (!existingGroupUserIds.contains(identifier)) {
                    String studentIdentifier = identifierMapper.getStudentIdentifier(sgs.getStudentId());
                    fireUserGroupUserDiscovered(identifier, userGroupIdentifier, studentIdentifier);
                }
            }
            count += userGroupStudents.length;
        }
        // Remove found ids from existing and we'll get the ones to remove
        existingGroupUserIds.removeAll(foundGroupUserIds);
        for (String identifier : existingGroupUserIds) {
            UserGroupUserEntity ugu = userGroupEntityController.findUserGroupUserEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, identifier);
            if (ugu != null)
                fireUserGroupUserRemoved(identifier, userGroupIdentifier, ugu.getUserSchoolDataIdentifier().getIdentifier());
        }
        return count;
    } else {
        logger.log(Level.WARNING, String.format("UserGroup is null for id %d - update of users is skipped", studentGroupId));
    }
    return 0;
}
Also used : StudentGroupStudent(fi.otavanopisto.pyramus.rest.model.StudentGroupStudent) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) ArrayList(java.util.ArrayList) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) StudentGroupUser(fi.otavanopisto.pyramus.rest.model.StudentGroupUser)

Example 15 with UserGroupUserEntity

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

the class PyramusUpdater method updateStudentGroupStudent.

public void updateStudentGroupStudent(Long studentGroupId, Long studentGroupStudentId) {
    StudentGroupStudent studentGroupStudent = pyramusClient.get().get(String.format("/students/studentGroups/%d/students/%d", studentGroupId, studentGroupStudentId), StudentGroupStudent.class);
    String identifier = identifierMapper.getStudentGroupStudentIdentifier(studentGroupStudentId);
    UserGroupUserEntity userGroupUserEntity = userGroupEntityController.findUserGroupUserEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, identifier);
    String userGroupIdentifier = identifierMapper.getStudentGroupIdentifier(studentGroupId);
    if (studentGroupStudent == null) {
        if (userGroupUserEntity != null)
            fireUserGroupUserRemoved(identifier, userGroupIdentifier, userGroupUserEntity.getUserSchoolDataIdentifier().getIdentifier());
    } else {
        String studentIdentifier = identifierMapper.getStudentIdentifier(studentGroupStudent.getStudentId());
        if (userGroupUserEntity == null) {
            fireUserGroupUserDiscovered(identifier, userGroupIdentifier, studentIdentifier);
        } else {
            fireUserGroupUserUpdated(identifier, userGroupIdentifier, studentIdentifier);
        }
    }
}
Also used : StudentGroupStudent(fi.otavanopisto.pyramus.rest.model.StudentGroupStudent) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity)

Aggregations

UserGroupUserEntity (fi.otavanopisto.muikku.model.users.UserGroupUserEntity)22 UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)11 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)8 EntityManager (javax.persistence.EntityManager)8 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)8 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)3 Path (javax.ws.rs.Path)3 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)2 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)2 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)2 StudentGroupType (fi.otavanopisto.muikku.plugins.schooldatapyramus.PyramusIdentifierMapper.StudentGroupType)2 StudentGroupStudent (fi.otavanopisto.pyramus.rest.model.StudentGroupStudent)2 StudentGroupUser (fi.otavanopisto.pyramus.rest.model.StudentGroupUser)2 ArrayList (java.util.ArrayList)2 DELETE (javax.ws.rs.DELETE)2 Tag (fi.otavanopisto.muikku.model.base.Tag)1 CommunicatorMessage (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage)1 CommunicatorMessageCategory (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageCategory)1 CommunicatorMessageId (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId)1 CommunicatorMessageRecipientUserGroup (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientUserGroup)1