utilities - pojo
The pojo
module provides all basic functions for interacting with pojos
Basic POJO Functions
Function | Parameters | Return Value | Description |
---|---|---|---|
create_pojo(entity_name, attributes=None, set_object_protection=True, _generate_auto_numbers=True) | entity_name: Entity name attributes: Optional attributes that will be passed to set_pojo_attributes set_object_protection: When True the object protection fields are set automatically._generate_auto_numbers: When True , all autonumber fields get a generated autonumber | A pojo | Create a new POJO with the given entity name |
get_pojo_by_uuid(entity_name, uuid) | entity_name: Entity name uuid: The UUID of the POJO | A POJO or None | Gets a POJO via UUID |
save_pojo(pojo) | pojo: A pojo | True if the pojo could be saved | Throws a PojoSaveFailedException when saving fails |
delete_pojo(pojo) | pojo: A pojo | True if the pojo could be deleted | Throws a PojoDeleteFailedException when deletion fails |
Helper Functions
Function | Parameters | Return Value | Description |
set_pojo_attributes(pojo, attributes, set_object_protection=True) | pojo: A pojo attributes: A dictionary of {python_id: value} set_object_protection: When True , the object protection fields are updated automatically | Sets the attributes of a pojo. See below for detailed description. | |
is_valid_date(pojo_attribute_date) | pojo_attribute_date: A date read from a pojo | True or False | Checks whether a date is valid, eg. not 01.01.1970 |
generate_auto_numbers(pojo) | pojo: A pojo | Generates the autonumbers for a pojo |
set_pojo_attributes
set_pojo_attributes
makes setting values on a pojo easier by handling some of the tedious work for you:
- The function expects python ids and will automatically convert the python id to the correct attribute name
- Values are converted according to the column type of the attribute:
Column Type | Accepted types |
---|---|
UUID | uuid.UUID objects or a string as expected by java.util.UUID.fromString |
Alpha / Alpha, E-mail / Alpha, gross / Alpha, phone number / Clob | Everything that can be converted to text |
Ja/No | Everything that can be converted to bool |
Date | datetime.datetime objects or a string in the format dd.mm.YYYY |
Time | datetime.datetime objects or a string in the format HH:MM |
Number without DP, up to 4/9 digits | Everything that can be converted to int. Strings like '5.32' as well as '5,32' are both accepted |
Currency / number with DP | Everything that can be converted to float. Strings like '5.32' as well as '5,32' are both accepted |
Examples
Creating a project and setting the pr_manager
from customizing import utilities
pojo = utilities.create_pojo(entity_name='Project')
attributes = {'pr_manager': 'R41'}
utilities.set_attributes(pojo=pojo, attributes=attributes)
utilities.save_pojo(pojo=pojo)