Skip to content

Commit

Permalink
finos#1378 added java example to show simple way to define and update…
Browse files Browse the repository at this point in the history
… table in vuu
  • Loading branch information
naleeha committed Jul 4, 2024
1 parent 48a8864 commit dcfc604
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 84 deletions.
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,37 @@
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.person.PersonProvider;
import org.finos.vuu.person.PersonStore;

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(
"Person",
"id",
new ColumnBuilder()
.addString("Id")
.addString("Name")
.addInt("Account")
.build(),
toScalaSeq(List.of())
),
(table, vs) -> new PersonProvider(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,60 @@
package org.finos.vuu.person;

import org.finos.toolbox.time.Clock;
import org.finos.vuu.core.table.DataTable;
import org.finos.vuu.core.table.RowWithData;
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) {

}
}
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
Expand Up @@ -7,7 +7,7 @@
import org.finos.toolbox.time.TestFriendlyClock;
import org.finos.vuu.core.module.TableDefContainer;
import org.finos.vuu.core.module.ViewServerModule;
import org.finos.vuu.module.MyExampleModule;
import org.finos.vuu.module.JavaExampleModule;
import org.finos.vuu.provider.MockProvider;
import org.finos.vuu.test.VuuServerTestCase;
import org.finos.vuu.viewport.ViewPort;
Expand All @@ -34,15 +34,15 @@ public void testVuuServerFunctionality() throws Exception{
final LifecycleContainer lifecycle = new LifecycleContainer(clock);
final TableDefContainer tableDefContainer = new TableDefContainer();

final ViewServerModule module = new MyExampleModule().create(tableDefContainer);
final ViewServerModule module = new JavaExampleModule().create(tableDefContainer, clock);

withVuuServer(toScalaSeq(module), (vuuServer) -> {

vuuServer.login("test", "test");

ViewPort viewport = vuuServer.createViewPort(MyExampleModule.NAME, "myTable");
ViewPort viewport = vuuServer.createViewPort(JavaExampleModule.NAME, "myTable");

MockProvider provider = vuuServer.getProvider(MyExampleModule.NAME, "myTable");
MockProvider provider = vuuServer.getProvider(JavaExampleModule.NAME, "myTable");

// provider.tick("123", Map.of("id", "123", "foo", "bar", "myInt", 123));
//
Expand Down

0 comments on commit dcfc604

Please sign in to comment.