Interface Customizing
Information
- Each object from the PLANTA link API should be imported from the
ppms.interface
namespace!
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.interface
package provides three basic classes for the implementation of your own mapping functions:BaseConverter
,BaseEnricher
, andBaseValidator
.
Parameters
Information
- The parameters of a mapping function are configured in the
register_parameters
class method - Via the
register_parameter
andunregister_parameter
class 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 parameters
dictionary.
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
check
method, the configured parameters are accessed viaself parameters
. As a result, the value of thevalue
parameter 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))
PY
Create a New Validator
Information
- Create a new file under
ppms.interface
and define a new class which inherits fromBaseValidator
. - Here, the
check(self, parameter
) method must be implemented. - The method must throw the
InvalidRecordException
if 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))
PY
Create a New Enricher
Information
- Create a new file under
ppms.interface
and 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'])
PY
Create a New Converter
Information
- Create a new file at
ppms.interface
and 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 a text to upper-case letters
from ppms.interface import BaseConverter class ToUppercase(BaseConverter): def convert(self, value): return value.upper()
PY
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
BaseInterfaceModule
class. - 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 | before_send(self) | Prepares the module for sending data | None |
2 | send(self) | Send the records as dictionaries | Must return all records individually via yield . The yield return value is either True , if the record was successfully received or False , if an error occurred |
3 | after_send(self, was_successful) | Here, opened resources can be closed again. The was_successful parameter indicates whether the transfer was successful. | None |
Import
Sequence | Signature | Use | Return value |
---|---|---|---|
1 | before_receive(self) | Prepares the module for receiving data | None |
2 | receive(self, record) | Is opened once for each record and receives the record. | Either returns True , when the record was processed successfully, or it throws a CantProcessRecordException |
3 | after_receive(self, was_successful) | Here, opened resources can be closed again. The was_successful parameter indicates whether the transfer was successful. | 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 from DT412 Dataitem:
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 with no decimal fraction digits, up to 4 digits | 2 | 2 | |
Transferred on | transferred_on | TRANSFERRED_ON | Alpha | 80 | 80 |