Skip to content

Commit

Permalink
Add the project name and project URL to bom processing notifications
Browse files Browse the repository at this point in the history
Previously, the user was only notified of the result of the BOM processing.

Now the user is told the name of the project for each notificication, and for errors, they are also given the project URL

Signed-off-by: Ross Murphy <[email protected]>
  • Loading branch information
2000rosser committed May 2, 2024
1 parent fd82e58 commit 063c2b3
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
package org.dependencytrack.tasks;

import alpine.common.logging.Logger;
import alpine.common.util.UrlUtil;
import alpine.event.framework.Event;
import alpine.event.framework.Subscriber;
import alpine.model.ConfigProperty;
import alpine.notification.Notification;
import alpine.notification.NotificationLevel;
import org.cyclonedx.BomParserFactory;
Expand Down Expand Up @@ -220,7 +222,7 @@ public void inform(final Event e) {
Notification.dispatch(new Notification()
.scope(NotificationScope.PORTFOLIO)
.group(NotificationGroup.BOM_PROCESSED)
.title(NotificationConstants.Title.BOM_PROCESSED)
.title(NotificationConstants.Title.BOM_PROCESSED + " on Project: [" + event.getProject().getName() + "]")
.level(NotificationLevel.INFORMATIONAL)
.content("A " + bomFormat.getFormatShortName() + " BOM was processed")
.subject(new BomConsumedOrProcessed(detachedProject, Base64.getEncoder().encodeToString(bomBytes), bomFormat, bomSpecVersion)));
Expand All @@ -229,12 +231,16 @@ public void inform(final Event e) {
if (bomProcessingFailedProject != null) {
bomProcessingFailedProject = qm.detach(Project.class, bomProcessingFailedProject.getId());
}
final ConfigProperty baseUrlProperty = qm.getConfigProperty(
ConfigPropertyConstants.GENERAL_BASE_URL.getGroupName(),
ConfigPropertyConstants.GENERAL_BASE_URL.getPropertyName()
);
Notification.dispatch(new Notification()
.scope(NotificationScope.PORTFOLIO)
.group(NotificationGroup.BOM_PROCESSING_FAILED)
.title(NotificationConstants.Title.BOM_PROCESSING_FAILED)
.title(NotificationConstants.Title.BOM_PROCESSING_FAILED + " on Project: [" + event.getProject().getName() + "]")
.level(NotificationLevel.ERROR)
.content("An error occurred while processing a BOM")
.content("An error occurred while processing a BOM: " + UrlUtil.normalize(baseUrlProperty.getPropertyValue()) + "/projects/" + event.getProject().getUuid())
.subject(new BomProcessingFailed(bomProcessingFailedProject, Base64.getEncoder().encodeToString(bomBytes), ex.getMessage(), bomProcessingFailedBomFormat, bomProcessingFailedBomVersion)));
} finally {
qm.commitSearchIndex(true, Component.class);
Expand Down

0 comments on commit 063c2b3

Please sign in to comment.