private void addActionFromRouteElem ( ControllerRouteModel < Raml > elem , Resource resource ) { Action action = new Action ( ) ; action . setType ( ActionType . valueOf ( elem . getHttpMethod ( ) . name ( ) ) ) ; action . setDescription ( elem . getDescription ( ) ) ; //handle body addBodyToAction ( elem , action ) ; //Handle responses addResponsesToAction ( elem , action ) ; //handle all route params for ( RouteParamModel < Raml > param : elem . getParams ( ) ) { AbstractParam ap = null ; //the param to add //Fill the param info depending on its type switch ( param . getParamType ( ) ) { case FORM : MimeType formMime = action . getBody ( ) . get ( "application/x-www-form-urlencoded" ) ; if ( formMime == null ) { //create default form mimeType formMime = new MimeType ( "application/x-www-form-urlencoded" ) ; } if ( formMime . getFormParameters ( ) == null ) { //why raml, why you ain't init that formMime . setFormParameters ( new LinkedHashMap < String , List < FormParameter > > ( 2 ) ) ; } ap = new FormParameter ( ) ; formMime . getFormParameters ( ) . put ( param . getName ( ) , singletonList ( ( FormParameter ) ap ) ) ; break ; case PARAM : case PATH_PARAM : if ( ! ancestorOrIHasParam ( resource , param . getName ( ) ) ) { ap = new UriParameter ( ) ; resource . getUriParameters ( ) . put ( param . getName ( ) , ( UriParameter ) ap ) ; } //we do nothing if the param has already been define in the resouce or its ancestor. break ; case QUERY : ap = new QueryParameter ( ) ; action . getQueryParameters ( ) . put ( param . getName ( ) , ( QueryParameter ) ap ) ; break ; case BODY : default : break ; //body is handled at the method level. } if ( ap == null ) { //no param has been created, we skip. continue ; } //Set param type ParamType type = typeConverter ( param . getValueType ( ) ) ; if ( type != null ) { ap . setType ( type ) ; } //set required, usually thanks to the notnull constraints annotation. if ( param . isMandatory ( ) ) { ap . setRequired ( true ) ; } else { ap . setRequired ( false ) ; } //set minimum if specified if ( param . getMin ( ) != null ) { ap . setMinimum ( BigDecimal . valueOf ( param . getMin ( ) ) ) ; //TODO warn if type is not number/integer } //set maximum if specified if ( param . getMax ( ) != null ) { ap . setMinimum ( BigDecimal . valueOf ( param . getMax ( ) ) ) ; //TODO warn if type is not number/integer } //set default value if ( param . getDefaultValue ( ) != null ) { ap . setRequired ( false ) ; ap . setDefaultValue ( param . getDefaultValue ( ) ) ; } } resource . getActions ( ) . put ( action . getType ( ) , action ) ; }
Set the resource action from the wisdom route element .