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 is 2.7, which can be quite different from 3.6 which you would 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 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.utilities when 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.log file
    • 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.log and the web interface log
import logging

logger = logging.getLogger(__name__)


def custom_event(event):
    logger.info('Custom event was called!')
    
    # ...
PY

Customizing API

utilities

The utilities package provides various helper functions.

Tip

  • Avoid importing any functions from their absolute namespace and use the utilities namespace 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)
PY
NamespaceTopic
utilities.cacheCaching expensive function calculations
utilities.customizerFunctions for getting text constants, global settings and listbox categories/values
utilities.dataVarious business logic functions
utilities.databaseFunctions for interacting with the database
utilities.enumsVarious Enums
utilities.exceptionCustom Exceptions
utilities.moduleFunctions for opening a module and fetching the return value of a module
utilities.session Functions for getting information about a session
utilities.pojoFunctions for interacting with POJOs
utilities.send_email

Classes for sending emails from Jython

utilities.uiDisplay messages to the user

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):
    ...
PY
NamespaceTopic
weblink.interfacesContains the web interface implementations
weblink.transformationContains the transformer implementations
weblink.exceptionsProvides exception classes that are better handled by the web framework
weblink.metadataDefines classes that give access to metadata information about the web interface

Server API

NamespaceTopic
Java Server APILow level API to access server functions