Skip to content

Commit

Permalink
EPMRPP-89659 || Add possibility to enable/disable group of notificati…
Browse files Browse the repository at this point in the history
…ons. (#1972)
  • Loading branch information
APiankouski authored Apr 18, 2024
1 parent 7634c68 commit 3e173e2
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ dependencies {
implementation 'com.epam.reportportal:commons'
implementation 'com.epam.reportportal:plugin-api'
} else {
implementation 'com.github.reportportal:commons-dao:a118727'
implementation 'com.github.reportportal:commons-dao:495edfb'
implementation 'com.github.reportportal:commons-reporting:d99e842'
implementation 'com.github.reportportal:commons:d7f9bec'
implementation 'com.github.reportportal:plugin-api:3ecb915657'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public LaunchNotificationRunner(GetProjectHandler getProjectHandler,
public void handle(LaunchFinishedEvent launchFinishedEvent, Map<String, String> projectConfig) {

boolean isNotificationsEnabled = BooleanUtils.toBoolean(
projectConfig.get(ProjectAttributeEnum.NOTIFICATIONS_ENABLED.getAttribute()));
projectConfig.get(ProjectAttributeEnum.NOTIFICATIONS_ENABLED.getAttribute()))
&& BooleanUtils.toBoolean(
projectConfig.get(ProjectAttributeEnum.NOTIFICATIONS_EMAIL_ENABLED.getAttribute()));

if (isNotificationsEnabled) {
getIntegrationHandler.getEnabledByProjectIdOrGlobalAndIntegrationGroup(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
//TODO need refactoring - split attributes validation logic
public class ProjectAttributeValidator {

private static String NOTIFICATION_ATTRIBUTE_PATTERN = "notifications.\\w+.enabled";

private final DelayBoundValidator delayBoundValidator;

public ProjectAttributeValidator(DelayBoundValidator delayBoundValidator) {
Expand All @@ -30,7 +32,8 @@ public void verifyProjectAttributes(Map<String, String> currentAttributes,
Map<String, String> newAttributes) {
Set<String> incompatibleAttributes = newAttributes.keySet()
.stream()
.filter(it -> !ProjectAttributeEnum.isPresent(it))
.filter(it -> !(ProjectAttributeEnum.isPresent(it) || it.matches(
NOTIFICATION_ATTRIBUTE_PATTERN)))
.collect(toSet());
expect(incompatibleAttributes, Set::isEmpty).verify(BAD_REQUEST_ERROR, incompatibleAttributes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,7 @@ public ProjectNotificationValidator(SenderCaseRepository senderCaseRepository) {
}

public void validateCreateRQ(Project project, SenderCaseDTO senderCaseDTO) {
validateRecipients(senderCaseDTO);

expect(senderCaseDTO.getType(), Objects::nonNull).verify(ErrorType.BAD_REQUEST_ERROR,
"Notification type");

normalizeCreateNotificationRQ(project, senderCaseDTO);
validateSenderCase(project, senderCaseDTO);

Optional<SenderCaseDTO> duplicate =
senderCaseRepository.findAllByProjectId(project.getId()).stream()
Expand All @@ -72,20 +67,27 @@ public void validateCreateRQ(Project project, SenderCaseDTO senderCaseDTO) {
}

public void validateUpdateRQ(Project project, SenderCaseDTO senderCaseDTO) {
validateRecipients(senderCaseDTO);

normalizeCreateNotificationRQ(project, senderCaseDTO);
validateSenderCase(project, senderCaseDTO);

Optional<SenderCaseDTO> duplicate =
senderCaseRepository.findAllByProjectId(project.getId()).stream()
.filter(senderCase -> !Objects.equals(senderCase.getId(), senderCaseDTO.getId()))
.map(NotificationConfigConverter.TO_CASE_RESOURCE)
.filter(o1 -> equalsWithoutRuleName(o1, senderCaseDTO)).findFirst();
expect(duplicate, Optional::isEmpty).verify(BAD_REQUEST_ERROR,
"Project email settings contain duplicate cases"
"Project notification settings contain duplicate cases"
);
}

private void validateSenderCase(Project project, SenderCaseDTO senderCaseDTO) {
validateRecipients(senderCaseDTO);

expect(senderCaseDTO.getType(), Objects::nonNull).verify(ErrorType.BAD_REQUEST_ERROR,
"Notification type");

normalizeCreateNotificationRQ(project, senderCaseDTO);
}

private void validateRecipients(SenderCaseDTO senderCaseDTO) {
List<String> recipients = senderCaseDTO.getRecipients();
expect(findByName(senderCaseDTO.getSendCase()), Optional::isPresent).verify(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ private static void cutAttributeToMaxLength(ItemAttributeResource entity) {
senderCase.setAttributesOperator(LogicalOperator.valueOf(resource.getAttributesOperator()));
senderCase.setRuleName(resource.getRuleName());
senderCase.setId(resource.getId());
senderCase.setType(resource.getType());
Optional.ofNullable(resource.getRuleDetails()).map(SenderCaseOptions::new)
.ifPresent(senderCase::setRuleDetails);
return senderCase;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ void shouldSendWhenNotificationsEnabled() {

final Map<String, String> mapping = ImmutableMap.<String, String>builder()
.put(ProjectAttributeEnum.NOTIFICATIONS_ENABLED.getAttribute(), "true")
.put(ProjectAttributeEnum.NOTIFICATIONS_EMAIL_ENABLED.getAttribute(), "true")
.build();

final Project project = new Project();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.epam.ta.reportportal.model.project.email.SenderCaseDTO;
import com.epam.ta.reportportal.ws.converter.converters.ProjectConverter;
import com.epam.ta.reportportal.ws.reporting.ItemAttributeResource;
import com.epam.ta.reportportal.ws.reporting.OperationCompletionRS;
import com.google.common.collect.Sets;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -75,6 +76,7 @@ public void beforeEach() {
updateNotificationRQ.setSendCase("always");
updateNotificationRQ.setAttributesOperator(LogicalOperator.AND.getOperator());
updateNotificationRQ.setRuleName(DEFAULT_RULE_NAME);
updateNotificationRQ.setType("email");
updateNotificationRQ.setRecipients(Collections.singletonList("OWNER"));
updateNotificationRQ.setLaunchNames(Collections.singletonList("test launch"));
updateNotificationRQ.setEnabled(true);
Expand Down Expand Up @@ -160,6 +162,7 @@ public void updateNotificationWithDuplicateContentButWithDifferentRuleNameTest()
when(modelForUpdate.getId()).thenReturn(1L);
when(modelForUpdate.getSendCase()).thenReturn(SendCase.ALWAYS);
when(modelForUpdate.getRuleName()).thenReturn("Rule2");
when(modelForUpdate.getType()).thenReturn("email");
when(modelForUpdate.getAttributesOperator()).thenReturn(LogicalOperator.AND);
when(modelForUpdate.getRecipients()).thenReturn(Collections.singleton("OWNER"));
when(modelForUpdate.getLaunchNames()).thenReturn(Collections.singleton("test launch1"));
Expand All @@ -170,6 +173,7 @@ public void updateNotificationWithDuplicateContentButWithDifferentRuleNameTest()
when(dupeUpdateNotification.getId()).thenReturn(2L);
when(dupeUpdateNotification.getSendCase()).thenReturn(SendCase.ALWAYS);
when(dupeUpdateNotification.getRuleName()).thenReturn("Rule3");
when(dupeUpdateNotification.getType()).thenReturn("email");
when(dupeUpdateNotification.getAttributesOperator()).thenReturn(LogicalOperator.AND);
when(dupeUpdateNotification.getRecipients()).thenReturn(Collections.singleton("OWNER"));
when(dupeUpdateNotification.getLaunchNames()).thenReturn(Collections.singleton("test launch"));
Expand All @@ -187,7 +191,7 @@ public void updateNotificationWithDuplicateContentButWithDifferentRuleNameTest()

assertTrue(assertThrows(ReportPortalException.class,
() -> service.updateNotification(project, updateNotificationRQ, rpUser)
).getMessage().contains("Project email settings contain duplicate cases"));
).getMessage().contains("Project notification settings contain duplicate cases"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ void updateNotification() throws Exception {
updateRq.setSendCase(SendCase.ALWAYS.getCaseString());
updateRq.setRecipients(List.of("[email protected]", "[email protected]"));
updateRq.setLaunchNames(List.of("launch"));
updateRq.setType("email");
updateRq.setAttributesOperator(LogicalOperator.AND.getOperator());

mockMvc.perform(
Expand Down

0 comments on commit 3e173e2

Please sign in to comment.