Skip to content

Commit

Permalink
Simplify Adapter serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
gartens committed May 29, 2024
1 parent 577e4c0 commit 8450e91
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
13 changes: 6 additions & 7 deletions webui/src/main/java/org/polypheny/db/webui/Crud.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@
import org.polypheny.db.webui.models.Uml;
import org.polypheny.db.webui.models.UnderlyingTables;
import org.polypheny.db.webui.models.catalog.AdapterModel;
import org.polypheny.db.webui.models.catalog.AdapterModel.AdapterSettingValueModel;
import org.polypheny.db.webui.models.catalog.PolyTypeModel;
import org.polypheny.db.webui.models.catalog.SnapshotModel;
import org.polypheny.db.webui.models.catalog.UiColumnDefinition;
Expand Down Expand Up @@ -2111,13 +2110,13 @@ void createAdapter( final Context ctx ) throws ServletException, IOException {

ConnectionMethod method = ConnectionMethod.UPLOAD;
if ( a.settings.containsKey( "method" ) ) {
method = ConnectionMethod.valueOf( a.settings.get( "method" ).value().toUpperCase() );
method = ConnectionMethod.valueOf( a.settings.get( "method" ).toUpperCase() );
}
AdapterTemplate adapter = AdapterManager.getAdapterTemplate( a.adapterName, a.type );
Map<String, AbstractAdapterSetting> allSettings = adapter.settings.stream().collect( Collectors.toMap( e -> e.name, e -> e ) );

for ( AdapterSettingValueModel entry : a.settings.values() ) {
AbstractAdapterSetting set = allSettings.get( entry.name() );
for ( Map.Entry<String, String> entry : a.settings.entrySet() ) {
AbstractAdapterSetting set = allSettings.get( entry.getKey() );
if ( set == null ) {
continue;
}
Expand All @@ -2128,15 +2127,15 @@ void createAdapter( final Context ctx ) throws ServletException, IOException {
ctx.json( RelationalResult.builder().exception( e ).build() );
return;
}
settings.put( set.name, entry.value() );
settings.put( set.name, entry.getValue() );
} else {
List<String> fileNames = HttpServer.mapper.readValue( entry.value(), new TypeReference<>() {
List<String> fileNames = HttpServer.mapper.readValue( entry.getValue(), new TypeReference<>() {
} );
String directory = handleUploadFiles( inputStreams, fileNames, setting, a );
settings.put( set.name, directory );
}
} else {
settings.put( set.name, entry.value() );
settings.put( set.name, entry.getValue() );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class AdapterModel extends IdEntity {
public AdapterType type;

@JsonProperty
public Map<String, AdapterSettingValueModel> settings;
public Map<String, String> settings;

@JsonProperty
public DeployMode mode;
Expand All @@ -62,7 +62,7 @@ public AdapterModel(
@JsonProperty("name") @Nullable String name,
@JsonProperty("adapterName") String adapterName,
@JsonProperty("type") AdapterType type,
@JsonProperty("settings") Map<String, AdapterSettingValueModel> settings,
@JsonProperty("settings") Map<String, String> settings,
@JsonProperty("mode") DeployMode mode,
@JsonProperty("indexMethods") List<IndexMethodModel> indexMethods ) {
super( id, name );
Expand All @@ -76,7 +76,7 @@ public AdapterModel(

@Nullable
public static AdapterModel from( LogicalAdapter adapter ) {
Map<String, AdapterSettingValueModel> settings = adapter.settings.entrySet().stream().collect( Collectors.toMap( Entry::getKey, s -> AdapterSettingValueModel.from( s.getKey(), s.getValue() ) ) );
Map<String, String> settings = adapter.settings;

Optional<Adapter<?>> a = AdapterManager.getInstance().getAdapter( adapter.id );
return a.map( dataStore -> new AdapterModel(
Expand All @@ -90,14 +90,4 @@ public static AdapterModel from( LogicalAdapter adapter ) {

}


public record AdapterSettingValueModel(@JsonProperty("name") String name, @JsonProperty("value") String value) {


public static AdapterSettingValueModel from( String name, String value ) {
return new AdapterSettingValueModel( name, value );
}

}

}

0 comments on commit 8450e91

Please sign in to comment.