Details
-
Improvement
-
Resolution: Unresolved
-
Minor
-
None
-
None
-
None
-
None
Description
Setting up a standard application and policy using the built-in template requires the UI jar, and only works by simulating the checkboxes from the setup. The code below shows how to hack it to work. It's a lot of code. There should be a way to do this from a builder method, and not resorting to UI classes.
import edu.internet2.middleware.grouper.grouperUi.beans.ui.GroupStemTemplateContainer
|
import edu.internet2.middleware.grouper.grouperUi.beans.ui.GrouperNewServiceTemplateLogic
|
import edu.internet2.middleware.grouper.grouperUi.beans.ui.GrouperTemplatePolicyGroupLogic
|
import edu.internet2.middleware.grouper.grouperUi.beans.ui.ServiceAction
|
|
class HelperMethods {
|
static void newApplicationTemplate(Stem parentStem, String templateKey, String templateFriendlyName, String templateDescription, List<String> myServiceActionIds = []) {
|
def stemTemplateContainer = new GroupStemTemplateContainer()
|
stemTemplateContainer.templateKey = templateKey
|
stemTemplateContainer.templateFriendlyName = templateFriendlyName
|
stemTemplateContainer.templateDescription = templateDescription
|
|
GrouperNewServiceTemplateLogic templateLogic = new GrouperNewServiceTemplateLogic()
|
templateLogic.stemId = parentStem.uuid
|
templateLogic.stemTemplateContainer = stemTemplateContainer
|
|
List<ServiceAction> selectedServiceActions = []
|
if (myServiceActionIds == null || myServiceActionIds.isEmpty()) {
|
selectedServiceActions = templateLogic.getServiceActions()
|
} else {
|
Map<String, ServiceAction> allPolicyServiceActionMap = templateLogic.getServiceActions().collectEntries { [it.id, it] }
|
selectedServiceActions = myServiceActionIds.collect { allPolicyServiceActionMap[it] }
|
}
|
templateLogic.validate(selectedServiceActions)
|
|
selectedServiceActions.each {serviceAction ->
|
serviceAction.getServiceActionType().createTemplateItem(serviceAction)
|
}
|
String errorKey = templateLogic.postCreateSelectedActions(selectedServiceActions)
|
if (errorKey != null) {
|
println "Creating policy group returned error: ${errorKey}"
|
}
|
}
|
|
static void newPolicyTemplate(Stem parentStem, String templateKey, String templateFriendlyName, String templateDescription, List<String> myServiceActionIds = []) {
|
// note that this doesn't work < 2.5.56 due to dependence on the UI
|
def policyStemTemplateContainer = new GroupStemTemplateContainer()
|
policyStemTemplateContainer.templateKey = templateKey
|
policyStemTemplateContainer.templateFriendlyName = templateFriendlyName
|
policyStemTemplateContainer.templateDescription = templateDescription
|
|
GrouperTemplatePolicyGroupLogic policyTemplateLogic = new GrouperTemplatePolicyGroupLogic()
|
policyTemplateLogic.stemId = parentStem.uuid
|
policyTemplateLogic.stemTemplateContainer = policyStemTemplateContainer
|
|
// simulate checking certain boxes in the ui
|
List<ServiceAction> selectedServiceActions = []
|
if (myServiceActionIds == null || myServiceActionIds.isEmpty()) {
|
selectedServiceActions = policyTemplateLogic.getServiceActions()
|
} else {
|
Map<String, ServiceAction> allPolicyServiceActionMap = policyTemplateLogic.getServiceActions().collectEntries { [it.id, it] }
|
selectedServiceActions = myServiceActionIds.collect { allPolicyServiceActionMap[it] }
|
}
|
|
policyTemplateLogic.validate(selectedServiceActions)
|
selectedServiceActions.each { serviceAction ->
|
serviceAction.getServiceActionType().createTemplateItem(serviceAction)
|
}
|
String policyErrorKey = policyTemplateLogic.postCreateSelectedActions(selectedServiceActions)
|
if (policyErrorKey != null) {
|
println "Creating policy group returned error: ${policyErrorKey}"
|
}
|
}
|
}
|
|
|
List<String> appServiceActionIds = [
|
'newAppStem',
|
'newAppServiceFolder',
|
'newAppPolicyFolder',
|
'newAppRefFolder',
|
'newAppRefType',
|
//'newAppAttributeFolder',
|
'newAppSecurityFolder',
|
'newAppSecurityType',
|
'newAppAdminsGroup',
|
'newAppAdminPrivilege',
|
'newAppAdminPrivilege2',
|
'newAppAdminPrivilege3',
|
'newAppReadersGroup',
|
'newAppReadersPrivilege',
|
'newAppUpdatersPrivilege',
|
'newAppUpdatersPrivilege2',
|
'newAppReadersGroupMemberOfUpdaters',
|
]
|
|
HelperMethods.newApplicationTemplate(appStem,
|
"grouper",
|
"Grouper",
|
"Policies for access to Grouper",
|
appServiceActionIds)
|
|
List<String> policyServiceActionIds = [
|
'policyGroupCreate',
|
'policyGroupType',
|
'policyGroupAllowGroupCreate',
|
'allowIntermediatgeGroupType',
|
'policyGroupAllowManualGroupCreate',
|
'policyGroupAddManualToAllow',
|
'allowManualGroupType',
|
'policyGroupDenyGroupCreate',
|
'denyIntermediatgeGroupType',
|
]
|
|
HelperMethods.newPolicyTemplate(policyStem,
|
"ui_access",
|
"Grouper UI access",
|
"Allows access to the Grouper UI",
|
policyServiceActionIds
|
)
|