Metadata and Groovy - Creating Metadata
Groovy and Metadata: Unlocking the Vault to Member Creation
In this part of the Metadata and Groovy series, I will explore how you can harness the capabilities of Groovy to create members dynamically.
How to Create Metadata
The Oracle EPM Groovy API provides a Dimension class that comes with some handy methods to create metadata.
saveMember(Map<String,Object> memberMap): Returns the new or updated member that was saved with the specified properties.
saveMember(Map<String,Object> memberMap, DynamicChildStrategy strategy): Returns the new or updated member that was saved with the specified properties.
DynamicChildStrategy is an enumeration that can be used as an optional parameter to saveMember to choose how the member is created / saved.
The enumeration values are:
ALWAYS_DYNAMIC: Always save as dynamic member, fail if buckets are exhausted or if parent is not enabled for dynamic children.
ALWAYS_DYNAMIC_IF_ENABLED: Same as ALWAYS_DYNAMIC if parent is dynamic else same as NEVER_DYNAMIC.
DYNAMIC_IF_AVAILABLE: Save as dynamic if buckets are available, save as normal member once buckets exhaust.
NEVER_DYNAMIC: Always save as normal member.
When using this approach, creating specific parents with Dynamic Children enabled allows for the runtime creation of metadata without the overhead of refreshing the database.
Creating a Member
Let's dive straight into a simple script that creates a Member.
/*RTPS:*/
Cube cube = (operation.hasCube() ? operation.getCube() : operation.application.getCube("OEP_WFP"))
Dimension dim = operation.application.getDimension("Employee", cube)
Map<String, Object> mbrProperties = [:]
mbrProperties["Member"] = "E00XX"
mbrProperties["Alias: Default"] = "Kazmi,Shehzad"
mbrProperties["Parent"] = "OWP_Existing Employees"
mbrProperties["Data Storage"] = "store"
// You can explicitly enable/disable Data Type, Plan Types, or Aggregation
// I am not setting these because it will inherit from Parent
//mbrProperties["Data Type"] = "unspecified"
//mbrProperties["Plan Type (OEP_WFP)"] = true
//mbrProperties["Plan Type (OEP_REP)"] = true
//mbrProperties["Aggregation (OEP_WFP)"] = "+"
//mbrProperties["Aggregation (OEP_REP)"] = "+"
Member savedMember = dim.saveMember(mbrProperties, DynamicChildStrategy.DYNAMIC_IF_AVAILABLE)
savedMember.toMap().each { k, v ->
println("${k} : ${v}")
}
The employee dimension before the script contains some members representing employees.
After executing the script we now have the additional member added.
To use this member, a database refresh is required as the parent OWP_Existing Employees is not enabled for dynamic children.
I have printed the properties of the Member that is returned by the saveMember function.
Log messages :
Data Storage (OEP_WFP) : store
Parent : OWP_Existing Employees
Two Pass Calculation : false
Alias: Default : Kazmi,Shehzad
Solve Order (OEP_WFP) : 0
Process Management Enabled : true
Old Name : E00XX
Formula : <none>
UDA :
Essbase Name : E00XX
UUID : 68c149bb-7d18-4651-8f10-10083d9a0230
Plan Type (OEP_WFP) : true
Aggregation (OEP_REP) : +
Member : E00XX
Data Storage : store
Hierarchy Type : none
Allow Upper Level Entity Input : false
Formula (OEP_REP) : <none>
Formula Description : <none>
Data Storage (OEP_REP) : store
Data Id : 1511996131396993
Solve Order (OEP_REP) : 0
Valid For Consolidations : false
Data Type : unspecified
Old Unique Name : <none>
Formula (OEP_WFP) : <none>
Plan Type (OEP_REP) : true
Aggregation (OEP_WFP) : +
As you can see, I only set the bare minimum properties in the Map for the Member Name, Alias, Parent Name, and Data Storage. All other properties have been derived from the parent or created when the member was saved.
Conclusion
In this part of the Groovy and Metadata series, I have covered how you can create a dimension Member.
Through the method saveMember() of the Dimension class we can create a member represented by the properties saved in a map.