use of com.blackducksoftware.integration.hub.notification.PolicyOverrideContentItem in project hub-alert by blackducksoftware.
the class PolicyOverrideProcessor method generateDataSet.
@Override
public Map<String, Object> generateDataSet(final Map<String, Object> inputData) {
final PolicyOverrideContentItem policyOverride = (PolicyOverrideContentItem) inputData.get(POLICY_CONTENT_ITEM);
final Map<String, Object> dataSet = super.generateDataSet(inputData);
final String person = StringUtils.join(" ", policyOverride.getFirstName(), policyOverride.getLastName());
dataSet.put(ItemTypeEnum.PERSON.name(), person);
return dataSet;
}
use of com.blackducksoftware.integration.hub.notification.PolicyOverrideContentItem in project hub-alert by blackducksoftware.
the class PolicyOverrideProcessor method process.
@Override
public void process(final NotificationContentItem notification) throws HubIntegrationException {
final PolicyOverrideContentItem policyOverrideContentItem = (PolicyOverrideContentItem) notification;
final Map<String, Object> dataMap = new HashMap<>();
for (final PolicyRuleView rule : policyOverrideContentItem.getPolicyRuleList()) {
dataMap.put(POLICY_CONTENT_ITEM, policyOverrideContentItem);
dataMap.put(POLICY_RULE, rule);
final String eventKey = generateEventKey(dataMap);
final Map<String, Object> dataSet = generateDataSet(dataMap);
final NotificationEvent event = new NotificationEvent(eventKey, NotificationCategoryEnum.POLICY_VIOLATION, dataSet);
if (getCache().hasEvent(event.getEventKey())) {
getCache().removeEvent(event);
} else {
event.setCategoryType(NotificationCategoryEnum.POLICY_VIOLATION_OVERRIDE);
getCache().addEvent(event);
}
}
}
use of com.blackducksoftware.integration.hub.notification.PolicyOverrideContentItem in project hub-alert by blackducksoftware.
the class PolicyOverrideProcessorTest method testProcessRemoveEvent.
@Test
public void testProcessRemoveEvent() throws HubIntegrationException, URISyntaxException {
// Test will break if ListProcessorCache is used because NotificationEvents does not have an equals method defined
final MapProcessorCache cache = new MapProcessorCache();
final PolicyOverrideProcessor policyOverrideProcessor = new PolicyOverrideProcessor(cache, new TestLogger());
final Date createdAt = new Date();
final ProjectVersionModel projectVersionModel = new ProjectVersionModel();
final String componentName = "Content item test";
final ComponentVersionView componentVersionView = new ComponentVersionView();
final String componentUrl = "google.com";
final String componentVersionUrl = "newest";
final PolicyRuleView policyRuleView = new PolicyRuleView();
final List<PolicyRuleView> policyRuleList = Arrays.asList(policyRuleView);
final String firstName = "B";
final String lastName = "Dawg";
final String componentIssueUrl = "broken.edu";
final PolicyOverrideContentItem notification = new PolicyOverrideContentItem(createdAt, projectVersionModel, componentName, componentVersionView, componentUrl, componentVersionUrl, policyRuleList, firstName, lastName, componentIssueUrl);
assertTrue(cache.getEvents().size() == 0);
final PolicyOverrideProcessor spyProcessor = Mockito.spy(policyOverrideProcessor);
Mockito.doReturn("key").when(spyProcessor).generateEventKey(Mockito.anyMap());
spyProcessor.process(notification);
assertTrue(cache.getEvents().size() == 1);
spyProcessor.process(notification);
assertTrue(cache.getEvents().size() == 0);
}
Aggregations