use of com.iggroup.oss.restdoclet.doclet.type.ControllerSummary 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));
}
Aggregations