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