Skip to content

Commit

Permalink
Functional test for schema mapper and java examples (#1424)
Browse files Browse the repository at this point in the history
* #1318 example of how to use schema mapper to get data and update in memory table

* #1318 helper function for scala and java collection converter

* #1318 notes on next things to try

* #1318 java example of using schema mapper

* #1318 fleshing out java schema mapper example

* #1318 fleshing out scala schema mapper example

* #1318 refactoring scala example into test

* #1318 added more scenario for schema mapper testing

* #1318 refactor schema mapper functional test to introduce base class

* #1318 using data source for the functional test more generic so it is agonostic to whether data is from ignite or rest api etc

* #1318 introduce function to create table columns from external schema

* #1318 adding virtualized table plugin table dependency in ignite plugin to be able to add schema mapper functional tests

* #1318 adding additional type for column builder

* #1318 adding additional test scenario to be implemented

* #1318 adding java usecase tests for schema mapper

* #1318 test cleanup

* #1318 SchemaMapper functional test for virtualised table

* #1318 clean up based on review comments

* #1318 schema mapper functional test for when table column type is different from field type

* #1378 added java helper and tests in dedicated module to keep java and scala separate to keep build happy

* #1378 added java example to show simple way to define and update table in vuu

* #1378 added java example to show how to auto map from entity to table

* #1378 pom clean up to make java working

* #1318 adding build path to vuu-java module

---------

Co-authored-by: Tomasz Rumak <[email protected]>
  • Loading branch information
naleeha and rumakt authored Jul 11, 2024
1 parent 396e3b9 commit b2b033a
Show file tree
Hide file tree
Showing 38 changed files with 1,060 additions and 116 deletions.
2 changes: 0 additions & 2 deletions benchmark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>

<dependency>
Expand Down
2 changes: 0 additions & 2 deletions example/apache-ignite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>

<dependency>
Expand Down
2 changes: 0 additions & 2 deletions example/basket/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>

<dependency>
Expand Down
2 changes: 0 additions & 2 deletions example/editable/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>

<dependency>
Expand Down
7 changes: 5 additions & 2 deletions example/main-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
<artifactId>vuu</artifactId>
<version>0.9.65-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.finos.vuu</groupId>
<artifactId>vuu-java</artifactId>
<version>0.9.65-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.finos.vuu</groupId>
Expand Down Expand Up @@ -71,8 +76,6 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.finos.vuu.core.module.simul.SimulationModule;
import org.finos.vuu.core.module.typeahead.TypeAheadModule;
import org.finos.vuu.core.module.vui.VuiStateModule;
import org.finos.vuu.module.MyExampleModule;
import org.finos.vuu.module.JavaExampleModule;
import org.finos.vuu.net.AlwaysHappyLoginValidator;
import org.finos.vuu.net.Authenticator;
import org.finos.vuu.net.LoggedInTokenValidator;
Expand Down Expand Up @@ -82,7 +82,7 @@ public static void main( String[] args )
.withModule(TypeAheadModule.apply(clock, lifecycle, tableDefContainer))
.withModule(AuthNModule.apply(authenticator, loginTokenValidator, clock, lifecycle, tableDefContainer))
//the modules above are scala, the modules below are java...
.withModule(new MyExampleModule().create(tableDefContainer)) ;
.withModule(new JavaExampleModule().create(tableDefContainer, clock)) ;

final VuuServer vuuServer = new VuuServer(config, lifecycle, clock, metrics);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.finos.vuu.module;

import org.finos.toolbox.time.Clock;
import org.finos.vuu.api.ColumnBuilder;
import org.finos.vuu.api.TableDef;
import org.finos.vuu.core.module.DefaultModule;
import org.finos.vuu.core.module.ModuleFactory;
import org.finos.vuu.core.module.TableDefContainer;
import org.finos.vuu.core.module.ViewServerModule;
import org.finos.vuu.core.table.Columns;
import org.finos.vuu.person.PersonStore;
import org.finos.vuu.person.auto.AutoMappedPersonProvider;
import org.finos.vuu.person.auto.EntitySchema;
import org.finos.vuu.person.manual.PersonProvider;

import java.util.List;

import static org.finos.vuu.util.ScalaCollectionConverter.toScalaSeq;

public class JavaExampleModule extends DefaultModule {

public static final String NAME = "JAVA_EXAMPLE";

public ViewServerModule create(final TableDefContainer tableDefContainer, Clock clock) {

return ModuleFactory.withNamespace(NAME, tableDefContainer)
.addTable(TableDef.apply(
"PersonManualMapped",
"Id",
new ColumnBuilder()
.addString("Id")
.addString("Name")
.addInt("Account")
.build(),
toScalaSeq(List.of())
),
(table, vs) -> new PersonProvider(table, new PersonStore(), clock)
)
.addTable(TableDef.apply(
"PersonAutoMapped",
"Id",
Columns.fromExternalSchema(EntitySchema.person),
toScalaSeq(List.of())
),
(table, vs) -> new AutoMappedPersonProvider(table, new PersonStore(), clock)
)
.asModule();
}

}

This file was deleted.

This file was deleted.

14 changes: 14 additions & 0 deletions example/main-java/src/main/java/org/finos/vuu/person/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.finos.vuu.person;

public class Person {

public String Id;
public String Name;
public Integer AccountNumber;

public Person(String id, String name, Integer accountNumber) {
Id = id;
Name = name;
AccountNumber = accountNumber;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.finos.vuu.person;

public class PersonStore {

public Person[] GetAll() {
return new Person[] {
new Person("uniqueId1", "Adam", 56440),
new Person("uniqueId2", "Natalie", 41687)
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package org.finos.vuu.person.auto;

import org.finos.toolbox.time.Clock;
import org.finos.vuu.core.table.DataTable;
import org.finos.vuu.core.table.RowWithData;
import org.finos.vuu.person.Person;
import org.finos.vuu.person.PersonStore;
import org.finos.vuu.provider.Provider;
import org.finos.vuu.util.schema.SchemaMapper;
import org.finos.vuu.util.schema.SchemaMapperBuilder;
import scala.collection.immutable.Map;
import scala.jdk.javaapi.OptionConverters;

import java.util.List;

import static org.finos.vuu.util.ScalaCollectionConverter.toScala;

public class AutoMappedPersonProvider implements Provider {

private final DataTable table;
private final PersonStore personStore;
private final Clock clock;
private final SchemaMapper schemaMapper;

public AutoMappedPersonProvider(final DataTable table, PersonStore personStore, Clock clock) {
this.table = table;
this.personStore = personStore;
this.clock = clock;

schemaMapper = CreateSchemaMapper(table);
}

private static SchemaMapper CreateSchemaMapper(DataTable table) {
return SchemaMapperBuilder.apply(EntitySchema.person, table.getTableDef().columns())
.build();
}

@Override
public void doStart() {
for (Person person : personStore.GetAll()) {
var rowMap = schemaMapper.toInternalRowMap(
toScala(List.of(person.Id, person.Name, person.AccountNumber))
);
var row = new RowWithData(getKeyValue(rowMap), rowMap);
table.processUpdate(row.key(), row, clock.now());
}
}

private String getKeyValue(Map<String, Object> rowMap) {
return OptionConverters.toJava(rowMap.get(table.getTableDef().keyField()))
.map(Object::toString)
.orElseThrow();
}

@Override
public void doStop() {

}

@Override
public void doInitialize() {

}

@Override
public void doDestroy() {

}

@Override
public String lifecycleId() {
return null;
}

@Override
public void subscribe(String key) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.finos.vuu.person.auto;

import org.finos.vuu.person.Person;
import org.finos.vuu.util.schema.ExternalEntitySchema;
import org.finos.vuu.util.schema.ExternalEntitySchemaBuilder;

import java.util.List;

import static org.finos.vuu.util.ScalaCollectionConverter.toScala;

public class EntitySchema {

public static ExternalEntitySchema person = ExternalEntitySchemaBuilder.apply()
.withEntity(Person.class)
.withIndex("ID_INDEX", toScala(List.of("Id")))
.build();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.finos.vuu.person.manual;

import org.finos.toolbox.time.Clock;
import org.finos.vuu.core.table.DataTable;
import org.finos.vuu.core.table.RowWithData;
import org.finos.vuu.person.Person;
import org.finos.vuu.person.PersonStore;
import org.finos.vuu.provider.Provider;

import java.util.Map;

public class PersonProvider implements Provider {

private final DataTable table;
private final PersonStore personStore;
private final Clock clock;

public PersonProvider(final DataTable table, PersonStore personStore, Clock clock){
this.table = table;
this.personStore = personStore;
this.clock = clock;
}

@Override
public void doStart() {

for (Person person : personStore.GetAll()) {
var row = new RowWithData(person.Id, Map.of( "Id", person.Id, "Name", person.Name, "Account", person.AccountNumber));
table.processUpdate(person.Id, row , clock.now());
}
}

@Override
public void doStop() {

}

@Override
public void doInitialize() {

}

@Override
public void doDestroy() {

}

@Override
public String lifecycleId() {
return null;
}

@Override
public String toString() {
return Provider.super.toString();
}

@Override
public void subscribe(String key) {

}
}
Loading

0 comments on commit b2b033a

Please sign in to comment.