Skip to content

Commit

Permalink
finos#1434 adding java example for implementing custom rpc handler fo…
Browse files Browse the repository at this point in the history
…r the view port - work in progress
  • Loading branch information
naleeha committed Aug 19, 2024
1 parent 36741c0 commit ee9fe69
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import org.finos.toolbox.time.Clock;
import org.finos.vuu.api.ColumnBuilder;
import org.finos.vuu.api.TableDef;
import org.finos.vuu.api.ViewPortDef;
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.PersonRpcHandler;
import org.finos.vuu.person.datasource.PersonStore;
import org.finos.vuu.person.auto.AutoMappedPersonProvider;
import org.finos.vuu.person.auto.EntitySchema;
import org.finos.vuu.person.manual.PersonProvider;
Expand All @@ -34,7 +36,11 @@ public ViewServerModule create(final TableDefContainer tableDefContainer, Clock
.build(),
toScalaSeq(List.of())
),
(table, vs) -> new PersonProvider(table, new PersonStore(), clock)
(table, vs) -> new PersonProvider(table, new PersonStore(), clock),
(table, provider, providerContainer, tableContainer) -> new ViewPortDef(
table.getTableDef().columns(),
new PersonRpcHandler(table, tableContainer)
)
)
.addTable(TableDef.apply(
"PersonAutoMapped",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.finos.vuu.person;

import org.finos.vuu.core.table.DataTable;
import org.finos.vuu.core.table.TableContainer;
import org.finos.vuu.net.rpc.*;
import scala.Function1;

import java.util.Arrays;

/* Work in Progress - do not use this as example yet
* */
public class PersonRpcHandler extends DefaultRpcHandler {
private final DataTable table;

public PersonRpcHandler(DataTable table, TableContainer tableContainer) {
this.table = table;

registerRpc("UpdateName", (params) -> processUpdateNameRpcRequest(params));
registerRpc("GetPeopleWithName", (params) -> processGetPeopleNameRpcRequest(params));
}

private void registerRpc(String functionName, Function1<RpcParams, RpcMethodCallResult> handlerFunc) {
this.registerRpcMethodHandler(functionName, new RpcFunctionMethodHandler(handlerFunc));
}

public RpcMethodCallResult processUpdateNameRpcRequest(RpcParams params) {
updateName(
params.namedParams().get("Id").get().toString(), //how to report error when expected param missing or fail to cast to right type
params.namedParams().get("Name").get().toString()
);
return new RpcMethodSuccess(""); //how to control what viewport action to trigger?
}

public RpcMethodCallResult processGetPeopleNameRpcRequest(RpcParams params) {
getPeopleWithNameThatStartWith(
Arrays.stream(params.params()).findFirst().toString()
);
return new RpcMethodSuccess(""); //need to return result
}

public String[] updateName(String id, String newName) {
//get person data from data source, update name, save to datasource?
//should update table row or allow lifecycle sync to pick up change?
return new String[0];
}

public String[] getPeopleWithNameThatStartWith(String search) {
return new String[0];
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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.person.datasource.PersonStore;
import org.finos.vuu.provider.Provider;
import org.finos.vuu.util.schema.SchemaMapper;
import org.finos.vuu.util.schema.SchemaMapperBuilder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package org.finos.vuu.person;
package org.finos.vuu.person.datasource;

import org.finos.vuu.person.Person;

public class PersonStore {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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.person.datasource.PersonStore;
import org.finos.vuu.provider.Provider;

import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@ case class RpcMethodSuccess(result: Any) extends RpcMethodCallResult
case class RpcMethodFailure(code: Int, error: String, exception: Exception) extends RpcMethodCallResult {
def this(error: String) = this(1, error, null)
}


0 comments on commit ee9fe69

Please sign in to comment.