-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Functional test for schema mapper and java examples (#1424)
* #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
Showing
38 changed files
with
1,060 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
example/main-java/src/main/java/org/finos/vuu/module/JavaExampleModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
30 changes: 0 additions & 30 deletions
30
example/main-java/src/main/java/org/finos/vuu/module/MyExampleModule.java
This file was deleted.
Oops, something went wrong.
48 changes: 0 additions & 48 deletions
48
example/main-java/src/main/java/org/finos/vuu/module/MyExampleProvider.java
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
example/main-java/src/main/java/org/finos/vuu/person/Person.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
example/main-java/src/main/java/org/finos/vuu/person/PersonStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}; | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
example/main-java/src/main/java/org/finos/vuu/person/auto/AutoMappedPersonProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
|
||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
example/main-java/src/main/java/org/finos/vuu/person/auto/EntitySchema.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
62 changes: 62 additions & 0 deletions
62
example/main-java/src/main/java/org/finos/vuu/person/manual/PersonProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
|
||
} | ||
} |
Oops, something went wrong.