Ejemplo n.º 1
0
        public void Should_map_and_return_newparticipant_with_address_and_organistaion()
        {
            var request = new ParticipantRequest
            {
                Title           = "Mr",
                FirstName       = "Test",
                LastName        = "Tester",
                Username        = "******",
                CaseRoleName    = "Claimant",
                HearingRoleName = "Representative",
                HouseNumber     = "123A",
                Street          = "Test Street",
                Postcode        = "SW1V 1AB",
                City            = "Westminister",
                County          = "London"
            };

            var newParticipant = new ParticipantRequestToNewParticipantMapper().MapRequestToNewParticipant(request, _caseType);

            newParticipant.Should().NotBeNull();
            var person = newParticipant.Person;

            person.Should().NotBeNull();
            person.Address.Should().NotBeNull();
            person.Organisation.Should().BeNull();
        }
        public static NewParticipant Map(ParticipantRequest requestParticipant, CaseType caseType)
        {
            var caseRole = caseType.CaseRoles.FirstOrDefault(x => x.Name == requestParticipant.CaseRoleName);
            if (caseRole == null) throw new BadRequestException($"Invalid case role [{requestParticipant.CaseRoleName}]");

            var hearingRole = caseRole.HearingRoles.FirstOrDefault(x => x.Name == requestParticipant.HearingRoleName);
            if (hearingRole == null) throw new BadRequestException($"Invalid hearing role [{requestParticipant.HearingRoleName}]");

            var person = new Person(requestParticipant.Title, requestParticipant.FirstName, requestParticipant.LastName,
                requestParticipant.Username)
            {
                MiddleNames = requestParticipant.MiddleNames,
                ContactEmail = requestParticipant.ContactEmail,
                TelephoneNumber = requestParticipant.TelephoneNumber
            };

            if(!string.IsNullOrEmpty(requestParticipant.OrganisationName))
            {
                person.Organisation = new Organisation(requestParticipant.OrganisationName);
            }

            return new NewParticipant
            {
                Person = person,
                CaseRole = caseRole,
                HearingRole = hearingRole,
                DisplayName = requestParticipant.DisplayName,
                Representee = requestParticipant.Representee
            };
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public async Task <User> UpdateParticipantUsername(ParticipantRequest participant)
        {
            // create user in AD if users email does not exist in AD.
            _logger.LogDebug("Checking for username with contact email {contactEmail}.", participant.ContactEmail);
            var userProfile = await GetUserByContactEmail(participant.ContactEmail);

            if (userProfile == null)
            {
                _logger.LogDebug("User with contact email {contactEmail} does not exist. Creating an account.", participant.ContactEmail);
                // create the user in AD.
                var newUser = await CreateNewUserInAD(participant);

                return(new User
                {
                    UserName = newUser.UserId,
                    Password = newUser.OneTimePassword
                });
            }

            participant.Username = userProfile.UserName;
            return(new User
            {
                UserName = userProfile.UserId
            });
        }
 public ParticipantRequestBuilder(UserRole userRole)
 {
     _participantRequest = Builder <ParticipantRequest> .CreateNew()
                           .With(x => x.Name        = $"Automation_{Name.FullName()}")
                           .With(x => x.Username    = $"Automation_{Internet.Email()}")
                           .With(x => x.DisplayName = $"Automation_{Internet.UserName()}")
                           .With(x => x.UserRole    = userRole)
                           .Build();
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Constructor sets the <see cref="Participant"/>; and the
 /// <see cref="Request"/>.
 /// </summary>
 /// <param name="participant">Required in this constructor.</param>
 /// <param name="request">Required in this constructor; and must not be
 /// <see cref="ParticipantRequest.None"/>.</param>
 /// <exception cref="ArgumentNullException"></exception>
 /// <exception cref="InvalidEnumArgumentException"></exception>
 public RequestCompositionEventArgs(IComposerParticipant <TTarget> participant, ParticipantRequest request)
 {
     if (!Enum.IsDefined(typeof(ParticipantRequest), request) ||
         (request == ParticipantRequest.None))
     {
         throw new InvalidEnumArgumentException(nameof(request), (int)request, typeof(ParticipantRequest));
     }
     Participant = participant ?? throw new ArgumentNullException(nameof(participant));
     Request     = request;
 }
 public ParticipantRequestBuilder(UserRole userRole)
 {
     _participantRequest = Builder <ParticipantRequest> .CreateNew()
                           .With(x => x.Name             = $"Automation_{Name.FullName()}")
                           .With(x => x.ParticipantRefId = Guid.NewGuid())
                           .With(x => x.Username         = $"Automation_{RandomNumber.Next()}@hmcts.net")
                           .With(x => x.DisplayName      = $"Automation_{Internet.UserName()}")
                           .With(x => x.UserRole         = userRole)
                           .Build();
 }
Ejemplo n.º 7
0
        public void Should_raise_bad_request_exception_on_invalid_hearing_role()
        {
            var request = new ParticipantRequest
            {
                CaseRoleName    = "Claimant",
                HearingRoleName = "Missing hearing role"
            };

            When(() => new ParticipantRequestToNewParticipantMapper().MapRequestToNewParticipant(request, _caseType))
            .Should().Throw <BadRequestException>().WithMessage("Invalid hearing role [Missing hearing role]");
        }
Ejemplo n.º 8
0
        public void Should_raise_bad_request_exception_on_invalid_case_role()
        {
            var request = new ParticipantRequest
            {
                CaseRoleName    = "Missing case role",
                HearingRoleName = "Representative"
            };

            When(() => ParticipantRequestToNewParticipantMapper.Map(request, _caseType))
            .Should().Throw <BadRequestException>().WithMessage("Invalid case role [Missing case role]");
        }
 public ParticipantRequestBuilder(string caseRole, string hearingRole)
 {
     _participantRequest = Builder <ParticipantRequest> .CreateNew()
                           .With(x => x.CaseRoleName    = caseRole)
                           .With(x => x.HearingRoleName = hearingRole)
                           .With(x => x.Title           = Name.Prefix())
                           .With(x => x.FirstName       = $"Automation_{Name.First()}")
                           .With(x => x.LastName        = $"Automation_{Name.Last()}")
                           .With(x => x.Username        = $"Automation_{RandomNumber.Next()}@hmcts.net")
                           .With(x => x.ContactEmail    = $"Automation_{RandomNumber.Next()}@hmcts.net")
                           .With(x => x.TelephoneNumber = Phone.Number())
                           .Build();
 }
Ejemplo n.º 10
0
        private ParticipantRequest AddParticipant(string userType, int number = 1)
        {
            var firstname = $"{UserData.AUTOMATED_FIRST_NAME_PREFIX}__{Faker.Name.First()}_{UserData.BOOKING_QUEUE_SUBSCRIBER_NAME_PREFIX}";
            var lastname  = $"{Faker.Name.Last()}_{userType} {number}";

            var participant = new ParticipantRequest()
            {
                Title            = UserData.TITLE,
                FirstName        = firstname,
                MiddleNames      = UserData.MIDDLE_NAME,
                LastName         = lastname,
                DisplayName      = $"{firstname} {lastname}",
                ContactEmail     = SetContactEmail(firstname, lastname),
                Username         = SetUsername(firstname, lastname),
                TelephoneNumber  = UserData.TELEPHONE_NUMBER,
                CaseRoleName     = userType,
                HearingRoleName  = userType,
                Representee      = null,
                OrganisationName = null
            };

            if (userType.Equals("Individual"))
            {
                participant.CaseRoleName    = _isCacdHearing ? RoleData.CACD_CASE_ROLE_NAME : RoleData.CASE_ROLE_NAME;
                participant.HearingRoleName = _isCacdHearing ? RoleData.APPELLANT_CASE_ROLE_NAME : RoleData.INDV_HEARING_ROLE_NAME;
            }

            if (userType.Equals("Representative"))
            {
                participant.CaseRoleName     = _isCacdHearing ? RoleData.CACD_CASE_ROLE_NAME : RoleData.CASE_ROLE_NAME;
                participant.HearingRoleName  = _isCacdHearing ? RoleData.CACD_REP_HEARING_ROLE_NAME : RoleData.REPRESENTATIVE_HEARING_ROLE_NAME;
                participant.Representee      = "Individual";
                participant.OrganisationName = UserData.ORGANISATION;
            }

            if (userType.Equals("Winger"))
            {
                participant.CaseRoleName    = _isCacdHearing ? RoleData.CACD_CASE_ROLE_NAME : RoleData.WINGER_ROLE_NAME;
                participant.HearingRoleName =
                    _isCacdHearing ? RoleData.CACD_REP_HEARING_ROLE_NAME : RoleData.WINGER_ROLE_NAME;
            }

            if (userType.Equals("Interpreter"))
            {
                participant.CaseRoleName    = _isCacdHearing ? RoleData.CACD_CASE_ROLE_NAME : RoleData.CASE_ROLE_NAME;
                participant.HearingRoleName = RoleData.INTERPRETER_HEARING_ROLE_NAME;
            }

            return(participant);
        }
Ejemplo n.º 11
0
        public NewParticipant MapRequestToNewParticipant(ParticipantRequest requestParticipant, CaseType caseType)
        {
            var caseRole = caseType.CaseRoles.FirstOrDefault(x => x.Name == requestParticipant.CaseRoleName);

            if (caseRole == null)
            {
                throw new BadRequestException($"Invalid case role [{requestParticipant.CaseRoleName}]");
            }

            var hearingRole = caseRole.HearingRoles.FirstOrDefault(x => x.Name == requestParticipant.HearingRoleName);

            if (hearingRole == null)
            {
                throw new BadRequestException($"Invalid hearing role [{requestParticipant.HearingRoleName}]");
            }
            Person person;

            if (hearingRole.UserRole.IsIndividual)
            {
                var address = new Address(requestParticipant.HouseNumber, requestParticipant.Street, requestParticipant.Postcode, requestParticipant.City, requestParticipant.County);
                person = new Person(requestParticipant.Title, requestParticipant.FirstName, requestParticipant.LastName,
                                    requestParticipant.Username, address);
            }
            else
            {
                person = new Person(requestParticipant.Title, requestParticipant.FirstName, requestParticipant.LastName,
                                    requestParticipant.Username);
            }

            person.MiddleNames     = requestParticipant.MiddleNames;
            person.ContactEmail    = requestParticipant.ContactEmail;
            person.TelephoneNumber = requestParticipant.TelephoneNumber;
            if (!string.IsNullOrEmpty(requestParticipant.OrganisationName))
            {
                person.Organisation = new Organisation(requestParticipant.OrganisationName);
            }

            return(new NewParticipant
            {
                Person = person,
                CaseRole = caseRole,
                HearingRole = hearingRole,
                DisplayName = requestParticipant.DisplayName,
                Representee = requestParticipant.Representee,
                Reference = requestParticipant.Reference,
            });
        }
Ejemplo n.º 12
0
        public static ParticipantRequest MapTo(EditParticipantRequest participant)
        {
            var newParticipant = new ParticipantRequest()
            {
                CaseRoleName     = participant.CaseRoleName,
                ContactEmail     = participant.ContactEmail,
                DisplayName      = participant.DisplayName,
                FirstName        = participant.FirstName,
                LastName         = participant.LastName,
                HearingRoleName  = participant.HearingRoleName,
                MiddleNames      = participant.MiddleNames,
                Representee      = participant.Representee,
                TelephoneNumber  = participant.TelephoneNumber,
                Title            = participant.Title,
                OrganisationName = participant.OrganisationName,
            };

            return(newParticipant);
        }
Ejemplo n.º 13
0
        private async Task <NewUserResponse> CreateNewUserInAD(ParticipantRequest participant)
        {
            const string BLANK = " ";

            _logger.LogDebug("Attempting to create an AD user with contact email {contactEmail}.", participant.ContactEmail);
            var createUserRequest = new CreateUserRequest
            {
                FirstName     = participant.FirstName?.Replace(BLANK, string.Empty),
                LastName      = participant.LastName?.Replace(BLANK, string.Empty),
                RecoveryEmail = participant.ContactEmail,
                IsTestUser    = false
            };

            var newUserResponse = await _userApiClient.CreateUserAsync(createUserRequest);

            _logger.LogDebug("Successfully created an AD user with contact email {contactEmail}.", participant.ContactEmail);
            participant.Username = newUserResponse.Username;
            return(newUserResponse);
        }
Ejemplo n.º 14
0
        public void Should_map_and_return_newparticipant_with_organistaion()
        {
            var request = new ParticipantRequest
            {
                Title            = "Mr",
                FirstName        = "Test",
                LastName         = "Tester",
                Username         = "******",
                CaseRoleName     = "Respondent",
                HearingRoleName  = "Representative",
                OrganisationName = "Test Corp Ltd"
            };

            var newParticipant = ParticipantRequestToNewParticipantMapper.Map(request, _caseType);

            newParticipant.Should().NotBeNull();
            var person = newParticipant.Person;

            person.Should().NotBeNull();
            person.Organisation.Should().NotBeNull();
        }
        public static ParticipantRequest MapToParticipantRequest(ParticipantDto participant)
        {
            var request = new ParticipantRequest
            {
                Name               = participant.Fullname,
                Username           = participant.Username,
                FirstName          = participant.FirstName,
                LastName           = participant.LastName,
                ContactEmail       = participant.ContactEmail,
                ContactTelephone   = participant.ContactTelephone,
                DisplayName        = participant.DisplayName,
                UserRole           = GetUserRole(participant.UserRole),
                HearingRole        = participant.HearingRole,
                CaseTypeGroup      = participant.CaseGroupType.ToString(),
                ParticipantRefId   = participant.ParticipantId,
                Representee        = participant.Representee,
                LinkedParticipants = LinkedParticipantToRequestMapper
                                     .MapToLinkedParticipantRequestList(participant.LinkedParticipants)
            };

            return(request);
        }
        public List <ParticipantRequest> Build()
        {
            var individuals     = _users.Where(x => x.UserType == UserType.Individual).ToList();
            var representatives = _users.Where(x => x.UserType == UserType.Representative).ToList();

            ValidateUsers(individuals.Count, representatives.Count);

            var indIndex = 0;
            var repIndex = 0;

            foreach (var user in _users)
            {
                if (user.UserType == UserType.CaseAdmin || user.UserType == UserType.VideoHearingsOfficer)
                {
                    continue;
                }

                var request = new ParticipantRequest();

                if (user.UserType == UserType.Individual)
                {
                    if (_isCACDCaseType)
                    {
                        request.CaseRoleName    = RoleData.CACD_CASE_ROLE_NAME;
                        request.HearingRoleName = RoleData.APPELLANT_CASE_ROLE_NAME;
                    }
                    else
                    {
                        request.CaseRoleName    = indIndex == 0 ? RoleData.FIRST_CASE_ROLE_NAME : RoleData.SECOND_CASE_ROLE_NAME;
                        request.HearingRoleName = RoleData.INDV_HEARING_ROLE_NAME;
                        indIndex++;
                    }
                }

                if (user.UserType == UserType.Representative)
                {
                    if (_isCACDCaseType)
                    {
                        request.CaseRoleName    = RoleData.CACD_CASE_ROLE_NAME;
                        request.HearingRoleName = RoleData.CACD_REP_HEARING_ROLE_NAME;
                    }
                    else
                    {
                        request.CaseRoleName    = repIndex == 0 ? RoleData.FIRST_CASE_ROLE_NAME : RoleData.SECOND_CASE_ROLE_NAME;
                        request.HearingRoleName = RoleData.REPRESENTATIVE_HEARING_ROLE_NAME;
                        request.Representee     = ChooseToRepresentIndividualIfPossible(individuals, repIndex);
                        repIndex++;
                    }

                    request.OrganisationName = UserData.ORGANISATION;
                }

                if (user.UserType == UserType.Interpreter || user.UserType == UserType.Witness)
                {
                    request.CaseRoleName    = _isCACDCaseType ? RoleData.CACD_CASE_ROLE_NAME : RoleData.FIRST_CASE_ROLE_NAME;
                    request.HearingRoleName = AddSpacesToUserType(user.UserType);
                }

                if (user.UserType == UserType.Winger)
                {
                    request.CaseRoleName    = RoleData.CACD_CASE_ROLE_NAME;
                    request.HearingRoleName = AddSpacesToUserType(user.UserType);
                }

                if (user.UserType != UserType.Individual &&
                    user.UserType != UserType.Representative &&
                    user.UserType != UserType.Winger &&
                    user.UserType != UserType.Witness &&
                    user.UserType != UserType.Interpreter)
                {
                    request.CaseRoleName    = AddSpacesToUserType(user.UserType);
                    request.HearingRoleName = AddSpacesToUserType(user.UserType);
                }

                request.ContactEmail    = user.ContactEmail;
                request.DisplayName     = user.DisplayName;
                request.FirstName       = user.FirstName;
                request.LastName        = user.LastName;
                request.MiddleNames     = UserData.MIDDLE_NAME;
                request.TelephoneNumber = UserData.TELEPHONE_NUMBER;
                request.Title           = UserData.TITLE;
                request.Username        = user.Username;

                _participants.Add(request);
            }

            return(_participants);
        }
        public List <ParticipantRequest> Build()
        {
            var individuals     = _users.Where(x => x.UserType == UserType.Individual).ToList();
            var representatives = _users.Where(x => x.UserType == UserType.Representative).ToList();

            ValidateUsers(individuals.Count, representatives.Count);

            var indIndex = 0;
            var repIndex = 0;

            foreach (var user in _users)
            {
                if (user.UserType == UserType.CaseAdmin)
                {
                    continue;
                }

                var request = new ParticipantRequest {
                    LinkedParticipants = new List <LinkedParticipantRequest>()
                };

                if (user.UserType == UserType.Individual)
                {
                    if (_isCACDCaseType)
                    {
                        request.CaseTypeGroup = RoleData.CACD_CASE_ROLE_NAME;
                        request.HearingRole   = RoleData.APPELLANT_CASE_ROLE_NAME;
                    }
                    else
                    {
                        request.CaseTypeGroup = indIndex == 0 ? RoleData.FIRST_CASE_ROLE_NAME : RoleData.SECOND_CASE_ROLE_NAME;
                        request.HearingRole   = RoleData.INDV_HEARING_ROLE_NAME;
                        indIndex++;
                    }
                }

                if (user.UserType == UserType.Representative)
                {
                    if (_isCACDCaseType)
                    {
                        request.CaseTypeGroup = RoleData.CACD_CASE_ROLE_NAME;
                        request.HearingRole   = RoleData.CACD_REP_HEARING_ROLE_NAME;
                    }
                    else
                    {
                        request.CaseTypeGroup = repIndex == 0 ? RoleData.FIRST_CASE_ROLE_NAME : RoleData.SECOND_CASE_ROLE_NAME;
                        request.HearingRole   = RoleData.REPRESENTATIVE_HEARING_ROLE_NAME;
                        request.Representee   = ChooseToRepresentIndividualIfPossible(individuals, repIndex);
                        repIndex++;
                    }
                }

                if (user.UserType == UserType.Interpreter)
                {
                    request.CaseTypeGroup = _isCACDCaseType ? RoleData.CACD_CASE_ROLE_NAME : RoleData.FIRST_CASE_ROLE_NAME;
                    request.HearingRole   = AddSpacesToUserType(user.UserType);
                }

                if (user.UserType == UserType.Witness)
                {
                    request.CaseTypeGroup = _isCACDCaseType ? RoleData.CACD_CASE_ROLE_NAME : RoleData.FIRST_CASE_ROLE_NAME;
                    request.HearingRole   = AddSpacesToUserType(user.UserType);
                }

                if (user.UserType == UserType.Winger)
                {
                    request.CaseTypeGroup = RoleData.CACD_CASE_ROLE_NAME;
                    request.HearingRole   = AddSpacesToUserType(user.UserType);
                }

                if (user.UserType != UserType.Individual &&
                    user.UserType != UserType.Representative &&
                    user.UserType != UserType.Winger &&
                    user.UserType != UserType.Witness &&
                    user.UserType != UserType.Interpreter)
                {
                    request.CaseTypeGroup = AddSpacesToUserType(user.UserType);
                    request.HearingRole   = AddSpacesToUserType(user.UserType);
                }

                request.ContactEmail     = user.ContactEmail;
                request.ContactTelephone = UserData.TELEPHONE_NUMBER;
                request.DisplayName      = user.DisplayName;
                request.FirstName        = user.FirstName;
                request.LastName         = user.LastName;
                request.Name             = $"{UserData.TITLE} {user.FirstName} {user.LastName}";
                request.ParticipantRefId = Guid.NewGuid();
                request.UserRole         = GetUserRoleFromUserType(user.UserType);
                request.Username         = user.Username;

                _participants.Add(request);
            }

            return(_participants);
        }
Ejemplo n.º 18
0
 public void Init()
 {
     instance = new ParticipantRequest();
 }