diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/control/DeploymentNotificationService.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/control/DeploymentNotificationService.java index 331898a82..f409b9d35 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/control/DeploymentNotificationService.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/control/DeploymentNotificationService.java @@ -20,6 +20,8 @@ package ch.puzzle.itc.mobiliar.business.deploy.control; +import java.util.ArrayList; + import ch.puzzle.itc.mobiliar.business.generator.control.extracted.ResourceDependencyResolverService; import ch.puzzle.itc.mobiliar.business.usersettings.control.UserSettingsService; import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.ConsumedResourceRelationEntity; @@ -34,6 +36,7 @@ import javax.mail.MessagingException; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; + import java.util.HashSet; import java.util.List; import java.util.Set; @@ -72,10 +75,19 @@ public String createAndSendMailForDeplyoments(final List deplo return message; } String subjectMessage = "Liima-Deploy for tracking id: " + deployments.get(0).getTrackingId(); + List filteredDeployments = new ArrayList<>(); + + // skip notification if deployment is preserved. Can happen if old deployments are stuck in progress that the scheduler tries to clean up. + for (DeploymentEntity deployment : deployments) { + if (!deployment.isPreserved()) { + log.log(Level.INFO, "Deployment notification for deployment %s will not be sent because it's preserved", deployment.getId()); + filteredDeployments.add(deployment); + } + } try { - Address[] emailRecipients = getAllRecipients(deployments); - if (notificationService.createAndSendMail(subjectMessage, getMessageContentForDeployments(deployments), emailRecipients)) { + Address[] emailRecipients = getAllRecipients(filteredDeployments); + if (notificationService.createAndSendMail(subjectMessage, getMessageContentForDeployments(filteredDeployments), emailRecipients)) { message = getSuccessfulSendMailToRecipientMessage(emailRecipients); } } catch (MessagingException e) { @@ -147,10 +159,6 @@ private Address[] getAllRecipients(final List deployments) if (deployment.isSendEmailConfirmation()) { emailRecipients.add(deployment.getDeploymentConfirmationUser()); } - // skip notification of favorites if deployment is preserved - if (deployment.isPreserved()) { - continue; - } groupIds.add(deployment.getResourceGroup().getId()); if (deployment.getResource().getConsumedMasterRelations() == null) { continue; diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/deploy/control/DeploymentNotificationServiceTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/deploy/control/DeploymentNotificationServiceTest.java index 60b34fddf..28e27ddfb 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/deploy/control/DeploymentNotificationServiceTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/deploy/control/DeploymentNotificationServiceTest.java @@ -235,4 +235,20 @@ public void createAndSendMailForDeplyoments_oneDeployment_noAddress_sending_Reci assertEquals("Notification email sent to following recipients: \ntestuser1@null\n", result); } + @Test + public void createAndSendMailForDeplyoments_archived() throws MessagingException { + // given + ArrayList deployments = new ArrayList(); + + DeploymentEntity deployment = new DeploymentEntity(); + deployment.setTrackingId(Integer.valueOf(12)); deployments.add(deployment); + deployment.setExResourcegroupId(123); + + // when + String result = deploymentNotificationService.createAndSendMailForDeplyoments(deployments); + + // then + assertNull(result); + } + }