core:GetObjectFromBatch (Preprocessor)
For Batch import, the value of the attribute rememberAs (see Single import) can be used to define a name under which an entity imported in a batch node is 'remembered'. Later processed batch nodes in the same Batch import can then use the GetObjetFromBatch preprocessor to refer to a previously 'remembered' entity.
The following structure can be directly integrated into the import structure based on the template preProcessor:GetObjectFromBatch (see Lobster SCM templates):
Parameter |
Type |
Meaning |
Content (fixed value/example) |
xsi:type |
String attribute |
type of preprocessor |
core:GetObjectFromBatch |
rememberedAs |
String attribute |
name of a 'remembered' entity |
myUser |
target |
String attribute |
name of the target element or attribute (with the prefix '@') to which the return value should be assigned |
linkedEntityId |
returnId |
Boolean attribute |
defines the return value (only ID or complete entity) |
true / false |
IValueResolver |
Placeholder |
instead of this node you can optionally use a Wertauflöser if only a detail of the entity should be used as return value |
see example below |
►NOTE◄ The Wertauflöser (see IValueResolver) is irrelevant if the returnId parameter has the value true, because then the ID (id) of the entity is always returned.
Example:
A Batch import should create a new company account ('Demo Company'), a new role ('Demo Role') and finally a new user ('demoUser'), who should have access to the new company and the new role at login.
In the batch node for creating the new company account, this is 'remembered' by the rememberAs attribute under the name 'demoCompany'.
The following batch node for creating the new role assigns the noted new company as owner of the role via GetObjectFromBatch preprocessor and notes the new role as "demoRole".
The third batch node for creating the user refers via GetObjectFromBatch preprocessor to the noted 'demoCompany' to assign it as owner and as 'Assigned Company'.
The first preprocessor sets the owner in the same way as the role with returnId=true.
When assigning the company (without technical necessity), the second preprocessor demonstrates how to proceed alternatively with returnId=false and a Wertauflöser (core:PropertyResolver).
The third preprocessor again uses the simpler variant with returnId=true to assign the remembered role 'demoRole' to the user.
►NOTE◄ The assignment of an owner has no functional meaning for the role with respect to access rights, since for this entity access is only restricted depending on the Role of session and the hierarchy between the roles (see Roles). However, it can still be useful to assign a specific owner to the role, for example, if the reference to the owning company is to be used as an regulating principle (for filtering or sorting, for example).
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
core
:BatchImport
xmlns:xsd
=
"http://www.w3.org/2001/XMLSchema"
xmlns:xsi
=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:core
=
"CORESYSTEM"
xmlns:base
=
"SCM.BASE"
>
<
batch
action
=
"CREATE"
rememberAs
=
"demoCompany"
>
<!-- The company created here shall be remembered as "demoCompany" -->
<
base
:CompanyAccount>
<
address
name1
=
"Demo Company"
/>
</
base
:User>
</
batch
>
<
batch
action
=
"CREATE"
rememberAs
=
"demoRole"
>
<
base
:Role
xmlns:base
=
"SCM.BASE"
ownerId
=
"-1"
active
=
"true"
>
<!-- This preprocessor remembers the company "demoCompany" and transforms into an attribute ownerId with the company's id as a value -->
<
preProcessor
xsi:type
=
"core:GetObjectFromBatch"
rememberedAs
=
"demoCompany"
returnId
=
"true"
target
=
"@ownerId"
/>
<
roleName
>Demo Role</
roleName
>
<
flatPermissionNames
>*</
flatPermissionNames
>
</
base
:Role>
</
batch
>
<
batch
action
=
"CREATE"
>
<
base
:User
username
=
"demoUser"
>
<!-- This preprocessor remembers the company "demoCompany" and transforms into an attribute ownerId with the company's id as a value -->
<
preProcessor
xsi:type
=
"core:GetObjectFromBatch"
rememberedAs
=
"demoCompany"
returnId
=
"true"
target
=
"@ownerId"
/>
<
companies
>
<!-- This preprocessor remembers the company "demoCompany" and transforms into an element named company with the company's id as a value -->
<
preProcessor
xsi:type
=
"core:GetObjectFromBatch"
rememberedAs
=
"demoCompany"
returnId
=
"false"
target
=
"company"
>
<
core
:PropertyResolver
property
=
"id"
></
core
:PropertyResolver>
</
preProcessor
>
</
companies
>
<
roles
>
<!-- This preprocessor remembers the role "demoRole" and transforms into an attribute ownerId with the role's id as a value -->
<
preProcessor
xsi:type
=
"core:GetObjectFromBatch"
rememberedAs
=
"demoRole"
returnId
=
"true"
target
=
"role"
/>
</
roles
>
<
address
name1
=
"Demo User"
/>
</
base
:User>
</
batch
>
</
core
:BatchImport>