Search in sources :

Example 6 with ApiMethod

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

the class RouteParserTests method testPlayParser.

@Test
@Ignore
public void testPlayParser() {
    Collection<ApiService> services = PlayRoutesParser.getPortalServices("/Users/maddid/SourceCode/bourne/isa/portal");
    boolean executionWindowsFound = false;
    boolean approvalsFound = false;
    for (ApiService service : services) {
        // System.out.println(service.path+"  "+service.getTitle());
        for (ApiMethod method : service.methods) {
            // System.out.println(method.httpMethod+"  "+method.path+"  "+method.getTitle());
            if (method.path.equals("/admin/api/executionwindows")) {
                // An admin service found
                executionWindowsFound = true;
            }
            if (method.path.equals("/api/approvals")) {
                // a Non Admin service Found
                approvalsFound = true;
            }
        }
    }
    TestCase.assertTrue(executionWindowsFound);
    TestCase.assertTrue(approvalsFound);
}
Also used : ApiService(com.emc.apidocs.model.ApiService) ApiMethod(com.emc.apidocs.model.ApiMethod) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with ApiMethod

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

the class SerializationTests method main.

public static void main(String[] args) throws Exception {
    ApiService service = new ApiService();
    service.javaClassName = "Dave";
    service.path = "/wobble";
    ApiMethod method = new ApiMethod();
    method.httpMethod = "GET";
    method.path = "/wobble/fred";
    service.addMethod(method);
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    String asJson = gson.toJson(service);
    System.out.println(asJson);
    ApiService back = gson.fromJson(asJson, ApiService.class);
    System.out.println(back.getFqJavaClassName() + " " + back.methods.size());
}
Also used : ApiService(com.emc.apidocs.model.ApiService) GsonBuilder(com.google.gson.GsonBuilder) ApiMethod(com.emc.apidocs.model.ApiMethod) Gson(com.google.gson.Gson)

Example 8 with ApiMethod

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

the class EnunciateFileReader method toApiMethod.

public ApiMethod toApiMethod(Node resourceNode, Map<String, ApiClass> types) {
    ApiMethod apiMethod = new ApiMethod();
    apiMethod.httpMethod = XMLUtils.getNodeText(resourceNode, EnunciateConstants.RESOURCE_HTTP_OPERATION);
    apiMethod.path = XMLUtils.getNodeText(resourceNode, EnunciateConstants.RESOURCE_PATH);
    String requestElementName = XMLUtils.getNodeText(resourceNode, EnunciateConstants.RESOURCE_REQUEST_ELEMENT_TYPE);
    if (requestElementName != null) {
        apiMethod.input = findElementType(requestElementName, types, resourceNode.getOwnerDocument());
    }
    String responseElementName = XMLUtils.getNodeText(resourceNode, EnunciateConstants.RESOURCE_RESPONSE_ELEMENT_TYPE);
    if (responseElementName != null) {
        apiMethod.output = findElementType(responseElementName, types, resourceNode.getOwnerDocument());
    }
    return apiMethod;
}
Also used : ApiMethod(com.emc.apidocs.model.ApiMethod)

Example 9 with ApiMethod

use of com.emc.apidocs.model.ApiMethod 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 10 with ApiMethod

use of com.emc.apidocs.model.ApiMethod 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)

Aggregations

ApiMethod (com.emc.apidocs.model.ApiMethod)10 ApiService (com.emc.apidocs.model.ApiService)8 ApiReferenceTocOrganizer (com.emc.apidocs.generating.ApiReferenceTocOrganizer)2 List (java.util.List)2 EnunciateFileReader (com.emc.apidocs.differencing.EnunciateFileReader)1 ApiClass (com.emc.apidocs.model.ApiClass)1 ApiDifferences (com.emc.apidocs.model.ApiDifferences)1 ApiServiceChanges (com.emc.apidocs.model.ApiServiceChanges)1 ImmutableList (com.google.common.collect.ImmutableList)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 JavaFile (com.squareup.javapoet.JavaFile)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Matcher (java.util.regex.Matcher)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1