Search in sources :

Example 16 with HubServicesFactory

use of com.blackducksoftware.integration.hub.service.HubServicesFactory in project hub-alert by blackducksoftware.

the class AccumulatorProcessor method process.

@Override
public DBStoreEvent process(final NotificationResults notificationData) throws Exception {
    if (notificationData != null) {
        try {
            final HubServicesFactory hubServicesFactory = globalProperties.createHubServicesFactoryAndLogErrors(logger);
            if (hubServicesFactory != null) {
                logger.info("Processing accumulated notifications");
                final NotificationItemProcessor notificationItemProcessor = new NotificationItemProcessor(globalProperties, hubServicesFactory.getRestConnection().logger);
                final DBStoreEvent storeEvent = notificationItemProcessor.process(notificationData.getNotificationContentItems());
                return storeEvent;
            }
        } catch (final Exception ex) {
            logger.error("Error occurred durring processing of accumulated notifications", ex);
        }
    } else {
        logger.info("No notifications to process");
    }
    return null;
}
Also used : HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) NotificationItemProcessor(com.blackducksoftware.integration.hub.alert.processor.NotificationItemProcessor) DBStoreEvent(com.blackducksoftware.integration.hub.alert.event.DBStoreEvent)

Example 17 with HubServicesFactory

use of com.blackducksoftware.integration.hub.service.HubServicesFactory in project hub-alert by blackducksoftware.

the class EmailGroupChannel method getEmailAddressesForGroup.

private List<String> getEmailAddressesForGroup(final HubServicesFactory hubServicesFactory, final String hubGroup) throws IntegrationException {
    final UserGroupService groupService = hubServicesFactory.createUserGroupService();
    final UserGroupView userGroupView = groupService.getGroupByName(hubGroup);
    if (userGroupView == null) {
        throw new IntegrationException("Could not find the Hub group: " + hubGroup);
    }
    logger.info(userGroupView.toString());
    logger.info(userGroupView.json);
    final List<UserView> users = hubServicesFactory.createHubService().getAllResponses(userGroupView, UserGroupView.USERS_LINK_RESPONSE);
    return users.stream().map(user -> user.email).collect(Collectors.toList());
}
Also used : AuditEntryRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper) TemplateException(freemarker.template.TemplateException) LoggerFactory(org.slf4j.LoggerFactory) MessagingException(javax.mail.MessagingException) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) GlobalEmailConfigEntity(com.blackducksoftware.integration.hub.alert.channel.email.repository.global.GlobalEmailConfigEntity) StringUtils(org.apache.commons.lang3.StringUtils) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) Gson(com.google.gson.Gson) TemplateNotFoundException(freemarker.template.TemplateNotFoundException) JmsListener(org.springframework.jms.annotation.JmsListener) GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) UserGroupService(com.blackducksoftware.integration.hub.service.UserGroupService) UserGroupView(com.blackducksoftware.integration.hub.api.generated.view.UserGroupView) EmailTarget(com.blackducksoftware.integration.hub.alert.channel.email.template.EmailTarget) Logger(org.slf4j.Logger) EmailGroupDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.channel.email.repository.distribution.EmailGroupDistributionConfigEntity) IOException(java.io.IOException) EmailGroupDistributionRepositoryWrapper(com.blackducksoftware.integration.hub.alert.channel.email.repository.distribution.EmailGroupDistributionRepositoryWrapper) Collectors(java.util.stream.Collectors) UserView(com.blackducksoftware.integration.hub.api.generated.view.UserView) MalformedTemplateNameException(freemarker.template.MalformedTemplateNameException) List(java.util.List) Component(org.springframework.stereotype.Component) CommonDistributionRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper) DistributionChannel(com.blackducksoftware.integration.hub.alert.channel.DistributionChannel) ParseException(freemarker.core.ParseException) GlobalEmailRepositoryWrapper(com.blackducksoftware.integration.hub.alert.channel.email.repository.global.GlobalEmailRepositoryWrapper) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) SupportedChannels(com.blackducksoftware.integration.hub.alert.channel.SupportedChannels) UserGroupView(com.blackducksoftware.integration.hub.api.generated.view.UserGroupView) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) UserGroupService(com.blackducksoftware.integration.hub.service.UserGroupService) UserView(com.blackducksoftware.integration.hub.api.generated.view.UserView)

Example 18 with HubServicesFactory

use of com.blackducksoftware.integration.hub.service.HubServicesFactory in project hub-alert by blackducksoftware.

the class HubDataActions method getHubGroups.

public List<HubGroup> getHubGroups() throws IntegrationException {
    final HubServicesFactory hubServicesFactory = globalProperties.createHubServicesFactory(logger);
    if (hubServicesFactory != null) {
        final List<UserGroupView> rawGroups = hubServicesFactory.createHubService().getAllResponses(ApiDiscovery.USERGROUPS_LINK_RESPONSE);
        final List<HubGroup> groups = new ArrayList<>();
        for (final UserGroupView userGroupView : rawGroups) {
            final HubGroup hubGroup = new HubGroup(userGroupView.name, userGroupView.active, userGroupView._meta.href);
            groups.add(hubGroup);
        }
        return groups;
    } else {
        throw new AlertException("Missing global configuration.");
    }
}
Also used : UserGroupView(com.blackducksoftware.integration.hub.api.generated.view.UserGroupView) ArrayList(java.util.ArrayList) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) HubGroup(com.blackducksoftware.integration.hub.alert.hub.model.HubGroup) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException)

Example 19 with HubServicesFactory

use of com.blackducksoftware.integration.hub.service.HubServicesFactory in project hub-alert by blackducksoftware.

the class NotificationItemProcessor method init.

public void init(final GlobalProperties globalProperties, final IntLogger intLogger) {
    HubServicesFactory hubServicesFactory;
    try {
        hubServicesFactory = globalProperties.createHubServicesFactory(intLogger);
        final ProjectService projectService = hubServicesFactory.createProjectService();
        final MapProcessorCache policyCache = new UserNotificationCache(projectService);
        final VulnerabilityCache vulnerabilityCache = new VulnerabilityCache(projectService, hubServicesFactory);
        getCacheList().add(policyCache);
        getCacheList().add(vulnerabilityCache);
        getProcessorMap().put(PolicyViolationContentItem.class, new PolicyViolationProcessor(policyCache, intLogger));
        getProcessorMap().put(PolicyViolationClearedContentItem.class, new PolicyViolationClearedProcessor(policyCache, intLogger));
        getProcessorMap().put(PolicyOverrideContentItem.class, new PolicyOverrideProcessor(policyCache, intLogger));
        getProcessorMap().put(VulnerabilityContentItem.class, new VulnerabilityProcessor(vulnerabilityCache, intLogger));
    } catch (final IntegrationException ex) {
        intLogger.error("Error building the notification processor", ex);
    }
}
Also used : HubIntegrationException(com.blackducksoftware.integration.hub.exception.HubIntegrationException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) ProjectService(com.blackducksoftware.integration.hub.service.ProjectService) MapProcessorCache(com.blackducksoftware.integration.hub.notification.MapProcessorCache)

Example 20 with HubServicesFactory

use of com.blackducksoftware.integration.hub.service.HubServicesFactory in project hub-fortify-ssc-integration-service by blackducksoftware.

the class RestConnectionHelper method createHubServicesFactory.

/**
 * Create the Hub Services factory based on logger
 *
 * @param logger
 * @return
 */
private static HubServicesFactory createHubServicesFactory(final IntLogger logger, final PropertyConstants propertyConstants) {
    final RestConnection restConnection = getApplicationPropertyRestConnection(propertyConstants);
    restConnection.logger = logger;
    // Adjust the number of connections in the connection pool. The keepAlive info is the same as the default
    // constructor
    final PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(5, TimeUnit.MINUTES);
    connManager.setDefaultMaxPerRoute(propertyConstants.getMaximumThreadSize());
    connManager.setMaxTotal(propertyConstants.getMaximumThreadSize());
    restConnection.getClientBuilder().setConnectionManager(connManager);
    // restConnection.getClientBuilder().setMaxConnPerRoute(propertyConstants.getMaximumThreadSize())
    // .setMaxConnTotal(propertyConstants.getMaximumThreadSize())
    // .setConnectionTimeToLive(5, TimeUnit.MINUTES);
    final HubServicesFactory hubServicesFactory = new HubServicesFactory(restConnection);
    return hubServicesFactory;
}
Also used : RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) CredentialsRestConnection(com.blackducksoftware.integration.hub.rest.CredentialsRestConnection) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager)

Aggregations

HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)21 Test (org.junit.Test)7 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)6 HubService (com.blackducksoftware.integration.hub.service.HubService)6 ProjectService (com.blackducksoftware.integration.hub.service.ProjectService)5 Logger (org.slf4j.Logger)5 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)4 ArrayList (java.util.ArrayList)4 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)3 HubGroup (com.blackducksoftware.integration.hub.alert.hub.model.HubGroup)3 HubProject (com.blackducksoftware.integration.hub.alert.hub.model.HubProject)3 ComponentVersionView (com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView)3 UserGroupView (com.blackducksoftware.integration.hub.api.generated.view.UserGroupView)3 ProjectVersionModel (com.blackducksoftware.integration.hub.notification.ProjectVersionModel)3 Date (java.util.Date)3 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)2 ProjectView (com.blackducksoftware.integration.hub.api.generated.view.ProjectView)2 NotificationContentItem (com.blackducksoftware.integration.hub.notification.NotificationContentItem)2 NotificationEvent (com.blackducksoftware.integration.hub.notification.NotificationEvent)2 NotificationResults (com.blackducksoftware.integration.hub.notification.NotificationResults)2