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