. . .

Data Modeling in Native Modules

Another way to create new classes and attributes is to directly amend the sourcecode while using the switch

update=true

In the sdk.properties file in order to automatically generate the new meta models and meta model attributes upon upload. A new class must be annotated with "@Model":

@Model( moduleName = "MyModule", isTransient = false, isInvisible=false)

The value of the attribute "moduleName" should equal the name of the own module while "isTransient" can be used to declare whether this class is transient or not (see next chapter). You can mark a class as invisible for the REST interface; also see the next chapter for more information.

Class attributes cause the generation of corresponding meta model attributes and don't require additional annotation. It is advisable to download the module right after the upload is finished in order to fetch automatically generated code.

Transient classes

By default, all data related to a class is stored in and retrieved from ApiOmat's own MongoDB. However in several use cases, data is to be stored in and retrieved from an external data source which then makes storing data in the MongoDB unnecessary. Therefore, a class can be set to transient in the Dashboard. The according cURL command looks like (METAMODELID is the id of the class):

Linux

Linux
curl -X PUT ${URL}/yambas/rest/modules/${MODULENAME}/metamodels/${METAMODELID} -d "{ \"transient\":\"true\"}" -u $AUTH -H "Content-Type:appliation/json"

Windows

Windows
curl -X PUT %URL%/yambas/rest/modules/%MODULENAME%/metamodels/%METAMODELID% -d "{ \"transient\":\"true\"}" -u %AUTH% -H "Content-Type:appliation/json"


Furthermore, the isTransient annotation can be adjusted in the source code before uploading the SDK again to achieve the same result.

The "transient" switch makes ApiOmat refrain from storing data inside its own MongoDB whilst henceforth the attribute "foreignId" will be used instead "id" to reference data of this class since "id" is only assigned by MongoDB. This can be noticed by the fact that the foreignId will conclude the HREF attributes of this class.


Example

A data model "Car" inside the module "Garage" is stored non-transient; new objects therefore receive IDs from the database while the HREF may look like:

http://.../yambas/rest/apps/models/Garage/Car/546af63abbb8c281fcc58e20

If the model has been set to transient and is stored in an external data source which creates IDs as incremental numerical values, the HREF might look as follows:

http://.../yambas/rest/apps/models/Garage/Car/123213

Finally, different hook methods will be executed; when accessing class objects, the do...() methods are called directly instead of the before..()/after..() methods. Please consult Development Basics to learn more about hook classes and other SDK classes.

Invisible classes

In some use cases not all classes should be exposed to the REST interface (neither the classes themselves, nor the data (instances of the class)). For example, when using our SQL module which crawls databases, classes of tables get created automatically, but you may not want to expose all the DB tables to the public.

To hide a class, you can set the isInvisible annotation to true.

The result will be that:

  • when you query a module's meta models, the invisible ones will not be returned

  • no instances of the class can be created, fetched, updated or deleted via the REST interface

  • BUT you can work with the class and its instances in Native Module Code

You can therefore use invisible classes inside your module for implementing your business logic or store internal data.

Inheritance

If you are inheriting from a invisible class, the subclass will also get invisible for security reasons.