use of com.synopsys.integration.alert.channel.email.database.job.EmailJobDetailsEntity 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.EmailJobDetailsEntity 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.EmailJobDetailsEntity 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.EmailJobDetailsEntity in project hub-alert by blackducksoftware.
the class StaticJobAccessorTest method createEmailJobTest.
@Test
void createEmailJobTest() {
UUID jobId = UUID.randomUUID();
EmailJobDetailsModel emailJobDetailsModel = new EmailJobDetailsModel(jobId, null, false, false, null, List.of());
DistributionJobRequestModel distributionJobRequestModel = createDistributionJobEntity(ChannelKeys.EMAIL.getUniversalKey(), emailJobDetailsModel);
EmailJobDetailsEntity emailJobDetailsEntity = new EmailJobDetailsEntity(null, null, false, false, null);
emailJobDetailsEntity.setEmailJobAdditionalEmailAddresses(List.of());
DistributionJobEntity distributionJobEntity = createDistributionJobEntity(jobId, distributionJobRequestModel);
distributionJobEntity.setEmailJobDetails(emailJobDetailsEntity);
BlackDuckJobDetailsEntity blackDuckJobDetailsEntity = createBlackDuckJobDetailsEntity(jobId, distributionJobRequestModel);
Mockito.when(emailJobDetailsAccessor.saveJobDetails(Mockito.any(), Mockito.any())).thenReturn(emailJobDetailsModel);
Mockito.when(blackDuckJobDetailsAccessor.saveBlackDuckJobDetails(Mockito.any(), Mockito.any())).thenReturn(blackDuckJobDetailsEntity);
Mockito.when(distributionJobRepository.save(Mockito.any())).thenReturn(distributionJobEntity);
DistributionJobModel createdJob = jobAccessor.createJob(distributionJobRequestModel);
assertEquals(jobId, createdJob.getJobId());
assertEquals(jobName, createdJob.getName());
}
use of com.synopsys.integration.alert.channel.email.database.job.EmailJobDetailsEntity in project hub-alert by blackducksoftware.
the class StaticJobAccessorTest method createEmailDistributionJobEntity.
private DistributionJobEntity createEmailDistributionJobEntity(UUID jobId) {
EmailJobDetailsEntity emailJobDetailsEntity = new EmailJobDetailsEntity();
DistributionJobEntity distributionJobEntity = new DistributionJobEntity(jobId, jobName, true, FrequencyType.REAL_TIME.name(), ProcessingType.DEFAULT.name(), ChannelKeys.EMAIL.getUniversalKey(), UUID.randomUUID(), DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp());
distributionJobEntity.setEmailJobDetails(emailJobDetailsEntity);
return distributionJobEntity;
}
Aggregations