Search in sources :

Example 1 with ParameterNamePredicate

use of com.iggroup.oss.restdoclet.doclet.util.ParameterNamePredicate in project RESTdoclet by IG-Group.

the class MethodBuilder method initRestParams.

/**
    * Initialises the REST-parameters of this method.
    * 
    * @param method method to initialise
    * @param methodDoc the method's Java documentation object.
    * @param baseUri the controller base uri
    */
private void initRestParams(Method method, final MethodDoc methodDoc, final String baseUri) {
    LOG.debug(method.getName());
    ArrayList<RestParameter> restParams = new ArrayList<RestParameter>();
    for (NameValuePair pair : new RequestMappingParamsParser(elementValue(methodDoc, RequestMapping.class, "params")).parse()) {
        final Predicate predicate = new ParameterNamePredicate(pair.getName());
        if (!CollectionUtils.exists(method.getRequestParams(), predicate)) {
            LOG.debug(pair.getName() + " - " + pair.getValue());
            restParams.add(new RestParameter(pair));
        }
    }
    AnnotationValue urlAnnotation = elementValue(methodDoc, RequestMapping.class, "value");
    if (urlAnnotation != null) {
        Boolean deprecatedMatch = false;
        String[] methodUris = parseValueAnnotation(urlAnnotation);
        String[] deprecatedURIs = DocTypeUtils.getDeprecatedURIs(methodDoc);
        for (final String uri : methodUris) {
            LOG.debug("uri:" + baseUri + uri);
            boolean deprecated = false;
            if (deprecatedURIs != null) {
                for (final String deprecatedUri : deprecatedURIs) {
                    LOG.debug("deprecated:" + deprecatedUri);
                    if (StringUtils.equals(deprecatedUri, uri)) {
                        LOG.debug("=DEPRECATED");
                        deprecated = true;
                        deprecatedMatch = true;
                        break;
                    }
                }
            }
            method.getUris().add(new Uri(baseUri + uri, deprecated));
        }
        if (deprecatedURIs != null && !deprecatedMatch) {
            LOG.warn("Deprecated URI tag on method " + methodDoc.name() + " does not match any service URIs.");
        }
    }
    method.setRestParams(restParams);
}
Also used : NameValuePair(com.iggroup.oss.restdoclet.doclet.util.NameValuePair) ArrayList(java.util.ArrayList) RequestMappingParamsParser(com.iggroup.oss.restdoclet.doclet.util.RequestMappingParamsParser) Uri(com.iggroup.oss.restdoclet.doclet.type.Uri) Predicate(org.apache.commons.collections.Predicate) ParameterNamePredicate(com.iggroup.oss.restdoclet.doclet.util.ParameterNamePredicate) RestParameter(com.iggroup.oss.restdoclet.doclet.type.RestParameter) AnnotationValue(com.sun.javadoc.AnnotationValue) ParameterNamePredicate(com.iggroup.oss.restdoclet.doclet.util.ParameterNamePredicate)

Aggregations

RestParameter (com.iggroup.oss.restdoclet.doclet.type.RestParameter)1 Uri (com.iggroup.oss.restdoclet.doclet.type.Uri)1 NameValuePair (com.iggroup.oss.restdoclet.doclet.util.NameValuePair)1 ParameterNamePredicate (com.iggroup.oss.restdoclet.doclet.util.ParameterNamePredicate)1 RequestMappingParamsParser (com.iggroup.oss.restdoclet.doclet.util.RequestMappingParamsParser)1 AnnotationValue (com.sun.javadoc.AnnotationValue)1 ArrayList (java.util.ArrayList)1 Predicate (org.apache.commons.collections.Predicate)1