Search in sources :

Example 46 with DistributionJobModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel in project hub-alert by blackducksoftware.

the class DistributionChannelMessageFieldModelTestActionTest method testConfigWithNullParamsTest.

@Test
public void testConfigWithNullParamsTest() throws AlertException {
    String expectedStatusMessage = "Test Result for null test";
    DistributionChannelMessageTestAction<MockDistributionJobDetailsModel> testAction = createTestAction(expectedStatusMessage);
    DistributionJobModel distributionJobModel = createDistributionJobModel();
    MessageResult messageResult = testAction.testConfig(distributionJobModel, "jobName", null, null);
    assertEquals(expectedStatusMessage, messageResult.getStatusMessage());
}
Also used : MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) Test(org.junit.jupiter.api.Test)

Example 47 with DistributionJobModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel in project hub-alert by blackducksoftware.

the class EmailTestActionHelperTest method verifyAllProjectsProperlyRetrieved.

@Test
public void verifyAllProjectsProperlyRetrieved() throws AlertException {
    ProviderDataAccessor providerDataAccessor = Mockito.mock(ProviderDataAccessor.class);
    List<ProviderProject> providerProjects = createProviderProjects();
    Mockito.when(providerDataAccessor.getProjectsByProviderConfigId(Mockito.anyLong())).thenReturn(providerProjects);
    Mockito.when(providerDataAccessor.getEmailAddressesForProjectHref(Mockito.anyLong(), Mockito.anyString())).thenAnswer(i -> Set.of(UUID.randomUUID().toString()));
    EmailTestActionHelper emailTestActionHelper = new EmailTestActionHelper(providerDataAccessor);
    DistributionJobModel distributionJobModel = createDefaultDistributionJobModel();
    Set<String> emailAddresses = emailTestActionHelper.createUpdatedEmailAddresses(distributionJobModel);
    assertEquals(providerProjects.size(), emailAddresses.size());
}
Also used : ProviderDataAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) Test(org.junit.jupiter.api.Test)

Example 48 with DistributionJobModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel in project hub-alert by blackducksoftware.

the class DefaultRestApiAuditAccessor method convertToAuditEntryModelFromNotification.

@Override
@Transactional
public AuditEntryModel convertToAuditEntryModelFromNotification(AlertNotificationModel notificationContentEntry) {
    List<AuditNotificationRelation> relations = auditNotificationRepository.findByNotificationId(notificationContentEntry.getId());
    List<Long> auditEntryIds = relations.stream().map(AuditNotificationRelation::getAuditEntryId).collect(Collectors.toList());
    List<AuditEntryEntity> auditEntryEntities = auditEntryRepository.findAllById(auditEntryIds);
    AuditEntryStatus overallStatus = null;
    String timeLastSent = null;
    OffsetDateTime timeLastSentOffsetDateTime = null;
    List<JobAuditModel> jobAuditModels = new ArrayList<>();
    for (AuditEntryEntity auditEntryEntity : auditEntryEntities) {
        UUID jobId = auditEntryEntity.getCommonConfigId();
        if (null != auditEntryEntity.getTimeLastSent() && (null == timeLastSentOffsetDateTime || timeLastSentOffsetDateTime.isBefore(auditEntryEntity.getTimeLastSent()))) {
            timeLastSentOffsetDateTime = auditEntryEntity.getTimeLastSent();
            timeLastSent = formatAuditDate(timeLastSentOffsetDateTime);
        }
        String id = contentConverter.getStringValue(auditEntryEntity.getId());
        String configId = contentConverter.getStringValue(jobId);
        String timeCreated = formatAuditDate(auditEntryEntity.getTimeCreated());
        AuditEntryStatus status = null;
        if (auditEntryEntity.getStatus() != null) {
            status = AuditEntryStatus.valueOf(auditEntryEntity.getStatus());
            overallStatus = getWorstStatus(overallStatus, status);
        }
        String errorMessage = auditEntryEntity.getErrorMessage();
        String errorStackTrace = auditEntryEntity.getErrorStackTrace();
        Optional<DistributionJobModel> distributionJobModel = jobAccessor.getJobById(jobId);
        String distributionConfigName = distributionJobModel.map(DistributionJobModelData::getName).orElse(null);
        String eventType = distributionJobModel.map(DistributionJobModelData::getChannelDescriptorName).orElse(null);
        String statusDisplayName = null;
        if (null != status) {
            statusDisplayName = status.getDisplayName();
        }
        AuditJobStatusModel auditJobStatusModel = new AuditJobStatusModel(jobId, timeCreated, timeLastSent, statusDisplayName);
        jobAuditModels.add(new JobAuditModel(id, configId, distributionConfigName, eventType, auditJobStatusModel, errorMessage, errorStackTrace));
    }
    String id = contentConverter.getStringValue(notificationContentEntry.getId());
    NotificationConfig notificationConfig = populateConfigFromEntity(notificationContentEntry);
    String overallStatusDisplayName = null;
    if (null != overallStatus) {
        overallStatusDisplayName = overallStatus.getDisplayName();
    }
    return new AuditEntryModel(id, notificationConfig, jobAuditModels, overallStatusDisplayName, timeLastSent);
}
Also used : ArrayList(java.util.ArrayList) JobAuditModel(com.synopsys.integration.alert.common.rest.model.JobAuditModel) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) OffsetDateTime(java.time.OffsetDateTime) AuditJobStatusModel(com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel) AuditNotificationRelation(com.synopsys.integration.alert.database.audit.AuditNotificationRelation) NotificationConfig(com.synopsys.integration.alert.common.rest.model.NotificationConfig) AuditEntryStatus(com.synopsys.integration.alert.common.enumeration.AuditEntryStatus) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) UUID(java.util.UUID) AuditEntryModel(com.synopsys.integration.alert.common.persistence.model.AuditEntryModel) Transactional(org.springframework.transaction.annotation.Transactional)

Example 49 with DistributionJobModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel in project hub-alert by blackducksoftware.

the class AuditEntryActions method resendNotification.

public ActionResponse<AuditEntryPageModel> resendNotification(Long notificationId, @Nullable UUID requestedJobId) {
    if (!authorizationManager.hasExecutePermission(ConfigContextEnum.GLOBAL, descriptorKey)) {
        return new ActionResponse<>(HttpStatus.FORBIDDEN, ActionResponse.FORBIDDEN_MESSAGE);
    }
    Optional<AlertNotificationModel> notification = notificationAccessor.findById(notificationId);
    if (notification.isEmpty()) {
        return new ActionResponse<>(HttpStatus.GONE, "No notification with this id exists.");
    }
    AlertNotificationModel notificationContent = notification.get();
    if (null != requestedJobId) {
        Optional<DistributionJobModel> optionalDistributionJob = jobAccessor.getJobById(requestedJobId);
        if (optionalDistributionJob.isEmpty()) {
            String message = String.format("The Distribution Job with this id could not be found. %s", requestedJobId.toString());
            return new ActionResponse<>(HttpStatus.GONE, message);
        }
        DistributionJobModel distributionJob = optionalDistributionJob.get();
        if (distributionJob.isEnabled()) {
            ProcessedNotificationDetails processedNotificationDetails = ProcessedNotificationDetails.fromDistributionJob(distributionJob);
            jobNotificationProcessor.processNotificationForJob(processedNotificationDetails, distributionJob.getProcessingType(), List.of(notificationContent));
        } else {
            UUID jobConfigId = distributionJob.getJobId();
            logger.warn("The Distribution Job with Id {} was disabled. This notification could not be sent", jobConfigId);
            String message = String.format("The Distribution Job is currently disabled. %s", jobConfigId);
            return new ActionResponse<>(HttpStatus.BAD_REQUEST, message);
        }
    } else {
        notificationProcessor.processNotifications(List.of(notificationContent), List.of(FrequencyType.DAILY, FrequencyType.REAL_TIME));
    }
    return get();
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) ProcessedNotificationDetails(com.synopsys.integration.alert.processor.api.distribute.ProcessedNotificationDetails) UUID(java.util.UUID) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)

Example 50 with DistributionJobModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel in project hub-alert by blackducksoftware.

the class JobConfigActionsTest method getPageTest.

@Test
public void getPageTest() throws Exception {
    int totalPages = 1;
    int pageNumber = 0;
    int pageSize = 10;
    RegisteredDescriptorModel registeredDescriptorModel = new RegisteredDescriptorModel(1L, "descriptorName", DESCRIPTOR_TYPE.name());
    AlertPagedModel<DistributionJobModel> pageOfJobs = new AlertPagedModel<>(totalPages, pageNumber, pageSize, List.of(distributionJobModel));
    Mockito.when(mockedDescriptorAccessor.getRegisteredDescriptors()).thenReturn(List.of(registeredDescriptorModel));
    Mockito.when(mockedJobAccessor.getPageOfJobs(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyString(), Mockito.anyCollection())).thenReturn(pageOfJobs);
    Mockito.when(mockedConfigurationFieldModelConverter.convertToFieldModel(Mockito.any())).thenReturn(fieldModel);
    ActionResponse<JobPagedModel> jobPagedModelActionResponse = defaultJobConfigActions.getPage(pageNumber, pageSize, "");
    assertTrue(jobPagedModelActionResponse.isSuccessful());
    assertTrue(jobPagedModelActionResponse.hasContent());
    assertEquals(HttpStatus.OK, jobPagedModelActionResponse.getHttpStatus());
}
Also used : JobPagedModel(com.synopsys.integration.alert.common.rest.model.JobPagedModel) RegisteredDescriptorModel(com.synopsys.integration.alert.common.persistence.model.RegisteredDescriptorModel) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) Test(org.junit.jupiter.api.Test)

Aggregations

DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)52 Test (org.junit.jupiter.api.Test)35 UUID (java.util.UUID)24 DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)20 DistributionJobEntity (com.synopsys.integration.alert.database.job.DistributionJobEntity)15 BlackDuckJobDetailsEntity (com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity)14 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)10 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)9 JobAccessor (com.synopsys.integration.alert.common.persistence.accessor.JobAccessor)9 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)8 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)8 AlertPagedModel (com.synopsys.integration.alert.common.rest.model.AlertPagedModel)8 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)8 AuditEntryEntity (com.synopsys.integration.alert.database.audit.AuditEntryEntity)8 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)7 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)7 NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)7 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)7 OffsetDateTime (java.time.OffsetDateTime)7 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)6