use of com.redhat.cloud.notifications.recipients.itservice.pojo.response.Email in project notifications-backend by RedHatInsights.
the class ITUserServiceTest method shouldPickPrimaryEMailAsUsersEmail.
@Test
void shouldPickPrimaryEMailAsUsersEmail() {
ITUserResponse itUserResponse = new ITUserResponse();
final PersonalInformation personalInformation = new PersonalInformation();
personalInformation.firstName = "myFirstname";
personalInformation.lastNames = "myLastname";
itUserResponse.personalInformation = personalInformation;
Authentication authentication = new Authentication();
authentication.principal = "myPrincipal";
authentication.providerName = "myProviderName";
itUserResponse.authentications = new ArrayList<>();
itUserResponse.authentications.add(authentication);
final AccountRelationship accountRelationship = new AccountRelationship();
Email primaryEmail = new Email();
primaryEmail.isPrimary = true;
primaryEmail.address = "first_adress@trashmail.org";
Email nonPrimaryEmail = new Email();
nonPrimaryEmail.isPrimary = false;
nonPrimaryEmail.address = "second_adress@trashmail.org";
accountRelationship.emails = new ArrayList<>();
accountRelationship.emails.add(nonPrimaryEmail);
accountRelationship.emails.add(primaryEmail);
itUserResponse.accountRelationships = new ArrayList<>();
itUserResponse.accountRelationships.add(accountRelationship);
itUserResponse.accountRelationships.get(0).permissions = List.of();
List<ITUserResponse> itUserResponses = List.of(itUserResponse);
when(itUserService.getUsers(any(ITUserRequest.class))).thenReturn(itUserResponses);
final List<User> someAccountId = rbacRecipientUsersProvider.getUsers("someAccountId", "someOrgId", true);
assertTrue(someAccountId.get(0).isActive());
assertEquals(someAccountId.get(0).getEmail(), "first_adress@trashmail.org");
}
use of com.redhat.cloud.notifications.recipients.itservice.pojo.response.Email in project notifications-backend by RedHatInsights.
the class RbacRecipientUsersProvider method transformToUser.
List<User> transformToUser(List<ITUserResponse> itUserResponses) {
List<User> users = new ArrayList<>();
for (ITUserResponse itUserResponse : itUserResponses) {
User user = new User();
user.setUsername(itUserResponse.authentications.get(0).principal);
final List<Email> emails = itUserResponse.accountRelationships.get(0).emails;
for (Email email : emails) {
if (email != null && email.isPrimary != null && email.isPrimary) {
String address = email.address;
user.setEmail(address);
}
}
user.setAdmin(false);
if (itUserResponse.accountRelationships != null) {
for (AccountRelationship accountRelationship : itUserResponse.accountRelationships) {
if (accountRelationship.permissions != null) {
for (Permission permission : accountRelationship.permissions) {
if (ORG_ADMIN_PERMISSION.equals(permission.permissionCode)) {
user.setAdmin(true);
}
}
}
}
}
user.setActive(true);
user.setFirstName(itUserResponse.personalInformation.firstName);
user.setLastName(itUserResponse.personalInformation.lastNames);
users.add(user);
}
return users;
}
Aggregations