Search in sources :

Example 1 with JobFieldModel

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();
}
Also used : HashMap(java.util.HashMap) JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) JsonObject(com.google.gson.JsonObject) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel)

Example 2 with JobFieldModel

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));
}
Also used : HashMap(java.util.HashMap) JobPagedModel(com.synopsys.integration.alert.common.rest.model.JobPagedModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel)

Example 3 with JobFieldModel

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;
}
Also used : HashSet(java.util.HashSet) CommonChannelDistributionValidator(com.synopsys.integration.alert.api.channel.CommonChannelDistributionValidator) JiraServerDescriptor(com.synopsys.integration.alert.channel.jira.server.descriptor.JiraServerDescriptor) Component(org.springframework.stereotype.Component) JiraServerChannelKey(com.synopsys.integration.alert.descriptor.api.JiraServerChannelKey) JiraFieldMappingValidator(com.synopsys.integration.alert.api.channel.jira.validation.JiraFieldMappingValidator) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) DistributionConfigurationValidator(com.synopsys.integration.alert.common.descriptor.validator.DistributionConfigurationValidator) ConfigurationFieldValidator(com.synopsys.integration.alert.common.descriptor.validator.ConfigurationFieldValidator) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) ConfigurationFieldValidator(com.synopsys.integration.alert.common.descriptor.validator.ConfigurationFieldValidator) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) HashSet(java.util.HashSet)

Example 4 with JobFieldModel

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;
        }
    }
}
Also used : JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) MultiJobFieldModel(com.synopsys.integration.alert.common.rest.model.MultiJobFieldModel) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel)

Example 5 with JobFieldModel

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;
}
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) Descriptor(com.synopsys.integration.alert.common.descriptor.Descriptor) ChannelDescriptor(com.synopsys.integration.alert.common.descriptor.ChannelDescriptor) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel)

Aggregations

JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)32 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)13 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)13 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)12 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)12 JobProviderProjectFieldModel (com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel)12 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)11 Test (org.junit.jupiter.api.Test)11 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)9 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)8 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)7 JobPagedModel (com.synopsys.integration.alert.common.rest.model.JobPagedModel)7 HashMap (java.util.HashMap)7 Set (java.util.Set)7 DescriptorMap (com.synopsys.integration.alert.common.descriptor.DescriptorMap)6 DescriptorProcessor (com.synopsys.integration.alert.common.descriptor.DescriptorProcessor)6 GlobalConfigExistsValidator (com.synopsys.integration.alert.common.descriptor.config.GlobalConfigExistsValidator)6 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)6 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)6 DescriptorAccessor (com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor)6