use of com.synopsys.integration.alert.common.rest.model.JobFieldModel 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.JobFieldModel in project hub-alert by blackducksoftware.
the class ConfigurationManager method copyJob.
public void copyJob(String jobToCopy, String newJobName) throws IntegrationException {
String response = alertRequestUtility.executeGetRequest(String.format("/api/configuration/job?searchTerm=%s", jobToCopy), String.format("Could not copy the Job %s.", jobToCopy));
JobPagedModel jobModel = gson.fromJson(response, JobPagedModel.class);
JobFieldModel jobFieldModel = jobModel.getJobs().stream().findFirst().orElseThrow(() -> new AlertRuntimeException(String.format("Cannot find job %s", jobToCopy), null));
jobFieldModel.setJobId(null);
FieldModel channelFieldModel = jobFieldModel.getFieldModels().stream().filter(model -> ChannelKeys.getChannelKey(model.getDescriptorName()) != null).findFirst().orElseThrow(() -> new AlertRuntimeException("Cannot find channel field model", null));
Map<String, FieldValueModel> channelKeyToValues = new HashMap<>();
channelKeyToValues.putAll(channelFieldModel.getKeyToValues());
channelKeyToValues.put(ChannelDescriptor.KEY_NAME, new FieldValueModel(List.of(newJobName), true));
channelFieldModel.setKeyToValues(channelKeyToValues);
String jobConfigBody = gson.toJson(jobFieldModel);
alertRequestUtility.executePostRequest("/api/configuration/job", jobConfigBody, String.format("Could not create the Job %s.", newJobName));
}
use of com.synopsys.integration.alert.common.rest.model.JobFieldModel in project hub-alert by blackducksoftware.
the class JiraServerDistributionConfigurationValidator method validate.
@Override
public Set<AlertFieldStatus> validate(JobFieldModel jobFieldModel) {
HashSet<AlertFieldStatus> validationResults = new HashSet<>();
ConfigurationFieldValidator configurationFieldValidator = ConfigurationFieldValidator.fromJobFieldModel(jobFieldModel);
commonChannelDistributionValidator.validate(configurationFieldValidator);
configurationFieldValidator.validateRequiredFieldsAreNotBlank(JiraServerDescriptor.KEY_JIRA_PROJECT_NAME, JiraServerDescriptor.KEY_ISSUE_TYPE);
configurationFieldValidator.validateRequiredRelatedSet(JiraServerDescriptor.KEY_OPEN_WORKFLOW_TRANSITION, JiraServerDescriptor.LABEL_OPEN_WORKFLOW_TRANSITION, JiraServerDescriptor.KEY_RESOLVE_WORKFLOW_TRANSITION);
// Validate custom field mappings
jobFieldModel.getFieldModels().stream().filter(fieldModel -> jiraServerChannelKey.getUniversalKey().equals(fieldModel.getDescriptorName())).findFirst().flatMap(fieldModel -> fieldModel.getFieldValueModel(JiraServerDescriptor.KEY_FIELD_MAPPING)).flatMap(fieldValueModel -> jiraFieldMappingValidator.validateFieldMappings(JiraServerDescriptor.KEY_FIELD_MAPPING, fieldValueModel)).ifPresent(validationResults::add);
validationResults.addAll(configurationFieldValidator.getValidationResults());
return validationResults;
}
use of com.synopsys.integration.alert.common.rest.model.JobFieldModel 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.JobFieldModel in project hub-alert by blackducksoftware.
the class JobConfigActions method getChannelFieldModelAndPopulateOtherJobModels.
private FieldModel getChannelFieldModelAndPopulateOtherJobModels(JobFieldModel jobFieldModel, Collection<FieldModel> otherJobModels) throws AlertException {
FieldModel channelFieldModel = null;
for (FieldModel fieldModel : jobFieldModel.getFieldModels()) {
Optional<Descriptor> descriptor = descriptorProcessor.retrieveDescriptor(fieldModel.getDescriptorName());
FieldModel updatedFieldModel = fieldModelProcessor.createCustomMessageFieldModel(fieldModel);
if (descriptor.filter(foundDescriptor -> DescriptorType.CHANNEL.equals(foundDescriptor.getType())).isPresent()) {
channelFieldModel = updatedFieldModel;
} else {
otherJobModels.add(updatedFieldModel);
}
}
return channelFieldModel;
}
Aggregations