use of com.blackducksoftware.integration.hub.api.generated.view.PolicyRuleView in project hub-alert by blackducksoftware.
the class PolicyViolationProcessor method process.
@Override
public void process(final NotificationContentItem notification) throws HubIntegrationException {
if (notification instanceof PolicyViolationContentItem) {
final PolicyViolationContentItem policyViolationContentItem = (PolicyViolationContentItem) notification;
final Map<String, Object> dataMap = new HashMap<>();
for (final PolicyRuleView rule : policyViolationContentItem.getPolicyRuleList()) {
dataMap.put(POLICY_CONTENT_ITEM, policyViolationContentItem);
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);
getCache().addEvent(event);
}
}
}
use of com.blackducksoftware.integration.hub.api.generated.view.PolicyRuleView in project hub-alert by blackducksoftware.
the class PolicyViolationProcessor method generateEventKey.
@Override
public String generateEventKey(final Map<String, Object> dataMap) throws HubIntegrationException {
final PolicyViolationContentItem content = (PolicyViolationContentItem) dataMap.get(POLICY_CONTENT_ITEM);
final PolicyRuleView rule = (PolicyRuleView) dataMap.get(POLICY_RULE);
final StringBuilder keyBuilder = new StringBuilder();
keyBuilder.append(NotificationEventConstants.EVENT_KEY_ISSUE_TYPE_NAME);
keyBuilder.append(NotificationEventConstants.EVENT_KEY_NAME_VALUE_SEPARATOR);
keyBuilder.append(NotificationEventConstants.EVENT_KEY_ISSUE_TYPE_VALUE_POLICY);
keyBuilder.append(NotificationEventConstants.EVENT_KEY_NAME_VALUE_PAIR_SEPARATOR);
keyBuilder.append(NotificationEventConstants.EVENT_KEY_HUB_PROJECT_VERSION_REL_URL_HASHED_NAME);
keyBuilder.append(NotificationEventConstants.EVENT_KEY_NAME_VALUE_SEPARATOR);
keyBuilder.append(hashString(content.getProjectVersion().getUrl()));
keyBuilder.append(NotificationEventConstants.EVENT_KEY_NAME_VALUE_PAIR_SEPARATOR);
keyBuilder.append(NotificationEventConstants.EVENT_KEY_HUB_COMPONENT_REL_URL_HASHED_NAME);
keyBuilder.append(NotificationEventConstants.EVENT_KEY_NAME_VALUE_SEPARATOR);
keyBuilder.append(hashString(content.getComponentUrl()));
keyBuilder.append(NotificationEventConstants.EVENT_KEY_NAME_VALUE_PAIR_SEPARATOR);
keyBuilder.append(NotificationEventConstants.EVENT_KEY_HUB_COMPONENT_VERSION_REL_URL_HASHED_NAME);
keyBuilder.append(NotificationEventConstants.EVENT_KEY_NAME_VALUE_SEPARATOR);
keyBuilder.append(hashString(content.getComponentVersionUrl()));
keyBuilder.append(NotificationEventConstants.EVENT_KEY_NAME_VALUE_PAIR_SEPARATOR);
keyBuilder.append(NotificationEventConstants.EVENT_KEY_HUB_POLICY_RULE_REL_URL_HASHED_NAME);
keyBuilder.append(NotificationEventConstants.EVENT_KEY_NAME_VALUE_SEPARATOR);
keyBuilder.append(hashString(getMetaHandler().getHref(rule)));
final String key = keyBuilder.toString();
return key;
}
use of com.blackducksoftware.integration.hub.api.generated.view.PolicyRuleView in project hub-alert by blackducksoftware.
the class PolicyViolationClearedProcessorTest method testProcess.
@Test
public void testProcess() throws URISyntaxException, HubIntegrationException {
final MapProcessorCache cache = new MapProcessorCache();
final PolicyViolationClearedProcessor policyViolationClearedProcessor = new PolicyViolationClearedProcessor(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 = "url";
final String componentVersionUrl = "newest";
final PolicyRuleView policyRuleView = new PolicyRuleView();
final List<PolicyRuleView> policyRuleList = Arrays.asList(policyRuleView);
final String componentIssueUrl = "broken.edu";
final PolicyViolationClearedContentItem notification = new PolicyViolationClearedContentItem(createdAt, projectVersionModel, componentName, componentVersionView, componentUrl, componentVersionUrl, policyRuleList, componentIssueUrl);
assertTrue(cache.getEvents().size() == 0);
final PolicyViolationClearedProcessor spyProcessor = Mockito.spy(policyViolationClearedProcessor);
Mockito.doReturn("key").when(spyProcessor).generateEventKey(Mockito.anyMap());
spyProcessor.process(notification);
assertTrue(cache.getEvents().size() == 1);
spyProcessor.process(notification);
assertTrue(cache.getEvents().size() == 0);
}
use of com.blackducksoftware.integration.hub.api.generated.view.PolicyRuleView 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.api.generated.view.PolicyRuleView in project hub-alert by blackducksoftware.
the class PolicyViolationProcessor method generateDataSet.
@Override
public Map<String, Object> generateDataSet(final Map<String, Object> inputData) {
final Map<String, Object> dataSet = new HashMap<>();
final PolicyViolationContentItem policyViolationContentItem = (PolicyViolationContentItem) inputData.get(POLICY_CONTENT_ITEM);
final PolicyRuleView rule = (PolicyRuleView) inputData.get(POLICY_RULE);
dataSet.put(ItemTypeEnum.RULE.name(), rule.name);
dataSet.put(ItemTypeEnum.COMPONENT.name(), policyViolationContentItem.getComponentName());
if (policyViolationContentItem.getComponentVersion() != null) {
dataSet.put(ItemTypeEnum.VERSION.name(), policyViolationContentItem.getComponentVersion().versionName);
} else {
dataSet.put(ItemTypeEnum.VERSION.name(), "?");
}
dataSet.put(NotificationEvent.DATA_SET_KEY_NOTIFICATION_CONTENT, policyViolationContentItem);
return dataSet;
}
Aggregations