public static void generatePolicyDescription ( PolicyBean policy ) throws Exception { PolicyDefinitionBean def = policy . getDefinition ( ) ; PolicyDefinitionTemplateBean templateBean = getTemplateBean ( def ) ; if ( templateBean == null ) { return ; } String cacheKey = def . getId ( ) + "::" + templateBean . getLanguage ( ) ; //$NON-NLS-1$ CompiledTemplate template = templateCache . get ( cacheKey ) ; if ( template == null ) { template = TemplateCompiler . compileTemplate ( templateBean . getTemplate ( ) ) ; templateCache . put ( cacheKey , template ) ; } try { // TODO hack to fix broken descriptions - this util should probably not know about encrypted data String jsonConfig = policy . getConfiguration ( ) ; if ( CurrentDataEncrypter . instance != null ) { EntityType entityType = EntityType . Api ; if ( policy . getType ( ) == PolicyType . Client ) { entityType = EntityType . ClientApp ; } else if ( policy . getType ( ) == PolicyType . Plan ) { entityType = EntityType . Plan ; } DataEncryptionContext ctx = new DataEncryptionContext ( policy . getOrganizationId ( ) , policy . getEntityId ( ) , policy . getEntityVersion ( ) , entityType ) ; jsonConfig = CurrentDataEncrypter . instance . decrypt ( jsonConfig , ctx ) ; } Map < String , Object > configMap = mapper . readValue ( jsonConfig , Map . class ) ; configMap = new PolicyConfigMap ( configMap ) ; String desc = ( String ) TemplateRuntime . execute ( template , configMap ) ; policy . setDescription ( desc ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; // TODO properly log the error policy . setDescription ( templateBean . getTemplate ( ) ) ; } }
Generates a dynamic description for the given policy and stores the result on the policy bean instance . This should be done prior to returning the policybean back to the user for a REST call to the management API .