Search in sources :

Example 6 with UserGroupUserEntity

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

the class UserGroupUserEntityDAO method listByUserGroupEntityAndArchived.

public List<UserGroupUserEntity> listByUserGroupEntityAndArchived(UserGroupEntity userGroupEntity, Boolean archived) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<UserGroupUserEntity> criteria = criteriaBuilder.createQuery(UserGroupUserEntity.class);
    Root<UserGroupUserEntity> root = criteria.from(UserGroupUserEntity.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(UserGroupUserEntity_.userGroupEntity), userGroupEntity), criteriaBuilder.equal(root.get(UserGroupUserEntity_.archived), archived)));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity)

Example 7 with UserGroupUserEntity

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

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

the class PyramusUpdater method updateStudentGroupStaffMember.

public void updateStudentGroupStaffMember(Long studentGroupId, Long studentGroupStaffMemberId) {
    StudentGroupUser studentGroupStaffMember = pyramusClient.get().get(String.format("/students/studentGroups/%d/staffmembers/%d", studentGroupId, studentGroupStaffMemberId), StudentGroupUser.class);
    String identifier = identifierMapper.getStudentGroupStaffMemberIdentifier(studentGroupStaffMemberId);
    UserGroupUserEntity userGroupUserEntity = userGroupEntityController.findUserGroupUserEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, identifier);
    String userGroupIdentifier = identifierMapper.getStudentGroupIdentifier(studentGroupId);
    if (studentGroupStaffMember == null) {
        if (userGroupUserEntity != null)
            fireUserGroupUserRemoved(identifier, userGroupIdentifier, userGroupUserEntity.getUserSchoolDataIdentifier().getIdentifier());
    } else {
        if (userGroupUserEntity == null) {
            String staffMemberIdentifier = identifierMapper.getStaffIdentifier(studentGroupStaffMember.getStaffMemberId());
            fireUserGroupUserDiscovered(identifier, userGroupIdentifier, staffMemberIdentifier);
        } else {
            fireUserGroupUserUpdated(identifier, userGroupIdentifier, userGroupUserEntity.getUserSchoolDataIdentifier().getIdentifier());
        }
    }
}
Also used : UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) StudentGroupUser(fi.otavanopisto.pyramus.rest.model.StudentGroupUser)

Example 9 with UserGroupUserEntity

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

the class DefaultSchoolDataUserGroupListener method onSchoolDataUserGroupUserRemovedEvent.

public void onSchoolDataUserGroupUserRemovedEvent(@Observes SchoolDataUserGroupUserRemovedEvent event) {
    String discoverId = getUserGroupUserDiscoveryId(event.getDataSource(), event.getIdentifier());
    discoveredUserGroupUsers.remove(discoverId);
    UserGroupUserEntity userGroupUserEntity = userGroupEntityController.findUserGroupUserEntityByDataSourceAndIdentifier(event.getDataSource(), event.getIdentifier());
    if (userGroupUserEntity != null) {
        userGroupEntityController.archiveUserGroupUserEntity(userGroupUserEntity);
    }
}
Also used : UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity)

Example 10 with UserGroupUserEntity

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

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