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;
}
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;
}
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;
}
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);
}
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"));
}
Aggregations