Search in sources :

Example 26 with FieldModel

use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.

the class JobConfigActions method deleteWithoutChecks.

@Override
protected ActionResponse<JobFieldModel> deleteWithoutChecks(UUID id) {
    try {
        Optional<DistributionJobModel> job = jobAccessor.getJobById(id);
        if (job.isPresent()) {
            LinkedList<FieldModel> processedFieldModels = new LinkedList<>();
            DistributionJobModel distributionJobModel = job.get();
            JobFieldModel jobFieldModel = JobFieldModelPopulationUtils.createJobFieldModelWithDefaultProviderProjectState(distributionJobModel);
            for (FieldModel fieldModel : jobFieldModel.getFieldModels()) {
                FieldModel preProcessedFieldModel = fieldModelProcessor.performBeforeDeleteAction(fieldModel);
                processedFieldModels.add(preProcessedFieldModel);
            }
            jobAccessor.deleteJob(distributionJobModel.getJobId());
            for (FieldModel preProcessedFieldModel : processedFieldModels) {
                fieldModelProcessor.performAfterDeleteAction(preProcessedFieldModel);
            }
        } else {
            return new ActionResponse<>(HttpStatus.NOT_FOUND);
        }
    } catch (AlertException ex) {
        logger.error("Error reading job", ex);
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
    }
    return new ActionResponse<>(HttpStatus.NO_CONTENT);
}
Also used : JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) 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) LinkedList(java.util.LinkedList) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)

Example 27 with FieldModel

use of com.synopsys.integration.alert.common.rest.model.FieldModel 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)

Example 28 with FieldModel

use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.

the class JobConfigActionsTest method createFieldModel.

private FieldModel createFieldModel() {
    String value = "testValue";
    Map<String, FieldValueModel> keyToValues = new HashMap<>();
    keyToValues.put(FieldModelTestAction.KEY_CUSTOM_TOPIC, new FieldValueModel(List.of(value), false));
    keyToValues.put(ChannelDescriptor.KEY_NAME, new FieldValueModel(List.of(value), false));
    return new FieldModel(descriptorKey.getUniversalKey(), ConfigContextEnum.DISTRIBUTION.name(), keyToValues);
}
Also used : HashMap(java.util.HashMap) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) 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 29 with FieldModel

use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.

the class ConfigActions method convertConfigurationModelList.

private List<FieldModel> convertConfigurationModelList(String descriptorName, String context, List<ConfigurationModel> configurationModels) {
    List<FieldModel> responseFieldModels = new LinkedList<>();
    List<FieldModel> fieldModelList = new LinkedList<>();
    if (null != configurationModels) {
        for (ConfigurationModel configurationModel : configurationModels) {
            FieldModel fieldModel = modelConverter.convertToFieldModel(configurationModel);
            fieldModelList.add(fieldModel);
        }
    }
    if (fieldModelList.isEmpty()) {
        fieldModelList.add(new FieldModel(descriptorName, context, new HashMap<>()));
    }
    for (FieldModel fieldModel : fieldModelList) {
        try {
            responseFieldModels.add(fieldModelProcessor.performAfterReadAction(fieldModel));
        } catch (AlertException ex) {
            logger.error("Error performing after read action", ex);
        }
    }
    return responseFieldModels;
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) HashMap(java.util.HashMap) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) MultiFieldModel(com.synopsys.integration.alert.common.rest.model.MultiFieldModel) LinkedList(java.util.LinkedList) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 30 with FieldModel

use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.

the class ConfigActions method readAllByContextAndDescriptorWithoutChecks.

@Override
protected ActionResponse<MultiFieldModel> readAllByContextAndDescriptorWithoutChecks(String context, String descriptorName) {
    ConfigContextEnum configContext = ConfigContextEnum.valueOf(context);
    Optional<DescriptorKey> descriptorKey = descriptorMap.getDescriptorKey(descriptorName);
    if (!descriptorKey.isPresent()) {
        return new ActionResponse<>(HttpStatus.BAD_REQUEST, String.format("Unknown descriptor: %s", descriptorName));
    }
    List<ConfigurationModel> configurationModels = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(descriptorKey.get(), configContext);
    List<FieldModel> fieldModels = convertConfigurationModelList(descriptorName, context, configurationModels);
    return new ActionResponse<>(HttpStatus.OK, new MultiFieldModel(fieldModels));
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) SettingsDescriptorKey(com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) MultiFieldModel(com.synopsys.integration.alert.common.rest.model.MultiFieldModel) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) MultiFieldModel(com.synopsys.integration.alert.common.rest.model.MultiFieldModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Aggregations

FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)73 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)43 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)31 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)28 Test (org.junit.jupiter.api.Test)26 HashMap (java.util.HashMap)25 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)21 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)21 ConfigurationFieldModelConverter (com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter)19 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)18 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)18 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)15 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)14 FieldUtility (com.synopsys.integration.alert.common.persistence.accessor.FieldUtility)13 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)13 List (java.util.List)13 Autowired (org.springframework.beans.factory.annotation.Autowired)13 DescriptorAccessor (com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor)12 JobProviderProjectFieldModel (com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel)12 MultiFieldModel (com.synopsys.integration.alert.common.rest.model.MultiFieldModel)12