Search in sources :

Example 41 with DistributionJobModel

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

the class JobConfigActions method validateJobsById.

public ActionResponse<List<JobFieldStatuses>> validateJobsById(JobIdsRequestModel jobIdsValidationModel) {
    List<PermissionKey> keys = gatherPermissionKeys();
    if (!getAuthorizationManager().anyReadPermission(keys)) {
        return ActionResponse.createForbiddenResponse();
    }
    List<UUID> jobIdsToValidate = jobIdsValidationModel.getJobIds();
    if (null == jobIdsToValidate || jobIdsToValidate.isEmpty()) {
        return new ActionResponse<>(HttpStatus.OK, List.of());
    }
    List<DistributionJobModel> distributionJobModels = jobAccessor.getJobsById(jobIdsToValidate);
    List<JobFieldModel> jobFieldModels = new LinkedList<>();
    for (DistributionJobModel distributionJobModel : distributionJobModels) {
        JobFieldModel jobFieldModel = JobFieldModelPopulationUtils.createJobFieldModelWithDefaultProviderProjectState(distributionJobModel);
        jobFieldModels.add(jobFieldModel);
    }
    return validateJobFieldModels(jobFieldModels);
}
Also used : PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) UUID(java.util.UUID) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) LinkedList(java.util.LinkedList) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)

Example 42 with DistributionJobModel

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

the class JobConfigActions method createDistributionJobRequestModel.

private DistributionJobRequestModel createDistributionJobRequestModel(Collection<ConfigurationFieldModel> configFieldModels, List<JobProviderProjectFieldModel> jobProjects, OffsetDateTime createdAt, @Nullable OffsetDateTime lastUpdated) throws AlertException {
    List<BlackDuckProjectDetailsModel> projectFilterDetails = jobProjects.stream().map(jobProject -> new BlackDuckProjectDetailsModel(jobProject.getName(), jobProject.getHref())).collect(Collectors.toList());
    Map<String, ConfigurationFieldModel> configuredFieldsMap = DataStructureUtils.mapToValues(configFieldModels, ConfigurationFieldModel::getFieldKey);
    DistributionJobModel fromResource = distributionJobModelExtractor.convertToJobModel(null, configuredFieldsMap, createdAt, lastUpdated, projectFilterDetails);
    return new DistributionJobRequestModel(fromResource.isEnabled(), fromResource.getName(), fromResource.getDistributionFrequency(), fromResource.getProcessingType(), fromResource.getChannelDescriptorName(), fromResource.getChannelGlobalConfigId(), fromResource.getBlackDuckGlobalConfigId(), fromResource.isFilterByProject(), fromResource.getProjectNamePattern().orElse(null), fromResource.getProjectVersionNamePattern().orElse(null), fromResource.getNotificationTypes(), projectFilterDetails, fromResource.getPolicyFilterPolicyNames(), fromResource.getVulnerabilityFilterSeverityNames(), fromResource.getDistributionJobDetails());
}
Also used : DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) IntegrationException(com.synopsys.integration.exception.IntegrationException) DistributionChannelTestAction(com.synopsys.integration.alert.common.channel.DistributionChannelTestAction) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DataStructureUtils(com.synopsys.integration.alert.common.util.DataStructureUtils) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) AbstractJobResourceActions(com.synopsys.integration.alert.common.action.api.AbstractJobResourceActions) JobAccessor(com.synopsys.integration.alert.common.persistence.accessor.JobAccessor) ProviderProjectExistencePopulator(com.synopsys.integration.alert.api.provider.ProviderProjectExistencePopulator) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) BlackDuckProjectDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.BlackDuckProjectDetailsModel) Map(java.util.Map) ListUtils(org.apache.commons.collections4.ListUtils) DateUtils(com.synopsys.integration.alert.common.util.DateUtils) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) JobPagedModel(com.synopsys.integration.alert.common.rest.model.JobPagedModel) Collection(java.util.Collection) Set(java.util.Set) JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) UUID(java.util.UUID) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) Collectors(java.util.stream.Collectors) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) Stream(java.util.stream.Stream) FieldModelProcessor(com.synopsys.integration.alert.common.rest.FieldModelProcessor) Optional(java.util.Optional) JobFieldStatuses(com.synopsys.integration.alert.common.rest.model.JobFieldStatuses) Descriptor(com.synopsys.integration.alert.common.descriptor.Descriptor) AlertFieldException(com.synopsys.integration.alert.common.exception.AlertFieldException) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) HashMap(java.util.HashMap) PKIXErrorResponseFactory(com.synopsys.integration.alert.component.certificates.web.PKIXErrorResponseFactory) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DescriptorActionMap(com.synopsys.integration.alert.common.descriptor.action.DescriptorActionMap) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) DescriptorType(com.synopsys.integration.alert.common.enumeration.DescriptorType) LinkedList(java.util.LinkedList) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) JobIdsRequestModel(com.synopsys.integration.alert.common.rest.model.JobIdsRequestModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) Logger(org.slf4j.Logger) ChannelDescriptor(com.synopsys.integration.alert.common.descriptor.ChannelDescriptor) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) HttpStatus(org.springframework.http.HttpStatus) Component(org.springframework.stereotype.Component) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) DescriptorProcessor(com.synopsys.integration.alert.common.descriptor.DescriptorProcessor) GlobalConfigExistsValidator(com.synopsys.integration.alert.common.descriptor.config.GlobalConfigExistsValidator) FieldModelTestAction(com.synopsys.integration.alert.common.action.FieldModelTestAction) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) BlackDuckProjectDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.BlackDuckProjectDetailsModel) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)

Example 43 with DistributionJobModel

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

the class JobConfigControllerTestIT method testGetValidationResultsForJobs.

@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testGetValidationResultsForJobs() throws Exception {
    final String urlPath = REQUEST_URL + "/validateJobsById";
    DistributionJobModel distributionJobModel = createAndSaveMockDistributionJob(-1L);
    JobIdsRequestModel jobIdsRequestModel = new JobIdsRequestModel(List.of(distributionJobModel.getJobId()));
    MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(urlPath).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf()).content(gson.toJson(jobIdsRequestModel)).contentType(MEDIA_TYPE);
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
Also used : JobIdsRequestModel(com.synopsys.integration.alert.common.rest.model.JobIdsRequestModel) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) DatabaseConfiguredFieldTest(com.synopsys.integration.alert.util.DatabaseConfiguredFieldTest)

Example 44 with DistributionJobModel

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

the class JobConfigControllerTestIT method testGetConfigById.

@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testGetConfigById() throws Exception {
    DistributionJobModel distributionJobModel = createAndSaveMockDistributionJob(-1L);
    String configId = String.valueOf(distributionJobModel.getJobId());
    String urlPath = REQUEST_URL + "/" + configId;
    MockHttpServletRequestBuilder request = MockMvcRequestBuilders.get(urlPath).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) DatabaseConfiguredFieldTest(com.synopsys.integration.alert.util.DatabaseConfiguredFieldTest)

Example 45 with DistributionJobModel

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

the class DistributionChannelMessageFieldModelTestActionTest method testConfigTest.

@Test
public void testConfigTest() throws AlertException {
    String expectedStatusMessage = "Test Result";
    DistributionChannelMessageTestAction<MockDistributionJobDetailsModel> testAction = createTestAction(expectedStatusMessage);
    DistributionJobModel distributionJobModel = createDistributionJobModel();
    MessageResult messageResult = testAction.testConfig(distributionJobModel, "jobName", "Test Topic", "Test Message");
    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)

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