Search in sources :

Example 1 with PolicyViolationContentItem

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);
        }
    }
}
Also used : PolicyViolationContentItem(com.blackducksoftware.integration.hub.notification.PolicyViolationContentItem) HashMap(java.util.HashMap) PolicyRuleView(com.blackducksoftware.integration.hub.api.generated.view.PolicyRuleView) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent)

Example 2 with PolicyViolationContentItem

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;
}
Also used : PolicyViolationContentItem(com.blackducksoftware.integration.hub.notification.PolicyViolationContentItem) PolicyRuleView(com.blackducksoftware.integration.hub.api.generated.view.PolicyRuleView)

Example 3 with PolicyViolationContentItem

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;
}
Also used : PolicyViolationContentItem(com.blackducksoftware.integration.hub.notification.PolicyViolationContentItem) HashMap(java.util.HashMap) PolicyRuleView(com.blackducksoftware.integration.hub.api.generated.view.PolicyRuleView)

Example 4 with PolicyViolationContentItem

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);
}
Also used : PolicyViolationContentItem(com.blackducksoftware.integration.hub.notification.PolicyViolationContentItem) ComponentVersionView(com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView) PolicyRuleView(com.blackducksoftware.integration.hub.api.generated.view.PolicyRuleView) ProjectVersionModel(com.blackducksoftware.integration.hub.notification.ProjectVersionModel) ResourceMetadata(com.blackducksoftware.integration.hub.api.generated.component.ResourceMetadata) Date(java.util.Date) Test(org.junit.Test)

Example 5 with PolicyViolationContentItem

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);
}
Also used : PolicyViolationContentItem(com.blackducksoftware.integration.hub.notification.PolicyViolationContentItem) PolicyRuleView(com.blackducksoftware.integration.hub.api.generated.view.PolicyRuleView) ProjectVersionModel(com.blackducksoftware.integration.hub.notification.ProjectVersionModel) ResourceMetadata(com.blackducksoftware.integration.hub.api.generated.component.ResourceMetadata) Date(java.util.Date) Test(org.junit.Test)

Aggregations

PolicyRuleView (com.blackducksoftware.integration.hub.api.generated.view.PolicyRuleView)5 PolicyViolationContentItem (com.blackducksoftware.integration.hub.notification.PolicyViolationContentItem)5 ResourceMetadata (com.blackducksoftware.integration.hub.api.generated.component.ResourceMetadata)2 ProjectVersionModel (com.blackducksoftware.integration.hub.notification.ProjectVersionModel)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 ComponentVersionView (com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView)1 NotificationEvent (com.blackducksoftware.integration.hub.notification.NotificationEvent)1