Skip to content

Commit

Permalink
adjusting webui model classes
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed Aug 28, 2023
1 parent 773bb28 commit 25caa61
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 136 deletions.
145 changes: 73 additions & 72 deletions webui/src/main/java/org/polypheny/db/webui/Crud.java

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions webui/src/main/java/org/polypheny/db/webui/HttpServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ private void crudRoutes( Javalin webuiServer, Crud crud ) {

webuiServer.get( "/getSources", crud::getSources );

webuiServer.post( "/getAvailableStoresForIndexes", ( ctx ) -> crud.getAvailableStoresForIndexes( ctx, gson ) );
webuiServer.post( "/getAvailableStoresForIndexes", crud::getAvailableStoresForIndexes );

webuiServer.post( "/removeAdapter", crud::removeAdapter );

Expand All @@ -319,7 +319,7 @@ private void crudRoutes( Javalin webuiServer, Crud crud ) {

webuiServer.get( "/getAvailableSources", crud::getAvailableSources );

webuiServer.post( "/addAdapter", ( ctx ) -> crud.addAdapter( ctx, gson ) );
webuiServer.post( "/addAdapter", crud::addAdapter );

webuiServer.post( "/pathAccess", crud::startAccessRequest );

Expand Down
43 changes: 11 additions & 32 deletions webui/src/main/java/org/polypheny/db/webui/crud/LanguageCrud.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.polypheny.db.catalog.entity.logical.LogicalTable;
import org.polypheny.db.catalog.exceptions.GenericRuntimeException;
import org.polypheny.db.catalog.logistic.EntityType;
import org.polypheny.db.catalog.logistic.Pattern;
import org.polypheny.db.config.RuntimeConfig;
import org.polypheny.db.information.InformationManager;
import org.polypheny.db.information.InformationObserver;
Expand All @@ -61,9 +60,9 @@
import org.polypheny.db.type.entity.graph.PolyGraph;
import org.polypheny.db.webui.Crud;
import org.polypheny.db.webui.models.FieldDefinition;
import org.polypheny.db.webui.models.Index;
import org.polypheny.db.webui.models.Placement;
import org.polypheny.db.webui.models.Placement.DocumentStore;
import org.polypheny.db.webui.models.IndexModel;
import org.polypheny.db.webui.models.PlacementModel;
import org.polypheny.db.webui.models.PlacementModel.DocumentStore;
import org.polypheny.db.webui.models.SortState;
import org.polypheny.db.webui.models.UiColumnDefinition;
import org.polypheny.db.webui.models.requests.EditCollectionRequest;
Expand Down Expand Up @@ -363,33 +362,23 @@ public void getDocumentDatabases( final Context ctx ) {


public void getGraphPlacements( final Context ctx ) {
Index index = ctx.bodyAsClass( Index.class );
IndexModel index = ctx.bodyAsClass( IndexModel.class );
ctx.json( getPlacements( index ) );
}


private Placement getPlacements( final Index index ) {
private PlacementModel getPlacements( final IndexModel index ) {
Catalog catalog = Catalog.getInstance();
String graphName = index.getSchema();
List<LogicalNamespace> namespaces = catalog.getSnapshot().getNamespaces( new Pattern( graphName ) );
if ( namespaces.size() != 1 ) {
throw new RuntimeException();
}
List<LogicalGraph> graphs = catalog.getSnapshot().graph().getGraphs( new Pattern( graphName ) );
if ( graphs.size() != 1 ) {
log.error( "The requested graph does not exist." );
return new Placement( new RuntimeException( "The requested graph does not exist." ) );
}
LogicalGraph graph = graphs.get( 0 );
LogicalGraph graph = Catalog.snapshot().graph().getGraph( index.namespaceId ).orElseThrow();
EntityType type = EntityType.ENTITY;
Placement p = new Placement( false, List.of(), EntityType.ENTITY );
PlacementModel p = new PlacementModel( false, List.of(), EntityType.ENTITY );
if ( type == EntityType.VIEW ) {
return p;
} else {
List<CatalogDataPlacement> placements = catalog.getSnapshot().alloc().getDataPlacements( graph.id );
for ( CatalogDataPlacement placement : placements ) {
Adapter<?> adapter = AdapterManager.getInstance().getAdapter( placement.adapterId );
p.addAdapter( new Placement.GraphStore(
p.addAdapter( new PlacementModel.GraphStore(
adapter.getUniqueName(),
adapter.getUniqueName(),
catalog.getSnapshot().alloc().getFromLogical( placement.adapterId ),
Expand All @@ -414,21 +403,11 @@ public void getFixedFields( Context context ) {


public void getCollectionPlacements( Context context ) {
Index index = context.bodyAsClass( Index.class );
String namespace = index.getSchema();
String collectionName = index.getTable();
IndexModel index = context.bodyAsClass( IndexModel.class );
Catalog catalog = Catalog.getInstance();
long namespaceId = catalog.getSnapshot().getNamespace( namespace ).orElseThrow().id;
List<LogicalCollection> collections = catalog.getSnapshot().doc().getCollections( namespaceId, new Pattern( collectionName ) );

if ( collections.size() != 1 ) {
context.json( new Placement( new RuntimeException( "The collation is not know" ) ) );
return;
}

LogicalCollection collection = collections.get( 0 );
LogicalCollection collection = catalog.getSnapshot().doc().getCollection( index.entityId ).orElseThrow();

Placement p = new Placement( false, List.of(), EntityType.ENTITY );
PlacementModel p = new PlacementModel( false, List.of(), EntityType.ENTITY );

List<AllocationEntity> allocs = catalog.getSnapshot().alloc().getFromLogical( collection.id );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,34 @@
package org.polypheny.db.webui.models;


import java.util.List;
import lombok.Getter;
import lombok.Value;


/**
* Schema for the index of a table
*/
@Getter
public class Index {
@Value
public class IndexModel {

private String schema;
private String table;
private String name;
private String storeUniqueName;
private String method;
private String[] columns;
public Long namespaceId;
public Long entityId;
public String name;
public String storeUniqueName;
public String method;
public List<Long> columnIds;


public Index( final String schema, final String table, final String name, final String method, final String[] columns ) {
this.schema = schema;
this.table = table;
public IndexModel( final Long namespaceId, final Long entityId, final String name, final String method, final List<Long> columnIds ) {
this.namespaceId = namespaceId;
this.entityId = entityId;
this.name = name;
this.method = method;
this.columns = columns;
this.columnIds = columnIds;
this.storeUniqueName = null;
}


/**
* Convert index to a row to display in the UI
*/
public String[] asRow() {
String[] row = new String[3];
row[0] = this.name;
row[1] = this.method;
row[2] = String.join( ",", this.columns );
return row;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
/**
* A model for the UI, modelling the placements of a table
*/
public class Placement {
public class PlacementModel {

Throwable exception;
public List<Store> stores = new ArrayList<>();
Expand All @@ -40,34 +40,34 @@ public class Placement {
String tableType;


public Placement( final boolean isPartitioned, final List<String> partitionNames, final EntityType entityType ) {
public PlacementModel( final boolean isPartitioned, final List<String> partitionNames, final EntityType entityType ) {
this.isPartitioned = isPartitioned;
this.partitionNames = partitionNames;
this.tableType = entityType.name();
}


public Placement( final Throwable exception ) {
public PlacementModel( final Throwable exception ) {
this.exception = exception;
}


public Placement addAdapter( final RelationalStore s ) {
public PlacementModel addAdapter( final RelationalStore s ) {
if ( s.columnPlacements.size() > 0 ) {
this.stores.add( s );
}
return this;
}


public Placement addAdapter( final GraphStore s ) {
public PlacementModel addAdapter( final GraphStore s ) {
this.stores.add( s );

return this;
}


public Placement addAdapter( final DocumentStore s ) {
public PlacementModel addAdapter( final DocumentStore s ) {
this.stores.add( s );

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.polypheny.db.webui.models;


import java.util.ArrayList;
import java.util.List;
import java.util.StringJoiner;


Expand All @@ -30,7 +30,7 @@ public class TableConstraint {
public String[] columns;


public TableConstraint( final String name, final String type, ArrayList<String> columns ) {
public TableConstraint( final String name, final String type, List<String> columns ) {
this.name = name;
this.type = type;
this.columns = columns.toArray( new String[0] );
Expand Down

0 comments on commit 25caa61

Please sign in to comment.