use of com.blackducksoftware.integration.hub.notification.PolicyViolationContentItem 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.notification.PolicyViolationContentItem 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.notification.PolicyViolationContentItem 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;
}
use of com.blackducksoftware.integration.hub.notification.PolicyViolationContentItem in project hub-alert by blackducksoftware.
the class PolicyViolationProcessorTest method testProcess.
@Test
public void testProcess() throws HubIntegrationException, URISyntaxException {
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 ResourceMetadata metaView = new ResourceMetadata();
metaView.href = "Meta href";
policyRuleView._meta = metaView;
final List<PolicyRuleView> policyRuleList = Arrays.asList(policyRuleView);
final String componentIssueUrl = "issueUrl";
final PolicyViolationContentItem notification = new PolicyViolationContentItem(createdAt, projectVersionModel, componentName, componentVersionView, componentUrl, componentVersionUrl, policyRuleList, componentIssueUrl);
processTestRun(notification);
}
use of com.blackducksoftware.integration.hub.notification.PolicyViolationContentItem in project hub-alert by blackducksoftware.
the class PolicyViolationProcessorTest method testProcessWithoutVersion.
@Test
public void testProcessWithoutVersion() throws URISyntaxException, HubIntegrationException {
final Date createdAt = new Date();
final ProjectVersionModel projectVersionModel = new ProjectVersionModel();
final String componentName = "Content item test";
final String componentUrl = "url";
final String componentVersionUrl = "newest";
final PolicyRuleView policyRuleView = new PolicyRuleView();
final ResourceMetadata metaView = new ResourceMetadata();
metaView.href = "Meta href";
policyRuleView._meta = metaView;
final List<PolicyRuleView> policyRuleList = Arrays.asList(policyRuleView);
final String componentIssueUrl = "issueUrl";
final PolicyViolationContentItem notification = new PolicyViolationContentItem(createdAt, projectVersionModel, componentName, null, componentUrl, componentVersionUrl, policyRuleList, componentIssueUrl);
processTestRun(notification);
}
Aggregations