Search in sources :

Example 11 with ApiService

use of com.emc.apidocs.model.ApiService in project coprhd-controller by CoprHD.

the class EnunciateFileReader method loadServices.

private Map<String, ApiService> loadServices(Document document) {
    Map<String, ApiClass> apiClasses = loadTypes(document);
    Map<String, ApiService> apiServices = Maps.newHashMap();
    NodeList resourceNodes = XMLUtils.getNodeList(document, EnunciateConstants.RESOURCES);
    for (int f = 0; f < resourceNodes.getLength(); f++) {
        Node resourceNode = resourceNodes.item(f);
        String serviceClass = XMLUtils.getNodeText(resourceNode, EnunciateConstants.RESOURCE_SERVICE_CLASS);
        ApiService apiService = null;
        if (apiClasses.containsKey(serviceClass)) {
            apiService = apiServices.get(serviceClass);
        } else {
            apiService = new ApiService();
            apiService.javaClassName = serviceClass;
            apiServices.put(serviceClass, apiService);
        }
        ApiMethod apiMethod = toApiMethod(resourceNode, apiClasses);
        System.out.println("Loaded Method " + serviceClass + " " + apiMethod.httpMethod + " " + apiMethod.path);
        apiService.addMethod(apiMethod);
    }
    return apiServices;
}
Also used : ApiService(com.emc.apidocs.model.ApiService) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ApiMethod(com.emc.apidocs.model.ApiMethod) ApiClass(com.emc.apidocs.model.ApiClass)

Example 12 with ApiService

use of com.emc.apidocs.model.ApiService in project coprhd-controller by CoprHD.

the class ApiReferenceTocOrganizer method organizeServices.

public Map<String, List<ApiService>> organizeServices(List<ApiService> services) {
    List<ApiService> allServices = Lists.newArrayList(services);
    Map<String, List<ApiService>> sortedServices = Maps.newLinkedHashMap();
    // Data Services appear in a different section
    removeObjectDataServices(allServices);
    for (Map.Entry<String, List<String>> entry : groups.entrySet()) {
        List<ApiService> categoryServices = Lists.newArrayList();
        List<ApiService> foundServices = Lists.newArrayList();
        for (String serviceName : entry.getValue()) {
            for (ApiService service : allServices) {
                // Find the service in the list of services
                if (service.getFqJavaClassName().equals(serviceName) || service.javaClassName.equals(serviceName)) {
                    foundServices.add(service);
                    categoryServices.add(service);
                }
            }
        }
        if (!categoryServices.isEmpty()) {
            // Only include non-empty categories
            sortedServices.put(entry.getKey(), categoryServices);
        }
        allServices.removeAll(foundServices);
    }
    // Generate an Exception for non-assigned services
    if (!allServices.isEmpty()) {
        String servicesLeft = "";
        for (ApiService service : allServices) {
            servicesLeft = servicesLeft + "\n" + service.getFqJavaClassName();
        }
        throw new RuntimeException(servicesLeft + " not assigned to any TOC category in ApiReferenceGrouping.txt");
    }
    return sortedServices;
}
Also used : ApiService(com.emc.apidocs.model.ApiService) List(java.util.List) Map(java.util.Map)

Example 13 with ApiService

use of com.emc.apidocs.model.ApiService in project coprhd-controller by CoprHD.

the class ApiPrimitiveMaker method makePrimitives.

/**
 * Accept a list of ApiServices and make primitives for each HTTP method in
 * the service
 *
 * @param services
 *            - a list of services
 *
 * @return a JavaFile representing java source code for the primitive
 */
public static Iterable<JavaFile> makePrimitives(final List<ApiService> services) {
    final Builder<JavaFile> builder = ImmutableList.<JavaFile>builder();
    final ApiReferenceTocOrganizer grouping = new ApiReferenceTocOrganizer(KnownPaths.getReferenceFile("ApiReferenceGrouping.txt"));
    final Map<String, List<ApiService>> groups = grouping.organizeServices(services);
    for (final Entry<String, List<ApiService>> groupEntry : groups.entrySet()) {
        for (final ApiService service : groupEntry.getValue()) {
            for (final ApiMethod method : service.methods) {
                if (blackListed(method)) {
                    _log.info("Method " + method.apiService.getFqJavaClassName() + "::" + method.javaMethodName + " is black listed");
                } else if (method.isDeprecated) {
                    _log.info("Method " + method.apiService.getFqJavaClassName() + "::" + method.javaMethodName + " is deprecated");
                } else {
                    builder.add(makePrimitive(groupEntry.getKey(), method));
                }
            }
        }
    }
    return builder.build();
}
Also used : ApiService(com.emc.apidocs.model.ApiService) ApiMethod(com.emc.apidocs.model.ApiMethod) JavaFile(com.squareup.javapoet.JavaFile) ApiReferenceTocOrganizer(com.emc.apidocs.generating.ApiReferenceTocOrganizer) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Example 14 with ApiService

use of com.emc.apidocs.model.ApiService in project coprhd-controller by CoprHD.

the class ApiDoclet method start.

/**
 * MAIN Entry Point into the Doclet
 */
public static boolean start(RootDoc root) {
    KnownPaths.init(contentDirectory, outputDirectory);
    init();
    loadServiceBlackList();
    loadMethodBlackList();
    List<ApiService> apiServices = findApiServices(root.classes());
    List<ApiErrorCode> errorCodes = findErrorCodes(root.classes());
    cleanupMethods(apiServices);
    saveMetaData(apiServices);
    ApiDifferences apiDifferences = calculateDifferences(apiServices);
    generateFiles(apiDifferences, apiServices, errorCodes);
    return true;
}
Also used : ApiService(com.emc.apidocs.model.ApiService) ApiDifferences(com.emc.apidocs.model.ApiDifferences) ApiErrorCode(com.emc.apidocs.model.ApiErrorCode)

Aggregations

ApiService (com.emc.apidocs.model.ApiService)14 ApiMethod (com.emc.apidocs.model.ApiMethod)8 File (java.io.File)3 List (java.util.List)3 ApiReferenceTocOrganizer (com.emc.apidocs.generating.ApiReferenceTocOrganizer)2 ApiDifferences (com.emc.apidocs.model.ApiDifferences)2 ImmutableList (com.google.common.collect.ImmutableList)2 JavaFile (com.squareup.javapoet.JavaFile)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 DifferenceEngine (com.emc.apidocs.differencing.DifferenceEngine)1 EnunciateFileReader (com.emc.apidocs.differencing.EnunciateFileReader)1 ApiClass (com.emc.apidocs.model.ApiClass)1 ApiErrorCode (com.emc.apidocs.model.ApiErrorCode)1 ApiServiceChanges (com.emc.apidocs.model.ApiServiceChanges)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 Map (java.util.Map)1