summaryrefslogtreecommitdiffstats
path: root/csarvalidation/src/main/java/org/onap
diff options
context:
space:
mode:
authorPawel <pawel.kasperkiewicz@nokia.com>2020-11-12 12:15:55 +0100
committerPawel <pawel.kasperkiewicz@nokia.com>2020-11-24 09:08:06 +0100
commitb6ff67fa1d21765f2f52f3643946c96b2f13aa07 (patch)
treea3c03d814bccabd9de7d16c2da87a0e3a0f7ea08 /csarvalidation/src/main/java/org/onap
parente1be6d1ea065340aaabce761705755970348c6c4 (diff)
Extract pm-dicrionary validation
Issue-ID: VNFSDK-713 Signed-off-by: Pawel <pawel.kasperkiewicz@nokia.com> Change-Id: Iee5a23a3a6c9215927aa2c453faab62d30453444
Diffstat (limited to 'csarvalidation/src/main/java/org/onap')
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/yaml/YamlFileValidator.java72
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/yaml/YamlLoader.java61
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/yaml/YamlValidator.java40
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/yaml/error/SchemaValidationError.java36
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/yaml/error/YamlDocumentValidationError.java42
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/yaml/exception/YamlProcessingException.java33
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java56
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocumentFactory.java52
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java42
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParametersList.java34
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java111
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationStep.java45
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchema.java37
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchemaFactory.java59
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaBranchNode.java80
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaLeafNode.java50
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNode.java66
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java84
18 files changed, 0 insertions, 1000 deletions
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/YamlFileValidator.java b/csarvalidation/src/main/java/org/onap/validation/yaml/YamlFileValidator.java
deleted file mode 100644
index 2de4f48..0000000
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/YamlFileValidator.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2020 Nokia
- *
- * 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.
- *
- */
-
-package org.onap.validation.yaml;
-
-import org.onap.validation.yaml.error.SchemaValidationError;
-import org.onap.validation.yaml.error.YamlDocumentValidationError;
-import org.onap.validation.yaml.exception.YamlProcessingException;
-import org.onap.validation.yaml.model.YamlDocument;
-import org.onap.validation.yaml.schema.YamlSchema;
-import org.onap.validation.yaml.schema.YamlSchemaFactory;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Collectors;
-
-public class YamlFileValidator {
-
- private static final int FIRST_DOCUMENT_INDEX = 1;
-
- public List<YamlDocumentValidationError> validateYamlFileWithSchema(String pathToFile)
- throws YamlProcessingException {
-
- List<YamlDocument> documents = new YamlLoader().loadMultiDocumentYamlFile(pathToFile);
- if(!documents.isEmpty()) {
- return validateDocuments(documents);
- } else {
- throw new YamlProcessingException("PM_Dictionary YAML file is empty");
- }
- }
-
- private List<YamlDocumentValidationError> validateDocuments(List<YamlDocument> documents)
- throws YamlProcessingException {
-
- List<YamlDocumentValidationError> yamlFileValidationErrors = new ArrayList<>();
- YamlSchema schema = extractSchema(documents);
- YamlValidator validator = new YamlValidator(schema);
-
- for (int index = FIRST_DOCUMENT_INDEX; index < documents.size(); index++) {
- List<SchemaValidationError> validationErrors = validator.validate(documents.get(index));
- yamlFileValidationErrors.addAll(transformErrors(index,validationErrors));
- }
-
- return yamlFileValidationErrors;
- }
-
- private List<YamlDocumentValidationError> transformErrors(int index, List<SchemaValidationError> validationErrors) {
- return validationErrors
- .stream()
- .map(error->new YamlDocumentValidationError(index, error.getPath(), error.getMessage()))
- .collect(Collectors.toList());
- }
-
- private YamlSchema extractSchema(List<YamlDocument> documents) throws YamlProcessingException {
- return new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0));
- }
-
-}
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/YamlLoader.java b/csarvalidation/src/main/java/org/onap/validation/yaml/YamlLoader.java
deleted file mode 100644
index 1a5eef9..0000000
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/YamlLoader.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright 2020 Nokia
- *
- * 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.
- *
- */
-
-package org.onap.validation.yaml;
-
-import org.onap.validation.yaml.exception.YamlProcessingException;
-import org.onap.validation.yaml.model.YamlDocument;
-import org.onap.validation.yaml.model.YamlDocumentFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.yaml.snakeyaml.Yaml;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-
-class YamlLoader {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(YamlLoader.class);
-
- List<YamlDocument> loadMultiDocumentYamlFile(URL path)
- throws YamlDocumentFactory.YamlDocumentParsingException {
- List<YamlDocument> documentsFromFile = new ArrayList<>();
- try (InputStream yamlStream = path.openStream()) {
- for (Object yamlDocument : new Yaml().loadAll(yamlStream)) {
- documentsFromFile.add(
- new YamlDocumentFactory().createYamlDocument(yamlDocument)
- );
- }
- } catch (IOException e) {
- LOGGER.error("Failed to load multi document YAML file",e);
- }
- return documentsFromFile;
- }
-
- List<YamlDocument> loadMultiDocumentYamlFile(String path)
- throws YamlProcessingException {
- try {
- return loadMultiDocumentYamlFile(new URL("file://" + path));
- } catch (MalformedURLException e) {
- throw new YamlProcessingException("Fail to read file under given path.", e);
- }
- }
-}
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/YamlValidator.java b/csarvalidation/src/main/java/org/onap/validation/yaml/YamlValidator.java
deleted file mode 100644
index 9430df4..0000000
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/YamlValidator.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2020 Nokia
- *
- * 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.
- *
- */
-
-package org.onap.validation.yaml;
-
-import org.onap.validation.yaml.exception.YamlProcessingException;
-import org.onap.validation.yaml.error.SchemaValidationError;
-import org.onap.validation.yaml.model.YamlDocument;
-import org.onap.validation.yaml.process.YamlValidationProcess;
-import org.onap.validation.yaml.schema.YamlSchema;
-
-import java.util.List;
-
-public class YamlValidator {
-
- private final YamlSchema schema;
-
- YamlValidator(YamlSchema schema) {
- this.schema = schema;
- }
-
- public List<SchemaValidationError> validate(YamlDocument document) throws YamlProcessingException {
- return new YamlValidationProcess(schema,document).validate();
- }
-
-}
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/error/SchemaValidationError.java b/csarvalidation/src/main/java/org/onap/validation/yaml/error/SchemaValidationError.java
deleted file mode 100644
index 6ffe6d4..0000000
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/error/SchemaValidationError.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2020 Nokia
- *
- * 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.
- *
- */
-
-package org.onap.validation.yaml.error;
-
-public class SchemaValidationError {
- private final String path;
- private final String message;
-
- public String getPath() {
- return path;
- }
-
- public String getMessage() {
- return message;
- }
-
- public SchemaValidationError(String path, String message) {
- this.path = path;
- this.message = message;
- }
-}
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/error/YamlDocumentValidationError.java b/csarvalidation/src/main/java/org/onap/validation/yaml/error/YamlDocumentValidationError.java
deleted file mode 100644
index f04708f..0000000
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/error/YamlDocumentValidationError.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2020 Nokia
- *
- * 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.
- *
- */
-
-package org.onap.validation.yaml.error;
-
-public class YamlDocumentValidationError {
- private final int yamlDocumentNumber;
- private final String path;
- private final String message;
-
- public YamlDocumentValidationError(int yamlDocumentNumber, String path, String message) {
- this.yamlDocumentNumber = yamlDocumentNumber;
- this.path = path;
- this.message = message;
- }
-
- public int getYamlDocumentNumber() {
- return yamlDocumentNumber;
- }
-
- public String getPath() {
- return path;
- }
-
- public String getMessage() {
- return message;
- }
-}
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/exception/YamlProcessingException.java b/csarvalidation/src/main/java/org/onap/validation/yaml/exception/YamlProcessingException.java
deleted file mode 100644
index 99c2437..0000000
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/exception/YamlProcessingException.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 2020 Nokia
- *
- * 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.
- *
- */
-
-package org.onap.validation.yaml.exception;
-
-public class YamlProcessingException extends Exception {
-
- public YamlProcessingException(String message, Throwable throwable) {
- super(message, throwable);
- }
-
- public YamlProcessingException(String message) {
- super(message);
- }
-
- public YamlProcessingException(Throwable throwable) {
- super(throwable);
- }
-}
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java b/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java
deleted file mode 100644
index 557b6fd..0000000
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2020 Nokia
- *
- * 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.
- *
- */
-
-package org.onap.validation.yaml.model;
-
-import java.util.Map;
-
-public class YamlDocument {
-
- private final Map<String, Object> yaml;
-
- YamlDocument(Map<String, Object> yaml) {
- this.yaml = yaml;
- }
-
- public Map<String, Object> getYaml() {
- return yaml;
- }
-
- public boolean containsKey(String key) {
- return yaml.containsKey(key);
- }
-
- public String getValue(String key) {
- return yaml.get(key).toString();
- }
-
- public YamlParametersList getListOfValues(String key) {
- return new YamlParameterListFactory().createYamlParameterList(
- yaml.get(key)
- );
- }
-
- public YamlDocument getSubStructure(String name)
- throws YamlDocumentFactory.YamlDocumentParsingException {
- return new YamlDocumentFactory().createYamlDocument(
- yaml.get(name)
- );
- }
-}
-
-
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocumentFactory.java b/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocumentFactory.java
deleted file mode 100644
index b56422c..0000000
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocumentFactory.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2020 Nokia
- *
- * 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.
- *
- */
-
-package org.onap.validation.yaml.model;
-
-import org.onap.validation.yaml.exception.YamlProcessingException;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class YamlDocumentFactory {
-
- public YamlDocument createYamlDocument(Object yaml) throws YamlDocumentParsingException {
- try {
- Map<String, Object> parsedYaml = transformMap((Map) yaml);
- return new YamlDocument(parsedYaml);
- } catch (ClassCastException e) {
- throw new YamlDocumentParsingException(
- String.format("Fail to parse given objects: %s as yaml document.", yaml), e
- );
- }
- }
-
- private Map<String, Object> transformMap(Map<Object, Object> yaml) {
- Map<String, Object> parsedYaml = new HashMap<>();
- for (Map.Entry<Object, Object> entry: yaml.entrySet()) {
- parsedYaml.put(entry.getKey().toString(), entry.getValue());
- }
- return parsedYaml;
- }
-
- public static class YamlDocumentParsingException extends YamlProcessingException {
- YamlDocumentParsingException(String message, Throwable throwable) {
- super(message, throwable);
- }
- }
-
-}
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java b/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java
deleted file mode 100644
index 5f41c5c..0000000
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2020 Nokia
- *
- * 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.
- *
- */
-
-package org.onap.validation.yaml.model;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-public class YamlParameterListFactory {
-
- public YamlParametersList createEmptyYamlParameterList() {
- return new YamlParametersList(Collections.emptyList());
- }
-
- public YamlParametersList createYamlParameterList(Object yaml) {
- List<String> parametersList = new ArrayList<>();
- if( yaml instanceof List) {
- for (Object element : (List) yaml) {
- parametersList.add(element.toString());
- }
- } else {
- parametersList.add(yaml.toString());
- }
- return new YamlParametersList(parametersList);
- }
-
-}
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParametersList.java b/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParametersList.java
deleted file mode 100644
index 2b93c74..0000000
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParametersList.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2020 Nokia
- *
- * 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.
- *
- */
-
-package org.onap.validation.yaml.model;
-
-import java.util.List;
-
-public class YamlParametersList {
-
- private final List<String> parameters;
-
- YamlParametersList(List<String> parameters) {
- this.parameters = parameters;
- }
-
- public List<String> getParameters() {
- return parameters;
- }
-
-}
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java b/csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java
deleted file mode 100644
index 273014b..0000000
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright 2020 Nokia
- *
- * 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.
- *
- */
-
-package org.onap.validation.yaml.process;
-
-import org.onap.validation.yaml.exception.YamlProcessingException;
-import org.onap.validation.yaml.error.SchemaValidationError;
-import org.onap.validation.yaml.model.YamlDocument;
-import org.onap.validation.yaml.schema.YamlSchema;
-import org.onap.validation.yaml.schema.node.YamlSchemaNode;
-
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Queue;
-
-public class YamlValidationProcess {
-
- private final Queue<YamlValidationStep> validationSteps;
- private final List<SchemaValidationError> errors;
- private final YamlSchema schema;
- private final YamlDocument document;
-
- public YamlValidationProcess(YamlSchema schema, YamlDocument document) {
- this.schema = schema;
- this.document = document;
- errors = new ArrayList<>();
- validationSteps = new LinkedList<>();
- }
-
- public List<SchemaValidationError> validate() throws YamlProcessingException {
- validationSteps.add(new YamlValidationStep(schema.getRootNodes(), document));
- while (!validationSteps.isEmpty()) {
- YamlValidationStep nextValidationNode = validationSteps.poll();
- validateStep(nextValidationNode);
- }
- return errors;
- }
-
- private void validateStep(YamlValidationStep validationNode)
- throws YamlProcessingException {
- for (YamlSchemaNode schemaNode : validationNode.getSchemaNodes()) {
- validateNode(validationNode.getDocument(), schemaNode);
- }
- }
-
- private void validateNode(YamlDocument document, YamlSchemaNode schemaNode)
- throws YamlProcessingException {
-
- if (document.containsKey(schemaNode.getName())) {
- if (schemaNode.isContainingSubStructure()) {
- addNextLevelNodeToValidationNodesQueue(document, schemaNode);
- } else if (!isValueOfNodeInAcceptedValuesList(document, schemaNode)) {
- addIncorrectValueError(document, schemaNode);
- }
- } else if (schemaNode.isRequired()) {
- addRequiredKeyNotFoundError(schemaNode);
- }
- }
-
- private boolean isValueOfNodeInAcceptedValuesList(YamlDocument document, YamlSchemaNode node) {
- return node.getAcceptedValues().isEmpty() ||
- node.getAcceptedValues().containsAll(
- document.getListOfValues(node.getName()).getParameters()
- );
- }
-
- private void addNextLevelNodeToValidationNodesQueue(YamlDocument document, YamlSchemaNode node)
- throws YamlProcessingException {
- validationSteps.add(
- new YamlValidationStep(
- node.getNextNodes(),
- document.getSubStructure(node.getName())
- )
- );
- }
-
- private void addRequiredKeyNotFoundError(YamlSchemaNode node) {
- errors.add(
- new SchemaValidationError(
- node.getPath(),
- String.format("Key not found: %s", node.getName())
- )
- );
- }
-
- private void addIncorrectValueError(YamlDocument document, YamlSchemaNode node) {
- errors.add(
- new SchemaValidationError(
- node.getPath() + node.getName(),
- String.format(
- "Value(s) is/are not in array of accepted values.%n value(s): %s%n accepted value(s): %s",
- document.getValue(node.getName()), node.getAcceptedValues())
- )
- );
- }
-}
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationStep.java b/csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationStep.java
deleted file mode 100644
index eb5ab8e..0000000
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationStep.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2020 Nokia
- *
- * 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.
- *
- */
-
-package org.onap.validation.yaml.process;
-
-import org.onap.validation.yaml.model.YamlDocument;
-import org.onap.validation.yaml.schema.node.YamlSchemaNode;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-class YamlValidationStep {
-
- private final List<YamlSchemaNode> schemaNodes;
- private final YamlDocument document;
-
- YamlValidationStep(List<YamlSchemaNode> nodes, YamlDocument yaml) {
- this.schemaNodes = new ArrayList<>(nodes);
- this.document = yaml;
- }
-
- List<YamlSchemaNode> getSchemaNodes() {
- return Collections.unmodifiableList(schemaNodes);
- }
-
- YamlDocument getDocument() {
- return document;
- }
-
-}
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchema.java b/csarvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchema.java
deleted file mode 100644
index 69bb6cd..0000000
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchema.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2020 Nokia
- *
- * 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.
- *
- */
-
-package org.onap.validation.yaml.schema;
-
-import org.onap.validation.yaml.schema.node.YamlSchemaNode;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-public class YamlSchema {
-
- private final List<YamlSchemaNode> rootNodes;
-
- public List<YamlSchemaNode> getRootNodes() {
- return Collections.unmodifiableList(rootNodes);
- }
-
- YamlSchema(List<YamlSchemaNode> rootNodes) {
- this.rootNodes = new ArrayList<>(rootNodes);
- }
-}
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchemaFactory.java b/csarvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchemaFactory.java
deleted file mode 100644
index df7d673..0000000
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchemaFactory.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2020 Nokia
- *
- * 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.
- *
- */
-
-
-package org.onap.validation.yaml.schema;
-
-import org.onap.validation.yaml.exception.YamlProcessingException;
-import org.onap.validation.yaml.model.YamlDocument;
-import org.onap.validation.yaml.model.YamlDocumentFactory;
-import org.onap.validation.yaml.schema.node.YamlSchemaNode;
-import org.onap.validation.yaml.schema.node.YamlSchemaNodeFactory;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class YamlSchemaFactory {
-
-
- private static final String ROOT_PATH = "/";
-
- public YamlSchema createTreeStructuredYamlSchema(YamlDocument schema)
- throws YamlProcessingException {
-
- return new YamlSchema(getRootNodes(schema));
- }
-
- private List<YamlSchemaNode> getRootNodes(YamlDocument yamlDocument)
- throws YamlProcessingException {
-
- List<YamlSchemaNode> nextNodes = new ArrayList<>();
- for(String nodeName: yamlDocument.getYaml().keySet()) {
- nextNodes.add(
- new YamlSchemaNodeFactory().createNode(
- nodeName,
- ROOT_PATH,
- new YamlDocumentFactory().createYamlDocument(
- yamlDocument.getYaml().get(nodeName)
- )
- )
- );
- }
- return nextNodes;
- }
-
-}
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaBranchNode.java b/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaBranchNode.java
deleted file mode 100644
index 0f5b480..0000000
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaBranchNode.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright 2020 Nokia
- *
- * 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.
- *
- */
-
-package org.onap.validation.yaml.schema.node;
-
-import org.onap.validation.yaml.exception.YamlProcessingException;
-import org.onap.validation.yaml.model.YamlDocument;
-import org.onap.validation.yaml.model.YamlDocumentFactory;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
-
-public class YamlSchemaBranchNode extends YamlSchemaNode {
-
- private final YamlDocument nextNodesInLazyForm;
- private Optional<List<YamlSchemaNode>> nextNodes;
-
- YamlSchemaBranchNode(String name, String path, boolean required, String comment,
- YamlDocument nextNodesInLazyForm) {
- super(name, path, required, comment);
- this.nextNodesInLazyForm = nextNodesInLazyForm;
- this.nextNodes = Optional.empty();
- }
-
- @Override
- public boolean isContainingSubStructure() {
- return true;
- }
-
- @Override
- public List<String> getAcceptedValues() {
- return Collections.emptyList();
- }
-
- @Override
- public synchronized List<YamlSchemaNode> getNextNodes() throws YamlSchemaProcessingException {
- try {
- return nextNodes.orElseGet(this::loadNextNodes);
- } catch (YamlSchemaLazyLoadingException lazyLoadingException) {
- throw new YamlSchemaProcessingException(lazyLoadingException);
- }
- }
-
- private List<YamlSchemaNode> loadNextNodes() {
- try {
- List<YamlSchemaNode> loadedNextNodes = new ArrayList<>();
- for (String key : nextNodesInLazyForm.getYaml().keySet()) {
- YamlDocument substructure = new YamlDocumentFactory()
- .createYamlDocument(nextNodesInLazyForm.getYaml().get(key));
- loadedNextNodes.add(new YamlSchemaNodeFactory().createNode(key, getPath() + getName() + "/", substructure));
- }
- nextNodes = Optional.of(loadedNextNodes);
- return loadedNextNodes;
- } catch (YamlProcessingException e) {
- throw new YamlSchemaLazyLoadingException("Lazy loading failed, due to yaml parsing exception.",e);
- }
- }
-
- static class YamlSchemaLazyLoadingException extends RuntimeException {
- YamlSchemaLazyLoadingException(String message, Throwable throwable) {
- super(message, throwable);
- }
- }
-}
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaLeafNode.java b/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaLeafNode.java
deleted file mode 100644
index c98f41e..0000000
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaLeafNode.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2020 Nokia
- *
- * 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.
- *
- */
-
-package org.onap.validation.yaml.schema.node;
-
-import org.onap.validation.yaml.model.YamlParametersList;
-
-import java.util.Collections;
-import java.util.List;
-
-public class YamlSchemaLeafNode extends YamlSchemaNode {
-
- private final YamlParametersList acceptedValues;
-
- YamlSchemaLeafNode(String name, String path, boolean required, String comment,
- YamlParametersList acceptedValues) {
- super(name, path, required, comment);
- this.acceptedValues = acceptedValues;
- }
-
- @Override
- public List<String> getAcceptedValues() {
- return acceptedValues.getParameters();
- }
-
- @Override
- public List<YamlSchemaNode> getNextNodes() {
- return Collections.emptyList();
- }
-
- @Override
- public boolean isContainingSubStructure() {
- return false;
- }
-
-}
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNode.java b/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNode.java
deleted file mode 100644
index 28913a2..0000000
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNode.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2020 Nokia
- *
- * 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.
- *
- */
-
-package org.onap.validation.yaml.schema.node;
-
-import org.onap.validation.yaml.exception.YamlProcessingException;
-
-import java.util.List;
-
-public abstract class YamlSchemaNode {
-
- private final String path;
- private final String name;
- private final boolean required;
- private final String comment;
-
-
- public String getName() {
- return name;
- }
-
- public String getPath() {
- return path;
- }
-
- public boolean isRequired() {
- return required;
- }
-
- public abstract List<String> getAcceptedValues();
-
- public abstract List<YamlSchemaNode> getNextNodes() throws YamlSchemaProcessingException;
-
- public abstract boolean isContainingSubStructure();
-
- public String getComment() {
- return comment;
- }
-
- YamlSchemaNode(String name, String path, boolean required, String comment) {
- this.name = name;
- this.path = path;
- this.required = required;
- this.comment = comment;
- }
-
- static class YamlSchemaProcessingException extends YamlProcessingException {
- YamlSchemaProcessingException(Throwable throwable) {
- super(throwable);
- }
- }
-}
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java b/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java
deleted file mode 100644
index 79a8f14..0000000
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright 2020 Nokia
- *
- * 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.
- *
- */
-
-package org.onap.validation.yaml.schema.node;
-
-import org.onap.validation.yaml.exception.YamlProcessingException;
-import org.onap.validation.yaml.model.YamlDocument;
-import org.onap.validation.yaml.model.YamlDocumentFactory;
-import org.onap.validation.yaml.model.YamlParameterListFactory;
-import org.onap.validation.yaml.model.YamlParametersList;
-
-import static org.onap.validation.yaml.model.YamlDocumentFactory.YamlDocumentParsingException;
-
-public class YamlSchemaNodeFactory {
-
- public static final String EMPTY_COMMENT = "no comment available";
- static final String STRUCTURE_KEY = "structure";
- static final String COMMENT_KEY = "comment";
- static final String VALUE_KET = "value";
- static final String PRESENCE_KEY = "presence";
- static final String PRESENCE_REQUIRED_KEY = "required";
-
- public YamlSchemaNode createNode(String nodeName, String path, YamlDocument yamlDocument)
- throws YamlProcessingException {
-
- YamlSchemaNode yamlSchemaNode;
- if(isYamlContainingKey(yamlDocument, STRUCTURE_KEY)) {
- yamlSchemaNode = new YamlSchemaBranchNode(
- nodeName, path, getIsPresenceRequired(yamlDocument), getComment(yamlDocument),
- getNextNodes(yamlDocument)
- );
- } else {
- yamlSchemaNode = new YamlSchemaLeafNode(
- nodeName, path, getIsPresenceRequired(yamlDocument), getComment(yamlDocument),
- getAcceptedValues(yamlDocument)
- );
- }
- return yamlSchemaNode;
- }
-
- private YamlDocument getNextNodes(YamlDocument yamlDocument)
- throws YamlDocumentParsingException {
- return new YamlDocumentFactory().createYamlDocument(yamlDocument.getYaml().get(STRUCTURE_KEY));
- }
-
- private String getComment(YamlDocument yamlDocument) {
-
- return isYamlContainingKey(yamlDocument, COMMENT_KEY)
- ? yamlDocument.getYaml().get(COMMENT_KEY).toString()
- : EMPTY_COMMENT;
- }
-
- private YamlParametersList getAcceptedValues(YamlDocument yamlDocument) {
-
- return isYamlContainingKey(yamlDocument, VALUE_KET)
- ? new YamlParameterListFactory().createYamlParameterList(yamlDocument.getYaml().get(VALUE_KET))
- : new YamlParameterListFactory().createEmptyYamlParameterList();
- }
-
- private boolean getIsPresenceRequired(YamlDocument yamlDocument) {
-
- return isYamlContainingKey(yamlDocument, PRESENCE_KEY)
- && yamlDocument.getYaml().get(PRESENCE_KEY).equals(PRESENCE_REQUIRED_KEY);
- }
-
- private boolean isYamlContainingKey(YamlDocument yamlDocument, String structureKey) {
- return yamlDocument.getYaml().containsKey(structureKey);
- }
-
-}