Skip to content

Commit

Permalink
fix nullpointer in notification service with preserved deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
yvespp committed Dec 18, 2023
1 parent eb23ac0 commit fe6750c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -72,10 +75,19 @@ public String createAndSendMailForDeplyoments(final List<DeploymentEntity> deplo
return message;
}
String subjectMessage = "Liima-Deploy for tracking id: " + deployments.get(0).getTrackingId();
List<DeploymentEntity> 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) {
Expand Down Expand Up @@ -147,10 +159,6 @@ private Address[] getAllRecipients(final List<DeploymentEntity> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DeploymentEntity> deployments = new ArrayList<DeploymentEntity>();

DeploymentEntity deployment = new DeploymentEntity();
deployment.setTrackingId(Integer.valueOf(12)); deployments.add(deployment);
deployment.setExResourcegroupId(123);

// when
String result = deploymentNotificationService.createAndSendMailForDeplyoments(deployments);

// then
assertNull(result);
}

}

0 comments on commit fe6750c

Please sign in to comment.