Programmatic Access to Models

When you build a One Network SDK module, the module definitions you create in Studio are used to generate a number of different artifacts including plain ol' Java object (POJO) representations of those models. As such you can instantiate them in any context just as you would any other object. If you want to work with core models, you must import them.

images/download/attachments/144835199/image2020-9-7_19-37-11-version-1-modificationdate-1645043107000-api-v2.png

If you want to work with application models, they are in a different package. The package name will depend on the package name you defined when the project was created. For example in the bookstore tutorial, found in the training guide, the package import code would be:

images/download/attachments/144835199/image2020-9-7_19-37-31-version-1-modificationdate-1645043107000-api-v2.png



You can find out the package name very easily if you don't happen to know it. Just look at your source tree. Find the model folder in your project under src. Follow it back up to src.

A second way to accomplish the task is to look at the generated POJO's in studio. In order for this trick to work you must have built your module project successfully at least once. Within any Java editor window in Studio, press Ctrl+Shift+R (open resource). Type the name of any of your models and find its POJO. Open the POJO and you'll find the package name at the top of the file.

Beyond that, it is a simple matter of instantiating the object you want to work with.

images/download/attachments/144835199/image2020-9-7_19-38-15-version-1-modificationdate-1645043107000-api-v2.png

Be sure you fill in all required fields and supply any related models needed.

You can easily review the required fields by looking at the write action you intend to use. The action's write mask will tell you what fields are required as well as which fields are model references. Model reference fields are listed in all caps as shown in the figure below. The buffer object requires an item and a site, both of which are references to other core models, as intrinsically necessary fields. BufferType in this case was set manually.

images/download/attachments/144835199/modeling_32-version-1-modificationdate-1645043116000-api-v2.png