Jython API
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 module Web Interfaces
- 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 is 2.7, which can be quite different from 3.6 which you use 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 cannot interact with panels, modules, data fields, or the like (not even message boxes)
- You do not work with dtp or mts records, instead you operatore with the same POJOs (Plain Old Java Object) that the project Server works with
- Currently, there are 2 places from which Jython code can be executed: 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 Entitätsbezeichnung 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.utilities
when you want to set the object protection fields - All data items where Virtuell = are loaded as attributes of the POJO and can be read or written, virtual data items do not exist in the POJO world
Working with unicode strings
- When you are working with data that is beyond the realm of plain ascii you need to use the Python 2.7 unicode string notation
u'Exämple'
- You need to be particularly careful when you write logging messages that write out user input data and turn the entire message into a unicode string like this:
logger.debug(u'Query: "{}"'.format(self.query))
Logging
You can use logging calls to debug your Jython code.
- Depending on what context the code is run in, the logging is written in different places:
- If the code is executed from an event, the logging is written in the
Event.log
file - If the code is executed from a web interface, the logging is written in the web interface logging table and can be viewed 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.log
and 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 instead use the
utilities
namespace - 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 |
---|---|
utilities.cache | Caching expensive function calculations |
utilities.customizer | Functions for getting text constants, global settings and listbox categories/values |
utilities.data | Various business logic functions |
utilities.database | Functions for interacting with the database |
utilities.enums | Various Enums |
utilities.exception | Custom Exceptions |
utilities.module | Function for opening a module |
utilities.pojo | Functions for interacting with POJOs |
utilities.send_email | Classes for sending emails from Jython |
utilities.ui | 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 instead use the weblink namespace
- This ensures 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 |
weblink.transformation | Contains the transformer implementations |
weblink.exceptions | 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 |
---|---|
Java Server API | Low level API to access server functions |
server.session | Functions for getting information about a session |