Search in sources :

Example 1 with EmailJobDetailsEntity

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);
}
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 EmailJobDetailsEntity

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());
}
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 3 with EmailJobDetailsEntity

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));
}
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 EmailJobDetailsEntity

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());
}
Also used : DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) 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) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) BlackDuckJobDetailsEntity(com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) Test(org.junit.jupiter.api.Test)

Example 5 with EmailJobDetailsEntity

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;
}
Also used : DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) EmailJobDetailsEntity(com.synopsys.integration.alert.channel.email.database.job.EmailJobDetailsEntity)

Aggregations

EmailJobDetailsEntity (com.synopsys.integration.alert.channel.email.database.job.EmailJobDetailsEntity)6 EmailJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel)5 UUID (java.util.UUID)5 EmailJobAdditionalEmailAddressEntity (com.synopsys.integration.alert.channel.email.database.job.additional.EmailJobAdditionalEmailAddressEntity)4 Test (org.junit.jupiter.api.Test)4 DistributionJobEntity (com.synopsys.integration.alert.database.job.DistributionJobEntity)2 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 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)1 DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)1 DistributionJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel)1 BlackDuckJobDetailsEntity (com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity)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