summaryrefslogtreecommitdiffstats
path: root/csarvalidation/src/main/java
diff options
context:
space:
mode:
authorBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>2020-08-27 13:35:16 +0200
committerBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>2020-08-27 14:17:03 +0200
commit2dec83af8abdb08d1db06afbcaec7325e098276a (patch)
tree4c90b897fc9ee6be42908aa35011bdf7f45d2a20 /csarvalidation/src/main/java
parent42253e812eb43110c4b49f23d13246943bb8a458 (diff)
Fix searching for path to PM_Dictionary in manifest file.
Signed-off-by: Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com> Change-Id: I3bf22f9095c560fa6c98e37b6d28b306e9af4d95 Issue-ID: VNFSDK-645
Diffstat (limited to 'csarvalidation/src/main/java')
-rw-r--r--csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745.java37
1 files changed, 30 insertions, 7 deletions
diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745.java b/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745.java
index a929418..b43dbba 100644
--- a/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745.java
+++ b/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745.java
@@ -29,6 +29,7 @@ import org.yaml.snakeyaml.error.YAMLException;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
@OnapCommandSchema(schema = "vtp-validate-csar-r816745.yaml")
public class VTPValidateCSARR816745 extends VTPValidateCSARBase {
@@ -65,18 +66,32 @@ public class VTPValidateCSARR816745 extends VTPValidateCSARBase {
}
private static final String PM_DICTIONARY = "onap_pm_dictionary";
+ private static final String SOURCE_ELEMENT_TAG = "Source";
@Override
protected void validateCSAR(CSARArchive csar) {
Map<String, Map<String, List<String>>> nonManoFields = csar.getManifest().getNonMano();
String rootPath = csar.getWorkspace().getPathToCsarFolder().map(Path::toString).orElse("/");
if (nonManoFields.containsKey(PM_DICTIONARY)) {
- validateYamlFile(rootPath+"/",getLocationOfPmDictionaryFile(nonManoFields));
+ getLocationOfPmDictionaryFile(nonManoFields, csar.getManifestMfFile().getName()).ifPresent(pmDictionary ->
+ validateYamlFile(rootPath+"/",pmDictionary)
+ );
}
}
- private String getLocationOfPmDictionaryFile(Map<String, Map<String, List<String>>> nonManoFields) {
- return nonManoFields.get(PM_DICTIONARY).get("source").get(0);
+ private Optional<String> getLocationOfPmDictionaryFile(Map<String, Map<String, List<String>>> nonManoFields, String manifestFileName) {
+ if(nonManoFields.get(PM_DICTIONARY).containsKey(SOURCE_ELEMENT_TAG)) {
+ return getPathToPmDictionary(nonManoFields, SOURCE_ELEMENT_TAG);
+ } else if(nonManoFields.get(PM_DICTIONARY).containsKey(SOURCE_ELEMENT_TAG.toLowerCase())) {
+ return getPathToPmDictionary(nonManoFields, SOURCE_ELEMENT_TAG.toLowerCase());
+ } else {
+ addPmDictionaryLoadingError(manifestFileName, PM_DICTIONARY +" in manifest does not contains key 'Source'");
+ return Optional.empty();
+ }
+ }
+
+ private Optional<String> getPathToPmDictionary(Map<String, Map<String, List<String>>> nonManoFields, String sourceElementTag) {
+ return Optional.ofNullable(nonManoFields.get(PM_DICTIONARY).get(sourceElementTag).get(0));
}
private void validateYamlFile(String rootPath, String artifactPath) {
@@ -86,14 +101,22 @@ public class VTPValidateCSARR816745 extends VTPValidateCSARBase {
addAllErrorsReportedByVaidator(artifactPath, validationErrors);
} catch (YamlProcessingException | YAMLException e) {
LOGGER.error("Failed to load PM_Dictionary file.", e);
- errors.add(new CSARPmDictionaryLoadingError(
- artifactPath,
- e.getMessage()
- ));
+ addPmDictionaryLoadingError(artifactPath, e);
}
}
+ private void addPmDictionaryLoadingError(String artifactPath, Exception e) {
+ addPmDictionaryLoadingError(artifactPath,e.getMessage());
+ }
+
+ private void addPmDictionaryLoadingError(String artifactPath, String message) {
+ errors.add(new CSARPmDictionaryLoadingError(
+ artifactPath,
+ message
+ ));
+ }
+
private void addAllErrorsReportedByVaidator(String artifactPath, List<YamlDocumentValidationError> validationErrors) {
for(YamlDocumentValidationError validationError: validationErrors) {
addPmDictionaryValidationError(artifactPath, validationError);