Search in sources :

Example 11 with FieldModel

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

the class FieldModelProcessor method createCustomMessageFieldModel.

public FieldModel createCustomMessageFieldModel(FieldModel fieldModel) throws AlertException {
    String id = fieldModel.getId();
    FieldModel upToDateFieldModel = fieldModel;
    if (StringUtils.isNotBlank(id)) {
        Long convertedId = Long.parseLong(id);
        upToDateFieldModel = populateTestFieldModel(convertedId, fieldModel);
    }
    return upToDateFieldModel;
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel)

Example 12 with FieldModel

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

the class FieldModelProcessor method populateTestFieldModel.

private FieldModel populateTestFieldModel(Long id, FieldModel fieldModel) throws AlertException {
    Collection<ConfigurationFieldModel> configurationFieldModels = fillFieldModelWithExistingData(id, fieldModel);
    Map<String, FieldValueModel> fields = new HashMap<>();
    for (ConfigurationFieldModel configurationFieldModel : configurationFieldModels) {
        FieldValueModel fieldValueModel = new FieldValueModel(configurationFieldModel.getFieldValues(), configurationFieldModel.isSet());
        fields.put(configurationFieldModel.getFieldKey(), fieldValueModel);
    }
    FieldModel newFieldModel = new FieldModel("", "", fieldModel.getCreatedAt(), fieldModel.getLastUpdated(), fields);
    return fieldModel.fill(newFieldModel);
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) HashMap(java.util.HashMap) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel)

Example 13 with FieldModel

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

the class DefaultDescriptorGlobalConfigUtility method getFieldModel.

public Optional<FieldModel> getFieldModel() throws AlertException {
    Optional<ConfigurationModel> configurationModelOptional = getConfiguration();
    if (configurationModelOptional.isPresent()) {
        ConfigurationModel configurationModel = configurationModelOptional.get();
        FieldModel fieldModel = configurationFieldModelConverter.convertToFieldModel(configurationModel);
        return Optional.ofNullable(apiAction.afterGetAction(fieldModel));
    }
    return Optional.empty();
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel)

Example 14 with FieldModel

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

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

the class AlertStartupInitializer method createFieldModelsFromDefinedFields.

private Set<ConfigurationFieldModel> createFieldModelsFromDefinedFields(DescriptorKey descriptorKey, List<DefinedFieldModel> fieldsForDescriptor, Map<String, ConfigurationFieldModel> existingConfiguredFields) {
    Set<ConfigurationFieldModel> configurationModels = new HashSet<>();
    logger.info("  ### Environment Variables ### ");
    for (DefinedFieldModel fieldModel : fieldsForDescriptor) {
        String key = fieldModel.getKey();
        String convertedKey = environmentUtility.convertKeyToProperty(descriptorKey, key);
        boolean hasEnvironmentValue = environmentUtility.hasEnvironmentValue(convertedKey);
        logger.info("    {}", convertedKey);
        logger.debug("         Environment Variable Found - {}", hasEnvironmentValue);
        String defaultValue = null;
        if (existingConfiguredFields.containsKey(key)) {
            Optional<String> fieldValue = existingConfiguredFields.get(key).getFieldValue();
            if (fieldValue.isPresent()) {
                defaultValue = fieldValue.get();
            }
        }
        environmentUtility.getEnvironmentValue(convertedKey, defaultValue).flatMap(value -> modelConverter.convertFromDefinedFieldModel(fieldModel, value, StringUtils.isNotBlank(value))).ifPresent(configurationModels::add);
    }
    return configurationModels;
}
Also used : DefinedFieldModel(com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) HashSet(java.util.HashSet) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) Map(java.util.Map) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) Order(org.springframework.core.annotation.Order) EnvironmentVariableUtility(com.synopsys.integration.alert.environment.EnvironmentVariableUtility) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) Collectors(java.util.stream.Collectors) EnvironmentVariableProcessor(com.synopsys.integration.alert.environment.EnvironmentVariableProcessor) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) List(java.util.List) Component(org.springframework.stereotype.Component) FieldModelProcessor(com.synopsys.integration.alert.common.rest.FieldModelProcessor) Optional(java.util.Optional) SettingsUtility(com.synopsys.integration.alert.common.descriptor.accessor.SettingsUtility) Comparator(java.util.Comparator) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DefinedFieldModel(com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel) HashSet(java.util.HashSet)

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