Information
-
This topic describes the public Jython API of PLANTA
-
These functions are guaranteed to be supported in future versions
Tip
-
When you have enabled the planta link web services you can reload your jython code by saving in the Web Interfaces module
-
This invokes a clearing of the jython cache and resets the imported modules
Quickstart
Information
-
The Jython code resides under
<server folder>/jython -
The Jython version may differ from the Python version used in regular customizing.
-
The Jython interpreter is embedded in the Java part of the project Server instead of the native c part
-
This means you have no access to the regular Python API (everything under
<server folder>/py) -
Instead you have access to the Jython API (everything under
<server folder>/jython), the Java API and small parts of the project Server Java API
-
-
At the time of writing there is no way to access the GUI from Jython, so you can't interact with panels, modules, datafields, or anything like that (Not even message boxes)
-
You do not work with dtp or mts records, instead you operate with the same POJOs (Plain Old Java Object) that the project Server works with
-
Currently there are 2 places where Jython code can be executed from: When calling a PLANTA link web interface (see Web-Schnittstellen in PLANTA link help area) or when an event (see Events in PLANTA customizing help area) with a Jython function is triggered
Introduction to working with POJOs
-
Every table in project that has a valid Universally Unique IDentifier DI gets turned into a POJO
-
The Entity name determines the class name of the object
-
The customizing.utilities package has all basic functions you need to interact with POJOs
-
The object protection fields (Creation user, changed date, ...) are not set automatically, you have to manually call set_object_protection_fields from
customizing.utilitieswhen you want to set the object protection fields -
All dataitems where Virtual = are loaded as attributes of the POJO and can be read or written, virtual dataitems don't exist in the POJO world
Working with unicode strings
-
When you work with data that is beyond the realm of plain ascii you have to use the Python 2.7 unicode string notation
u'Example' -
You need to be especially careful when you write logging messages that write out user input data and turn the entire message into an unicode string like this:
logger.debug(u'Query: "{}"'.format(self.query))
Logging
You can use logging calls to debug your Jython code.
-
Depending on the context in which the code is run, the logging is written in different places:
-
If the code is executed from an event the logging is written in the
Event.logfile -
If the code is executed from a web interface the logging is written in the web interface logging table and can be consulted in the PLANTA link web logging modules
-
-
If a web interface performs an operation that triggers an event the event log is written in both
Event.logand the web interface log
import logging
logger = logging.getLogger(__name__)
def custom_event(event):
logger.info('Custom event was called!')
# ...
Customizing API
utilities
The utilities package provides various helper functions.
Tip
-
Avoid importing any functions from their absolute namespace and use the
utilitiesnamespace instead -
This ensures that your code will stay compatible with future releases
# from customizing.utilities.database import db_select Don't do this!
from customizing import utilities # Do this!
utilities.db_select(query)
|
Namespace |
Topic |
|---|---|
|
Caching expensive function calculations |
|
|
Functions for getting text constants, global settings and listbox categories/values |
|
|
Various business logic functions |
|
|
Functions for interacting with the database |
|
|
Various Enums |
|
|
Custom Exceptions |
|
|
Functions for opening a module and fetching the return value of a module |
|
|
Functions for getting information about a session |
|
|
Functions for interacting with POJOs |
|
|
Classes for sending emails from Jython |
|
|
Display messages to the user |
weblink
The weblink package implements the web interface framework for PLANTA link.
Tip
-
Avoid importing any functions from their absolute namespace and use the weblink namespace instead
-
This ensures that your code will stay compatible with future releases
# from customizing.weblink.transformation.planta.base import Transformer Don't do this!
from customizing import weblink # Do this!
class MyTransformer(weblink.Transformer):
...
|
Namespace |
Topic |
|---|---|
|
weblink.interfaces |
Contains the web interface implementations |
|
Contains the transformer implementations |
|
|
Provides exception classes that are better handled by the web framework |
|
|
weblink.metadata |
Defines classes that give access to metadata information about the web interface |
Server API
|
Namespace |
Topic |
|---|---|
|
Low level API to access server functions |