Search in sources :

Example 1 with Uri

use of com.iggroup.oss.restdoclet.doclet.type.Uri in project RESTdoclet by IG-Group.

the class RestDocumentationMojo method services.

/**
    * Generates services from the documentation of controllers and
    * data-binders.
    * 
    * @throws BeansNotFoundException if a bean with an identifier or Java type
    *            can't be found.
    * @throws IOException if services can't be marshaled.
    * @throws JavadocNotFoundException if a controller's documentation can't be
    *            found.
    * @throws JiBXException if a JiBX exception occurs.
    */
private void services() throws IOException, JavadocNotFoundException, JiBXException {
    LOG.info("Generating services");
    DirectoryBuilder dirs = new DirectoryBuilder(baseDirectory, outputDirectory);
    int identifier = 1;
    List<Service> services = new ArrayList<Service>();
    LOG.info("Looking for mappings");
    HashMap<String, ArrayList<Method>> uriMethodMappings = new HashMap<String, ArrayList<Method>>();
    HashMap<String, Controller> uriControllerMappings = new HashMap<String, Controller>();
    HashMap<String, Collection<Uri>> multiUriMappings = new HashMap<String, Collection<Uri>>();
    for (Controller controller : controllers) {
        LOG.info(new StringBuilder().append("- Controller ").append(controller.getType()).toString());
        for (Method method : controller.getMethods()) {
            LOG.info(new StringBuilder().append("... for Method ").append(method.toString()));
            if (excludeMethod(method)) {
                continue;
            }
            // Collate multiple uris into one string key.
            Collection<Uri> uris = method.getUris();
            if (!uris.isEmpty()) {
                String multiUri = "";
                for (Uri uri : uris) {
                    multiUri = multiUri + ", " + uri;
                }
                multiUriMappings.put(multiUri, uris);
                ArrayList<Method> methodList = uriMethodMappings.get(multiUri);
                if (methodList == null) {
                    methodList = new ArrayList<Method>();
                    uriMethodMappings.put(multiUri, methodList);
                }
                methodList.add(method);
                uriControllerMappings.put(multiUri, controller);
            }
        }
    }
    LOG.info("Processing controllers...");
    for (String uri : uriControllerMappings.keySet()) {
        LOG.info(new StringBuilder().append("Processing controllers for ").append(uri).toString());
        Controller controller = uriControllerMappings.get(uri);
        LOG.info(new StringBuilder().append("Found controller ").append(uriControllerMappings.get(uri).getType()).toString());
        ArrayList<Method> matches = uriMethodMappings.get(uri);
        LOG.info(new StringBuilder().append("Found methods ").append(matches.toString()).append(" ").append(matches.size()).toString());
        Service service = new Service(identifier, multiUriMappings.get(uri), new Controller(controller.getType(), controller.getJavadoc(), matches));
        services.add(service);
        service.assertValid();
        JiBXUtils.marshallService(service, ServiceUtils.serviceFile(dirs, identifier));
        identifier++;
    }
    LOG.info("Processing services...");
    Services list = new Services();
    for (Service service : services) {
        org.apache.commons.collections.Predicate predicate = new ControllerTypePredicate(service.getController().getType());
        if (CollectionUtils.exists(list.getControllers(), predicate)) {
            ControllerSummary controller = (ControllerSummary) CollectionUtils.find(list.getControllers(), predicate);
            controller.addService(service);
        } else {
            ControllerSummary controller = new ControllerSummary(service.getController().getType(), service.getController().getJavadoc());
            controller.addService(service);
            list.addController(controller);
        }
    }
    LOG.info("Marshalling services...");
    list.assertValid();
    JiBXUtils.marshallServices(list, ServiceUtils.servicesFile(dirs));
}
Also used : HashMap(java.util.HashMap) ControllerTypePredicate(com.iggroup.oss.restdoclet.doclet.util.ControllerTypePredicate) ArrayList(java.util.ArrayList) Service(com.iggroup.oss.restdoclet.doclet.type.Service) Method(com.iggroup.oss.restdoclet.doclet.type.Method) Controller(com.iggroup.oss.restdoclet.doclet.type.Controller) DirectoryBuilder(com.iggroup.oss.restdoclet.plugin.io.DirectoryBuilder) Uri(com.iggroup.oss.restdoclet.doclet.type.Uri) Services(com.iggroup.oss.restdoclet.doclet.type.Services) Collection(java.util.Collection) ControllerSummary(com.iggroup.oss.restdoclet.doclet.type.ControllerSummary)

Example 2 with Uri

use of com.iggroup.oss.restdoclet.doclet.type.Uri in project RESTdoclet by IG-Group.

the class ServiceConfig method getServiceByUri.

/**
    * Get a service by application name and service URI and operation name
    * (GETP, PUT, POST,...)
    * 
    * @param applicationName
    * @param id
    * @return service
    * @throws FileNotFoundException
    * @throws JiBXException parsing error
    */
public static Service getServiceByUri(final String applicationName, final String uri) throws FileNotFoundException, JiBXException {
    LOGGER.debug("getServiceByUri " + configPath + " - " + applicationName + " - " + uri);
    Services services;
    File servicesConfigFile = new File(configPath + File.separator + applicationName + File.separator + "restdoc-services.xml");
    services = JiBXUtils.unmarshallServices(new FileInputStream(servicesConfigFile));
    for (Service service : services.getServices()) {
        LOGGER.debug(service.getContext() + " - " + service.getUris() + " - " + service.getIdentifier());
        for (Uri serviceUri : service.getUris()) {
            LOGGER.debug(serviceUri);
            if (serviceUri.getUri().equalsIgnoreCase(uri)) {
                LOGGER.debug("match");
                return getService(applicationName, Integer.toString(service.getIdentifier()));
            }
        }
    }
    return null;
}
Also used : Services(com.iggroup.oss.restdoclet.doclet.type.Services) Service(com.iggroup.oss.restdoclet.doclet.type.Service) File(java.io.File) Uri(com.iggroup.oss.restdoclet.doclet.type.Uri) FileInputStream(java.io.FileInputStream)

Example 3 with Uri

use of com.iggroup.oss.restdoclet.doclet.type.Uri 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)

Example 4 with Uri

use of com.iggroup.oss.restdoclet.doclet.type.Uri in project RESTdoclet by IG-Group.

the class ServiceConfig method findServices.

/**
    * Find services with URI's containing the given search term
    * 
    * @param searchTerm
    * @return list of service summary objects
    * @throws FileNotFoundException
    * @throws JiBXException if the service configuration files don't parse
    */
public static Collection<Service> findServices(final String searchTerm) throws FileNotFoundException, JiBXException {
    LOGGER.info("Searching for " + searchTerm);
    Collection<Service> matchingServices = new ArrayList<Service>();
    String lowerSearchTerm = searchTerm.toLowerCase();
    for (String application : getApplicationNames()) {
        for (Service service : getServices(application)) {
            for (Uri uri : service.getUris()) {
                if (uri.getUri().contains(lowerSearchTerm)) {
                    matchingServices.add(service);
                }
            }
        }
    }
    return matchingServices;
}
Also used : ArrayList(java.util.ArrayList) Service(com.iggroup.oss.restdoclet.doclet.type.Service) Uri(com.iggroup.oss.restdoclet.doclet.type.Uri)

Aggregations

Uri (com.iggroup.oss.restdoclet.doclet.type.Uri)4 Service (com.iggroup.oss.restdoclet.doclet.type.Service)3 ArrayList (java.util.ArrayList)3 Services (com.iggroup.oss.restdoclet.doclet.type.Services)2 Controller (com.iggroup.oss.restdoclet.doclet.type.Controller)1 ControllerSummary (com.iggroup.oss.restdoclet.doclet.type.ControllerSummary)1 Method (com.iggroup.oss.restdoclet.doclet.type.Method)1 RestParameter (com.iggroup.oss.restdoclet.doclet.type.RestParameter)1 ControllerTypePredicate (com.iggroup.oss.restdoclet.doclet.util.ControllerTypePredicate)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 DirectoryBuilder (com.iggroup.oss.restdoclet.plugin.io.DirectoryBuilder)1 AnnotationValue (com.sun.javadoc.AnnotationValue)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Predicate (org.apache.commons.collections.Predicate)1