INTRO
Sometimes you need to enrich your entity view with the combination of attribute values or attributes that belong to some other entity… and there is a way to do it using computed content feature.
Following are the two use cases I happen to encounter most often.
Show parent attribute in a child entity
- You have
report
andreportColumn
entities. - Entity
reportColumn
is an array of embedded objects insidereport
. - Entity
report
has areportName
attribute.
The goal is to add report.reportName
to reportColumn
entity as reportName
attribute.
High level steps:
- Create a new entity named
reportNameCC
, save it, **DO NOT PUBLISH**. - In the
Computed Content
tab of the entity add parameters and SQL. - Edit
reportColumn
entity- add embedded object with type
reportNameCC
; - add delegate property to embedded
reportNameCC
.
- add embedded object with type
Computed Content Entity
- Goto Organization → Metadata Model
- Press Create entity and create empty
reportNameCC
entity. - Save but **DO NOT PUBLISH!**
- Open
Computed Content
tab and fill in:Input Attributes
-- entities that are participating in the computation.Query
-- templated SQL query that does computation.Computed Properties
-- output properties to be used when this computed content entity would be embedded.
Input Attributes
Add 2 entities: report
and reportColumn
. Both should have required properties added too:
Aliases and names would be used in the query.
Query
Templated SQL query is not very user friendly but it gets the job done.
We want to have SQL that for every report extracts all report columns and adds reportName
to them:
select
c.$cId$ as "id_i",
c.$cId$ as "parent_id_i",
r.$rFrom$ as "from_h",
$path(c.$cPath$)$ as "path_i",
$type()$ as "type_i",
r.$rName$ as "reportName" -- (1)
from $r$ r
inner join $c$ c on r.$rId$ = c.$cParentId$
(1)
Should be used as an output in Computed Properties
Computed Properties
We should add computed property and it is just a mapping to SQL column defined in SQL query above:
Now press Preview result to check if there is a data:
And if it is there publish the changes.
Apply Computed Content Column
- Goto Organization → Metadata Model.
- Find and edit
reportColumn
entity. - Press Add property and add property as
Embedded object
with typereportNameCC
: - Press Add property and add another property as
Delegated scalar property
, setVia property
to previously added computed content propertyreportNameCC
, setDelegate property
toreportName
: - Publish changes.
Now there is an "issue": I can see 2 report names when I open the report column:
We can hide computed column embedded property with layout change:
- Open web browser console (
Ctrl + Shift + I
in most browsers) - Execute
OpenDebuggingTools()
javascript function (Or you can press :Ctrl + Shift + T
): - We can blacklist a property to hide it from this layout view. Edit the layout:
{
"_type": "entity.controller",
"children": {
"_type": "entity.page.detail",
"showViolations": true,
"children": {
"_type": "grid",
"items":
{
"cols": 14,
"children": {
"_type": "entity.entity",
"children":
{
"_type": "entity.property",
"name": "description"
},
{
"_type": "entity.card",
"title": "General information",
"children": {
"_type": "entity.property.rest",
"propertyTypes": r"S", "SRE"]
}
},
{
"_type": "entity.property.rest",
"propertyTypes": r"SEE", "AEE"],
"blacklist": "reportNameCC"]
}
]
}
}
]
}
}
}Where
reportNameCC
is a blacklisted property. -
Press
CTRL + S
(orCMD + S
on OSX) to save the layout.
The result is:
Unfortunately, there is no way to hide it from the right panel view:
Concatenate Attribute Values
- You have
report
entity. - It has
reportName
,year
andtype
string properties.
The goal is to add reportFullName
property to report
which is a concatenation of type
+ reportName
+ year
.
Computed Content Entity
- Goto Organization → Metadata Model
- Press Create entity and create empty
reportNameCC
entity. - Save but **DO NOT PUBLISH!**
- Open
Computed Content
tab and fill in:Input Attributes
-- entities that are participating in the computation.Query
-- templated SQL query that does computation.Computed Properties
-- output properties to be used when this computed content entity would be embedded.
Input Attributes
Add entity: report
with required properties + properties that we would like to use for concatenation:
Aliases and names would be used in the query.
Query
SQL should just select everything and concatenate rType
, rName
and rYear
:
.. code:: sql
select
r.$rId$ as "id_i",
r.$rId$ as "parent_id_i",
r.$rFrom$ as "from_h",
$path(r.$rPath$)$ as "path_i",
$type()$ as "type_i",
r.$rType$ || ' ' || r.$rName$ || ' ' || r.$rYear$ as "fullName" -- (1)
from $r$ r
(1)
Should be used as an output in Computed Properties
Computed Properties
We should add computed property and it is just a mapping to SQL column defined in SQL query above:
Now press Preview result to check if there is a data:
And if it is there, publish the changes.
Apply Computed Content Column
- Goto Organization → Metadata Model
- Find and edit
report
entity. - Press Add property and add property as
Embedded object
with typereportFullNameCC
: - Press Add property and add another property as
Delegated scalar property
, setVia property
to previously added computed content propertyreportFullNameCC
, setDelegate property
tofullName
: - Publish.
What if you would like to concatenate reference attribute?
Now imagine that instead of plain string there is an attribute with dropdown values -- brand
-- and you want to add its value to the concatenation.
- Goto Organization → Metadata Model
- Find and open
reportFullNameCC
entity. - Goto
Computed Content
tab and add another input entityBrand
: - Change the Query to
select
r.$rId$ as "id_i",
r.$rId$ as "parent_id_i",
r.$rFrom$ as "from_h",
$path(r.$rPath$)$ as "path_i",
$type()$ as "type_i",
b.$bName$ || ' ' || r.$rType$ || ' ' || r.$rName$ || ' ' || r.$rYear$ as "fullName" -- (1)
from $r$ r
left join $b$ b on b.$bId$ = r."brand_ri" -- (2)(1)
Hereb.$bName$
is added. Value from the joinedBrand
entity.(2)
Join condition is a simple one (although not obvious). You have to join referenced entity (Brand
) by itsId
with the main entity (Report
) by the reference idbrand_ri
. It would always be name of the reference attribute +_ri
. -
Publish
OUTRO
That is it, not the easiest implementation one can wish for, but it gets the job done.