Bug 8351: Enforce check-style rules for restconf - sal-rest-docgen 51/56451/2
authormatus.kubica <matus.kubica@pantheon.tech>
Wed, 3 May 2017 10:56:12 +0000 (12:56 +0200)
committerMatúš Kubica <Matus.Kubica@pantheon.tech>
Wed, 3 May 2017 10:59:08 +0000 (10:59 +0000)
    Organize Imports for Checkstyle compliance.
    Checkstyle compliance: line length.
    Checkstyle compliance: various types of small changes.
    Checkstyle compliant Exception handling.
    Checkstyle final clean up & enforcement.
    Add the fail on violation flag into the pom.xml .

Change-Id: If4a4a3b17f8a0b93433fb41813f2560b334fd45c
Signed-off-by: matus.kubica <matus.kubica@pantheon.tech>
17 files changed:
restconf/sal-rest-docgen/pom.xml
restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/api/ApiDocService.java
restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/ApiDocServiceImpl.java
restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/BaseYangSwaggerGenerator.java
restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/ModelGenerator.java
restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/model/builder/OperationBuilder.java
restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/mountpoints/MountPointSwagger.java
restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/Api.java
restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/ApiDeclaration.java
restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/Operation.java
restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/Parameter.java
restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/Resource.java
restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/ResourceList.java
restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/ResponseMessage.java
restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/util/RestDocgenUtil.java
restconf/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/ApiDocGeneratorTest.java
restconf/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/MountPointSwaggerTest.java

index bc5606bd3a4b053b1599273f2ec30f93e891074b..f9f334c9e0403b5bfef8c6638010f60772ee99a8 100644 (file)
 
         </configuration>
       </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-checkstyle-plugin</artifactId>
+        <configuration>
+          <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+        </configuration>
+      </plugin>
     </plugins>
   </build>
 </project>
\ No newline at end of file
index e30dff77bf56824c6fa76fff1b5e84f39039e4b1..993d97b054fb9b12f98a4027d3c90bff8d9f751b 100644 (file)
@@ -31,7 +31,7 @@ public interface ApiDocService {
      */
     @GET
     @Produces(MediaType.APPLICATION_JSON)
-    public Response getRootDoc(@Context javax.ws.rs.core.UriInfo uriInfo);
+    Response getRootDoc(@Context javax.ws.rs.core.UriInfo uriInfo);
 
     /**
      * Generates Swagger compliant document listing APIs for module.
@@ -39,7 +39,7 @@ public interface ApiDocService {
     @GET
     @Path("/{module}({revision})")
     @Produces(MediaType.APPLICATION_JSON)
-    public Response getDocByModule(@PathParam("module") String module,
+    Response getDocByModule(@PathParam("module") String module,
             @PathParam("revision") String revision, @Context javax.ws.rs.core.UriInfo uriInfo);
 
     /**
@@ -48,7 +48,7 @@ public interface ApiDocService {
     @GET
     @Path("/ui")
     @Produces(MediaType.TEXT_HTML)
-    public Response getApiExplorer(@Context javax.ws.rs.core.UriInfo uriInfo);
+    Response getApiExplorer(@Context javax.ws.rs.core.UriInfo uriInfo);
 
     /**
      * Generates index document for Swagger UI. This document lists out all
@@ -58,12 +58,12 @@ public interface ApiDocService {
     @GET
     @Path("/mounts")
     @Produces(MediaType.APPLICATION_JSON)
-    public Response getListOfMounts(@Context javax.ws.rs.core.UriInfo uriInfo);
+    Response getListOfMounts(@Context javax.ws.rs.core.UriInfo uriInfo);
 
     @GET
     @Path("/mounts/{instance}")
     @Produces(MediaType.APPLICATION_JSON)
-    public Response getMountRootDoc(@PathParam("instance") String instanceNum,
+    Response getMountRootDoc(@PathParam("instance") String instanceNum,
             @Context javax.ws.rs.core.UriInfo uriInfo);
 
     /**
@@ -72,7 +72,7 @@ public interface ApiDocService {
     @GET
     @Path("/mounts/{instance}/{module}({revision})")
     @Produces(MediaType.APPLICATION_JSON)
-    public Response getMountDocByModule(@PathParam("instance") String instanceNum,
+    Response getMountDocByModule(@PathParam("instance") String instanceNum,
             @PathParam("module") String module, @PathParam("revision") String revision,
             @Context javax.ws.rs.core.UriInfo uriInfo);
 
index ea70f2655170981a9ffa084765595ef312beb3e8..2f22fa9a426bc5db11d82f021d0523f99f4a9c68 100644 (file)
@@ -81,6 +81,7 @@ public class ApiDocServiceImpl implements ApiDocService {
         return Response.seeOther(uriInfo.getBaseUriBuilder().path("../explorer/index.html").build()).build();
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
     public synchronized Response getListOfMounts(final UriInfo uriInfo) {
         final ByteArrayOutputStream baos = new ByteArrayOutputStream();
index c6c7f1d28d23f2750adb8a895915fb7120e5f02d..7ffc4c58169500bbbffe35eab9678adc4013e1dd 100644 (file)
@@ -174,14 +174,14 @@ public class BaseYangSwaggerGenerator {
         return basePath;
     }
 
-    public ApiDeclaration getSwaggerDocSpec(final Module m, final String basePath, final String context,
-            final SchemaContext schemaContext) {
+    public ApiDeclaration getSwaggerDocSpec(final Module module, final String basePath, final String context,
+                                            final SchemaContext schemaContext) {
         final ApiDeclaration doc = createApiDeclaration(basePath);
 
         final List<Api> apis = new ArrayList<>();
         boolean hasAddRootPostLink = false;
 
-        final Collection<DataSchemaNode> dataSchemaNodes = m.getChildNodes();
+        final Collection<DataSchemaNode> dataSchemaNodes = module.getChildNodes();
         LOG.debug("child nodes size [{}]", dataSchemaNodes.size());
         for (final DataSchemaNode node : dataSchemaNodes) {
             if ((node instanceof ListSchemaNode) || (node instanceof ContainerSchemaNode)) {
@@ -204,22 +204,22 @@ public class BaseYangSwaggerGenerator {
                      * only one root post link is added for this module.
                      */
                     if (!hasAddRootPostLink) {
-                        LOG.debug("Has added root post link for module {}", m.getName());
-                        addRootPostLink(m, (DataNodeContainer) node, pathParams, resourcePath, "config", apis);
+                        LOG.debug("Has added root post link for module {}", module.getName());
+                        addRootPostLink(module, (DataNodeContainer) node, pathParams, resourcePath, "config", apis);
 
                         hasAddRootPostLink = true;
                     }
 
-                    addApis(node, apis, resourcePath, pathParams, schemaContext, true, m.getName(), "config");
+                    addApis(node, apis, resourcePath, pathParams, schemaContext, true, module.getName(), "config");
                 }
                 pathParams = new ArrayList<>();
                 resourcePath = getDataStorePath("operational", context);
 
-                addApis(node, apis, resourcePath, pathParams, schemaContext, false, m.getName(), "operational");
+                addApis(node, apis, resourcePath, pathParams, schemaContext, false, module.getName(), "operational");
             }
         }
 
-        final Set<RpcDefinition> rpcs = m.getRpcs();
+        final Set<RpcDefinition> rpcs = module.getRpcs();
         for (final RpcDefinition rpcDefinition : rpcs) {
             final String resourcePath;
             resourcePath = getDataStorePath("operations", context);
@@ -234,7 +234,7 @@ public class BaseYangSwaggerGenerator {
             JSONObject models = null;
 
             try {
-                models = this.jsonConverter.convertToJsonSchema(m, schemaContext);
+                models = this.jsonConverter.convertToJsonSchema(module, schemaContext);
                 doc.setModels(models);
                 if (LOG.isDebugEnabled()) {
                     LOG.debug(this.mapper.writeValueAsString(doc));
@@ -293,7 +293,7 @@ public class BaseYangSwaggerGenerator {
         LOG.debug("Adding path: [{}]", resourcePath);
         api.setPath(resourcePath.concat(getContent(dataStore)));
 
-        Iterable<DataSchemaNode> childSchemaNodes = Collections.<DataSchemaNode> emptySet();
+        Iterable<DataSchemaNode> childSchemaNodes = Collections.<DataSchemaNode>emptySet();
         if ((node instanceof ListSchemaNode) || (node instanceof ContainerSchemaNode)) {
             final DataNodeContainer dataNodeContainer = (DataNodeContainer) node;
             childSchemaNodes = dataNodeContainer.getChildNodes();
index 75bfe75d0cd3d5ca00c586851690dd91f031633b..f4ba8d41899199b2b82055e311a9d72017374006 100644 (file)
@@ -99,15 +99,16 @@ public class ModelGenerator {
     }
 
     /**
-     * Creates Json models from provided module according to swagger spec
+     * Creates Json models from provided module according to swagger spec.
      *
      * @param module        - Yang module to be converted
      * @param schemaContext - SchemaContext of all Yang files used by Api Doc
      * @return JSONObject containing data used for creating examples and models in Api Doc
-     * @throws IOException
-     * @throws JSONException
+     * @throws IOException if I/O operation fails
+     * @throws JSONException when things are amiss
      */
-    public JSONObject convertToJsonSchema(final Module module, final SchemaContext schemaContext) throws IOException, JSONException {
+    public JSONObject convertToJsonSchema(final Module module,
+                                          final SchemaContext schemaContext) throws IOException, JSONException {
         final JSONObject models = new JSONObject();
         models.put(UNIQUE_EMPTY_IDENTIFIER, new JSONObject());
         topLevelModule = module;
@@ -118,13 +119,14 @@ public class ModelGenerator {
         return models;
     }
 
-    private void processModules(final Module module, final JSONObject models, final SchemaContext schemaContext) throws JSONException {
+    private void processModules(final Module module, final JSONObject models,
+                                final SchemaContext schemaContext) throws JSONException {
         createConcreteModelForPost(models, module.getName() + BaseYangSwaggerGenerator.MODULE_NAME_SUFFIX,
                 createPropertiesForPost(module, schemaContext, module.getName()));
     }
 
-    private void processContainersAndLists(final Module module, final JSONObject models, final SchemaContext schemaContext)
-            throws IOException, JSONException {
+    private void processContainersAndLists(final Module module, final JSONObject models,
+                                           final SchemaContext schemaContext) throws IOException, JSONException {
         final String moduleName = module.getName();
 
         for (final DataSchemaNode childNode : module.getChildNodes()) {
@@ -137,21 +139,24 @@ public class ModelGenerator {
     }
 
     /**
-     * Process the RPCs for a Module Spits out a file each of the name <rpcName>-input.json and <rpcName>-output.json
-     * for each RPC that contains input & output elements
+     * Process the RPCs for a Module Spits out a file each of the name
+     * {@code <rpcName>-input.json and <rpcName>-output.json}
+     * for each RPC that contains input & output elements.
      *
-     * @param module
-     * @throws JSONException
-     * @throws IOException
+     * @param module module
+     * @throws JSONException when things are amiss
+     * @throws IOException if I/O operation fails
      */
-    private void processRPCs(final Module module, final JSONObject models, final SchemaContext schemaContext) throws JSONException,
+    private void processRPCs(final Module module, final JSONObject models,
+                             final SchemaContext schemaContext) throws JSONException,
             IOException {
         final Set<RpcDefinition> rpcs = module.getRpcs();
         final String moduleName = module.getName();
         for (final RpcDefinition rpc : rpcs) {
             final ContainerSchemaNode input = rpc.getInput();
             if (!input.getChildNodes().isEmpty()) {
-                final JSONObject properties = processChildren(input.getChildNodes(), moduleName, models, true, schemaContext);
+                final JSONObject properties =
+                        processChildren(input.getChildNodes(), moduleName, models, true, schemaContext);
 
                 final String filename = "(" + rpc.getQName().getLocalName() + ")input";
                 final JSONObject childSchema = getSchemaTemplate();
@@ -165,7 +170,8 @@ public class ModelGenerator {
 
             final ContainerSchemaNode output = rpc.getOutput();
             if (!output.getChildNodes().isEmpty()) {
-                final JSONObject properties = processChildren(output.getChildNodes(), moduleName, models, true, schemaContext);
+                final JSONObject properties =
+                        processChildren(output.getChildNodes(), moduleName, models, true, schemaContext);
                 final String filename = "(" + rpc.getQName().getLocalName() + ")output";
                 final JSONObject childSchema = getSchemaTemplate();
                 childSchema.put(TYPE_KEY, OBJECT_TYPE);
@@ -249,12 +255,14 @@ public class ModelGenerator {
         }
     }
 
-    private JSONObject processDataNodeContainer(final DataNodeContainer dataNode, final String parentName, final JSONObject models,
-                                                final boolean isConfig, final SchemaContext schemaContext) throws JSONException, IOException {
+    private JSONObject processDataNodeContainer(
+            final DataNodeContainer dataNode, final String parentName, final JSONObject models, final boolean isConfig,
+            final SchemaContext schemaContext) throws JSONException, IOException {
         if (dataNode instanceof ListSchemaNode || dataNode instanceof ContainerSchemaNode) {
             final Iterable<DataSchemaNode> containerChildren = dataNode.getChildNodes();
             final String localName = ((SchemaNode) dataNode).getQName().getLocalName();
-            final JSONObject properties = processChildren(containerChildren, parentName + "/" + localName, models, isConfig, schemaContext);
+            final JSONObject properties =
+                    processChildren(containerChildren, parentName + "/" + localName, models, isConfig, schemaContext);
             final String nodeName = parentName + (isConfig ? OperationBuilder.CONFIG : OperationBuilder.OPERATIONAL)
                     + localName;
 
@@ -285,7 +293,8 @@ public class ModelGenerator {
         models.put(nodePostName, postSchema);
     }
 
-    private JSONObject createPropertiesForPost(final DataNodeContainer dataNodeContainer, final SchemaContext schemaContext, final String parentName)
+    private JSONObject createPropertiesForPost(final DataNodeContainer dataNodeContainer,
+                                               final SchemaContext schemaContext, final String parentName)
             throws JSONException {
         final JSONObject properties = new JSONObject();
         for (final DataSchemaNode childNode : dataNodeContainer.getChildNodes()) {
@@ -307,8 +316,9 @@ public class ModelGenerator {
     /**
      * Processes the nodes.
      */
-    private JSONObject processChildren(final Iterable<DataSchemaNode> nodes, final String parentName, final JSONObject models,
-                                       final boolean isConfig, final SchemaContext schemaContext)
+    private JSONObject processChildren(
+            final Iterable<DataSchemaNode> nodes, final String parentName, final JSONObject models,
+            final boolean isConfig, final SchemaContext schemaContext)
             throws JSONException, IOException {
         final JSONObject properties = new JSONObject();
         for (final DataSchemaNode node : nodes) {
@@ -349,7 +359,8 @@ public class ModelGenerator {
         return properties;
     }
 
-    private JSONObject processLeafListNode(final LeafListSchemaNode listNode, final SchemaContext schemaContext) throws JSONException {
+    private JSONObject processLeafListNode(final LeafListSchemaNode listNode,
+                                           final SchemaContext schemaContext) throws JSONException {
         final JSONObject props = new JSONObject();
         props.put(TYPE_KEY, ARRAY_TYPE);
 
@@ -370,8 +381,9 @@ public class ModelGenerator {
         return props;
     }
 
-    private void processChoiceNode(final Iterable<DataSchemaNode> nodes, final String moduleName, final JSONObject models,
-                                   final SchemaContext schemaContext, final boolean isConfig, final JSONObject properties)
+    private void processChoiceNode(
+            final Iterable<DataSchemaNode> nodes, final String moduleName, final JSONObject models,
+            final SchemaContext schemaContext, final boolean isConfig, final JSONObject properties)
             throws JSONException, IOException {
         for (final DataSchemaNode node : nodes) {
             final String name = resolveNodesName(node, topLevelModule, schemaContext);
@@ -388,9 +400,10 @@ public class ModelGenerator {
                 property = processLeafListNode((LeafListSchemaNode) node, schemaContext);
 
             } else if (node instanceof ChoiceSchemaNode) {
-                if (((ChoiceSchemaNode) node).getCases().iterator().hasNext())
+                if (((ChoiceSchemaNode) node).getCases().iterator().hasNext()) {
                     processChoiceNode(((ChoiceSchemaNode) node).getCases().iterator().next().getChildNodes(),
                             moduleName, models, schemaContext, isConfig, properties);
+                }
                 continue;
 
             } else if (node instanceof AnyXmlSchemaNode) {
@@ -409,7 +422,8 @@ public class ModelGenerator {
         }
     }
 
-    private static void processConstraints(final ConstraintDefinition constraints, final JSONObject props) throws JSONException {
+    private static void processConstraints(final ConstraintDefinition constraints,
+                                           final JSONObject props) throws JSONException {
         final boolean isMandatory = constraints.isMandatory();
         props.put(REQUIRED_KEY, isMandatory);
 
@@ -423,7 +437,8 @@ public class ModelGenerator {
         }
     }
 
-    private JSONObject processLeafNode(final LeafSchemaNode leafNode, final SchemaContext schemaContext) throws JSONException {
+    private JSONObject processLeafNode(final LeafSchemaNode leafNode,
+                                       final SchemaContext schemaContext) throws JSONException {
         final JSONObject property = new JSONObject();
 
         final String leafDescription = leafNode.getDescription();
@@ -462,7 +477,8 @@ public class ModelGenerator {
 
             } else if (leafTypeDef instanceof IdentityrefTypeDefinition) {
                 final String name = topLevelModule.getName();
-                jsonType = name + ":" + ((IdentityrefTypeDefinition) leafTypeDef).getIdentity().getQName().getLocalName();
+                jsonType =
+                        name + ":" + ((IdentityrefTypeDefinition) leafTypeDef).getIdentity().getQName().getLocalName();
 
             } else if (leafTypeDef instanceof StringTypeDefinition) {
                 jsonType = processStringType(leafTypeDef, property, node.getQName().getLocalName());
@@ -502,28 +518,30 @@ public class ModelGenerator {
         return jsonType;
     }
 
-    private String processLeafRef(final DataSchemaNode node, final JSONObject property, final SchemaContext schemaContext,
-                                  final TypeDefinition<?> leafTypeDef) {
-        RevisionAwareXPath xPath = ((LeafrefTypeDefinition) leafTypeDef).getPathStatement();
+    private String processLeafRef(final DataSchemaNode node, final JSONObject property,
+                                  final SchemaContext schemaContext, final TypeDefinition<?> leafTypeDef) {
+        RevisionAwareXPath xpath = ((LeafrefTypeDefinition) leafTypeDef).getPathStatement();
         final SchemaNode schemaNode;
 
-        final String xPathString = STRIP_PATTERN.matcher(xPath.toString()).replaceAll("");
-        xPath = new RevisionAwareXPathImpl(xPathString, xPath.isAbsolute());
+        final String xPathString = STRIP_PATTERN.matcher(xpath.toString()).replaceAll("");
+        xpath = new RevisionAwareXPathImpl(xPathString, xpath.isAbsolute());
 
         final Module module;
-        if (xPath.isAbsolute()) {
+        if (xpath.isAbsolute()) {
             module = findModule(schemaContext, leafTypeDef.getQName());
-            schemaNode = SchemaContextUtil.findDataSchemaNode(schemaContext, module, xPath);
+            schemaNode = SchemaContextUtil.findDataSchemaNode(schemaContext, module, xpath);
         } else {
             module = findModule(schemaContext, node.getQName());
-            schemaNode = SchemaContextUtil.findDataSchemaNodeForRelativeXPath(schemaContext, module, node, xPath);
+            schemaNode = SchemaContextUtil.findDataSchemaNodeForRelativeXPath(schemaContext, module, node, xpath);
         }
 
-        return processTypeDef(((TypedSchemaNode) schemaNode).getType(), (DataSchemaNode) schemaNode, property, schemaContext);
+        return processTypeDef(((TypedSchemaNode) schemaNode).getType(), (DataSchemaNode) schemaNode,
+                property, schemaContext);
     }
 
-    private static Module findModule(final SchemaContext schemaContext, final QName qName) {
-        return schemaContext.findModuleByNamespaceAndRevision(qName.getNamespace(), qName.getRevision());
+    private static Module findModule(final SchemaContext schemaContext, final QName qualifiedName) {
+        return schemaContext
+                .findModuleByNamespaceAndRevision(qualifiedName.getNamespace(), qualifiedName.getRevision());
     }
 
     private static String processBinaryType(final JSONObject property) throws JSONException {
@@ -533,7 +551,8 @@ public class ModelGenerator {
         return "bin1 bin2";
     }
 
-    private static String processEnumType(final EnumTypeDefinition enumLeafType, final JSONObject property) throws JSONException {
+    private static String processEnumType(final EnumTypeDefinition enumLeafType,
+                                          final JSONObject property) throws JSONException {
         final List<EnumPair> enumPairs = enumLeafType.getValues();
         final List<String> enumNames = new ArrayList<>();
         for (final EnumPair enumPair : enumPairs) {
@@ -544,7 +563,8 @@ public class ModelGenerator {
         return enumLeafType.getValues().iterator().next().getName();
     }
 
-    private static String processBitsType(final BitsTypeDefinition bitsType, final JSONObject property) throws JSONException {
+    private static String processBitsType(final BitsTypeDefinition bitsType,
+                                          final JSONObject property) throws JSONException {
         property.put(MIN_ITEMS, 0);
         property.put(UNIQUE_ITEMS_KEY, true);
         final List<String> enumNames = new ArrayList<>();
@@ -557,7 +577,8 @@ public class ModelGenerator {
         return enumNames.iterator().next() + " " + enumNames.get(enumNames.size() - 1);
     }
 
-    private static String processStringType(final TypeDefinition<?> stringType, final JSONObject property, final String nodeName)
+    private static String processStringType(final TypeDefinition<?> stringType,
+                                            final JSONObject property, final String nodeName)
             throws JSONException {
         StringTypeDefinition type = (StringTypeDefinition) stringType;
         List<LengthConstraint> lengthConstraints = ((StringTypeDefinition) stringType).getLengthConstraints();
index d24636bfee060451de3cf7cda594036fbfc027e1..bb14d5a593e75eaac73569cb9cf652f3547b5210 100644 (file)
@@ -93,7 +93,8 @@ public final class OperationBuilder {
         public static final String METHOD_NAME = "POST";
         private final DataNodeContainer dataNodeContainer;
 
-        public Post(final String nodeName, final String parentName, final String description, final DataNodeContainer dataNodeContainer) {
+        public Post(final String nodeName, final String parentName, final String description,
+                    final DataNodeContainer dataNodeContainer) {
             super(nodeName, description, parentName.replace("_module", ""));
             this.dataNodeContainer = dataNodeContainer;
             spec.setType(CONFIG + nodeName + METHOD_NAME);
index fcd85c06f2dfb54dce27c7f5f472e81f7e75a017..caf01d4ba55c08d25e9d60125be008a6da88ca3f 100644 (file)
@@ -40,16 +40,16 @@ public class MountPointSwagger extends BaseYangSwaggerGenerator implements Mount
     private static final String DATASTORES_REVISION = "-";
     private static final String DATASTORES_LABEL = "Datastores";
     private static final String RESTCONF_DRAFT = "18";
+    private static final AtomicReference<MountPointSwagger> SELF_REF = new AtomicReference<>();
 
     private DOMMountPointService mountService;
     private final Map<YangInstanceIdentifier, Long> instanceIdToLongId =
             new TreeMap<>((o1, o2) -> o1.toString().compareToIgnoreCase(o2.toString()));
     private final Map<Long, YangInstanceIdentifier> longIdToInstanceId = new HashMap<>();
+
     private final Object lock = new Object();
 
     private final AtomicLong idKey = new AtomicLong(0);
-
-    private static final AtomicReference<MountPointSwagger> selfRef = new AtomicReference<>();
     private SchemaService globalSchema;
     private static boolean newDraft;
 
@@ -219,20 +219,20 @@ public class MountPointSwagger extends BaseYangSwaggerGenerator implements Mount
     }
 
     public static MountPointSwagger getInstance() {
-        MountPointSwagger swagger = selfRef.get();
+        MountPointSwagger swagger = SELF_REF.get();
         if (swagger == null) {
-            selfRef.compareAndSet(null, new MountPointSwagger());
-            swagger = selfRef.get();
+            SELF_REF.compareAndSet(null, new MountPointSwagger());
+            swagger = SELF_REF.get();
         }
         newDraft = false;
         return swagger;
     }
 
     public static MountPointSwagger getInstanceDraft18() {
-        MountPointSwagger swagger = selfRef.get();
+        MountPointSwagger swagger = SELF_REF.get();
         if (swagger == null) {
-            selfRef.compareAndSet(null, new MountPointSwagger());
-            swagger = selfRef.get();
+            SELF_REF.compareAndSet(null, new MountPointSwagger());
+            swagger = SELF_REF.get();
         }
         newDraft = true;
         return swagger;
index 8871c97591726c5cde864ffaf08ccabe90940673..71004bc9763ed74230442f457a2f088c919d7832 100644 (file)
@@ -13,7 +13,7 @@ import java.util.List;
  * Implementation of swagger spec (see <a href=
  * "https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#522-api-object"
  * > https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#522-api
- * -object</a>)
+ * -object</a>).
  */
 public class Api {
 
index d918637a36b3fc8c0a7114597ef16bfa84434249..3d735ac2f6898e49729cf6b7729a7052b9389593 100644 (file)
@@ -14,7 +14,7 @@ import org.json.JSONObject;
  * Implementation of swagger spec (see <a href=
  * "https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#52-api-declaration"
  * > https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#52-api-
- * declaration</a>)
+ * declaration</a>).
  */
 public class ApiDeclaration {
     private String apiVersion;
index e6d96b13fcad82f846a4ce544d8b97561aeb99ac..b00fc19a1eff857b2132c28bf898dc4c26648404 100644 (file)
@@ -13,7 +13,7 @@ import java.util.List;
  * Implementation of swagger spec (see <a href=
  * "https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#523-operation-object"
  * > https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#523-
- * operation-object</a>)
+ * operation-object</a>).
  */
 public class Operation {
     private String method;
index bbca7e5ca61683fe45b67e48122e2cbf054c08f3..01eed235f19f3616842b7ef9bca819bdcfaf13b2 100644 (file)
@@ -11,7 +11,7 @@ package org.opendaylight.netconf.sal.rest.doc.swagger;
  * Implementation of swagger spec (see <a href=
  * "https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#524-parameter-object"
  * > https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#524-
- * parameter-object</a>)
+ * parameter-object</a>).
  */
 public class Parameter {
     private String name;
index a8e15c289f1fdd6f5355d890ca59c25718b4f40d..9bbc82c3649a4f6409c9a3417dffc79b83560318 100644 (file)
@@ -11,7 +11,7 @@ package org.opendaylight.netconf.sal.rest.doc.swagger;
  * Implementation of swagger spec (see <a href=
  * "https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#512-resource-object"
  * > https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#512-
- * resource-object</a>)
+ * resource-object</a>).
  */
 public class Resource {
     private String path;
index f2a71133341789feca25eaed595dc59334a25235..3e8c7b72b295f081b8a38756411b0f0637a66c40 100644 (file)
@@ -13,7 +13,7 @@ import java.util.List;
  * Implementation of swagger spec (see <a href=
  * "https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#51-resource-listing"
  * > https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#51-
- * resource-listing</a>)
+ * resource-listing</a>).
  */
 public class ResourceList {
     private String apiVersion;
index 7867e404e32fd387414c9281f7b415bfcd8b1de7..381a73d8378af68fe03febd8d7c5f1438d220f1c 100644 (file)
@@ -11,7 +11,7 @@ package org.opendaylight.netconf.sal.rest.doc.swagger;
  * Implementation of swagger spec (see <a href=
  * "https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#525-response-message-object"
  * > https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#525-
- * response-message-object</a>)
+ * response-message-object</a>).
  */
 public class ResponseMessage {
     private int code;
index 409378ae88ee16d9aac17f6f27ee0b643e33766f..f709d036524b6183d06eb6134a6dec89675ce73d 100644 (file)
@@ -22,7 +22,7 @@ public class RestDocgenUtil {
     private RestDocgenUtil() {
     }
 
-    private static final Map<URI, Map<Date, Module>> namespaceAndRevisionToModule = new HashMap<>();
+    private static final Map<URI, Map<Date, Module>> NAMESPACE_AND_REVISION_TO_MODULE = new HashMap<>();
 
     /**
      * Resolve path argument name for {@code node}.
@@ -54,10 +54,10 @@ public class RestDocgenUtil {
         final URI namespace = node.getQName().getNamespace();
         final Date revision = node.getQName().getRevision();
 
-        Map<Date, Module> revisionToModule = namespaceAndRevisionToModule.get(namespace);
+        Map<Date, Module> revisionToModule = NAMESPACE_AND_REVISION_TO_MODULE.get(namespace);
         if (revisionToModule == null) {
             revisionToModule = new HashMap<>();
-            namespaceAndRevisionToModule.put(namespace, revisionToModule);
+            NAMESPACE_AND_REVISION_TO_MODULE.put(namespace, revisionToModule);
         }
         Module module = revisionToModule.get(revision);
         if (module == null) {
index ee1b1eea056a786939a3c055fe847c89b8e49a64..91cbcec2c7d3888077d4af2d28b8f18c83588946 100644 (file)
@@ -64,7 +64,7 @@ public class ApiDocGeneratorTest {
     }
 
     /**
-     * Method: getApiDeclaration(String module, String revision, UriInfo uriInfo)
+     * Method: getApiDeclaration(String module, String revision, UriInfo uriInfo).
      */
     @Test
     public void testGetModuleDoc() throws Exception {
@@ -98,8 +98,8 @@ public class ApiDocGeneratorTest {
         final Api cont1Api = findApi("/config/toaster2:lst/cont1", doc);
         assertNotNull("Api /config/toaster2:lst/cont1 wasn't found", cont1Api);
         assertTrue("POST for cont11 in cont1 is missing",
-                findOperation(cont1Api.getOperations(), "POST", "(config)cont1POST", "toaster2/lst/cont1(config)cont11-TOP",
-                        "toaster2/lst/cont1(config)lst11-TOP"));
+            findOperation(cont1Api.getOperations(), "POST", "(config)cont1POST", "toaster2/lst/cont1(config)cont11-TOP",
+                    "toaster2/lst/cont1(config)lst11-TOP"));
 
         // no POST URI
         final Api cont11Api = findApi("/config/toaster2:lst/cont1/cont11", doc);
@@ -109,7 +109,7 @@ public class ApiDocGeneratorTest {
     }
 
     /**
-     * Tries to find operation with name {@code operationName} and with summary {@code summary}
+     * Tries to find operation with name {@code operationName} and with summary {@code summary}.
      */
     private boolean findOperation(final List<Operation> operations, final String operationName, final String type,
                                   final String... searchedParameters) {
@@ -149,7 +149,7 @@ public class ApiDocGeneratorTest {
     }
 
     /**
-     * Tries to find {@code Api} with path {@code path}
+     * Tries to find {@code Api} with path {@code path}.
      */
     private Api findApi(final String path, final ApiDeclaration doc) {
         for (final Api api : doc.getApis()) {
@@ -246,8 +246,8 @@ public class ApiDocGeneratorTest {
 
                 // testing bugs.opendaylight.org bug 1290. UnionType model type.
                 final String jsonString = doc.getModels().toString();
-                assertTrue(jsonString.contains(
-                        "testUnion\":{\"type\":\"-2147483648\",\"required\":false,\"enum\":[\"-2147483648\",\"Some testUnion\"]}"));
+                assertTrue(jsonString.contains("testUnion\":{\"type\":\"-2147483648\",\"required\":false,"
+                        + "\"enum\":[\"-2147483648\",\"Some testUnion\"]}"));
             }
         }
     }
@@ -265,7 +265,8 @@ public class ApiDocGeneratorTest {
 
                 final JSONObject models = doc.getModels();
                 final JSONObject inputTop = models.getJSONObject("(make-toast)input-TOP");
-                final String testString = "{\"toaster:input\":{\"type\":\"object\",\"items\":{\"$ref\":\"(make-toast)input\"}}}";
+                final String testString =
+                        "{\"toaster:input\":{\"type\":\"object\",\"items\":{\"$ref\":\"(make-toast)input\"}}}";
                 assertEquals(testString, inputTop.getJSONObject("properties").toString());
                 final JSONObject input = models.getJSONObject("(make-toast)input");
                 final JSONObject properties = input.getJSONObject("properties");
@@ -278,17 +279,18 @@ public class ApiDocGeneratorTest {
     /**
      * Tests whether from yang files are generated all required paths for HTTP operations (GET, DELETE, PUT, POST)
      *
+     * <p>
      * If container | list is augmented then in path there should be specified module name followed with collon (e. g.
      * "/config/module1:element1/element2/module2:element3")
      *
-     * @param doc
-     * @throws Exception
+     * @param doc Api declaration
+     * @throws Exception if operation fails
      */
     private void validateToaster(final ApiDeclaration doc) throws Exception {
         final Set<String> expectedUrls = new TreeSet<>(Arrays.asList(new String[]{"/config/toaster2:toaster",
-                "/operational/toaster2:toaster", "/operations/toaster2:cancel-toast",
-                "/operations/toaster2:make-toast", "/operations/toaster2:restock-toaster",
-                "/config/toaster2:toaster/toasterSlot/{slotId}/toaster-augmented:slotInfo"}));
+            "/operational/toaster2:toaster", "/operations/toaster2:cancel-toast",
+            "/operations/toaster2:make-toast", "/operations/toaster2:restock-toaster",
+            "/config/toaster2:toaster/toasterSlot/{slotId}/toaster-augmented:slotInfo"}));
 
         final Set<String> actualUrls = new TreeSet<>();
 
index b04064577465679862e4436bcac3c9302bcf5b7e..a8c9bebecc46d699268b064262895968103daa53 100644 (file)
@@ -37,7 +37,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 public class MountPointSwaggerTest {
 
     private static final String HTTP_URL = "http://localhost/path";
-    private static final YangInstanceIdentifier instanceId = YangInstanceIdentifier.builder()
+    private static final YangInstanceIdentifier INSTANCE_ID = YangInstanceIdentifier.builder()
             .node(QName.create("nodes"))
             .node(QName.create("node"))
             .nodeWithKey(QName.create("node"), QName.create("id"), "123").build();
@@ -66,14 +66,14 @@ public class MountPointSwaggerTest {
         final UriInfo mockInfo = setUpSwaggerForDocGeneration();
 
         assertEquals(0, this.swagger.getInstanceIdentifiers().size());
-        this.swagger.onMountPointCreated(instanceId); // add this ID into the list of
+        this.swagger.onMountPointCreated(INSTANCE_ID); // add this ID into the list of
                                                  // mount points
         assertEquals(1, this.swagger.getInstanceIdentifiers().size());
         assertEquals((Long) 1L, this.swagger.getInstanceIdentifiers().entrySet().iterator().next()
                 .getValue());
         assertEquals(INSTANCE_URL, this.swagger.getInstanceIdentifiers().entrySet().iterator().next()
                 .getKey());
-        this.swagger.onMountPointRemoved(instanceId); // remove ID from list of mount
+        this.swagger.onMountPointRemoved(INSTANCE_ID); // remove ID from list of mount
                                                  // points
         assertEquals(0, this.swagger.getInstanceIdentifiers().size());
     }
@@ -81,7 +81,7 @@ public class MountPointSwaggerTest {
     @Test
     public void testGetResourceListGoodId() throws Exception {
         final UriInfo mockInfo = setUpSwaggerForDocGeneration();
-        this.swagger.onMountPointCreated(instanceId); // add this ID into the list of
+        this.swagger.onMountPointCreated(INSTANCE_ID); // add this ID into the list of
                                                  // mount points
         final ResourceList resourceList = this.swagger.getResourceList(mockInfo, 1L);
 
@@ -97,7 +97,7 @@ public class MountPointSwaggerTest {
     @Test
     public void testGetDataStoreApi() throws Exception {
         final UriInfo mockInfo = setUpSwaggerForDocGeneration();
-        this.swagger.onMountPointCreated(instanceId); // add this ID into the list of
+        this.swagger.onMountPointCreated(INSTANCE_ID); // add this ID into the list of
                                                  // mount points
 
         final ApiDeclaration mountPointApi = this.swagger.getMountPointApi(mockInfo, 1L, "Datastores", "-");
@@ -116,9 +116,9 @@ public class MountPointSwaggerTest {
                     .getNotes());
         }
         final Set<String> expectedApis = new TreeSet<>(Arrays.asList(new String[] {
-                "/config" + INSTANCE_URL + "yang-ext:mount",
-                "/operational" + INSTANCE_URL + "yang-ext:mount",
-                "/operations" + INSTANCE_URL + "yang-ext:mount",}));
+            "/config" + INSTANCE_URL + "yang-ext:mount",
+            "/operational" + INSTANCE_URL + "yang-ext:mount",
+            "/operations" + INSTANCE_URL + "yang-ext:mount",}));
         assertEquals(expectedApis, actualApis);
     }
 
@@ -134,7 +134,7 @@ public class MountPointSwaggerTest {
         when(mountPoint.getSchemaContext()).thenReturn(context);
 
         final DOMMountPointService service = mock(DOMMountPointService.class);
-        when(service.getMountPoint(instanceId)).thenReturn(Optional.of(mountPoint));
+        when(service.getMountPoint(INSTANCE_ID)).thenReturn(Optional.of(mountPoint));
         this.swagger.setMountService(service);
         this.swagger.setGlobalSchema(schemaService);