Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions oap-stdlib-test/src/test/java/oap/dictionary/DictionaryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public void extendIgnoreDuplicate() {
}

@Test
public void extendFilter() {
var values = Dictionaries
public void testExtendFilter() {
List<? extends Dictionary> values = Dictionaries
.getDictionary( "test-dictionary-extends-filter" )
.getValue( "id2" )
.getValues();
Expand All @@ -122,4 +122,19 @@ public void extendFilter() {
assertThat( values.get( 0 ).getExternalId() ).isEqualTo( 111 );
assertThat( values.get( 1 ).getExternalId() ).isEqualTo( 113 );
}

@Test
public void testExtendFilterMap() {
List<? extends Dictionary> values = Dictionaries
.getDictionary( "test-dictionary-extends-filter-map" )
.getValue( "id2" )
.getValues();

assertThat( values ).hasSize( 2 );
assertThat( values.get( 0 ).getId() ).isEqualTo( "id111" );
assertThat( values.get( 1 ).getId() ).isEqualTo( "id22" );

assertThat( values.get( 0 ).getExternalId() ).isEqualTo( 111 );
assertThat( values.get( 1 ).getExternalId() ).isEqualTo( 113 );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
name = test-dictionary-extends
version = 1
values {
id1 {
title = title1
enabled = true
eid = 1
values {
id11 {
title = title11
enabled = true
eid = 11
values {
id111 {
title = title111
eid = 111
tags = [test]
}
id112 {
title = title112
eid = 112
}
}
}
id12 {
title = title12
enabled = true
eid = 12
}
}
}
id2 {
title = title2
enabled = true
eid = 2
values {
<extends> = [{
path = /id1/id11
filter = test
}]
id22 {
title = title21
eid = 1
}
}
}
}
}
32 changes: 28 additions & 4 deletions oap-stdlib/src/main/java/oap/dictionary/DictionaryParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import oap.util.function.Try;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.jspecify.annotations.NonNull;

import java.io.IOException;
import java.io.UncheckedIOException;
Expand Down Expand Up @@ -297,10 +298,29 @@ private static ArrayList<Dictionary> parseValues( Map<?, ?> values, String path,
ArrayList<Dictionary> dv = new ArrayList<>();

values.forEach( ( key, value ) -> {
if( value instanceof Map map ) {
map.put( "id", key );
if( "<extends>".equals( key ) ) {
if( value instanceof Map map ) {
Extends anExtends = getExtends( map );
dv.add( new DictionaryExtends( anExtends ) );
} else if( value instanceof List list ) {
for( Object v : list ) {
if( v instanceof Map map ) {
Extends anExtends = getExtends( map );
dv.add( new DictionaryExtends( anExtends ) );
} else {
throw new DictionaryError( "<extends> = [{path = ...[, filter = ...]}]" );
}
}
} else {
throw new DictionaryError( "<extends> = list | map" );
}
} else {

if( value instanceof Map map ) {
map.put( "id", key );
}
dv.add( parseAsDictionaryValue( value, path + "['" + key + "']", false, idStrategy ) );
}
dv.add( parseAsDictionaryValue( value, path + "['" + key + "']", false, idStrategy ) );
} );

return dv;
Expand All @@ -310,11 +330,15 @@ private static Optional<Extends> getExtendsOpt( Map<?, ?> map ) {
Map<?, ?> m = getValueOpt( Map.class, map, "extends", _ -> Optional.empty() ).orElse( null );
if( m == null ) return Optional.empty();

return Optional.of( getExtends( m ) );
}

private static @NonNull Extends getExtends( Map<?, ?> m ) {
String path = getString( m, "path" );
Optional<String> filter = getStringOpt( m, "filter" );
Boolean ignoreDuplicate = getBooleanOpt( m, "ignoreDuplicate" ).orElse( false );

return Optional.of( new Extends( path, filter, ignoreDuplicate ) );
return new Extends( path, filter, ignoreDuplicate );
}

private static String getString( Map<?, ?> map, String field ) {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</distributionManagement>

<properties>
<oap.project.version>25.4.9</oap.project.version>
<oap.project.version>25.4.10</oap.project.version>

<oap.deps.config.version>25.0.1</oap.deps.config.version>
<oap.deps.oap-teamcity.version>25.0.0</oap.deps.oap-teamcity.version>
Expand Down
Loading