Die nachfolgenden Inhalte sind nur in englischer Sprache verfügbar.

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-Schnittstellen
  • 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!')
    
    # ...
PY

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)
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.moduleFunction for opening a module
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 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):
    ...
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
server.sessionFunctions for getting information about a session