Search in sources :

Example 1 with CommonDistributionConfigEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity 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 CommonDistributionConfigEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity in project hub-alert by blackducksoftware.

the class AuditEntryControllerTestIT method testPostConfig.

@Test
@WithMockUser(roles = "ADMIN")
public void testPostConfig() throws Exception {
    CommonDistributionConfigEntity commonEntity = mockCommonDistributionEntity.createEntity();
    final MockNotificationEntity mockNotifications = new MockNotificationEntity();
    NotificationEntity notificationEntity = mockNotifications.createEntity();
    notificationEntity = notificationRepository.save(notificationEntity);
    commonEntity = commonDistributionRepository.save(commonEntity);
    mockAuditEntity.setCommonConfigId(commonEntity.getId());
    AuditEntryEntity auditEntity = mockAuditEntity.createEntity();
    auditEntity = auditEntryRepository.save(auditEntity);
    auditNotificationRepository.save(new AuditNotificationRelation(auditEntity.getId(), notificationEntity.getId()));
    final String resendUrl = auditUrl + "/" + String.valueOf(auditEntity.getId()) + "/" + "/resend";
    final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(resendUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN"));
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
Also used : MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) AuditNotificationRelation(com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation) MockAuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 3 with CommonDistributionConfigEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity in project hub-alert by blackducksoftware.

the class DistributionChannelTest method receiveMessageTest.

@Test
public void receiveMessageTest() {
    final GlobalProperties globalProperties = new TestGlobalProperties();
    final Gson gson = new Gson();
    final AuditEntryRepositoryWrapper auditEntryRepository = Mockito.mock(AuditEntryRepositoryWrapper.class);
    final GlobalEmailRepositoryWrapper globalEmailRepositoryWrapper = Mockito.mock(GlobalEmailRepositoryWrapper.class);
    final EmailGroupDistributionRepositoryWrapper emailGroupRepositoryWrapper = Mockito.mock(EmailGroupDistributionRepositoryWrapper.class);
    final CommonDistributionRepositoryWrapper commonRepositoryWrapper = Mockito.mock(CommonDistributionRepositoryWrapper.class);
    final EmailGroupChannel channel = new EmailGroupChannel(globalProperties, gson, auditEntryRepository, globalEmailRepositoryWrapper, emailGroupRepositoryWrapper, commonRepositoryWrapper);
    final Long commonId = 1L;
    final EmailGroupEvent event = new EmailGroupEvent(createProjectData("Distribution Channel Test"), commonId);
    final String jsonRepresentation = gson.toJson(event);
    final CommonDistributionConfigEntity commonEntity = new CommonDistributionConfigEntity(commonId, SupportedChannels.EMAIL_GROUP, "Email Config", DigestTypeEnum.REAL_TIME, false);
    Mockito.when(commonRepositoryWrapper.findOne(Mockito.anyLong())).thenReturn(commonEntity);
    final EmailGroupDistributionConfigEntity specificEntity = new EmailGroupDistributionConfigEntity("admins", "", "TEST SUBJECT LINE");
    Mockito.when(emailGroupRepositoryWrapper.findOne(Mockito.anyLong())).thenReturn(specificEntity);
    channel.receiveMessage(jsonRepresentation);
}
Also used : CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) EmailGroupDistributionRepositoryWrapper(com.blackducksoftware.integration.hub.alert.channel.email.repository.distribution.EmailGroupDistributionRepositoryWrapper) AuditEntryRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper) EmailGroupChannel(com.blackducksoftware.integration.hub.alert.channel.email.EmailGroupChannel) Gson(com.google.gson.Gson) GlobalEmailRepositoryWrapper(com.blackducksoftware.integration.hub.alert.channel.email.repository.global.GlobalEmailRepositoryWrapper) CommonDistributionRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper) EmailGroupEvent(com.blackducksoftware.integration.hub.alert.channel.email.EmailGroupEvent) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) EmailGroupDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.channel.email.repository.distribution.EmailGroupDistributionConfigEntity) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) Test(org.junit.Test)

Example 4 with CommonDistributionConfigEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity 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 5 with CommonDistributionConfigEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity in project hub-alert by blackducksoftware.

the class AuditEntryHandlerTestIT method resendNotificationTestIt.

@Test
public void resendNotificationTestIt() {
    final MockNotificationEntity mockNotification = new MockNotificationEntity();
    final MockCommonDistributionEntity mockDistributionConfig = new MockCommonDistributionEntity();
    final NotificationEntity savedNotificationEntity = notificationRepository.save(mockNotification.createEntity());
    final CommonDistributionConfigEntity savedConfigEntity = commonDistributionRepository.save(mockDistributionConfig.createEntity());
    final AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(new AuditEntryEntity(savedConfigEntity.getId(), new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), StatusEnum.SUCCESS, null, null));
    final AuditEntryEntity badAuditEntryEntity_1 = auditEntryRepository.save(new AuditEntryEntity(-1L, new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), StatusEnum.FAILURE, "Failed: stuff happened", ""));
    auditNotificationRepository.save(new AuditNotificationRelation(savedAuditEntryEntity.getId(), savedNotificationEntity.getId()));
    final AuditEntryEntity badAuditEntryEntity_2 = auditEntryRepository.save(new AuditEntryEntity(savedConfigEntity.getId(), new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), StatusEnum.FAILURE, "Failed: stuff happened", ""));
    final AuditEntryEntity badAuditEntryEntityBoth = auditEntryRepository.save(new AuditEntryEntity(-1L, new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), StatusEnum.FAILURE, "Failed: stuff happened", ""));
    final ResponseEntity<String> invalidIdResponse = auditEntryHandler.resendNotification(-1L);
    assertEquals(HttpStatus.BAD_REQUEST, invalidIdResponse.getStatusCode());
    final ResponseEntity<String> invalidReferenceResponse_1 = auditEntryHandler.resendNotification(badAuditEntryEntity_1.getId());
    assertEquals(HttpStatus.GONE, invalidReferenceResponse_1.getStatusCode());
    final ResponseEntity<String> invalidReferenceResponse_2 = auditEntryHandler.resendNotification(badAuditEntryEntity_2.getId());
    assertEquals(HttpStatus.GONE, invalidReferenceResponse_2.getStatusCode());
    final ResponseEntity<String> invalidReferenceResponseBoth = auditEntryHandler.resendNotification(badAuditEntryEntityBoth.getId());
    assertEquals(HttpStatus.GONE, invalidReferenceResponseBoth.getStatusCode());
    final ResponseEntity<String> validResponse = auditEntryHandler.resendNotification(savedAuditEntryEntity.getId());
    assertEquals(HttpStatus.OK, validResponse.getStatusCode());
}
Also used : MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) AuditNotificationRelation(com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) MockCommonDistributionEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockCommonDistributionEntity) MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) Date(java.sql.Date) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Aggregations

CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)49 Test (org.junit.Test)38 CommonDistributionConfigRestModel (com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel)24 CommonDistributionRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper)22 CommonDistributionConfigActions (com.blackducksoftware.integration.hub.alert.web.actions.distribution.CommonDistributionConfigActions)18 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)14 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)7 AlertFieldException (com.blackducksoftware.integration.hub.alert.exception.AlertFieldException)7 AuditEntryEntity (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity)6 NotificationEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)6 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)6 DigestTypeEnum (com.blackducksoftware.integration.hub.alert.enumeration.DigestTypeEnum)6 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)5 AuditNotificationRelation (com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation)5 AbstractChannelEvent (com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent)5 NotificationModel (com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel)5 ConfiguredProjectEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity)4 DistributionProjectRelation (com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation)4 ArrayList (java.util.ArrayList)4 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)3