Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

EN | ES

Info

This feature is available since version 2.0.2-RELEASE of the client Library, and 2.0.0-fireball of onesait Platform

Table of Contents

Introduction

As we already know, onesait Platform’s architecture is Data Centric, in which ontologies (abstraction of database entities) are the core of the platform, this is the reason why all platform’s modules need them to work properly. Read: /wiki/spaces/PT/pages/333316099

The platform offers an abstraction to work transparently with ontologies through a Spring Repository:(Client APIS) What is the Spring client librery, aka Client4SpringBoot, and how to use it?

However, there are situations in which due to technical requirements or other decisions, it is preferred to work directly with the database entities using frameworks such as Spring Data, iBatis ..., and CRUD operations are performed with these frameworks, instead of being the platform that performs them.

...

The Onesait Platform Java client library now provides a client -NotifierClient- that allows us to create the ontologies from Java classes and notify the platform of the CRUD operations that we perform with our framework, so that although the platform does not perform these operations, it will be aware of them, and as the ontology definition exists, all modules can be used seamlessly.

Notifier Client

Provided Operations

The client provides the following operations:

  • Create/Update ontology from a Java class: a JSON Schema will be generated from a Java class to create the ontology in the platform.

  • JSON validation of the Java entity: this operations should be executed just before creating/updating a instance: the entity will be serialized in JSON, and the platform will validate it against the JSON Schema of the ontology referenced.

  • CRUD notifications: this operation should be executed just after the Java CRUD operations/process. When using CRUD operations in the Java application, we shall notify the platform. This operation is available in a synchronous format as well as asynchronous.

Client instatiation

We can create a client in two different ways:

...

The last argument of the constructor allows you to avoid SSL verification, in cases where certificates are self-signed.

Creating ontology from Java Class

Suppose we have a Spring Data entity over MongoDB -Message.java-

...

This code will generate the following Ontology.

...

JSON Schema Validation

Whenever you want to store or update ontology data, you can use this method to check if data is valid. We can call it with the Java object itself, or with the name of the Ontology and the serialized object (JSON String).

...

On the other hand, if validation passes, then code flow will continue.

Notifications to the onesait Platform

You can choose the sync/async version to fit your needs.

...

  • QueryType: only for QUERY operations. Enum {SQL, NATIVE}

  • Query: only for QUERY operations, and it will carry the query.

  • Payload: for INSERT/UPDATE, it will contain the JSON serialized object.

  • Operation: Enum {INSERT,UPDATE,DELETE,QUERY}

  • Id: instance id for cases such as DELETE/UPDATE by ID

Here’s an example

...

Practice Example

You can make use of these operations inside your business logic, for example, when a new message is stored in the database, you can validate its content previously, and then notify the platform:

...

Here’s the link to the full example: https://github.com/onesaitplatform/onesaitplatform-spring-boot-example

Spring Boot Wrapper for the library

For applications developed with Spring Boot, a wrapper is provided to easy the use of this library.

Properties

In addition to the dependency inyection:

...

We can configure the client to use username + password credentials, or an API key.

@OPEntity annotation

This annotation will be used in our Entity Model classes. For example, if you use Spring Data:

...

Code Block
@Attributes(required = true)

@OPValidateSchema annotation

This annotation will attempt to validate the serialized Java object with its ontology schema synchronously, so if it fails, an exception will be thrown. It is used at attribute/argument level.

Code Block
@Override
Message save(@OPValidateSchema Message entity);

@OPNotifierOperation annotation

This annotation allows you to notify the platform with CRUD operations performed at the Spring Boot application, either synchronously or asynchronously. It is used at method level, and has the following attributes:

  • async: boolean default false. Wether the notification is performed sync/async.

  • ontology: Ontology name. f.e. Message

  • operationType: QUERY, INSERT, UPDATE, DELETE. Operation type

  • queryType: SQL, NATIVE, default NATIVE. As query operations will be made with Spring Data interface or similar frameworks, this attribute can be left empty.

  • id: SpEL expression that references the id of the Java object. This id is the unique identifier of the object . f.e. “#p0” default is #p0

  • payload: SpEL expression that references the object that will be send as the payload in the notification. f.e. “#p1”. default is #p0

Use examples:

INSERT

Code Block
breakoutModewide
@OPNotifierOperation(ontology = "Message", operationType = OperationType.INSERT, async = true)
public void createMessage(@OPValidateSchema Message message) {
  ....
}

...