use of com.synopsys.integration.alert.common.rest.model.FieldValueModel in project hub-alert by blackducksoftware.
the class EmailConfigActionTestIT method createEmailFieldModel.
private FieldModel createEmailFieldModel() {
Map<String, FieldValueModel> fieldValuesMap = new HashMap<>();
fieldValuesMap.put(EmailPropertyKeys.JAVAMAIL_FROM_KEY.getPropertyKey(), new FieldValueModel(List.of(TEST_FROM), false));
fieldValuesMap.put(EmailPropertyKeys.JAVAMAIL_HOST_KEY.getPropertyKey(), new FieldValueModel(List.of(TEST_SMTP_HOST), false));
fieldValuesMap.put(EmailPropertyKeys.JAVAMAIL_PORT_KEY.getPropertyKey(), new FieldValueModel(List.of(TEST_SMTP_PORT), false));
fieldValuesMap.put(EmailPropertyKeys.JAVAMAIL_AUTH_KEY.getPropertyKey(), new FieldValueModel(List.of(TEST_AUTH_REQUIRED), false));
fieldValuesMap.put(EmailPropertyKeys.JAVAMAIL_PASSWORD_KEY.getPropertyKey(), new FieldValueModel(List.of(TEST_AUTH_PASSWORD), false));
fieldValuesMap.put(EmailPropertyKeys.JAVAMAIL_USER_KEY.getPropertyKey(), new FieldValueModel(List.of(TEST_AUTH_USER), false));
fieldValuesMap.put(EmailPropertyKeys.JAVAMAIL_EHLO_KEY.getPropertyKey(), new FieldValueModel(List.of("true"), false));
return new FieldModel(ChannelKeys.EMAIL.getUniversalKey(), ConfigContextEnum.GLOBAL.name(), fieldValuesMap);
}
use of com.synopsys.integration.alert.common.rest.model.FieldValueModel in project hub-alert by blackducksoftware.
the class BlackDuckProviderService method createBlackDuckProvider.
private String createBlackDuckProvider() {
Map<String, FieldValueModel> keyToValues = new HashMap<>();
keyToValues.put("provider.common.config.enabled", new FieldValueModel(List.of("true"), true));
keyToValues.put("provider.common.config.name", new FieldValueModel(List.of(blackDuckProviderUniqueName), true));
keyToValues.put("blackduck.url", new FieldValueModel(List.of(blackDuckProviderUrl), true));
keyToValues.put("blackduck.api.key", new FieldValueModel(List.of(blackDuckApiToken), true));
keyToValues.put("blackduck.timeout", new FieldValueModel(List.of(blackDuckTimeout), true));
FieldModel blackDuckProviderConfiguration = new FieldModel(blackDuckProviderKey, ConfigContextEnum.GLOBAL.name(), keyToValues);
String blackDuckConfigBody = gson.toJson(blackDuckProviderConfiguration);
try {
alertRequestUtility.executePostRequest("/api/configuration/validate", blackDuckConfigBody, "Validating the Black Duck provider failed.");
alertRequestUtility.executePostRequest("/api/configuration/test", blackDuckConfigBody, "Testing the Black Duck provider failed.");
String creationResponse = alertRequestUtility.executePostRequest("/api/configuration", blackDuckConfigBody, "Could not create the Black Duck provider.");
JsonObject jsonObject = gson.fromJson(creationResponse, JsonObject.class);
String blackDuckProviderID = jsonObject.get("id").getAsString();
intLogger.info(String.format("Configured the Black Duck provider, ID %s.", blackDuckProviderID));
return blackDuckProviderID;
} catch (IntegrationException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
use of com.synopsys.integration.alert.common.rest.model.FieldValueModel in project hub-alert by blackducksoftware.
the class GlobalConfigurationValidatorAsserter method assertInvalidValue.
public void assertInvalidValue(String key, String invalidValue, Consumer<AlertFieldStatus> additionalAsserts) {
FieldValueModel apiKeyFieldValueModel = new FieldValueModel(List.of(invalidValue), true);
defaultKeyToValues.put(key, apiKeyFieldValueModel);
Set<AlertFieldStatus> alertFieldStatuses = runValidation();
assertEquals(1, alertFieldStatuses.size(), alertFieldStatuses.toString());
AlertFieldStatus alertFieldStatus = alertFieldStatuses.stream().findFirst().orElseThrow();
assertEquals(key, alertFieldStatus.getFieldName());
additionalAsserts.accept(alertFieldStatus);
}
use of com.synopsys.integration.alert.common.rest.model.FieldValueModel in project hub-alert by blackducksoftware.
the class ConfigurationFieldModelConverter method populateAndSecureFields.
private void populateAndSecureFields(ConfigurationFieldModel fieldModel, Map<String, FieldValueModel> fields) {
String key = fieldModel.getFieldKey();
Collection<String> values = (!fieldModel.isSensitive()) ? fieldModel.getFieldValues() : List.of();
FieldValueModel fieldValueModel = new FieldValueModel(values, fieldModel.isSet());
fields.put(key, fieldValueModel);
}
use of com.synopsys.integration.alert.common.rest.model.FieldValueModel in project hub-alert by blackducksoftware.
the class ConfigurationFieldModelConverter method convertToConfigurationFieldModelMap.
public final Map<String, ConfigurationFieldModel> convertToConfigurationFieldModelMap(FieldModel fieldModel) {
ConfigContextEnum context = EnumUtils.getEnum(ConfigContextEnum.class, fieldModel.getContext());
String descriptorName = fieldModel.getDescriptorName();
DescriptorKey descriptorKey = getDescriptorKey(descriptorName).orElseThrow(() -> new AlertRuntimeException("Could not find a Descriptor with the name: " + descriptorName));
List<DefinedFieldModel> fieldsForContext = descriptorAccessor.getFieldsForDescriptor(descriptorKey, context);
Map<String, ConfigurationFieldModel> configurationModels = new HashMap<>();
for (DefinedFieldModel definedField : fieldsForContext) {
fieldModel.getFieldValueModel(definedField.getKey()).flatMap(fieldValueModel -> convertFromDefinedFieldModel(definedField, fieldValueModel.getValues(), fieldValueModel.getIsSet())).ifPresent(configurationFieldModel -> configurationModels.put(configurationFieldModel.getFieldKey(), configurationFieldModel));
}
return configurationModels;
}
Aggregations