[ 
https://issues.apache.org/jira/browse/SOLR-183?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12478508
 ] 

Hoss Man commented on SOLR-183:
-------------------------------

Ryan: this patch is nice and simple ... but it has me wondering if it might be 
more generally usefull to have this in a SolrParams decorator that applied it 
at the outermost level to all of the methods which don't take in a default? ...

  SolrParams myParams = ...  
  myParams = new RequiredSolrParams(myParams, "sort", "q", "qf", 
"f.foo.facet.limit");

...

  public class RequiredSolrParams extends SolrParams {
    ...
    SolrParams nested;
    Set<String> required;
    ...
    public String get(String param) {
      String val = nester.get(param);
      if (null == val) throw new SolrException( 400, "Missing parameter: 
"+param );
      return val; 
    }
    ...
    public String get(String param, String def) {
       return nested.get(param, def); // bypass exception throwing when default
    }
    ...
  }


?

> add getRequiredParameter() to SolrParams
> ----------------------------------------
>
>                 Key: SOLR-183
>                 URL: https://issues.apache.org/jira/browse/SOLR-183
>             Project: Solr
>          Issue Type: Wish
>            Reporter: Ryan McKinley
>            Priority: Trivial
>         Attachments: SOLR-183-required-param.patch
>
>
> I find myself including this with every patch, so i'll just separate it out.  
> This simply adds a utilty function to SolrParams that throws a 400 if the 
> parameter is missing:
> /** returns the value of the param, or throws a 400 exception if missing */
>   public String getRequiredParameter(String param) throws SolrException {
>     String val = get(param);
>     if( val == null ) {
>       throw new SolrException( 400, "Missing parameter: "+param );
>     }
>     return val;
>   }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to