Search in sources :

Example 1 with AlertException

use of com.blackducksoftware.integration.hub.alert.exception.AlertException in project hub-alert by blackducksoftware.

the class DistributionConfigActions method saveConfig.

@Override
public D saveConfig(final R restModel) throws AlertException {
    if (restModel != null) {
        try {
            D createdEntity = getObjectTransformer().configRestModelToDatabaseEntity(restModel, getDatabaseEntityClass());
            CommonDistributionConfigEntity commonEntity = getObjectTransformer().configRestModelToDatabaseEntity(restModel, CommonDistributionConfigEntity.class);
            if (createdEntity != null && commonEntity != null) {
                createdEntity = getRepository().save(createdEntity);
                commonEntity.setDistributionConfigId(createdEntity.getId());
                commonEntity = commonDistributionRepository.save(commonEntity);
                configuredProjectsActions.saveConfiguredProjects(commonEntity, restModel);
                notificationTypesActions.saveNotificationTypes(commonEntity, restModel);
                cleanUpStaleChannelConfigurations();
                return createdEntity;
            }
        } catch (final Exception e) {
            throw new AlertException(e.getMessage(), e);
        }
    }
    return null;
}
Also used : CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) AlertFieldException(com.blackducksoftware.integration.hub.alert.exception.AlertFieldException) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException)

Example 2 with AlertException

use of com.blackducksoftware.integration.hub.alert.exception.AlertException in project hub-alert by blackducksoftware.

the class ConfigActions method saveNewConfigUpdateFromSavedConfig.

public D saveNewConfigUpdateFromSavedConfig(final R restModel) throws AlertException {
    if (restModel != null && StringUtils.isNotBlank(restModel.getId())) {
        try {
            D createdEntity = objectTransformer.configRestModelToDatabaseEntity(restModel, databaseEntityClass);
            createdEntity = updateNewConfigWithSavedConfig(createdEntity, restModel.getId());
            if (createdEntity != null) {
                createdEntity = repositoryWrapper.save(createdEntity);
                return createdEntity;
            }
        } catch (final Exception e) {
            throw new AlertException(e.getMessage(), e);
        }
    }
    return null;
}
Also used : AlertFieldException(com.blackducksoftware.integration.hub.alert.exception.AlertFieldException) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException)

Example 3 with AlertException

use of com.blackducksoftware.integration.hub.alert.exception.AlertException in project hub-alert by blackducksoftware.

the class CommonDistributionConfigActions method saveConfig.

@Override
public CommonDistributionConfigEntity saveConfig(final CommonDistributionConfigRestModel restModel) throws AlertException {
    if (restModel != null) {
        try {
            CommonDistributionConfigEntity createdEntity = getObjectTransformer().configRestModelToDatabaseEntity(restModel, getDatabaseEntityClass());
            if (createdEntity != null) {
                createdEntity = getCommonDistributionRepository().save(createdEntity);
                getConfiguredProjectsActions().saveConfiguredProjects(createdEntity, restModel);
                getNotificationTypesActions().saveNotificationTypes(createdEntity, restModel);
                return createdEntity;
            }
        } catch (final Exception e) {
            throw new AlertException(e.getMessage(), e);
        }
    }
    return null;
}
Also used : CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException)

Example 4 with AlertException

use of com.blackducksoftware.integration.hub.alert.exception.AlertException in project hub-alert by blackducksoftware.

the class RestDistributionChannelTest method sendMessageFailureTest.

@Test
public void sendMessageFailureTest() {
    final GlobalProperties globalProperties = new TestGlobalProperties();
    final ChannelRestConnectionFactory channelRestConnectionFactory = new ChannelRestConnectionFactory(globalProperties);
    final RestDistributionChannel<AbstractChannelEvent, GlobalChannelConfigEntity, DistributionChannelConfigEntity> restChannel = new RestDistributionChannel<AbstractChannelEvent, GlobalChannelConfigEntity, DistributionChannelConfigEntity>(null, null, null, null, null, null, channelRestConnectionFactory) {

        @Override
        public String getApiUrl() {
            return null;
        }

        @Override
        public Request createRequest(final ChannelRequestHelper channelRequestHelper, final DistributionChannelConfigEntity config, final ProjectData projectData) throws AlertException {
            return new Request.Builder().uri("http://google.com").build();
        }
    };
    final SlackEvent event = new SlackEvent(createProjectData("Rest channel test"), 1L);
    final SlackDistributionConfigEntity config = new SlackDistributionConfigEntity("more garbage", "garbage", "garbage");
    Exception thrownException = null;
    try {
        restChannel.sendAuditedMessage(event, config);
    } catch (final IntegrationException ex) {
        thrownException = ex;
    }
    assertNotNull(thrownException);
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) SlackEvent(com.blackducksoftware.integration.hub.alert.channel.slack.SlackEvent) GlobalChannelConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalChannelConfigEntity) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) AbstractChannelEvent(com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) DistributionChannelConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.distribution.DistributionChannelConfigEntity) SlackDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.channel.slack.repository.distribution.SlackDistributionConfigEntity) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) Test(org.junit.Test) ChannelTest(com.blackducksoftware.integration.hub.alert.channel.ChannelTest)

Example 5 with AlertException

use of com.blackducksoftware.integration.hub.alert.exception.AlertException in project hub-alert by blackducksoftware.

the class AuditEntryActionsTest method testGetException.

@Test
public void testGetException() throws AlertException, IOException {
    final AuditEntryRepositoryWrapper auditEntryRepository = Mockito.mock(AuditEntryRepositoryWrapper.class);
    final NotificationRepositoryWrapper notificationRepository = Mockito.mock(NotificationRepositoryWrapper.class);
    final VulnerabilityRepositoryWrapper vulnerabilityRepository = Mockito.mock(VulnerabilityRepositoryWrapper.class);
    final AuditNotificationRepositoryWrapper auditNotificationRepository = Mockito.mock(AuditNotificationRepositoryWrapper.class);
    final CommonDistributionRepositoryWrapper commonDistributionRepositoryWrapper = Mockito.mock(CommonDistributionRepositoryWrapper.class);
    final ObjectTransformer objectTransformer = new ObjectTransformer();
    final ObjectTransformer spyObjectTransformer = Mockito.spy(objectTransformer);
    final MockAuditEntryEntity mockAuditEntryEntity = new MockAuditEntryEntity();
    final MockNotificationEntity mockNotificationEntity = new MockNotificationEntity();
    final MockCommonDistributionEntity mockCommonDistributionEntity = new MockCommonDistributionEntity();
    Mockito.when(auditEntryRepository.findOne(Mockito.anyLong())).thenReturn(mockAuditEntryEntity.createEmptyEntity());
    Mockito.when(commonDistributionRepositoryWrapper.findOne(Mockito.anyLong())).thenReturn(mockCommonDistributionEntity.createEntity());
    Mockito.doThrow(new AlertException()).when(spyObjectTransformer).databaseEntityToConfigRestModel(Mockito.any(), Mockito.any());
    Mockito.when(notificationRepository.findAll(Mockito.any())).thenReturn(Arrays.asList(mockNotificationEntity.createEntity()));
    final AuditEntryActions auditEntryActions = new AuditEntryActions(auditEntryRepository, new NotificationManager(notificationRepository, vulnerabilityRepository, auditEntryRepository, auditNotificationRepository), auditNotificationRepository, commonDistributionRepositoryWrapper, spyObjectTransformer, null, null, null);
    auditEntryActions.get(1L);
    assertTrue(outputLogger.isLineContainingText("Problem converting audit entry"));
}
Also used : AuditNotificationRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper) NotificationRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.NotificationRepositoryWrapper) CommonDistributionRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper) MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) NotificationManager(com.blackducksoftware.integration.hub.alert.NotificationManager) AuditEntryRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper) ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) AuditNotificationRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper) VulnerabilityRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.VulnerabilityRepositoryWrapper) MockAuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity) MockCommonDistributionEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockCommonDistributionEntity) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) Test(org.junit.Test)

Aggregations

AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)24 Test (org.junit.Test)9 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)8 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)8 CommonDistributionRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper)6 AlertFieldException (com.blackducksoftware.integration.hub.alert.exception.AlertFieldException)5 ObjectTransformer (com.blackducksoftware.integration.hub.alert.web.ObjectTransformer)5 CommonDistributionConfigRestModel (com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel)5 ArrayList (java.util.ArrayList)4 Logger (org.slf4j.Logger)4 NotificationManager (com.blackducksoftware.integration.hub.alert.NotificationManager)3 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)3 AuditNotificationRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper)3 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)3 DistributionChannelConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.distribution.DistributionChannelConfigEntity)3 GlobalChannelConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalChannelConfigEntity)3 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)3 AbstractChannelEvent (com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent)3 Field (java.lang.reflect.Field)3 AuditEntryEntity (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity)2