Search in sources :

Example 1 with UserGroupView

use of com.blackducksoftware.integration.hub.api.generated.view.UserGroupView in project hub-alert by blackducksoftware.

the class HubDataActionsTest method testGetHubGroups.

@Test
public void testGetHubGroups() throws Exception {
    final GlobalProperties globalProperties = Mockito.mock(GlobalProperties.class);
    final HubServicesFactory hubServicesFactory = Mockito.mock(HubServicesFactory.class);
    final HubService hubService = Mockito.mock(HubService.class);
    final List<UserGroupView> userGroups = new ArrayList<>();
    final Boolean active = true;
    final String username = "User";
    final String href = "href";
    final UserGroupView userGroup = new UserGroupView();
    final ResourceMetadata metaView = new ResourceMetadata();
    metaView.href = href;
    userGroup._meta = metaView;
    userGroup.active = active;
    userGroup.name = username;
    userGroups.add(userGroup);
    Mockito.when(hubService.getAllResponses(ApiDiscovery.USERGROUPS_LINK_RESPONSE)).thenReturn(userGroups);
    Mockito.when(hubServicesFactory.createHubService()).thenReturn(hubService);
    Mockito.when(hubServicesFactory.createHubService()).thenReturn(hubService);
    Mockito.when(globalProperties.createHubServicesFactory(Mockito.any(Logger.class))).thenReturn(hubServicesFactory);
    final HubDataActions hubDataActions = new HubDataActions(globalProperties);
    final List<HubGroup> hubGroups = hubDataActions.getHubGroups();
    assertEquals(1, hubGroups.size());
    final HubGroup hubGroup = hubGroups.get(0);
    assertEquals(active, hubGroup.getActive());
    assertEquals(username, hubGroup.getName());
    assertEquals(href, hubGroup.getUrl());
}
Also used : ArrayList(java.util.ArrayList) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) ResourceMetadata(com.blackducksoftware.integration.hub.api.generated.component.ResourceMetadata) Logger(org.slf4j.Logger) HubGroup(com.blackducksoftware.integration.hub.alert.hub.model.HubGroup) UserGroupView(com.blackducksoftware.integration.hub.api.generated.view.UserGroupView) GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) HubService(com.blackducksoftware.integration.hub.service.HubService) Test(org.junit.Test)

Example 2 with UserGroupView

use of com.blackducksoftware.integration.hub.api.generated.view.UserGroupView 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 3 with UserGroupView

use of com.blackducksoftware.integration.hub.api.generated.view.UserGroupView 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)

Aggregations

UserGroupView (com.blackducksoftware.integration.hub.api.generated.view.UserGroupView)3 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)3 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)2 HubGroup (com.blackducksoftware.integration.hub.alert.hub.model.HubGroup)2 ArrayList (java.util.ArrayList)2 Logger (org.slf4j.Logger)2 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)1 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)1 DistributionChannel (com.blackducksoftware.integration.hub.alert.channel.DistributionChannel)1 SupportedChannels (com.blackducksoftware.integration.hub.alert.channel.SupportedChannels)1 EmailGroupDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.channel.email.repository.distribution.EmailGroupDistributionConfigEntity)1 EmailGroupDistributionRepositoryWrapper (com.blackducksoftware.integration.hub.alert.channel.email.repository.distribution.EmailGroupDistributionRepositoryWrapper)1 GlobalEmailConfigEntity (com.blackducksoftware.integration.hub.alert.channel.email.repository.global.GlobalEmailConfigEntity)1 GlobalEmailRepositoryWrapper (com.blackducksoftware.integration.hub.alert.channel.email.repository.global.GlobalEmailRepositoryWrapper)1 EmailTarget (com.blackducksoftware.integration.hub.alert.channel.email.template.EmailTarget)1 CommonDistributionRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper)1 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)1 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)1 ResourceMetadata (com.blackducksoftware.integration.hub.api.generated.component.ResourceMetadata)1 UserView (com.blackducksoftware.integration.hub.api.generated.view.UserView)1