JavaScript Extension Development API for Oracle Visual Builder Cloud Service - Classic Applications

Class: bop/js/api/entity/DataModelFactory

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
Name Type Attributes Description
id String

Unique ID of the created Entity.

singularName String

Singular name for the created Entity.

pluralName String <optional>

Plural name for the created Entity.

description String <optional>

Human-readable description of what's the meaning of the created Entity.

properties Array.<entity/js/api/Property>

Array of properties assigned to the created Entity.

Version:
  • 17.1.1
Source:
See:
  • Entity representing an entity object
  • Property representing a property of an entity
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
Name Type Attributes Default Description
id String

ID of the created Property

name String

Name of the created Property.

type entity/js/api/PropertyType

Type of the created Property.

initialValue String <optional>

Initial value which will be set for the created Property if no other value will be provided.

classification entity/js/api/PropertyClassification <optional>
PropertyClassification.BASIC

Classification of the created Property.

Version:
  • 17.1.1
Source:
See:
Returns:
Type
entity/js/api/Property
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
Name Type Attributes Default Description
sourceEntity entity/js/api/Entity

Entity being considered as source. Source Entity always contains the reference to the target.

targetEntity entity/js/api/Entity

Entity being considered as target.

cardinality entity/js/api/RelationCardinality

Cardinality of the created relation.

propertyId String

ID of the created reference Property.

propertyName String <optional>
Singular name of the target Entity

Name of the created reference Property.

displayNameProperty entity/js/api/Property <optional>
Primary key Property from the target Entity

Default Property display name of the referenced column. The display name will be used as the target’s property value. See also the example below.

childRelationship Boolean <optional>
false

true if this relation is a Parent/Child relationship type or false if it's relation between two standalone objects.

Version:
  • 17.1.1
Source:
See:
Returns:
Type
entity/js/api/Relation
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
});