Search in sources :

Example 1 with EmailJobAdditionalEmailAddressEntity

use of com.synopsys.integration.alert.channel.email.database.job.additional.EmailJobAdditionalEmailAddressEntity in project hub-alert by blackducksoftware.

the class DefaultEmailJobDetailsAccessor method saveConcreteJobDetails.

@Override
@Transactional(propagation = Propagation.REQUIRED)
public EmailJobDetailsModel saveConcreteJobDetails(UUID jobId, EmailJobDetailsModel jobDetails) {
    EmailJobDetailsEntity jobDetailsToSave = new EmailJobDetailsEntity(jobId, jobDetails.getSubjectLine().orElse(null), jobDetails.isProjectOwnerOnly(), jobDetails.isAdditionalEmailAddressesOnly(), jobDetails.getAttachmentFileType());
    EmailJobDetailsEntity savedJobDetails = emailJobDetailsRepository.save(jobDetailsToSave);
    additionalEmailAddressRepository.bulkDeleteByJobId(jobId);
    List<EmailJobAdditionalEmailAddressEntity> additionalEmailAddressEntitiesToSave = jobDetails.getAdditionalEmailAddresses().stream().map(emailAddress -> new EmailJobAdditionalEmailAddressEntity(jobId, emailAddress)).collect(Collectors.toList());
    List<EmailJobAdditionalEmailAddressEntity> savedAdditionalEmailAddressEntities = additionalEmailAddressRepository.saveAll(additionalEmailAddressEntitiesToSave);
    savedJobDetails.setEmailJobAdditionalEmailAddresses(savedAdditionalEmailAddressEntities);
    return convertToModel(savedJobDetails);
}
Also used : EmailJobAdditionalEmailAddressRepository(com.synopsys.integration.alert.channel.email.database.job.additional.EmailJobAdditionalEmailAddressRepository) Autowired(org.springframework.beans.factory.annotation.Autowired) EmailChannelKey(com.synopsys.integration.alert.descriptor.api.EmailChannelKey) UUID(java.util.UUID) DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) Collectors(java.util.stream.Collectors) EmailJobDetailsAccessor(com.synopsys.integration.alert.common.persistence.accessor.EmailJobDetailsAccessor) List(java.util.List) Component(org.springframework.stereotype.Component) EmailJobDetailsEntity(com.synopsys.integration.alert.channel.email.database.job.EmailJobDetailsEntity) Propagation(org.springframework.transaction.annotation.Propagation) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) Optional(java.util.Optional) EmailJobDetailsRepository(com.synopsys.integration.alert.channel.email.database.job.EmailJobDetailsRepository) EmailJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel) Transactional(org.springframework.transaction.annotation.Transactional) EmailJobAdditionalEmailAddressEntity(com.synopsys.integration.alert.channel.email.database.job.additional.EmailJobAdditionalEmailAddressEntity) EmailJobDetailsEntity(com.synopsys.integration.alert.channel.email.database.job.EmailJobDetailsEntity) EmailJobAdditionalEmailAddressEntity(com.synopsys.integration.alert.channel.email.database.job.additional.EmailJobAdditionalEmailAddressEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with EmailJobAdditionalEmailAddressEntity

use of com.synopsys.integration.alert.channel.email.database.job.additional.EmailJobAdditionalEmailAddressEntity in project hub-alert by blackducksoftware.

the class EmailJobDetailsAccessorTest method retrieveAdditionalEmailAddressesForJobTest.

@Test
void retrieveAdditionalEmailAddressesForJobTest() {
    UUID jobId = UUID.randomUUID();
    String additionalEmailAddress = "fake@synopsys.com";
    EmailJobAdditionalEmailAddressEntity emailJobAdditionalEmailAddressEntity = new EmailJobAdditionalEmailAddressEntity(jobId, additionalEmailAddress);
    Mockito.when(additionalEmailAddressRepository.findByJobId(Mockito.eq(jobId))).thenReturn(List.of(emailJobAdditionalEmailAddressEntity));
    List<String> newEmailAddresses = emailJobDetailsAccessor.retrieveAdditionalEmailAddressesForJob(jobId);
    assertEquals(1, newEmailAddresses.size());
    String newEmailAddress = newEmailAddresses.get(0);
    assertEquals(additionalEmailAddress, newEmailAddress);
}
Also used : UUID(java.util.UUID) EmailJobAdditionalEmailAddressEntity(com.synopsys.integration.alert.channel.email.database.job.additional.EmailJobAdditionalEmailAddressEntity) Test(org.junit.jupiter.api.Test)

Example 3 with EmailJobAdditionalEmailAddressEntity

use of com.synopsys.integration.alert.channel.email.database.job.additional.EmailJobAdditionalEmailAddressEntity in project hub-alert by blackducksoftware.

the class EmailJobDetailsAccessorTest method retrieveDetailsUnknownIdTest.

@Test
void retrieveDetailsUnknownIdTest() {
    UUID jobId = UUID.randomUUID();
    String additionalEmailAddress = "fake@synopsys.com";
    EmailJobDetailsEntity emailJobDetailsEntity = new EmailJobDetailsEntity(jobId, null, false, false, null);
    EmailJobAdditionalEmailAddressEntity emailJobAdditionalEmailAddressEntity = new EmailJobAdditionalEmailAddressEntity(jobId, additionalEmailAddress);
    Mockito.when(emailJobDetailsRepository.findById(Mockito.any())).thenReturn(Optional.empty());
    Mockito.when(additionalEmailAddressRepository.findByJobId(Mockito.any())).thenReturn(List.of(emailJobAdditionalEmailAddressEntity));
    Optional<EmailJobDetailsModel> foundJobDetailsModel = emailJobDetailsAccessor.retrieveDetails(jobId);
    assertTrue(foundJobDetailsModel.isEmpty());
}
Also used : EmailJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel) EmailJobDetailsEntity(com.synopsys.integration.alert.channel.email.database.job.EmailJobDetailsEntity) UUID(java.util.UUID) EmailJobAdditionalEmailAddressEntity(com.synopsys.integration.alert.channel.email.database.job.additional.EmailJobAdditionalEmailAddressEntity) Test(org.junit.jupiter.api.Test)

Example 4 with EmailJobAdditionalEmailAddressEntity

use of com.synopsys.integration.alert.channel.email.database.job.additional.EmailJobAdditionalEmailAddressEntity in project hub-alert by blackducksoftware.

the class EmailJobDetailsAccessorTest method retrieveDetailsTest.

@Test
void retrieveDetailsTest() {
    UUID jobId = UUID.randomUUID();
    String additionalEmailAddress = "fake@synopsys.com";
    EmailJobDetailsEntity emailJobDetailsEntity = new EmailJobDetailsEntity(jobId, null, false, false, null);
    EmailJobAdditionalEmailAddressEntity emailJobAdditionalEmailAddressEntity = new EmailJobAdditionalEmailAddressEntity(jobId, additionalEmailAddress);
    Mockito.when(emailJobDetailsRepository.findById(Mockito.any())).thenReturn(Optional.of(emailJobDetailsEntity));
    Mockito.when(additionalEmailAddressRepository.findByJobId(Mockito.any())).thenReturn(List.of(emailJobAdditionalEmailAddressEntity));
    EmailJobDetailsModel foundJobDetailsModel = emailJobDetailsAccessor.retrieveDetails(jobId).orElse(null);
    assertNotNull(foundJobDetailsModel);
    assertEquals(jobId, foundJobDetailsModel.getJobId());
    assertEquals(1, foundJobDetailsModel.getAdditionalEmailAddresses().size());
    assertEquals(additionalEmailAddress, foundJobDetailsModel.getAdditionalEmailAddresses().get(0));
}
Also used : EmailJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel) EmailJobDetailsEntity(com.synopsys.integration.alert.channel.email.database.job.EmailJobDetailsEntity) UUID(java.util.UUID) EmailJobAdditionalEmailAddressEntity(com.synopsys.integration.alert.channel.email.database.job.additional.EmailJobAdditionalEmailAddressEntity) Test(org.junit.jupiter.api.Test)

Example 5 with EmailJobAdditionalEmailAddressEntity

use of com.synopsys.integration.alert.channel.email.database.job.additional.EmailJobAdditionalEmailAddressEntity in project hub-alert by blackducksoftware.

the class EmailJobDetailsAccessorTest method saveEmailJobDetailsTest.

@Test
void saveEmailJobDetailsTest() {
    UUID jobId = UUID.randomUUID();
    String additionalEmailAddress = "fake@synopsys.com";
    EmailJobDetailsModel emailJobDetailsModel = new EmailJobDetailsModel(null, null, false, false, null, List.of(additionalEmailAddress));
    EmailJobDetailsEntity emailJobDetailsEntity = new EmailJobDetailsEntity(jobId, null, false, false, null);
    EmailJobAdditionalEmailAddressEntity emailJobAdditionalEmailAddressEntity = new EmailJobAdditionalEmailAddressEntity(jobId, additionalEmailAddress);
    Mockito.when(emailJobDetailsRepository.save(Mockito.any())).thenReturn(emailJobDetailsEntity);
    Mockito.when(additionalEmailAddressRepository.saveAll(Mockito.any())).thenReturn(List.of(emailJobAdditionalEmailAddressEntity));
    Mockito.when(additionalEmailAddressRepository.findByJobId(Mockito.any())).thenReturn(List.of(emailJobAdditionalEmailAddressEntity));
    EmailJobDetailsModel newEmailJobDetails = emailJobDetailsAccessor.saveJobDetails(jobId, emailJobDetailsModel);
    Mockito.verify(additionalEmailAddressRepository).bulkDeleteByJobId(Mockito.any());
    assertEquals(jobId, newEmailJobDetails.getJobId());
    assertEquals(1, newEmailJobDetails.getAdditionalEmailAddresses().size());
    assertEquals(additionalEmailAddress, newEmailJobDetails.getAdditionalEmailAddresses().get(0));
}
Also used : EmailJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel) EmailJobDetailsEntity(com.synopsys.integration.alert.channel.email.database.job.EmailJobDetailsEntity) UUID(java.util.UUID) EmailJobAdditionalEmailAddressEntity(com.synopsys.integration.alert.channel.email.database.job.additional.EmailJobAdditionalEmailAddressEntity) Test(org.junit.jupiter.api.Test)

Aggregations

EmailJobAdditionalEmailAddressEntity (com.synopsys.integration.alert.channel.email.database.job.additional.EmailJobAdditionalEmailAddressEntity)5 UUID (java.util.UUID)5 EmailJobDetailsEntity (com.synopsys.integration.alert.channel.email.database.job.EmailJobDetailsEntity)4 EmailJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel)4 Test (org.junit.jupiter.api.Test)4 EmailJobDetailsRepository (com.synopsys.integration.alert.channel.email.database.job.EmailJobDetailsRepository)1 EmailJobAdditionalEmailAddressRepository (com.synopsys.integration.alert.channel.email.database.job.additional.EmailJobAdditionalEmailAddressRepository)1 EmailJobDetailsAccessor (com.synopsys.integration.alert.common.persistence.accessor.EmailJobDetailsAccessor)1 DistributionJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel)1 EmailChannelKey (com.synopsys.integration.alert.descriptor.api.EmailChannelKey)1 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Component (org.springframework.stereotype.Component)1 Propagation (org.springframework.transaction.annotation.Propagation)1 Transactional (org.springframework.transaction.annotation.Transactional)1