From f925587e61afd94d8510420e2c4df886e12cfad5 Mon Sep 17 00:00:00 2001 From: Rishi Chail Date: Mon, 28 Sep 2020 12:30:58 +0100 Subject: IS: Add CheckStyle goal to Maven Issue-ID: CCSDK-2746 https: //jira.onap.org/browse/CCSDK-2746 Change-Id: I0442b62cbecb16c979a43d3d5d68fdb1c62a2276 --- .../onap/cps/rest/controller/RestController.java | 4 +- .../src/main/java/org/onap/cps/api/CPService.java | 55 ------------- .../src/main/java/org/onap/cps/api/CpService.java | 55 +++++++++++++ .../java/org/onap/cps/api/impl/CPServiceImpl.java | 89 ---------------------- .../java/org/onap/cps/api/impl/CpServiceImpl.java | 89 ++++++++++++++++++++++ .../org/onap/cps/spi/ModelPersistencyService.java | 7 +- cps/pom.xml | 6 +- 7 files changed, 153 insertions(+), 152 deletions(-) delete mode 100644 cps/cps-service/src/main/java/org/onap/cps/api/CPService.java create mode 100644 cps/cps-service/src/main/java/org/onap/cps/api/CpService.java delete mode 100644 cps/cps-service/src/main/java/org/onap/cps/api/impl/CPServiceImpl.java create mode 100644 cps/cps-service/src/main/java/org/onap/cps/api/impl/CpServiceImpl.java diff --git a/cps/cps-rest/src/main/java/org/onap/cps/rest/controller/RestController.java b/cps/cps-rest/src/main/java/org/onap/cps/rest/controller/RestController.java index d2f1a3e03..dc6411009 100644 --- a/cps/cps-rest/src/main/java/org/onap/cps/rest/controller/RestController.java +++ b/cps/cps-rest/src/main/java/org/onap/cps/rest/controller/RestController.java @@ -29,7 +29,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; import org.glassfish.jersey.media.multipart.FormDataParam; -import org.onap.cps.api.CPService; +import org.onap.cps.api.CpService; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.parser.api.YangParserException; import org.springframework.beans.factory.annotation.Autowired; @@ -39,7 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired; public class RestController { @Autowired - private CPService cpService; + private CpService cpService; @POST @Path("uploadYangFile") diff --git a/cps/cps-service/src/main/java/org/onap/cps/api/CPService.java b/cps/cps-service/src/main/java/org/onap/cps/api/CPService.java deleted file mode 100644 index 51622c3b0..000000000 --- a/cps/cps-service/src/main/java/org/onap/cps/api/CPService.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.cps.api; - -import java.io.File; -import java.io.IOException; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.parser.api.YangParserException; - -/** - * Configuration and persistency service interface which holds methods for parsing and storing yang models and data. - */ -public interface CPService { - - /** - * Parse and validate a string representing a yang model to generate a schema context. - * - * @param yangModelContent the input stream - * @return the schema context - */ - SchemaContext parseAndValidateModel(final String yangModelContent) throws IOException, YangParserException; - - /** - * Parse and validate a file representing a yang model to generate a schema context. - * - * @param yangModelFile the yang file - * @return the schema context - */ - SchemaContext parseAndValidateModel(final File yangModelFile) throws IOException, YangParserException; - - /** - * Store schema context for a yang model. - * - * @param schemaContext the schema context - */ - void storeSchemaContext(final SchemaContext schemaContext); - -} diff --git a/cps/cps-service/src/main/java/org/onap/cps/api/CpService.java b/cps/cps-service/src/main/java/org/onap/cps/api/CpService.java new file mode 100644 index 000000000..a5ab485f6 --- /dev/null +++ b/cps/cps-service/src/main/java/org/onap/cps/api/CpService.java @@ -0,0 +1,55 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.api; + +import java.io.File; +import java.io.IOException; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.parser.api.YangParserException; + +/** + * Configuration and persistency service interface which holds methods for parsing and storing yang models and data. + */ +public interface CpService { + + /** + * Parse and validate a string representing a yang model to generate a schema context. + * + * @param yangModelContent the input stream + * @return the schema context + */ + SchemaContext parseAndValidateModel(final String yangModelContent) throws IOException, YangParserException; + + /** + * Parse and validate a file representing a yang model to generate a schema context. + * + * @param yangModelFile the yang file + * @return the schema context + */ + SchemaContext parseAndValidateModel(final File yangModelFile) throws IOException, YangParserException; + + /** + * Store schema context for a yang model. + * + * @param schemaContext the schema context + */ + void storeSchemaContext(final SchemaContext schemaContext); + +} diff --git a/cps/cps-service/src/main/java/org/onap/cps/api/impl/CPServiceImpl.java b/cps/cps-service/src/main/java/org/onap/cps/api/impl/CPServiceImpl.java deleted file mode 100644 index 5bd6e4490..000000000 --- a/cps/cps-service/src/main/java/org/onap/cps/api/impl/CPServiceImpl.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.cps.api.impl; - - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.Iterator; -import java.util.ServiceLoader; -import org.onap.cps.api.CPService; -import org.onap.cps.spi.ModelPersistencyService; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.parser.api.YangParser; -import org.opendaylight.yangtools.yang.model.parser.api.YangParserException; -import org.opendaylight.yangtools.yang.model.parser.api.YangParserFactory; -import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode; -import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class CPServiceImpl implements CPService { - - private final static Logger LOGGER = LoggerFactory.getLogger(CPServiceImpl.class); - - private static final YangParserFactory PARSER_FACTORY; - - static { - final Iterator it = - ServiceLoader.load(YangParserFactory.class).iterator(); - if (!it.hasNext()) { - throw new IllegalStateException("No YangParserFactory found"); - } - PARSER_FACTORY = it.next(); - } - - @Autowired - private ModelPersistencyService modelPersistencyService; - - @Override - public SchemaContext parseAndValidateModel(final String yangModelContent) - throws IOException, YangParserException { - final File tempFile = File.createTempFile("yang", ".yang"); - try (BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile))) { - writer.write(yangModelContent); - } catch (IOException e) { - LOGGER.error("Unable to write to temporary file {}", e.getMessage()); - } - return parseAndValidateModel(tempFile); - } - - @Override - public SchemaContext parseAndValidateModel(final File yangModelFile) throws IOException, YangParserException { - final YangTextSchemaSource yangTextSchemaSource = YangTextSchemaSource.forFile(yangModelFile); - final YangParser yangParser = PARSER_FACTORY.createParser(StatementParserMode.DEFAULT_MODE); - yangParser.addSource(yangTextSchemaSource); - return yangParser.buildEffectiveModel(); - } - - @Override - public void storeSchemaContext(final SchemaContext schemaContext) { - for (final Module module : schemaContext.getModules()) { - modelPersistencyService.storeModule(module.getName(), module.toString(), - module.getRevision().toString()); - } - } -} diff --git a/cps/cps-service/src/main/java/org/onap/cps/api/impl/CpServiceImpl.java b/cps/cps-service/src/main/java/org/onap/cps/api/impl/CpServiceImpl.java new file mode 100644 index 000000000..b71e4714b --- /dev/null +++ b/cps/cps-service/src/main/java/org/onap/cps/api/impl/CpServiceImpl.java @@ -0,0 +1,89 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.api.impl; + + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Iterator; +import java.util.ServiceLoader; +import org.onap.cps.api.CpService; +import org.onap.cps.spi.ModelPersistencyService; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.parser.api.YangParser; +import org.opendaylight.yangtools.yang.model.parser.api.YangParserException; +import org.opendaylight.yangtools.yang.model.parser.api.YangParserFactory; +import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode; +import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class CpServiceImpl implements CpService { + + private static final Logger LOGGER = LoggerFactory.getLogger(CpServiceImpl.class); + + private static final YangParserFactory PARSER_FACTORY; + + static { + final Iterator it = + ServiceLoader.load(YangParserFactory.class).iterator(); + if (!it.hasNext()) { + throw new IllegalStateException("No YangParserFactory found"); + } + PARSER_FACTORY = it.next(); + } + + @Autowired + private ModelPersistencyService modelPersistencyService; + + @Override + public SchemaContext parseAndValidateModel(final String yangModelContent) + throws IOException, YangParserException { + final File tempFile = File.createTempFile("yang", ".yang"); + try (BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile))) { + writer.write(yangModelContent); + } catch (final IOException e) { + LOGGER.error("Unable to write to temporary file {}", e.getMessage()); + } + return parseAndValidateModel(tempFile); + } + + @Override + public SchemaContext parseAndValidateModel(final File yangModelFile) throws IOException, YangParserException { + final YangTextSchemaSource yangTextSchemaSource = YangTextSchemaSource.forFile(yangModelFile); + final YangParser yangParser = PARSER_FACTORY.createParser(StatementParserMode.DEFAULT_MODE); + yangParser.addSource(yangTextSchemaSource); + return yangParser.buildEffectiveModel(); + } + + @Override + public void storeSchemaContext(final SchemaContext schemaContext) { + for (final Module module : schemaContext.getModules()) { + modelPersistencyService.storeModule(module.getName(), module.toString(), + module.getRevision().toString()); + } + } +} diff --git a/cps/cps-service/src/main/java/org/onap/cps/spi/ModelPersistencyService.java b/cps/cps-service/src/main/java/org/onap/cps/spi/ModelPersistencyService.java index e0286c1b2..f88c6b241 100644 --- a/cps/cps-service/src/main/java/org/onap/cps/spi/ModelPersistencyService.java +++ b/cps/cps-service/src/main/java/org/onap/cps/spi/ModelPersistencyService.java @@ -26,9 +26,10 @@ public interface ModelPersistencyService { /** * Store the module from a yang model in the database. - * @param name - * @param moduleContent - * @param revision + * + * @param name module name + * @param moduleContent module content + * @param revision module revision */ void storeModule(final String name, final String moduleContent, final String revision); diff --git a/cps/pom.xml b/cps/pom.xml index 1c1b2b151..7f50cb143 100644 --- a/cps/pom.xml +++ b/cps/pom.xml @@ -86,9 +86,9 @@ true true true - true + false warning - true + true @@ -111,4 +111,4 @@ cps-ri - \ No newline at end of file + -- cgit 1.2.3-korg