use of com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel in project hub-alert by blackducksoftware.
the class ConfigurationManager method createJob.
public String createJob(Map<String, FieldValueModel> channelFields, String jobName, String blackDuckProviderId, String blackDuckProjectName, List<NotificationType> notificationTypes) throws IntegrationException {
List<String> notificationTypeNames = notificationTypes.stream().map(Enum::name).collect(Collectors.toList());
Map<String, FieldValueModel> providerKeyToValues = new HashMap<>();
providerKeyToValues.put(ProviderDescriptor.KEY_PROVIDER_CONFIG_ID, new FieldValueModel(List.of(blackDuckProviderId), true));
providerKeyToValues.put(ProviderDescriptor.KEY_NOTIFICATION_TYPES, new FieldValueModel(notificationTypeNames, true));
providerKeyToValues.put(ProviderDescriptor.KEY_PROCESSING_TYPE, new FieldValueModel(List.of(ProcessingType.DEFAULT.name()), true));
providerKeyToValues.put(ProviderDescriptor.KEY_FILTER_BY_PROJECT, new FieldValueModel(List.of("true"), true));
providerKeyToValues.put(ProviderDescriptor.KEY_CONFIGURED_PROJECT, new FieldValueModel(List.of(blackDuckProjectName), true));
FieldModel jobProviderConfiguration = new FieldModel(blackDuckProviderKey, ConfigContextEnum.DISTRIBUTION.name(), providerKeyToValues);
FieldModel jobConfiguration = new FieldModel(channelKey, ConfigContextEnum.DISTRIBUTION.name(), channelFields);
JobFieldModel jobFieldModel = new JobFieldModel(null, Set.of(jobConfiguration, jobProviderConfiguration), List.of(new JobProviderProjectFieldModel(blackDuckProjectName, "href", false)));
String jobConfigBody = gson.toJson(jobFieldModel);
alertRequestUtility.executePostRequest("/api/configuration/job/validate", jobConfigBody, String.format("Validating the Job %s failed.", jobName));
alertRequestUtility.executePostRequest("/api/configuration/job/test", jobConfigBody, String.format("Testing the Job %s failed.", jobName));
String creationResponse = alertRequestUtility.executePostRequest("/api/configuration/job", jobConfigBody, String.format("Could not create the Job %s.", jobName));
JsonObject jsonObject = gson.fromJson(creationResponse, JsonObject.class);
return jsonObject.get("jobId").getAsString();
}
use of com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel in project hub-alert by blackducksoftware.
the class AbstractJobResourceActions method correctProjectsField.
// FIXME More tech debt until we fix the Jobs API
private void correctProjectsField(JobFieldModel jobFieldModel) {
List<JobProviderProjectFieldModel> projects = jobFieldModel.getConfiguredProviderProjects();
if (null == projects) {
projects = List.of();
}
String projectFieldKey = "channel.common.configured.project";
for (FieldModel fieldModel : jobFieldModel.getFieldModels()) {
Map<String, FieldValueModel> keyToValues = fieldModel.getKeyToValues();
if (keyToValues.containsKey(projectFieldKey)) {
FieldValueModel projectFieldValues = createProjectFieldValues(projects);
keyToValues.put(projectFieldKey, projectFieldValues);
return;
}
}
}
use of com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel in project hub-alert by blackducksoftware.
the class JobConfigActions method findJobFieldModel.
@Override
protected Optional<JobFieldModel> findJobFieldModel(UUID id) {
Optional<DistributionJobModel> optionalJob = jobAccessor.getJobById(id);
if (optionalJob.isPresent()) {
DistributionJobModel distributionJobModel = optionalJob.get();
List<JobProviderProjectFieldModel> jobProviderProjects = JobFieldModelPopulationUtils.createJobProviderProjects(distributionJobModel);
providerProjectExistencePopulator.populateJobProviderProjects(distributionJobModel.getBlackDuckGlobalConfigId(), jobProviderProjects);
JobFieldModel jobFieldModel = JobFieldModelPopulationUtils.createJobFieldModel(distributionJobModel, jobProviderProjects);
return Optional.of(jobFieldModel);
}
return Optional.empty();
}
use of com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel in project hub-alert by blackducksoftware.
the class JobConfigActions method createWithoutChecks.
@Override
protected ActionResponse<JobFieldModel> createWithoutChecks(JobFieldModel resource) {
try {
Set<ConfigurationFieldModel> configurationFieldModels = new HashSet<>();
for (FieldModel fieldModel : resource.getFieldModels()) {
FieldModel beforeSaveEventFieldModel = fieldModelProcessor.performBeforeSaveAction(fieldModel);
Collection<ConfigurationFieldModel> savedFieldsModels = modelConverter.convertToConfigurationFieldModelMap(beforeSaveEventFieldModel).values();
configurationFieldModels.addAll(savedFieldsModels);
}
List<JobProviderProjectFieldModel> configuredProviderProjects = Optional.ofNullable(resource.getConfiguredProviderProjects()).orElse(List.of());
DistributionJobRequestModel jobRequestModel = createDistributionJobRequestModel(configurationFieldModels, configuredProviderProjects, DateUtils.createCurrentDateTimestamp(), null);
DistributionJobModel savedJob = jobAccessor.createJob(jobRequestModel);
JobFieldModel savedJobFieldModel = JobFieldModelPopulationUtils.createJobFieldModel(savedJob, configuredProviderProjects);
Set<FieldModel> updatedFieldModels = new HashSet<>();
for (FieldModel fieldModel : savedJobFieldModel.getFieldModels()) {
FieldModel updatedModel = fieldModelProcessor.performAfterSaveAction(fieldModel);
updatedFieldModels.add(updatedModel);
}
savedJobFieldModel.setFieldModels(updatedFieldModels);
return new ActionResponse<>(HttpStatus.OK, savedJobFieldModel);
} 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 JobFieldModelPopulationUtils method createJobFieldModel.
public static JobFieldModel createJobFieldModel(DistributionJobModel jobModel, List<JobProviderProjectFieldModel> jobProviderProjects) {
FieldModel providerFieldModel = new FieldModel(DEFAULT_PROVIDER_NAME, ConfigContextEnum.DISTRIBUTION.name(), new HashMap<>());
populateProviderFields(providerFieldModel, jobModel, jobProviderProjects);
FieldModel channelFieldModel = new FieldModel(jobModel.getChannelDescriptorName(), ConfigContextEnum.DISTRIBUTION.name(), new HashMap<>());
populateChannelFields(channelFieldModel, jobModel);
String jobIdString = Optional.ofNullable(jobModel.getJobId()).map(UUID::toString).orElse(null);
return new JobFieldModel(jobIdString, Set.of(providerFieldModel, channelFieldModel), jobProviderProjects);
}
Aggregations