From 7e5575aae5a54ab676a601ee68b5bfc4b83f72b6 Mon Sep 17 00:00:00 2001 From: "matus.kubica" Date: Wed, 3 May 2017 12:56:12 +0200 Subject: [PATCH] Bug 8351: Enforce check-style rules for restconf - sal-rest-docgen 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 --- restconf/sal-rest-docgen/pom.xml | 7 ++ .../sal/rest/doc/api/ApiDocService.java | 12 +- .../sal/rest/doc/impl/ApiDocServiceImpl.java | 1 + .../doc/impl/BaseYangSwaggerGenerator.java | 20 ++-- .../sal/rest/doc/impl/ModelGenerator.java | 105 +++++++++++------- .../doc/model/builder/OperationBuilder.java | 3 +- .../doc/mountpoints/MountPointSwagger.java | 16 +-- .../netconf/sal/rest/doc/swagger/Api.java | 2 +- .../sal/rest/doc/swagger/ApiDeclaration.java | 2 +- .../sal/rest/doc/swagger/Operation.java | 2 +- .../sal/rest/doc/swagger/Parameter.java | 2 +- .../sal/rest/doc/swagger/Resource.java | 2 +- .../sal/rest/doc/swagger/ResourceList.java | 2 +- .../sal/rest/doc/swagger/ResponseMessage.java | 2 +- .../sal/rest/doc/util/RestDocgenUtil.java | 6 +- .../rest/doc/impl/ApiDocGeneratorTest.java | 28 ++--- .../rest/doc/impl/MountPointSwaggerTest.java | 18 +-- 17 files changed, 131 insertions(+), 99 deletions(-) diff --git a/restconf/sal-rest-docgen/pom.xml b/restconf/sal-rest-docgen/pom.xml index bc5606bd3a..f9f334c9e0 100644 --- a/restconf/sal-rest-docgen/pom.xml +++ b/restconf/sal-rest-docgen/pom.xml @@ -154,6 +154,13 @@ + + org.apache.maven.plugins + maven-checkstyle-plugin + + checkstyle.violationSeverity=error + + \ No newline at end of file diff --git a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/api/ApiDocService.java b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/api/ApiDocService.java index e30dff77bf..993d97b054 100644 --- a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/api/ApiDocService.java +++ b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/api/ApiDocService.java @@ -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); diff --git a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/ApiDocServiceImpl.java b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/ApiDocServiceImpl.java index ea70f26551..2f22fa9a42 100644 --- a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/ApiDocServiceImpl.java +++ b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/ApiDocServiceImpl.java @@ -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(); diff --git a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/BaseYangSwaggerGenerator.java b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/BaseYangSwaggerGenerator.java index c6c7f1d28d..7ffc4c5816 100644 --- a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/BaseYangSwaggerGenerator.java +++ b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/BaseYangSwaggerGenerator.java @@ -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 apis = new ArrayList<>(); boolean hasAddRootPostLink = false; - final Collection dataSchemaNodes = m.getChildNodes(); + final Collection 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 rpcs = m.getRpcs(); + final Set 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 childSchemaNodes = Collections. emptySet(); + Iterable childSchemaNodes = Collections.emptySet(); if ((node instanceof ListSchemaNode) || (node instanceof ContainerSchemaNode)) { final DataNodeContainer dataNodeContainer = (DataNodeContainer) node; childSchemaNodes = dataNodeContainer.getChildNodes(); diff --git a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/ModelGenerator.java b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/ModelGenerator.java index 75bfe75d0c..f4ba8d4189 100644 --- a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/ModelGenerator.java +++ b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/ModelGenerator.java @@ -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 -input.json and -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 -input.json and -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 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 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 nodes, final String parentName, final JSONObject models, - final boolean isConfig, final SchemaContext schemaContext) + private JSONObject processChildren( + final Iterable 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 nodes, final String moduleName, final JSONObject models, - final SchemaContext schemaContext, final boolean isConfig, final JSONObject properties) + private void processChoiceNode( + final Iterable 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 enumPairs = enumLeafType.getValues(); final List 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 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 lengthConstraints = ((StringTypeDefinition) stringType).getLengthConstraints(); diff --git a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/model/builder/OperationBuilder.java b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/model/builder/OperationBuilder.java index d24636bfee..bb14d5a593 100644 --- a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/model/builder/OperationBuilder.java +++ b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/model/builder/OperationBuilder.java @@ -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); diff --git a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/mountpoints/MountPointSwagger.java b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/mountpoints/MountPointSwagger.java index fcd85c06f2..caf01d4ba5 100644 --- a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/mountpoints/MountPointSwagger.java +++ b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/mountpoints/MountPointSwagger.java @@ -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 SELF_REF = new AtomicReference<>(); private DOMMountPointService mountService; private final Map instanceIdToLongId = new TreeMap<>((o1, o2) -> o1.toString().compareToIgnoreCase(o2.toString())); private final Map longIdToInstanceId = new HashMap<>(); + private final Object lock = new Object(); private final AtomicLong idKey = new AtomicLong(0); - - private static final AtomicReference 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; diff --git a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/Api.java b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/Api.java index 8871c97591..71004bc976 100644 --- a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/Api.java +++ b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/Api.java @@ -13,7 +13,7 @@ import java.util.List; * Implementation of swagger spec (see https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#522-api - * -object) + * -object). */ public class Api { diff --git a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/ApiDeclaration.java b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/ApiDeclaration.java index d918637a36..3d735ac2f6 100644 --- a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/ApiDeclaration.java +++ b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/ApiDeclaration.java @@ -14,7 +14,7 @@ import org.json.JSONObject; * Implementation of swagger spec (see https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#52-api- - * declaration) + * declaration). */ public class ApiDeclaration { private String apiVersion; diff --git a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/Operation.java b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/Operation.java index e6d96b13fc..b00fc19a1e 100644 --- a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/Operation.java +++ b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/Operation.java @@ -13,7 +13,7 @@ import java.util.List; * Implementation of swagger spec (see https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#523- - * operation-object) + * operation-object). */ public class Operation { private String method; diff --git a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/Parameter.java b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/Parameter.java index bbca7e5ca6..01eed235f1 100644 --- a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/Parameter.java +++ b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/Parameter.java @@ -11,7 +11,7 @@ package org.opendaylight.netconf.sal.rest.doc.swagger; * Implementation of swagger spec (see https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#524- - * parameter-object) + * parameter-object). */ public class Parameter { private String name; diff --git a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/Resource.java b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/Resource.java index a8e15c289f..9bbc82c364 100644 --- a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/Resource.java +++ b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/Resource.java @@ -11,7 +11,7 @@ package org.opendaylight.netconf.sal.rest.doc.swagger; * Implementation of swagger spec (see https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#512- - * resource-object) + * resource-object). */ public class Resource { private String path; diff --git a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/ResourceList.java b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/ResourceList.java index f2a7113334..3e8c7b72b2 100644 --- a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/ResourceList.java +++ b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/ResourceList.java @@ -13,7 +13,7 @@ import java.util.List; * Implementation of swagger spec (see https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#51- - * resource-listing) + * resource-listing). */ public class ResourceList { private String apiVersion; diff --git a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/ResponseMessage.java b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/ResponseMessage.java index 7867e404e3..381a73d837 100644 --- a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/ResponseMessage.java +++ b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/swagger/ResponseMessage.java @@ -11,7 +11,7 @@ package org.opendaylight.netconf.sal.rest.doc.swagger; * Implementation of swagger spec (see https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#525- - * response-message-object) + * response-message-object). */ public class ResponseMessage { private int code; diff --git a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/util/RestDocgenUtil.java b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/util/RestDocgenUtil.java index 409378ae88..f709d03652 100644 --- a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/util/RestDocgenUtil.java +++ b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/util/RestDocgenUtil.java @@ -22,7 +22,7 @@ public class RestDocgenUtil { private RestDocgenUtil() { } - private static final Map> namespaceAndRevisionToModule = new HashMap<>(); + private static final Map> 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 revisionToModule = namespaceAndRevisionToModule.get(namespace); + Map 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) { diff --git a/restconf/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/ApiDocGeneratorTest.java b/restconf/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/ApiDocGeneratorTest.java index ee1b1eea05..91cbcec2c7 100644 --- a/restconf/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/ApiDocGeneratorTest.java +++ b/restconf/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/ApiDocGeneratorTest.java @@ -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 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) * + *

* 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 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 actualUrls = new TreeSet<>(); diff --git a/restconf/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/MountPointSwaggerTest.java b/restconf/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/MountPointSwaggerTest.java index b040645774..a8c9bebecc 100644 --- a/restconf/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/MountPointSwaggerTest.java +++ b/restconf/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/MountPointSwaggerTest.java @@ -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 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); -- 2.36.6