Skip to content

Commit

Permalink
Support lists for metadata properties in items files
Browse files Browse the repository at this point in the history
Signed-off-by: Cody Cutrer <cody@cutrer.us>
  • Loading branch information
ccutrer committed Jul 25, 2024
1 parent e157448 commit c3fdd86
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ ModelBinding:
;

ModelProperty:
key=ID '=' value=ValueType
key=ID '=' value+=ValueType (',' value+=ValueType)*
;

ValueType returns ecore::EJavaObject:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,15 @@ private void internalDispatchBindings(@Nullable BindingConfigReader reader, Stri
String config = binding.getConfiguration();

Configuration configuration = new Configuration();
binding.getProperties().forEach(p -> configuration.put(p.getKey(), p.getValue()));
binding.getProperties().forEach(p -> {
Object value = p.getValue();
// Single valued lists get unwrapped to just their one value for
// backwards compatibility
if (value instanceof List listValue && listValue.size() == 1) {
value = listValue.get(0);
}
configuration.put(p.getKey(), value);
});

BindingConfigReader localReader = reader;
if (reader == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,41 @@ public void testMetadataUpdate() {
assertThat(metadata3, is(nullValue()));
}

@Test
public void testMetadataPropertyTypes() {
String model = "Switch simple { namespace=\"value\"[string=\"string\", bool=false, int=2, stringList=\"string1\",\"string2\", boolList=false,true] } ";

modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream(model.getBytes()));
Item item = itemRegistry.get("simple");
assertThat(item, is(notNullValue()));

Metadata res = metadataRegistry.get(new MetadataKey("namespace", "simple"));
assertThat(res, is(notNullValue()));
assertThat(res.getValue(), is("value"));
assertThat(res.getConfiguration(), is(notNullValue()));
var config = res.getConfiguration();
assertThat(config.size(), is(5));
assertThat(config.get("string"), is("string"));
assertThat(config.get("bool"), is(false));
assertThat(config.get("int"), is(new BigDecimal("2")));

var list = config.get("stringList");
assertThat(list, is(notNullValue()));
assertThat(list, instanceOf(List.class));
List<Object> values = (List<Object>) list;
assertThat(values.size(), is(2));
assertThat(values.get(0), is("string1"));
assertThat(values.get(1), is("string2"));

list = config.get("boolList");
assertThat(list, is(notNullValue()));
assertThat(list, instanceOf(List.class));
values = (List<Object>) list;
assertThat(values.size(), is(2));
assertThat(values.get(0), is(false));
assertThat(values.get(1), is(true));
}

@Test
public void testTagUpdate() {
modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream("Switch s [foo]".getBytes()));
Expand Down

0 comments on commit c3fdd86

Please sign in to comment.