I’m currently upgrading from A12 2021.06 to 2022.06. Within this upgrade we are forced to use the new JsonRPC operations.
As we are using a custom data loader we need to execute e.g. the LIST_DOCUMENTS RPC calls on our own.
Is there some public utility to create such RPC payload and dispatch it afterwards?
I found the RequestBuilder builder and the dispatchJsonRpc2Requests function that exactly provides such a functionallity but unfortunately are for internal use only.
Cheers
Stefan
Hi @stefan-sparse-array,
at least the request builder should be public. For doing the request you can just call the fetch method of the default connector. Here is a simplified example:
import { JsonRpc2Request} from "@com.mgmtp.a12.dataservices/dataservices-access/lib/json-rpc";
import { ConnectorLocator } from "@com.mgmtp.a12.utils/utils-connector/lib/main";
const request = JsonRpc2Request.build(rpcRequests);
const documentsResponse = (await ConnectorLocator.getInstance().getServerConnector().fetchData(request)) as Response;
Hi @stefan-sparse-array,
for me it does not seem difficult. With the right typing the request is easily build. Here a example of your use case:
import {
DocumentJsonRpc2Request,
JsonRpc2Request,
ListDocumentsJsonRpc2Response
} from "@com.mgmtp.a12.dataservices/dataservices-access";
import {
ConnectorLocator,
RestRequestPayload,
RestServerConnector
} from "@com.mgmtp.a12.utils/utils-connector/lib/main";
const request: DocumentJsonRpc2Request.ListDocumentsJsonRpc2Request = {
id: "any",
jsonrpc: "2.0",
method: "LIST_DOCUMENTS",
params: {
documentModelName: "xxx",
filter: { filters: [], fulltext: "", lang: "en" },
page: {},
sort: []
}
};
const serverConnector = ConnectorLocator.getInstance().getServerConnector();
if (!(serverConnector instanceof RestServerConnector)) {
throw new Error(`"ServerConnector" needs to be a "RestServerConnector".`);
}
try {
const painDocumentList = serverConnector
.fetchData(JsonRpc2Request.build([request]))
.then(response => response.json())
.then(data =>
!Array.isArray(data) || !ListDocumentsJsonRpc2Response.isInstance(data[0])
? Promise.reject("Data is not suitable!")
: data[0]
);
} catch (e: unknown) {
console.error("An error occurred while fetching data.", e);
}
@markus-agile-fog , @stefan-cold-haze thanks a lot for the examples but it feels like this is something each and every project communicating with the platform server needs to implement anyway, thus maybe an official service would be helpful and would reduce implementation effort even more.