Search in sources :

Example 1 with ApiField

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

the class ApiClassDiffTests method generateMergedList.

/**
 * Generates a merged list with changes
 */
public static List<ApiField> generateMergedList(List<ApiField> sequenceA, List<ApiField> sequenceB) {
    int[][] lcs = computeLcs(sequenceA, sequenceB);
    List<ApiField> mergedFields = Lists.newArrayList();
    int aPos = sequenceA.size();
    int bPos = sequenceB.size();
    while (aPos > 0 || bPos > 0) {
        if (aPos > 0 && bPos > 0 && sequenceA.get(aPos - 1).compareTo(sequenceB.get(bPos - 1)) == 0) {
            ApiField field = sequenceA.get(aPos - 1);
            field.changeState = ChangeState.NOT_CHANGED;
            mergedFields.add(field);
            aPos--;
            bPos--;
        } else if (bPos > 0 && (aPos == 0 || lcs[aPos][bPos - 1] >= lcs[aPos - 1][bPos])) {
            ApiField field = sequenceB.get(bPos - 1);
            field.changeState = ChangeState.ADDED;
            mergedFields.add(field);
            bPos--;
        } else {
            ApiField field = sequenceA.get(aPos - 1);
            field.changeState = ChangeState.REMOVED;
            mergedFields.add(field);
            aPos--;
        }
    }
    // Backtracking generates the list from back to front,
    // so reverse it to get front-to-back.
    Collections.reverse(mergedFields);
    return mergedFields;
}
Also used : ApiField(com.emc.apidocs.model.ApiField)

Example 2 with ApiField

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

the class ApiClassDiffTests method main.

public static void main(String[] args) throws Exception {
    List<ApiField> sequenceA = Lists.newArrayList(newField("A"), newField("B"), newField("P"), newField("C"));
    List<ApiField> sequenceB = Lists.newArrayList(newField("A"), newField("B"), newField("E"), newField("D"), newField("C"));
    List<ApiField> diffList = generateMergedList(sequenceA, sequenceB);
    System.out.println("OUTPUT : ");
    for (ApiField s : diffList) {
        switch(s.changeState) {
            case NOT_CHANGED:
                System.out.print("- ");
                break;
            case REMOVED:
                System.out.print("< ");
                break;
            case ADDED:
                System.out.print("> ");
                break;
        }
        System.out.println(s.name);
    }
    ApiClass apiClass = new ApiClass();
    apiClass.fields = diffList;
    System.out.println("CONTAINS CHANGES :" + containsChanges(apiClass));
}
Also used : ApiClass(com.emc.apidocs.model.ApiClass) ApiField(com.emc.apidocs.model.ApiField)

Example 3 with ApiField

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

the class MethodProcessor method addDataServiceInformation.

/**
 * Data services mainly use headers, and thus the @param comments contain more information than usual
 */
public static void addDataServiceInformation(MethodDoc method, ApiMethod apiMethod) {
    Tag[] urlFormat = method.tags("@UrlFormat");
    if (urlFormat.length > 0) {
        apiMethod.urlFormat = urlFormat[0].text();
        // Update method path as Data service paths can't be picked up from the code
        if (apiMethod.urlFormat.startsWith(S3_URL_FORMAT)) {
            // S3 services have a URL format that's more comment style, so need to extract it
            int hostStyleEnd = apiMethod.urlFormat.indexOf("\n");
            apiMethod.path = apiMethod.urlFormat.substring(S3_URL_FORMAT.length(), hostStyleEnd);
        } else if (apiMethod.urlFormat.startsWith(ATMOS_URL_FORMAT)) {
            // S3 services have a URL format that's more comment style, so need to extract it
            int hostStyleEnd = apiMethod.urlFormat.indexOf("\n");
            apiMethod.path = apiMethod.urlFormat.substring(ATMOS_URL_FORMAT.length(), hostStyleEnd);
        } else {
            apiMethod.path = Utils.mergePaths(apiMethod.path, apiMethod.urlFormat);
        }
    }
    for (Tag tag : method.tags("@param")) {
        if (tag.text().startsWith("request") || tag.text().startsWith("response")) {
            try {
                Matcher param = DATA_SERVICE_PARAM_PATTERN.matcher(tag.text());
                if (param.find()) {
                    if (!param.group(4).equals("")) {
                        ApiField desc = new ApiField();
                        desc.name = param.group(3);
                        desc.primitiveType = param.group(6);
                        desc.min = Integer.valueOf(param.group(4));
                        desc.max = Integer.valueOf(param.group(5));
                        desc.description = param.group(7);
                        // Now find out where it goes
                        if (param.group(1).equals("request")) {
                            if (param.group(2) == null || param.group(2).equals("Header")) {
                                apiMethod.headerParameters.add(desc);
                            }
                        } else {
                            if (param.group(2) == null || param.group(2).equals("Header")) {
                                apiMethod.responseHeaders.add(desc);
                            }
                        }
                    } else {
                        DocReporter.printWarning("Ignoring :" + tag.text());
                    }
                } else {
                    DocReporter.printWarning("Data Services parameter did not match RegEx pattern");
                    DocReporter.printWarning(tag.text());
                }
            } catch (Exception e) {
                DocReporter.printError(tag.text());
                throw new RuntimeException(e);
            }
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) Tag(com.sun.javadoc.Tag) ParamTag(com.sun.javadoc.ParamTag) ApiField(com.emc.apidocs.model.ApiField)

Example 4 with ApiField

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

the class EnunciateFileReader method toApiField.

private ApiField toApiField(Node elementNode) {
    ApiField apiField = new ApiField();
    apiField.name = XMLUtils.getNodeText(elementNode, EnunciateConstants.ELEMENT_NAME);
    String typeName = XMLUtils.getNodeText(elementNode, EnunciateConstants.ELEMENT_CHOICE_TYPENAME);
    if (typeName == null) {
        typeName = XMLUtils.getNodeText(elementNode, EnunciateConstants.ELEMENT_TYPENAME);
    }
    if (typeName != null) {
        boolean isPrimitive = typeName.equals("string") || typeName.equals("dateTime") || typeName.equals("long") || typeName.equals("boolean") || typeName.equals("int") || typeName.equals("double");
        if (isPrimitive) {
            apiField.primitiveType = typeName;
        } else {
            apiField.type = loadType(typeName, elementNode.getOwnerDocument());
        }
    } else {
        System.out.println("Warning: Unable to find typeName for element " + apiField.name);
    }
    return apiField;
}
Also used : ApiField(com.emc.apidocs.model.ApiField)

Example 5 with ApiField

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

the class ApiPrimitiveMaker method makeResponseParameters.

/**
 * Make the parameters in this response entity
 *
 * @param fieldName
 *            output field name generator
 * @param prefix
 *            A prefix to prepend the output field name
 * @param field
 *            The field in this response
 * @return A list of fields in the response entity
 */
private static ImmutableList<FieldSpec> makeResponseParameters(final ParameterFieldName.Output fieldName, final String prefix, final ApiField field) {
    final ImmutableList.Builder<FieldSpec> builder = ImmutableList.<FieldSpec>builder();
    final String parameterName = makeOutputParameterName(prefix, field);
    if (field.isPrimitive()) {
        builder.add(makeOutputParameter(fieldName, parameterName, field));
    } else {
        for (ApiField subField : field.type.fields) {
            builder.addAll(makeResponseParameters(fieldName, parameterName, subField));
        }
    }
    return builder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) FieldSpec(com.squareup.javapoet.FieldSpec) ApiField(com.emc.apidocs.model.ApiField)

Aggregations

ApiField (com.emc.apidocs.model.ApiField)18 FieldSpec (com.squareup.javapoet.FieldSpec)4 ApiClass (com.emc.apidocs.model.ApiClass)3 ImmutableList (com.google.common.collect.ImmutableList)3 Builder (com.google.common.collect.ImmutableList.Builder)2 ParamTag (com.sun.javadoc.ParamTag)2 Matcher (java.util.regex.Matcher)2 CustomServicesConstants (com.emc.storageos.primitives.CustomServicesConstants)1 BasicInputParameter (com.emc.storageos.primitives.input.BasicInputParameter)1 InputParameter (com.emc.storageos.primitives.input.InputParameter)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ClassDoc (com.sun.javadoc.ClassDoc)1 FieldDoc (com.sun.javadoc.FieldDoc)1 MemberDoc (com.sun.javadoc.MemberDoc)1 MethodDoc (com.sun.javadoc.MethodDoc)1 Parameter (com.sun.javadoc.Parameter)1 Tag (com.sun.javadoc.Tag)1 List (java.util.List)1 Map (java.util.Map)1 Node (org.w3c.dom.Node)1