Search in sources :

Example 1 with JobProviderProjectFieldModel

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();
}
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 JobProviderProjectFieldModel

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;
        }
    }
}
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 3 with JobProviderProjectFieldModel

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

Example 4 with JobProviderProjectFieldModel

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());
    }
}
Also used : JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) 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) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) HashSet(java.util.HashSet)

Example 5 with JobProviderProjectFieldModel

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

Aggregations

JobProviderProjectFieldModel (com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel)9 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)8 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)7 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)4 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)4 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)4 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)3 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)3 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)3 DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 JsonObject (com.google.gson.JsonObject)1 ProviderProjectExistencePopulator (com.synopsys.integration.alert.api.provider.ProviderProjectExistencePopulator)1 FieldModelTestAction (com.synopsys.integration.alert.common.action.FieldModelTestAction)1 AbstractJobResourceActions (com.synopsys.integration.alert.common.action.api.AbstractJobResourceActions)1 DistributionChannelTestAction (com.synopsys.integration.alert.common.channel.DistributionChannelTestAction)1 ChannelDescriptor (com.synopsys.integration.alert.common.descriptor.ChannelDescriptor)1 Descriptor (com.synopsys.integration.alert.common.descriptor.Descriptor)1 DescriptorMap (com.synopsys.integration.alert.common.descriptor.DescriptorMap)1