An API factory object to create instances of various data model related objects.
Please be aware that using DataModelFactory
is supposed to be used only in BOP implementation (specifically to be used inside
custom EntityProvider implementation). But it for example doesn't make sense to create an Entity
instance inside your custom component code because such Entity will never be properly registered into Application Builder data model.
- Version:
- 17.1.1
- Source:
- See:
-
- Entity representing an entity object
- Property representing a property of an entity
- Relation representing a relation between two entities
- EntityProvider which is the place where
DataModelFactory
should be mainly used
Methods
(static) createEntity(params) → {entity/js/api/Entity}
stable API
Creates a new instance of Entity object.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
Object | An Object literal with following properties. Properties
|
- Version:
- 17.1.1
- Source:
- See:
Returns:
- Type
- entity/js/api/Entity
Example
Creates simple Entity with three properties.
var firstName = DataModelFactory.createProperty({
id: 'firstname',
name: 'Firstname',
type: PropertyType.TEXT
});
var lastName = DataModelFactory.createProperty({
id: 'lastname',
name: 'Lastname',
type: PropertyType.TEXT
});
var age = DataModelFactory.createProperty({
id: 'age',
name: 'Age',
type: PropertyType.NUMBER
});
var employee = DataModelFactory.createEntity({
id: 'my.custom.bop.Employee',
singularName: 'Employee',
pluralName: 'Employees',
description: 'Business object representation of Employee object',
properties: [firstName, lastName, age]
});
(static) createProperty(params) → {entity/js/api/Property}
stable API
Creates a new instance of Property object.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
Object | An Object literal with following properties Properties
|
- Version:
- 17.1.1
- Source:
- See:
-
- Property representing a property of an entity
- PropertyType for list of all available PropertyTypes
- PropertyClassification for list of all available PropertyClassifications
Returns:
Examples
Creates an instance of a Property initialized with mandatory parameters only.
var firstname = DataModelFactory.createProperty({
id: 'firstname',
name: 'Firstname',
type: PropertyType.TEXT
});
Creates an instance of a Property initialized with all possible input parameters.
var hiddenField = DataModelFactory.createProperty({
id: 'hiddenField',
name: 'Hidden Field',
type: PropertyType.NUMBER,
classification: PropertyClassification.IGNORE,
initialValue: 'Value not defined yet.'
});
(static) createRelation(params) → {entity/js/api/Relation}
stable API
Creates a new relation between two Entities.
Creating relation in fact creates a new Property in the source Entity. Such Property has always type set to Property.REFERENCE and it's value is either ID referencing target Entity record or can be empty in case of no target Entity record assigned.
Please note that although the method returns an instance of Relation object, usual API client don't need to process that instance anyhow. Currently it's part of the documentation just for it's completeness and it will be extended with more functionality in the future versions of Application Builder APIs.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
Object | An object literal with following properties Properties
|
- Version:
- 17.1.1
- Source:
- See:
-
- Entity representing an entity object
- Property representing a property of an entity
- Relation representing a relation between two entities
- RelationCardinality listing all possible cardinalitites
Returns:
Examples
Creates a new relation where Employee Entity holds a reference to Department Entity.
// Let's assume two entities already exists: Employee (ID, Firstname, Lastname) and Department (ID, Name)
DataModelFactory.createRelation({
sourceEntity: employee,
targetEntity: department,
cardinality: RelationCardinality.MANY_TO_ONE,
propertyId: 'ref2Department'
});
Specifies also default display name property to show Department name automatically on all relevant places. For example Employee table configured to show Firstname, Lastname and Department columns will always show department name value instead of department ID.
// Let's assume two entities already exists: Employee (ID, Firstname, Lastname) and Department (ID, Name)
DataModelFactory.createRelation({
sourceEntity: employee,
targetEntity: department,
cardinality: RelationCardinality.MANY_TO_ONE,
propertyId: 'ref2Department',
displayNameProperty: department.getProperty('name')
});
Creates a new relation with all mandatory and optional parameters specified.
// Let's assume two entities already exists: Employee (ID, Firstname, Lastname) and Department (ID, Name)
DataModelFactory.createRelation({
sourceEntity: employee,
targetEntity: department,
cardinality: RelationCardinality.MANY_TO_ONE,
propertyId: 'ref2Department',
propertyName: 'Reference to Department',
displayNameProperty: department.getProperty('name'),
childRelationship: true
});