Search in sources :

Example 1 with PolicyRuleView

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);
        }
    }
}
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 PolicyRuleView

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

Example 3 with PolicyRuleView

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);
}
Also used : 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) TestLogger(com.blackducksoftware.integration.test.TestLogger) PolicyViolationClearedContentItem(com.blackducksoftware.integration.hub.notification.PolicyViolationClearedContentItem) Date(java.util.Date) MapProcessorCache(com.blackducksoftware.integration.hub.notification.MapProcessorCache) Test(org.junit.Test)

Example 4 with PolicyRuleView

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

Example 5 with PolicyRuleView

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

Aggregations

PolicyRuleView (com.blackducksoftware.integration.hub.api.generated.view.PolicyRuleView)9 PolicyViolationContentItem (com.blackducksoftware.integration.hub.notification.PolicyViolationContentItem)5 ProjectVersionModel (com.blackducksoftware.integration.hub.notification.ProjectVersionModel)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 ComponentVersionView (com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView)3 NotificationEvent (com.blackducksoftware.integration.hub.notification.NotificationEvent)3 ResourceMetadata (com.blackducksoftware.integration.hub.api.generated.component.ResourceMetadata)2 MapProcessorCache (com.blackducksoftware.integration.hub.notification.MapProcessorCache)2 PolicyOverrideContentItem (com.blackducksoftware.integration.hub.notification.PolicyOverrideContentItem)2 PolicyViolationClearedContentItem (com.blackducksoftware.integration.hub.notification.PolicyViolationClearedContentItem)2 TestLogger (com.blackducksoftware.integration.test.TestLogger)2