Interface Customizing
Information
Each object from the PLANTA link API should be imported from the
ppms.interfacenamespace!
Create New Mapping Function
Information
You can create new mapping functions under /py/api/ppms/wrapper/customer/ppms/interface/blocks/.
To do so, simply create an enricher.py, converter.py, or validator.py file at this position and fill it with individual mapping functions
The
ppms.interfacepackage provides three basic classes for the implementation of your own mapping functions:BaseConverter,BaseEnricher, andBaseValidator.
Parameter
Information
The parameters of a mapping function are configured in the
register_parametersclass method.Via the
register_parameterandunregister_parameterclass methods you can add new parameters or delete parameters of the parent class.See also the documentation in the Mappings API
You can access the value of your own parameters within the instance via the
self parametersdictionary.
Example
Here, a validator is defined which checks whether the transferred value matches the configured value.
For this purpose, a new parameter with the key "value" is registered. This parameter has no standard value but it is a mandatory field.
Within the
checkmethod, the configured parameters are accessed viaself parameters. As a result, the value of thevalueparameter is opened.Afterwards it is checked whether the transferred value matches the configured value.
from ppms.interface import BaseValidator, InvalidRecordException
class Equals(BaseValidator):
@classmethod
def register_parameters(cls):
super(Equals, cls).register_parameters()
cls.register_parameter(name='value', default='', validator_cls=MandatoryValidator)
def check(self, value):
check_value = self.parameters['value']
if value != check_value:
raise InvalidRecordException('"%s" is not equal to "%s"' % (value, check_value))
Create a New Validator
Information
Create a new file under
ppms.interfaceand define a new class which inherits fromBaseValidator.Here, the
check(self, parameter) method must be implemented.The method must throw the
InvalidRecordExceptionif the validation has failed.
Example: Validator that checks whether a particular task exists
from ppms.interface import BaseValidator, InvalidRecordException
class TaskExists(BaseValidator):
@classmethod
def register_parameters(cls):
super(TaskExists, cls).register_parameters()
cls.register_parameter(name='project', default='', validator_cls=MandatoryValidator)
def check(self, task_id):
pr_id = self.parameters['project']
task_record = ppms.search_record(463, [pr_id, task_id], [1097, 1098], True)
if task_record is None:
raise InvalidRecordException('There is no task "%s" in project "%s"' % (task_id, pr_id))
Create a New Enricher
Information
Create a new file under
ppms.interfaceand define a new class that inherits fromBaseEnricher.Here you have to implement the
enrich(self, parameter)method.The method must return the edited value.
Example: Enricher for replacing a text by another one
from ppms.interface import BaseEnricher
class Replacer(BaseEnricher):
"""Gives access to the str.replace function"""
@classmethod
def register_parameters(cls):
super(Replacer, cls).register_parameters()
cls.register_parameter(name='old_value', default='', validator_cls=MandatoryValidator)
cls.register_parameter(name='new_value', default='', validator_cls=MandatoryValidator)
def enrich(self, arg):
return arg.replace(self.parameters['old_value'],
self.parameters['new_value'])
Create a New Converter
Information
Create a new file at
ppms.interfaceand define a new class that inherits fromBaseConverter.Here, the
convert(self, parameter)method must be implemented.The method must return the converted value.
Example: Converter for converting text into capital letters
from ppms.interface import BaseConverter
class ToUppercase(BaseConverter):
def convert(self, value):
return value.upper()
Add a New Mapping Function to the Listbox
Information
Under PLANTA Link → Interface Administration → Interface Administration you can add the new mapping functions so that they are displayed in the object listbox
Create a New Module Class
Information
The module classes implement an individual transfer logic and constitute docking points to other systems.
Each module class to be used for the interface must inherit from the
BaseInterfaceModuleclass.The module class parameters work in the same way as the interface component parameters.
The basic class defines 6 methods, 3 for import and 3 for export.
Export
Sequence | Signature | Use | Return value |
|---|---|---|---|
1 |
| Prepares the module for sending data | None |
2 |
| Send the records as dictionaries | Must return all records individually via |
3 |
| Here, opened resources can be closed again. | None |
Import
Sequence | Signature | Use | Return value |
|---|---|---|---|
1 |
| Prepares the module for receiving data | None |
2 |
| Is opened once for each record and receives the record. | Either returns |
3 |
| Here, opened resources can be closed again. | None |
Create a New Pool Table
Notes
Pool tables can be created in PLANTA project just like any other table.
In order for PLANTA link to be able to use a table correctly as a pool table, it must contain the following data items:
data item | DI Python ID | SQL ID | Column type | DB length | DF length | Miscellaneous |
|---|---|---|---|---|---|---|
UUID | uuid | UUID | UUID | 16 | 36 | PK |
Interface configuration | config_id | CONFIG_ID | UUID | 16 | 36 | FC for DT 560 |
Status | status | STATUS | Number without DP up to 4 digits | 2 | 2 | |
Transferred on | transferred_on | TRANSFERRED_ON | Alpha | 80 | 80 |
Things to Note for Interface Customizing
Things to Note for Import Interfaces
Caution
For interfaces which import into a table which contains a primary key with auto number, e.g. (DT463), the primary key must always be at the first position in the target data area of the target module. This is relevant for later updates.