private void applySeverityAndParamToChange ( RuleActivation request , RuleActivationContext context , ActiveRuleChange change ) { RuleWrapper rule = context . getRule ( ) ; ActiveRuleWrapper activeRule = context . getActiveRule ( ) ; ActiveRuleWrapper parentActiveRule = context . getParentActiveRule ( ) ; // First apply severity String severity ; if ( request . isReset ( ) ) { // load severity from parent profile, else from default values severity = firstNonNull ( parentActiveRule != null ? parentActiveRule . get ( ) . getSeverityString ( ) : null , rule . get ( ) . getSeverityString ( ) ) ; } else if ( context . getRulesProfile ( ) . isBuiltIn ( ) ) { // for builtin quality profiles, the severity from profile, when null use the default severity of the rule severity = firstNonNull ( request . getSeverity ( ) , rule . get ( ) . getSeverityString ( ) ) ; } else { // load severity from request, else keep existing one (if already activated), else from parent, else from default severity = firstNonNull ( request . getSeverity ( ) , activeRule == null ? null : activeRule . get ( ) . getSeverityString ( ) , parentActiveRule != null ? parentActiveRule . get ( ) . getSeverityString ( ) : null , rule . get ( ) . getSeverityString ( ) ) ; } change . setSeverity ( severity ) ; // Apply param values for ( RuleParamDto ruleParamDto : rule . getParams ( ) ) { String paramKey = ruleParamDto . getName ( ) ; String paramValue ; if ( request . isReset ( ) ) { // load params from parent profile, else from default values paramValue = firstNonNull ( parentActiveRule != null ? parentActiveRule . getParamValue ( paramKey ) : null , rule . getParamDefaultValue ( paramKey ) ) ; } else if ( context . getRulesProfile ( ) . isBuiltIn ( ) ) { // use the value defined in the profile definition, else the rule default value paramValue = firstNonNull ( context . getRequestedParamValue ( request , paramKey ) , rule . getParamDefaultValue ( paramKey ) ) ; } else { String parentValue = parentActiveRule != null ? parentActiveRule . getParamValue ( paramKey ) : null ; String activeRuleValue = activeRule == null ? null : activeRule . getParamValue ( paramKey ) ; paramValue = context . hasRequestedParamValue ( request , paramKey ) ? // If the request contains the parameter then we're using either value from request, or parent value, or default value firstNonNull ( context . getRequestedParamValue ( request , paramKey ) , parentValue , rule . getParamDefaultValue ( paramKey ) ) // If the request doesn't contain the parameter, then we're using either value in DB, or parent value, or default value : firstNonNull ( activeRuleValue , parentValue , rule . getParamDefaultValue ( paramKey ) ) ; } change . setParameter ( paramKey , validateParam ( ruleParamDto , paramValue ) ) ; } }
Update severity and params