static List<PropertyFieldDefinition> create(PropertyField[] fields) { List<PropertyFieldDefinition> definitions = new ArrayList<>(); for (PropertyField field : fields) { definitions.add(PropertyFieldDefinition.build(field.key()) .name(field.name()) .description(field.description()) .indicativeSize(field.indicativeSize()) .type(field.type()) .options(field.options()) .build()); } return definitions; }
public PropertyFieldDefinition build() { Preconditions.checkArgument(!StringUtils.isEmpty(key), "Key must be set"); Preconditions.checkArgument(!StringUtils.isEmpty(name), "Name must be set"); return new PropertyFieldDefinition(this); } }
private static void addField(PropertyFieldDefinition fieldDefinition, Settings.Definition.Builder builder) { builder.addFieldsBuilder() .setKey(fieldDefinition.key()) .setName(fieldDefinition.name()) .setDescription(fieldDefinition.description()) .setType(Settings.Type.valueOf(fieldDefinition.type().name())) .addAllOptions(fieldDefinition.options()) .build(); }
private static void checkFieldType(SetRequest request, PropertyDefinition definition, ListMultimap<String, String> valuesByFieldKeys) { for (PropertyFieldDefinition fieldDefinition : definition.fields()) { for (String value : valuesByFieldKeys.get(fieldDefinition.key())) { PropertyDefinition.Result result = fieldDefinition.validate(value); checkRequest(result.isValid(), "Error when validating setting with key '%s'. Field '%s' has incorrect value '%s'.", request.getKey(), fieldDefinition.key(), value); } } }
static PropertyDefinition create(Property annotation) { Builder builder = PropertyDefinition.builder(annotation.key()) .name(annotation.name()) .defaultValue(annotation.defaultValue()) .description(annotation.description()) .category(annotation.category()) .type(annotation.type()) .options(asList(annotation.options())) .multiValues(annotation.multiValues()) .propertySetKey(annotation.propertySetKey()) .fields(PropertyFieldDefinition.create(annotation.fields())) .deprecatedKey(annotation.deprecatedKey()); List<String> qualifiers = new ArrayList<>(); if (annotation.project()) { qualifiers.add(Qualifiers.PROJECT); } if (annotation.module()) { qualifiers.add(Qualifiers.MODULE); } if (annotation.global()) { builder.onQualifiers(qualifiers); } else { builder.onlyOnQualifiers(qualifiers); } return builder.build(); }
public static Set<String> extractPropertySetKeys(PropertyDto propertyDto, PropertyDefinition definition) { Set<String> propertySetKeys = new HashSet<>(); definition.fields() .forEach(field -> COMMA_SPLITTER.splitToList(propertyDto.getValue()) .forEach(setId -> propertySetKeys.add(generatePropertySetKey(propertyDto.getKey(), setId, field.key())))); return propertySetKeys; }
private static void checkFieldType(SetRequest request, PropertyDefinition definition, ListMultimap<String, String> valuesByFieldKeys) { for (PropertyFieldDefinition fieldDefinition : definition.fields()) { for (String value : valuesByFieldKeys.get(fieldDefinition.key())) { PropertyDefinition.Result result = fieldDefinition.validate(value); checkRequest(result.isValid(), "Error when validating setting with key '%s'. Field '%s' has incorrect value '%s'.", request.getKey(), fieldDefinition.key(), value); } } }
static PropertyDefinition create(Property annotation) { Builder builder = PropertyDefinition.builder(annotation.key()) .name(annotation.name()) .defaultValue(annotation.defaultValue()) .description(annotation.description()) .category(annotation.category()) .type(annotation.type()) .options(Arrays.asList(annotation.options())) .multiValues(annotation.multiValues()) .propertySetKey(annotation.propertySetKey()) .fields(PropertyFieldDefinition.create(annotation.fields())) .deprecatedKey(annotation.deprecatedKey()); List<String> qualifiers = newArrayList(); if (annotation.project()) { qualifiers.add(Qualifiers.PROJECT); } if (annotation.module()) { qualifiers.add(Qualifiers.MODULE); } if (annotation.global()) { builder.onQualifiers(qualifiers); } else { builder.onlyOnQualifiers(qualifiers); } return builder.build(); }
public static Set<String> extractPropertySetKeys(PropertyDto propertyDto, PropertyDefinition definition) { Set<String> propertySetKeys = new HashSet<>(); definition.fields() .forEach(field -> COMMA_SPLITTER.splitToList(propertyDto.getValue()) .forEach(setId -> propertySetKeys.add(generatePropertySetKey(propertyDto.getKey(), setId, field.key())))); return propertySetKeys; }
@Test public void does_not_returned_secured_and_license_settings_in_property_set_when_not_authenticated() { definitions.addComponent(PropertyDefinition .builder("foo") .type(PropertyType.PROPERTY_SET) .fields(asList( PropertyFieldDefinition.build("key").name("Key").build(), PropertyFieldDefinition.build("plugin.license.secured").name("License").type(LICENSE).build(), PropertyFieldDefinition.build("secret.secured").name("Secured").build())) .build()); propertyDb.insertPropertySet("foo", null, ImmutableMap.of("key", "key1", "plugin.license.secured", "ABCD", "secret.secured", "123456")); executeAndVerify(null, null, "does_not_returned_secured_and_license_settings_in_property_set_when_not_authenticated.json"); }
@Test public void should_support_property_sets_from_annotation() { Properties props = AnnotationUtils.getAnnotation(WithPropertySet.class, Properties.class); Property prop = props.value()[0]; PropertyDefinition def = PropertyDefinition.create(prop); assertThat(def.type()).isEqualTo(PropertyType.PROPERTY_SET); assertThat(def.fields()).hasSize(2); assertThat(def.fields().get(0).key()).isEqualTo("first"); assertThat(def.fields().get(0).name()).isEqualTo("First"); assertThat(def.fields().get(0).description()).isEqualTo("Description"); assertThat(def.fields().get(0).type()).isEqualTo(PropertyType.STRING); assertThat(def.fields().get(0).options()).containsOnly("A", "B"); assertThat(def.fields().get(0).indicativeSize()).isEqualTo(20); assertThat(def.fields().get(1).key()).isEqualTo("second"); assertThat(def.fields().get(1).name()).isEqualTo("Second"); assertThat(def.fields().get(1).type()).isEqualTo(PropertyType.INTEGER); assertThat(def.fields().get(1).options()).isEmpty(); assertThat(def.fields().get(1).indicativeSize()).isEqualTo(5); }
public PropertyFieldDefinition build() { Preconditions.checkArgument(!Strings.isNullOrEmpty(key), "Key must be set"); Preconditions.checkArgument(!Strings.isNullOrEmpty(name), "Name must be set"); return new PropertyFieldDefinition(this); } }
static PropertyDefinition create(Property annotation) { Builder builder = PropertyDefinition.builder(annotation.key()) .name(annotation.name()) .defaultValue(annotation.defaultValue()) .description(annotation.description()) .category(annotation.category()) .type(annotation.type()) .options(asList(annotation.options())) .multiValues(annotation.multiValues()) .propertySetKey(annotation.propertySetKey()) .fields(PropertyFieldDefinition.create(annotation.fields())) .deprecatedKey(annotation.deprecatedKey()); List<String> qualifiers = new ArrayList<>(); if (annotation.project()) { qualifiers.add(Qualifiers.PROJECT); } if (annotation.module()) { qualifiers.add(Qualifiers.MODULE); } if (annotation.global()) { builder.onQualifiers(qualifiers); } else { builder.onlyOnQualifiers(qualifiers); } return builder.build(); }
@Test public void return_property_set() { logIn(); definitions.addComponent(PropertyDefinition .builder("foo") .type(PropertyType.PROPERTY_SET) .fields(asList( PropertyFieldDefinition.build("key").name("Key").build(), PropertyFieldDefinition.build("size").name("Size").build())) .build()); propertyDb.insertPropertySet("foo", null, ImmutableMap.of("key", "key1", "size", "size1"), ImmutableMap.of("key", "key2")); ValuesWsResponse result = executeRequestForGlobalProperties("foo"); assertThat(result.getSettingsList()).hasSize(1); Settings.Setting value = result.getSettings(0); assertThat(value.getKey()).isEqualTo("foo"); assertFieldValues(value, ImmutableMap.of("key", "key1", "size", "size1"), ImmutableMap.of("key", "key2")); }
@Test public void should_support_property_sets() { PropertyDefinition def = PropertyDefinition.builder("hello") .name("Hello") .fields( PropertyFieldDefinition.build("first").name("First").description("Description").options("A", "B").build(), PropertyFieldDefinition.build("second").name("Second").type(PropertyType.INTEGER).indicativeSize(5).build()) .build(); assertThat(def.type()).isEqualTo(PropertyType.PROPERTY_SET); assertThat(def.fields()).hasSize(2); assertThat(def.fields().get(0).key()).isEqualTo("first"); assertThat(def.fields().get(0).name()).isEqualTo("First"); assertThat(def.fields().get(0).description()).isEqualTo("Description"); assertThat(def.fields().get(0).type()).isEqualTo(PropertyType.STRING); assertThat(def.fields().get(0).options()).containsOnly("A", "B"); assertThat(def.fields().get(0).indicativeSize()).isEqualTo(20); assertThat(def.fields().get(1).key()).isEqualTo("second"); assertThat(def.fields().get(1).name()).isEqualTo("Second"); assertThat(def.fields().get(1).type()).isEqualTo(PropertyType.INTEGER); assertThat(def.fields().get(1).options()).isEmpty(); assertThat(def.fields().get(1).indicativeSize()).isEqualTo(5); }
public PropertyFieldDefinition build() { Preconditions.checkArgument(!StringUtils.isEmpty(key), "Key must be set"); Preconditions.checkArgument(!StringUtils.isEmpty(name), "Name must be set"); return new PropertyFieldDefinition(this); } }
@Test public void return_property_set() { logIn(); definitions.addComponent(PropertyDefinition .builder("foo") .type(PropertyType.PROPERTY_SET) .fields(asList( PropertyFieldDefinition.build("key").name("Key").build(), PropertyFieldDefinition.build("size").name("Size").build())) .build()); propertyDb.insertPropertySet("foo", null, ImmutableMap.of("key", "key1", "size", "size1"), ImmutableMap.of("key", "key2")); executeAndVerify(null, null, "return_property_set.json"); }
private static void addField(PropertyFieldDefinition fieldDefinition, Settings.Definition.Builder builder) { builder.addFieldsBuilder() .setKey(fieldDefinition.key()) .setName(fieldDefinition.name()) .setDescription(fieldDefinition.description()) .setType(Settings.Type.valueOf(fieldDefinition.type().name())) .addAllOptions(fieldDefinition.options()) .build(); }
@Test public void return_property_set_for_component() { logInAsProjectUser(); definitions.addComponent(PropertyDefinition .builder("foo") .type(PropertyType.PROPERTY_SET) .onQualifiers(PROJECT) .fields(asList( PropertyFieldDefinition.build("key").name("Key").build(), PropertyFieldDefinition.build("size").name("Size").build())) .build()); propertyDb.insertPropertySet("foo", project, ImmutableMap.of("key", "key1", "size", "size1"), ImmutableMap.of("key", "key2")); ValuesWsResponse result = executeRequestForProjectProperties("foo"); assertThat(result.getSettingsList()).hasSize(1); Settings.Setting value = result.getSettings(0); assertThat(value.getKey()).isEqualTo("foo"); assertFieldValues(value, ImmutableMap.of("key", "key1", "size", "size1"), ImmutableMap.of("key", "key2")); }
@Test public void do_not_return_secured_and_license_settings_in_property_set_when_not_authenticated() { definitions.addComponent(PropertyDefinition .builder("foo") .type(PropertyType.PROPERTY_SET) .fields(asList( PropertyFieldDefinition.build("key").name("Key").build(), PropertyFieldDefinition.build("plugin.license.secured").name("License").type(LICENSE).build(), PropertyFieldDefinition.build("secret.secured").name("Secured").build())) .build()); propertyDb.insertPropertySet("foo", null, ImmutableMap.of("key", "key1", "plugin.license.secured", "ABCD", "secret.secured", "123456")); ValuesWsResponse result = executeRequestForGlobalProperties(); assertFieldValues(result.getSettings(0), ImmutableMap.of("key", "key1")); }