Factory (Common API)

Overview - Common API - Client API - Admin API - Runtime API

Factory

Use the Factory to create instances of Resource: transactions, participants and assets.

Details

  • Module common

See also

Method Summary

Name Returns Description
constructor void Create the factory.

Note: Only to be called by framework code. Applications should retrieve instances from BusinessNetworkDefinition

newConcept Resource Create a new Concept with a given namespace and type name
newEvent Resource Create a new event object. The identifier of the event is set to a UUID.
newRelationship Relationship Create a new Relationship with a given namespace, type and identifier. A relationship is a typed pointer to an instance. I.e the relationship with namespace = 'org.acme', type = 'Vehicle' and id = 'ABC' creates` a pointer that points at an instance of org.acme.Vehicle with the id ABC.
newResource Resource Create a new Resource with a given namespace, type name and id
newTransaction Resource Create a new transaction object. The identifier of the transaction is set to a UUID.

Method Details

new Factory()

Create the factory.

Note: Only to be called by framework code. Applications should retrieve instances from BusinessNetworkDefinition

Parameters

Name Type Optional Description
modelManager ModelManager false The ModelManager to use for this registry

newResource

Resource newResource( string ns, string type, string id, [Object options] )

Create a new Resource with a given namespace, type name and id

Returns

Resource - the new instance

Parameters

Name Type Optional Description
ns string false the namespace of the Resource
type string false the type of the Resource
id string false the identifier
options Object true an optional set of options

Sub-options

Name Type Optional Description
options.disableValidation boolean true pass true if you want the factory to return a Resource instead of a ValidatedResource. Defaults to false.
options.generate string true Pass one of:
sample
return a resource instance with generated sample data.
empty
return a resource instance with empty property values.
options.includeOptionalFields boolean true if options.generate is specified, whether optional fields should be generated.
options.allowEmptyId boolean true if options.allowEmptyId is specified as true, a zero length string for id is allowed (allows it to be filled in later).

newConcept

Resource newConcept( string ns, string type, [Object options] )

Create a new Concept with a given namespace and type name

Returns

Resource - the new instance

Parameters

Name Type Optional Description
ns string false the namespace of the Concept
type string false the type of the Concept
options Object true an optional set of options

Sub-options

Name Type Optional Description
options.disableValidation boolean true pass true if you want the factory to return a Concept instead of a ValidatedConcept. Defaults to false.
options.generate string true Pass one of:
sample
return a resource instance with generated sample data.
empty
return a resource instance with empty property values.
options.includeOptionalFields boolean true if options.generate is specified, whether optional fields should be generated.

newRelationship

Relationship newRelationship( string ns, string type, string id )

Create a new Relationship with a given namespace, type and identifier. A relationship is a typed pointer to an instance. I.e the relationship with namespace = 'org.acme', type = 'Vehicle' and id = 'ABC' creates` a pointer that points at an instance of org.acme.Vehicle with the id ABC.

Returns

Relationship - the new relationship instance

Parameters

Name Type Optional Description
ns string false the namespace of the Resource
type string false the type of the Resource
id string false the identifier

newTransaction

Resource newTransaction( string ns, string type, [string id], [Object options] )

Create a new transaction object. The identifier of the transaction is set to a UUID.

Returns

Resource - A resource for the new transaction.

Parameters

Name Type Optional Description
ns string false the namespace of the transaction.
type string false the type of the transaction.
id string true an optional identifier for the transaction; if you do not specify one then an identifier will be automatically generated.
options Object true an optional set of options

Sub-options

Name Type Optional Description
options.generate string true Pass one of:
sample
return a resource instance with generated sample data.
empty
return a resource instance with empty property values.
options.includeOptionalFields boolean true if options.generate is specified, whether optional fields should be generated.
options.allowEmptyId boolean true if options.allowEmptyId is specified as true, a zero length string for id is allowed (allows it to be filled in later).

newEvent

Resource newEvent( string ns, string type, [string id], [Object options] )

Create a new event object. The identifier of the event is set to a UUID.

Returns

Resource - A resource for the new event.

Parameters

Name Type Optional Description
ns string false the namespace of the event.
type string false the type of the event.
id string true an optional identifier for the event; if you do not specify one then an identifier will be automatically generated.
options Object true an optional set of options

Sub-options

Name Type Optional Description
options.generate string true Pass one of:
sample
return a resource instance with generated sample data.
empty
return a resource instance with empty property values.
options.includeOptionalFields boolean true if options.generate is specified, whether optional fields should be generated.
options.allowEmptyId boolean true if options.allowEmptyId is specified as true, a zero length string for id is allowed (allows it to be filled in later).