use of com.redhat.cloud.notifications.recipients.User in project notifications-backend by RedHatInsights.
the class RbacRecipientUsersProviderTest method shouldReturnNoUsersWhenGroupNotFound.
@Test
public void shouldReturnNoUsersWhenGroupNotFound() {
UUID nonExistentGroup = UUID.randomUUID();
mockNotFoundGroup(nonExistentGroup);
List<User> users = rbacRecipientUsersProvider.getGroupUsers(accountId, orgId, false, nonExistentGroup);
assertEquals(0, users.size());
}
use of com.redhat.cloud.notifications.recipients.User in project notifications-backend by RedHatInsights.
the class RbacRecipientUsersProvider method getWithPagination.
private List<User> getWithPagination(Function<Integer, Page<RbacUser>> fetcher) {
List<User> users = new ArrayList<>();
int page = 0;
Page<RbacUser> rbacUsers;
do {
rbacUsers = fetcher.apply(page++);
for (RbacUser rbacUser : rbacUsers.getData()) {
User user = new User();
user.setUsername(rbacUser.getUsername());
user.setEmail(rbacUser.getEmail());
user.setAdmin(rbacUser.getOrgAdmin());
user.setActive(rbacUser.getActive());
user.setFirstName(rbacUser.getFirstName());
user.setLastName(rbacUser.getLastName());
users.add(user);
}
} while (rbacUsers.getData().size() == rbacElementsPerPage);
return users;
}
use of com.redhat.cloud.notifications.recipients.User in project notifications-backend by RedHatInsights.
the class EmailSubscriptionTypeProcessor method processAggregateEmailsByAggregationKey.
private void processAggregateEmailsByAggregationKey(EmailAggregationKey aggregationKey, LocalDateTime startTime, LocalDateTime endTime, EmailSubscriptionType emailSubscriptionType, boolean delete) {
final EmailTemplate emailTemplate = emailTemplateFactory.get(aggregationKey.getBundle(), aggregationKey.getApplication());
TemplateInstance subject;
TemplateInstance body;
if (useTemplatesFromDb) {
Optional<AggregationEmailTemplate> aggregationEmailTemplate = templateRepository.findAggregationEmailTemplate(aggregationKey.getBundle(), aggregationKey.getApplication(), emailSubscriptionType);
if (aggregationEmailTemplate.isEmpty()) {
if (delete) {
emailAggregationRepository.purgeOldAggregation(aggregationKey, endTime);
}
return;
} else {
String subjectData = aggregationEmailTemplate.get().getSubjectTemplate().getData();
subject = templateService.compileTemplate(subjectData, "subject");
String bodyData = aggregationEmailTemplate.get().getBodyTemplate().getData();
body = templateService.compileTemplate(bodyData, "body");
}
} else {
if (!emailTemplate.isEmailSubscriptionSupported(emailSubscriptionType)) {
if (delete) {
emailAggregationRepository.purgeOldAggregation(aggregationKey, endTime);
}
return;
}
subject = emailTemplate.getTitle(null, emailSubscriptionType);
body = emailTemplate.getBody(null, emailSubscriptionType);
}
if (subject == null || body == null) {
if (delete) {
emailAggregationRepository.purgeOldAggregation(aggregationKey, endTime);
}
return;
}
try {
for (Map.Entry<User, Map<String, Object>> aggregation : emailAggregator.getAggregated(aggregationKey, emailSubscriptionType, startTime, endTime).entrySet()) {
Context.ContextBuilder contextBuilder = new Context.ContextBuilder();
aggregation.getValue().forEach(contextBuilder::withAdditionalProperty);
Action action = new Action();
action.setContext(contextBuilder.build());
action.setEvents(List.of());
action.setAccountId(aggregationKey.getAccountId());
action.setApplication(aggregationKey.getApplication());
action.setBundle(aggregationKey.getBundle());
// We don't have a eventtype as this aggregates over multiple event types
action.setEventType(null);
action.setTimestamp(LocalDateTime.now(ZoneOffset.UTC));
Event event = new Event();
event.setId(UUID.randomUUID());
event.setAction(action);
emailSender.sendEmail(aggregation.getKey(), event, subject, body);
}
} finally {
if (delete) {
emailAggregationRepository.purgeOldAggregation(aggregationKey, endTime);
}
}
}
Aggregations