use of com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel in project hub-alert by blackducksoftware.
the class JobConfigActions method updateWithoutChecks.
@Override
protected ActionResponse<JobFieldModel> updateWithoutChecks(UUID id, JobFieldModel resource) {
try {
Optional<DistributionJobModel> jobModel = jobAccessor.getJobById(id);
if (jobModel.isPresent()) {
DistributionJobModel previousJob = jobModel.get();
JobFieldModel jobFieldModel = JobFieldModelPopulationUtils.createJobFieldModelWithDefaultProviderProjectState(previousJob);
Map<String, FieldModel> descriptorAndContextToPreviousFieldModel = new HashMap<>();
for (FieldModel previousJobFieldModel : jobFieldModel.getFieldModels()) {
descriptorAndContextToPreviousFieldModel.put(previousJobFieldModel.getDescriptorName() + previousJobFieldModel.getContext(), previousJobFieldModel);
}
Set<ConfigurationFieldModel> configurationFieldModels = new HashSet<>();
for (FieldModel fieldModel : resource.getFieldModels()) {
FieldModel beforeUpdateEventFieldModel = fieldModelProcessor.performBeforeUpdateAction(fieldModel);
String beforeFieldModelId = beforeUpdateEventFieldModel.getId();
Long fieldModelId = (StringUtils.isNotBlank(beforeFieldModelId)) ? Long.parseLong(beforeFieldModelId) : null;
Collection<ConfigurationFieldModel> updatedFieldModels = fieldModelProcessor.fillFieldModelWithExistingData(fieldModelId, beforeUpdateEventFieldModel);
configurationFieldModels.addAll(updatedFieldModels);
}
List<JobProviderProjectFieldModel> configuredProviderProjects = Optional.ofNullable(resource.getConfiguredProviderProjects()).orElse(List.of());
DistributionJobRequestModel jobRequestModel = createDistributionJobRequestModel(configurationFieldModels, configuredProviderProjects, previousJob.getCreatedAt(), DateUtils.createCurrentDateTimestamp());
DistributionJobModel savedJob = jobAccessor.updateJob(previousJob.getJobId(), jobRequestModel);
JobFieldModel savedJobFieldModel = JobFieldModelPopulationUtils.createJobFieldModel(savedJob, configuredProviderProjects);
Set<FieldModel> updatedFieldModels = new HashSet<>();
for (FieldModel fieldModel : savedJobFieldModel.getFieldModels()) {
FieldModel previousFieldModel = descriptorAndContextToPreviousFieldModel.get(fieldModel.getDescriptorName() + fieldModel.getContext());
FieldModel updatedModel = fieldModelProcessor.performAfterUpdateAction(previousFieldModel, fieldModel);
updatedFieldModels.add(updatedModel);
}
savedJobFieldModel.setFieldModels(updatedFieldModels);
return new ActionResponse<>(HttpStatus.OK, savedJobFieldModel);
} else {
return new ActionResponse<>(HttpStatus.NOT_FOUND);
}
} catch (AlertException ex) {
logger.error("Error creating job", ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
}
}
use of com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel in project hub-alert by blackducksoftware.
the class BlackDuckProjectExistencePopulator method populateJobProviderProjects.
private void populateJobProviderProjects(ConfigurationModel providerGlobalConfig, List<JobProviderProjectFieldModel> configuredProviderProjects) {
BlackDuckApiClient blackDuckApiClient;
try {
blackDuckApiClient = createBlackDuckApiClient(providerGlobalConfig);
} catch (AlertException e) {
logger.debug("Failed to initialize BlackDuck services", e);
return;
}
for (JobProviderProjectFieldModel project : configuredProviderProjects) {
boolean exists = doesProjectExist(blackDuckApiClient, project);
project.setMissing(!exists);
}
}
use of com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel in project hub-alert by blackducksoftware.
the class JobConfigControllerTestIT method createTestJobFieldModel.
private JobFieldModel createTestJobFieldModel(String channelId, String providerId, ConfigurationModel providerGlobalConfig) {
String descriptorName = ChannelKeys.SLACK.getUniversalKey();
String context = ConfigContextEnum.DISTRIBUTION.name();
FieldValueModel providerConfigField = new FieldValueModel(List.of(providerGlobalConfig.getConfigurationId().toString()), true);
FieldValueModel slackChannelName = new FieldValueModel(List.of("channelName"), true);
FieldValueModel frequency = new FieldValueModel(List.of(FrequencyType.DAILY.name()), true);
FieldValueModel name = new FieldValueModel(List.of("name"), true);
FieldValueModel provider = new FieldValueModel(List.of(blackDuckProviderKey.getUniversalKey()), true);
FieldValueModel channel = new FieldValueModel(List.of("channel_slack"), true);
FieldValueModel webhook = new FieldValueModel(List.of("http://slack_webhook_url"), true);
Map<String, FieldValueModel> fields = Map.of(SlackDescriptor.KEY_CHANNEL_NAME, slackChannelName, SlackDescriptor.KEY_WEBHOOK, webhook, ChannelDescriptor.KEY_NAME, name, ChannelDescriptor.KEY_PROVIDER_TYPE, provider, ProviderDescriptor.KEY_PROVIDER_CONFIG_ID, providerConfigField, ChannelDescriptor.KEY_CHANNEL_NAME, channel, ChannelDescriptor.KEY_FREQUENCY, frequency);
FieldModel fieldModel = new FieldModel(descriptorName, context, fields);
if (StringUtils.isNotBlank(channelId)) {
fieldModel.setId(channelId);
}
String bdDescriptorName = blackDuckProviderKey.getUniversalKey();
String bdContext = ConfigContextEnum.DISTRIBUTION.name();
FieldValueModel notificationType = new FieldValueModel(List.of("vulnerability"), true);
FieldValueModel formatType = new FieldValueModel(List.of(ProcessingType.DEFAULT.name()), true);
FieldValueModel filterByProject = new FieldValueModel(List.of("false"), true);
FieldValueModel projectNames = new FieldValueModel(List.of("project"), true);
Map<String, FieldValueModel> bdFields = Map.of(ProviderDescriptor.KEY_NOTIFICATION_TYPES, notificationType, ProviderDescriptor.KEY_PROVIDER_CONFIG_ID, providerConfigField, ProviderDescriptor.KEY_PROCESSING_TYPE, formatType, ProviderDescriptor.KEY_FILTER_BY_PROJECT, filterByProject, ProviderDescriptor.KEY_CONFIGURED_PROJECT, projectNames);
FieldModel bdFieldModel = new FieldModel(bdDescriptorName, bdContext, bdFields);
if (StringUtils.isNotBlank(providerId)) {
bdFieldModel.setId(providerId);
}
return new JobFieldModel(UUID.randomUUID().toString(), Set.of(fieldModel, bdFieldModel), List.of(new JobProviderProjectFieldModel("project", "href", false)));
}
use of com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel 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());
}
Aggregations