Api docs: single row per VPP API message 72/7772/1
authorMarek Gradzki <[email protected]>
Tue, 25 Jul 2017 13:44:21 +0000 (15:44 +0200)
committerMarek Gradzki <[email protected]>
Tue, 25 Jul 2017 14:23:02 +0000 (16:23 +0200)
Lists all of supported CUD operations in single cell.

Change-Id: I5f23200d869221f797ed8b4b5ca0512baa92486b
Signed-off-by: Marek Gradzki <[email protected]>
release-notes/src/main/asciidoc/api_docs/api_docs_index.adoc
vpp-integration/api-docs/api/src/main/java/io/fd/hc2vpp/docs/api/CoverageUnit.java
vpp-integration/api-docs/api/src/main/java/io/fd/hc2vpp/docs/api/JavaApiMessage.java
vpp-integration/api-docs/core/src/main/java/io/fd/hc2vpp/docs/core/CoverageGenerator.java
vpp-integration/api-docs/core/src/main/java/io/fd/hc2vpp/docs/core/PluginMethodReference.java
vpp-integration/api-docs/scripts/src/main/groovy/io/fd/hc2vpp/docs/scripts/ApiDocsIndexGenerator.groovy

index 08dfeb2..a9029d6 100644 (file)
@@ -1,4 +1,4 @@
-== VPP api to Yang index
+== VPP API to Yang index
 
 // TODO - generate this file based on list of JVPP plugins used
 
index 06cb59f..e04d283 100644 (file)
 
 package io.fd.hc2vpp.docs.api;
 
+import java.util.Collection;
 import java.util.List;
 import java.util.Objects;
+import java.util.Set;
 
 /**
  * Represents mapping between single supported VPP binary api and its binding
@@ -42,11 +44,11 @@ public class CoverageUnit {
     /**
      * Operations supported for this api
      */
-    private final List<Operation> supportedOperations;
+    private final Collection<Operation> supportedOperations;
 
     private CoverageUnit(final VppApiMessage vppApi, final JavaApiMessage javaApi,
                          final List<YangType> yangTypes,
-                         final List<Operation> supportedOperations) {
+                         final Collection<Operation> supportedOperations) {
         this.vppApi = vppApi;
         this.javaApi = javaApi;
         this.yangTypes = yangTypes;
@@ -65,7 +67,7 @@ public class CoverageUnit {
         return yangTypes;
     }
 
-    public List<Operation> getSupportedOperations() {
+    public Collection<Operation> getSupportedOperations() {
         return supportedOperations;
     }
 
@@ -95,7 +97,7 @@ public class CoverageUnit {
         private VppApiMessage vppApi;
         private JavaApiMessage javaApi;
         private List<YangType> yangTypes;
-        private List<Operation> supportedOperations;
+        private Set<Operation> supportedOperations;
 
         public CoverageUnitBuilder setVppApi(final VppApiMessage vppApi) {
             this.vppApi = vppApi;
@@ -112,7 +114,7 @@ public class CoverageUnit {
             return this;
         }
 
-        public CoverageUnitBuilder setSupportedOperations(final List<Operation> supportedOperations) {
+        public CoverageUnitBuilder setSupportedOperations(final Set<Operation> supportedOperations) {
             this.supportedOperations = supportedOperations;
             return this;
         }
index db4575c..a25fdc2 100644 (file)
@@ -26,14 +26,14 @@ public class JavaApiMessage {
     /**
      * Name of the call
      */
-    private final String api;
+    private final String name;
 
-    public JavaApiMessage(final String api) {
-        this.api = api;
+    public JavaApiMessage(final String name) {
+        this.name = name;
     }
 
-    public String getApi() {
-        return api;
+    public String getName() {
+        return name;
     }
 
     @Override
@@ -46,11 +46,11 @@ public class JavaApiMessage {
         }
 
         final JavaApiMessage that = (JavaApiMessage) o;
-        return Objects.equals(this.api, that.api);
+        return Objects.equals(this.name, that.name);
     }
 
     @Override
     public int hashCode() {
-        return Objects.hash(api);
+        return Objects.hash(name);
     }
 }
index 4a8a778..ff6c9b7 100644 (file)
@@ -34,7 +34,7 @@ import io.fd.hc2vpp.docs.api.PluginCoverage;
 import io.fd.hc2vpp.docs.api.YangType;
 import io.fd.honeycomb.translate.write.WriterFactory;
 import java.lang.reflect.Field;
-import java.util.LinkedList;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.stream.Collectors;
@@ -63,53 +63,62 @@ public class CoverageGenerator implements VppApiUtils {
 
         final Set<CoverageUnit> coverageUnits = writerBuilder.getWriteHandlers().stream()
                 .flatMap(handler -> {
+                    LOG.debug("Processing writer handling nodes: {}", handler.getHandledNodes());
                     // extracts customizer class from handler
                     final Class<?> customizerClass = getCustomizerClass(handler.getWriter());
 
                     // scans within write method
                     final Set<PluginMethodReference> writeReferences =
                             new CoverageScanner(customizerClass, WRITE, pluginClass).scan();
+                    LOG.debug("writeReferences: {}", writeReferences);
 
                     // scans within update method
                     final Set<PluginMethodReference> updateReferences =
                             new CoverageScanner(customizerClass, UPDATE, pluginClass).scan();
+                    LOG.debug("updateReferences: {}", updateReferences);
 
                     // scans within delete method
                     final Set<PluginMethodReference> deleteReferences =
                             new CoverageScanner(customizerClass, DELETE, pluginClass).scan();
+                    LOG.debug("deleteReferences: {}", deleteReferences);
 
                     return Stream.of(writeReferences.stream(), updateReferences.stream(), deleteReferences.stream())
-                            .flatMap(pluginMethodReferenceStream -> pluginMethodReferenceStream)
-                            .map(reference -> {
-                                final CoverageUnit.CoverageUnitBuilder builder = new CoverageUnit.CoverageUnitBuilder();
-
-                                // binds vpp api name and generateLink bind with version
-                                builder.setVppApi(fromJvppApi(version, reference.getName()));
-
-                                //binds java api reference
-                                builder.setJavaApi(new JavaApiMessage(reference.getName()));
-
-                                // binds Yang types with links from pre-build index
-                                // TODO - use deserialized yii e.g. /module:parent-node/child-node
-                                builder.setYangTypes(handler.getHandledNodes().stream()
-                                        .map(type -> new YangType(type, yangTypeIndex.getLinkForType(type)))
-                                        .collect(Collectors.toList()));
-
-                                final String callerClassLink = classPathIndex.linkForClass(reference.getCaller());
-                                final List<Operation> supportedOperations = new LinkedList<>();
-                                if (writeReferences.contains(reference)) {
-                                    supportedOperations.add(new Operation(callerClassLink, WRITE));
+                        .flatMap(pluginMethodReferenceStream -> pluginMethodReferenceStream)
+                        .collect(Collectors.groupingBy(PluginMethodReference::getName)).entrySet().stream()
+                        .map(vppMessageReferenceByName -> {
+                            final String jvppMethodName = vppMessageReferenceByName.getKey();
+                            final CoverageUnit.CoverageUnitBuilder builder = new CoverageUnit.CoverageUnitBuilder();
+
+                            // binds vpp api name and generateLink bind with version
+                            builder.setVppApi(fromJvppApi(version, jvppMethodName));
+
+                            //binds java api reference
+                            builder.setJavaApi(new JavaApiMessage(jvppMethodName));
+
+                            // binds Yang types with links from pre-build index
+                            // TODO - use deserialized yii e.g. /module:parent-node/child-node
+                            builder.setYangTypes(handler.getHandledNodes().stream()
+                                .map(type -> new YangType(type, yangTypeIndex.getLinkForType(type)))
+                                .collect(Collectors.toList()));
+
+
+                            final Set<Operation> supportedOperations = new HashSet<>();
+                            vppMessageReferenceByName.getValue().stream().forEach(
+                                reference -> {
+                                    final String callerClassLink = classPathIndex.linkForClass(reference.getCaller());
+                                    if (writeReferences.contains(reference)) {
+                                        supportedOperations.add(new Operation(callerClassLink, WRITE));
+                                    }
+                                    if (updateReferences.contains(reference)) {
+                                        supportedOperations.add(new Operation(callerClassLink, UPDATE));
+                                    }
+                                    if (deleteReferences.contains(reference)) {
+                                        supportedOperations.add(new Operation(callerClassLink, DELETE));
+                                    }
                                 }
-
-                                if (updateReferences.contains(reference)) {
-                                    supportedOperations.add(new Operation(callerClassLink, UPDATE));
-                                }
-
-                                if (deleteReferences.contains(reference)) {
-                                    supportedOperations.add(new Operation(callerClassLink, DELETE));
-                                }
-                                return builder.setSupportedOperations(supportedOperations).build();
-                            });
+                            );
+                            return builder.setSupportedOperations(supportedOperations).build();
+                        });
                 }).collect(Collectors.toSet());
 
         return new PluginCoverage(pluginClass.getSimpleName(), coverageUnits, true);
index 5a98639..4e03b4a 100644 (file)
@@ -53,4 +53,9 @@ public class PluginMethodReference {
     public String getName() {
         return name;
     }
+
+    @Override
+    public String toString() {
+            return "PluginMethodReference{name=" + this.name + ", caller=" + this.caller + ", owner=" + this.owner + ", " + "}";
+    }
 }
index 238f4a2..437def6 100644 (file)
@@ -139,14 +139,14 @@ class ApiDocsIndexGenerator {
     }
 
     private static String javaApi(final JavaApiMessage javaApi) {
-        "$TABLE_PART_MARK${javaApi.api}$NL"
+        "$TABLE_PART_MARK${javaApi.name}$NL"
     }
 
     private static String yangTypes(final List<YangType> yangTypes) {
         "$NL$TABLE_PART_MARK$NL ${yangTypes.stream().map { yangType -> " ${yangType.link}[${yangType.type}]" }.collect(Collectors.joining(NL))}"
     }
 
-    private static String supportedOperations(final List<Operation> operations) {
+    private static String supportedOperations(final Collection<Operation> operations) {
         "$NL$TABLE_PART_MARK${operations.stream().map { reference -> " ${reference.link}[${reference.operation}]" }.collect(Collectors.joining(NL))}"
     }