use of com.redhat.cloud.notifications.recipients.User in project notifications-backend by RedHatInsights.
the class TemplateEngineResource method render.
@PUT
@Path("/render")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
public Response render(@NotNull @Valid RenderEmailTemplateRequest renderEmailTemplateRequest) {
User user = createInternalUser();
String payload = renderEmailTemplateRequest.getPayload();
try {
Action action = actionParser.fromJsonString(payload);
TemplateInstance subjectTemplate = templateService.compileTemplate(renderEmailTemplateRequest.getSubjectTemplate(), "subject");
String subject = templateService.renderTemplate(user, action, subjectTemplate);
TemplateInstance bodyTemplate = templateService.compileTemplate(renderEmailTemplateRequest.getBodyTemplate(), "body");
String body = templateService.renderTemplate(user, action, bodyTemplate);
return Response.ok(new RenderEmailTemplateResponse.Success(subject, body)).build();
} catch (Exception e) {
return Response.status(Response.Status.BAD_REQUEST).entity(new RenderEmailTemplateResponse.Error(e.getMessage())).build();
}
}
use of com.redhat.cloud.notifications.recipients.User in project notifications-backend by RedHatInsights.
the class TemplateEngineResource method createInternalUser.
private User createInternalUser() {
User user = new User();
user.setUsername("jdoe");
user.setEmail("jdoe@jdoe.com");
user.setFirstName("John");
user.setLastName("Doe");
user.setActive(true);
user.setAdmin(false);
return user;
}
use of com.redhat.cloud.notifications.recipients.User in project notifications-backend by RedHatInsights.
the class RbacRecipientUsersProvider method getUsers.
@CacheResult(cacheName = "rbac-recipient-users-provider-get-users")
public List<User> getUsers(String accountId, String orgId, boolean adminsOnly) {
Timer.Sample getUsersTotalTimer = Timer.start(meterRegistry);
List<User> users;
List<ITUserResponse> usersPaging;
List<ITUserResponse> usersTotal = new ArrayList<>();
int firstResult = 0;
do {
ITUserRequest request = new ITUserRequest(accountId, orgId, useOrgId, adminsOnly, firstResult, maxResultsPerPage);
usersPaging = retryOnItError(() -> itUserService.getUsers(request));
usersTotal.addAll(usersPaging);
firstResult += maxResultsPerPage;
} while (usersPaging.size() == maxResultsPerPage);
LOGGER.info("usersTotal: " + usersTotal);
users = transformToUser(usersTotal);
// Micrometer doesn't like when tags are null and throws a NPE.
String accountIdTag = accountId == null ? "" : accountId;
getUsersTotalTimer.stop(meterRegistry.timer("rbac.get-users.total", "accountId", accountIdTag, "users", String.valueOf(users.size())));
rbacUsers.set(users.size());
return users;
}
use of com.redhat.cloud.notifications.recipients.User 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;
}
use of com.redhat.cloud.notifications.recipients.User in project notifications-backend by RedHatInsights.
the class LifecycleITest method setupEmailMock.
private void setupEmailMock(String accountId, String orgId, String username) {
Mockito.when(emailTemplateFactory.get(anyString(), anyString())).thenReturn(new Blank());
User user = new User();
user.setUsername(username);
user.setAdmin(true);
user.setActive(true);
user.setEmail("user email");
user.setFirstName("user firstname");
user.setLastName("user lastname");
Mockito.when(rbacRecipientUsersProvider.getUsers(eq(accountId), eq(orgId), eq(true))).thenReturn(List.of(user));
updateField(emailSender, "bopUrl", getMockServerUrl() + EMAIL_SENDER_MOCK_PATH, EmailSender.class);
}
Aggregations