aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/sdc/toscaparser/api/ImportsLoader.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/onap/sdc/toscaparser/api/ImportsLoader.java')
-rw-r--r--src/main/java/org/onap/sdc/toscaparser/api/ImportsLoader.java709
1 files changed, 345 insertions, 364 deletions
diff --git a/src/main/java/org/onap/sdc/toscaparser/api/ImportsLoader.java b/src/main/java/org/onap/sdc/toscaparser/api/ImportsLoader.java
index 5ef639b..019adb3 100644
--- a/src/main/java/org/onap/sdc/toscaparser/api/ImportsLoader.java
+++ b/src/main/java/org/onap/sdc/toscaparser/api/ImportsLoader.java
@@ -7,9 +7,9 @@
* 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.
@@ -37,202 +37,197 @@ import java.util.*;
public class ImportsLoader {
- private static Logger log = LoggerFactory.getLogger(ImportsLoader.class.getName());
- private static final String FILE = "file";
- private static final String REPOSITORY = "repository";
- private static final String NAMESPACE_URI = "namespace_uri";
- private static final String NAMESPACE_PREFIX = "namespace_prefix";
+ private static Logger log = LoggerFactory.getLogger(ImportsLoader.class.getName());
+ private static final String FILE = "file";
+ private static final String REPOSITORY = "repository";
+ private static final String NAMESPACE_URI = "namespace_uri";
+ private static final String NAMESPACE_PREFIX = "namespace_prefix";
private String IMPORTS_SECTION[] = {FILE, REPOSITORY, NAMESPACE_URI, NAMESPACE_PREFIX};
-
- private ArrayList<Object> importslist;
- private String path;
- private ArrayList<String> typeDefinitionList;
-
- private LinkedHashMap<String,Object> customDefs;
- private LinkedHashMap<String,Object> allCustomDefs;
- private ArrayList<LinkedHashMap<String,Object>> nestedToscaTpls;
- private LinkedHashMap<String,Object> repositories;
-
- @SuppressWarnings("unchecked")
- public ImportsLoader(ArrayList<Object>_importslist,
- String _path,
- Object _typeDefinitionList,
- LinkedHashMap<String,Object> tpl) {
-
- this.importslist = _importslist;
- customDefs = new LinkedHashMap<String,Object>();
- allCustomDefs = new LinkedHashMap<String,Object>();
- nestedToscaTpls = new ArrayList<LinkedHashMap<String,Object>>();
- if((_path == null || _path.isEmpty()) && tpl == null) {
- //msg = _('Input tosca template is not provided.')
- //log.warning(msg)
- ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE184", "ValidationError: Input tosca template is not provided"));
- }
-
- this.path = _path;
- this.repositories = new LinkedHashMap<String,Object>();
-
- if(tpl != null && tpl.get("repositories") != null) {
- this.repositories = (LinkedHashMap<String,Object>)tpl.get("repositories");
- }
- this.typeDefinitionList = new ArrayList<String>();
- if(_typeDefinitionList != null) {
- if(_typeDefinitionList instanceof ArrayList) {
- this.typeDefinitionList = (ArrayList<String>)_typeDefinitionList;
- }
- else {
- this.typeDefinitionList.add((String)_typeDefinitionList);
- }
- }
- _validateAndLoadImports();
- }
-
- public LinkedHashMap<String,Object> getCustomDefs() {
- return allCustomDefs;
- }
-
- public ArrayList<LinkedHashMap<String,Object>> getNestedToscaTpls() {
- return nestedToscaTpls;
+
+ private ArrayList<Object> importslist;
+ private String path;
+ private ArrayList<String> typeDefinitionList;
+
+ private LinkedHashMap<String, Object> customDefs;
+ private LinkedHashMap<String, Object> allCustomDefs;
+ private ArrayList<LinkedHashMap<String, Object>> nestedToscaTpls;
+ private LinkedHashMap<String, Object> repositories;
+
+ @SuppressWarnings("unchecked")
+ public ImportsLoader(ArrayList<Object> _importslist,
+ String _path,
+ Object _typeDefinitionList,
+ LinkedHashMap<String, Object> tpl) {
+
+ this.importslist = _importslist;
+ customDefs = new LinkedHashMap<String, Object>();
+ allCustomDefs = new LinkedHashMap<String, Object>();
+ nestedToscaTpls = new ArrayList<LinkedHashMap<String, Object>>();
+ if ((_path == null || _path.isEmpty()) && tpl == null) {
+ //msg = _('Input tosca template is not provided.')
+ //log.warning(msg)
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE184", "ValidationError: Input tosca template is not provided"));
+ }
+
+ this.path = _path;
+ this.repositories = new LinkedHashMap<String, Object>();
+
+ if (tpl != null && tpl.get("repositories") != null) {
+ this.repositories = (LinkedHashMap<String, Object>) tpl.get("repositories");
+ }
+ this.typeDefinitionList = new ArrayList<String>();
+ if (_typeDefinitionList != null) {
+ if (_typeDefinitionList instanceof ArrayList) {
+ this.typeDefinitionList = (ArrayList<String>) _typeDefinitionList;
+ } else {
+ this.typeDefinitionList.add((String) _typeDefinitionList);
+ }
+ }
+ _validateAndLoadImports();
+ }
+
+ public LinkedHashMap<String, Object> getCustomDefs() {
+ return allCustomDefs;
}
-
- @SuppressWarnings({ "unchecked", "unused" })
- public void _validateAndLoadImports() {
- Set<String> importNames = new HashSet<String>();
-
- if(importslist == null) {
+
+ public ArrayList<LinkedHashMap<String, Object>> getNestedToscaTpls() {
+ return nestedToscaTpls;
+ }
+
+ @SuppressWarnings({"unchecked", "unused"})
+ public void _validateAndLoadImports() {
+ Set<String> importNames = new HashSet<String>();
+
+ if (importslist == null) {
//msg = _('"imports" keyname is defined without including templates.')
//log.error(msg)
- ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE185",
- "ValidationError: \"imports\" keyname is defined without including templates"));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE185",
+ "ValidationError: \"imports\" keyname is defined without including templates"));
return;
- }
-
- for(Object importDef: importslist) {
- String fullFileName = null;
- LinkedHashMap<String,Object> customType = null;
- if(importDef instanceof LinkedHashMap) {
- for(Map.Entry<String,Object> me: ((LinkedHashMap<String,Object>)importDef).entrySet()) {
- String importName = me.getKey();
- Object importUri = me.getValue();
- if(importNames.contains(importName)) {
+ }
+
+ for (Object importDef : importslist) {
+ String fullFileName = null;
+ LinkedHashMap<String, Object> customType = null;
+ if (importDef instanceof LinkedHashMap) {
+ for (Map.Entry<String, Object> me : ((LinkedHashMap<String, Object>) importDef).entrySet()) {
+ String importName = me.getKey();
+ Object importUri = me.getValue();
+ if (importNames.contains(importName)) {
//msg = (_('Duplicate import name "%s" was found.') % import_name)
//log.error(msg)
ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE186", String.format(
- "ValidationError: Duplicate import name \"%s\" was found",importName)));
- }
- importNames.add(importName); //???
-
- // _loadImportTemplate returns 2 objects
- Object ffnct[] = _loadImportTemplate(importName, importUri);
- fullFileName = (String)ffnct[0];
- customType = (LinkedHashMap<String,Object>)ffnct[1];
- String namespacePrefix = "";
- if(importUri instanceof LinkedHashMap) {
- namespacePrefix = (String)
- ((LinkedHashMap<String,Object>)importUri).get(NAMESPACE_PREFIX);
- }
-
- if(customType != null) {
- TypeValidation tv = new TypeValidation(customType, importDef);
+ "ValidationError: Duplicate import name \"%s\" was found", importName)));
+ }
+ importNames.add(importName); //???
+
+ // _loadImportTemplate returns 2 objects
+ Object ffnct[] = _loadImportTemplate(importName, importUri);
+ fullFileName = (String) ffnct[0];
+ customType = (LinkedHashMap<String, Object>) ffnct[1];
+ String namespacePrefix = "";
+ if (importUri instanceof LinkedHashMap) {
+ namespacePrefix = (String)
+ ((LinkedHashMap<String, Object>) importUri).get(NAMESPACE_PREFIX);
+ }
+
+ if (customType != null) {
+ TypeValidation tv = new TypeValidation(customType, importDef);
_updateCustomDefs(customType, namespacePrefix);
- }
- }
- }
- else { // old style of imports
- // _loadImportTemplate returns 2 objects
- Object ffnct[] = _loadImportTemplate(null,importDef);
- fullFileName = (String)ffnct[0];
- customType = (LinkedHashMap<String,Object>)ffnct[1];
- if(customType != null) {
- TypeValidation tv = new TypeValidation(customType,importDef);
- _updateCustomDefs(customType,null);
+ }
}
- }
+ } else { // old style of imports
+ // _loadImportTemplate returns 2 objects
+ Object ffnct[] = _loadImportTemplate(null, importDef);
+ fullFileName = (String) ffnct[0];
+ customType = (LinkedHashMap<String, Object>) ffnct[1];
+ if (customType != null) {
+ TypeValidation tv = new TypeValidation(customType, importDef);
+ _updateCustomDefs(customType, null);
+ }
+ }
_updateNestedToscaTpls(fullFileName, customType);
-
- }
+
+ }
}
- /**
- * This method is used to get consolidated custom definitions by passing custom Types from
- * each import. The resultant collection is then passed back which contains all import
- * definitions
- *
- * @param customType the custom type
- * @param namespacePrefix the namespace prefix
- */
- @SuppressWarnings("unchecked")
- private void _updateCustomDefs(LinkedHashMap<String,Object> customType, String namespacePrefix) {
- LinkedHashMap<String,Object> outerCustomTypes;
- for(String typeDef: typeDefinitionList) {
- if(typeDef.equals("imports")) {
- customDefs.put("imports", customType.get(typeDef));
- if (allCustomDefs.isEmpty() || allCustomDefs.get("imports") == null){
- allCustomDefs.put("imports",customType.get(typeDef));
- }
- else if (customType.get(typeDef) != null){
- Set<Object> allCustomImports = new HashSet<>((ArrayList<Object>)allCustomDefs.get("imports"));
- allCustomImports.addAll((ArrayList<Object>) customType.get(typeDef));
- allCustomDefs.put("imports", new ArrayList<>(allCustomImports));
- }
- }
- else {
- outerCustomTypes = (LinkedHashMap<String,Object>)customType.get(typeDef);
- if(outerCustomTypes != null) {
- if(namespacePrefix != null && !namespacePrefix.isEmpty()) {
- LinkedHashMap<String,Object> prefixCustomTypes = new LinkedHashMap<String,Object>();
- for(Map.Entry<String,Object> me: outerCustomTypes.entrySet()) {
- String typeDefKey = me.getKey();
- String nameSpacePrefixToKey = namespacePrefix + "." + typeDefKey;
- prefixCustomTypes.put(nameSpacePrefixToKey, outerCustomTypes.get(typeDefKey));
- }
- customDefs.putAll(prefixCustomTypes);
- allCustomDefs.putAll(prefixCustomTypes);
- }
- else {
- customDefs.putAll(outerCustomTypes);
- allCustomDefs.putAll(outerCustomTypes);
- }
- }
- }
- }
- }
-
- private void _updateNestedToscaTpls(String fullFileName,LinkedHashMap<String,Object> customTpl) {
- if(fullFileName != null && customTpl != null) {
- LinkedHashMap<String,Object> tt = new LinkedHashMap<String,Object>();
- tt.put(fullFileName, customTpl);
- nestedToscaTpls.add(tt);
- }
+ /**
+ * This method is used to get consolidated custom definitions by passing custom Types from
+ * each import. The resultant collection is then passed back which contains all import
+ * definitions
+ *
+ * @param customType the custom type
+ * @param namespacePrefix the namespace prefix
+ */
+ @SuppressWarnings("unchecked")
+ private void _updateCustomDefs(LinkedHashMap<String, Object> customType, String namespacePrefix) {
+ LinkedHashMap<String, Object> outerCustomTypes;
+ for (String typeDef : typeDefinitionList) {
+ if (typeDef.equals("imports")) {
+ customDefs.put("imports", customType.get(typeDef));
+ if (allCustomDefs.isEmpty() || allCustomDefs.get("imports") == null) {
+ allCustomDefs.put("imports", customType.get(typeDef));
+ } else if (customType.get(typeDef) != null) {
+ Set<Object> allCustomImports = new HashSet<>((ArrayList<Object>) allCustomDefs.get("imports"));
+ allCustomImports.addAll((ArrayList<Object>) customType.get(typeDef));
+ allCustomDefs.put("imports", new ArrayList<>(allCustomImports));
+ }
+ } else {
+ outerCustomTypes = (LinkedHashMap<String, Object>) customType.get(typeDef);
+ if (outerCustomTypes != null) {
+ if (namespacePrefix != null && !namespacePrefix.isEmpty()) {
+ LinkedHashMap<String, Object> prefixCustomTypes = new LinkedHashMap<String, Object>();
+ for (Map.Entry<String, Object> me : outerCustomTypes.entrySet()) {
+ String typeDefKey = me.getKey();
+ String nameSpacePrefixToKey = namespacePrefix + "." + typeDefKey;
+ prefixCustomTypes.put(nameSpacePrefixToKey, outerCustomTypes.get(typeDefKey));
+ }
+ customDefs.putAll(prefixCustomTypes);
+ allCustomDefs.putAll(prefixCustomTypes);
+ } else {
+ customDefs.putAll(outerCustomTypes);
+ allCustomDefs.putAll(outerCustomTypes);
+ }
+ }
+ }
+ }
+ }
+
+ private void _updateNestedToscaTpls(String fullFileName, LinkedHashMap<String, Object> customTpl) {
+ if (fullFileName != null && customTpl != null) {
+ LinkedHashMap<String, Object> tt = new LinkedHashMap<String, Object>();
+ tt.put(fullFileName, customTpl);
+ nestedToscaTpls.add(tt);
+ }
}
- private void _validateImportKeys(String importName, LinkedHashMap<String,Object> importUri) {
- if(importUri.get(FILE) == null) {
+ private void _validateImportKeys(String importName, LinkedHashMap<String, Object> importUri) {
+ if (importUri.get(FILE) == null) {
//log.warning(_('Missing keyname "file" in import "%(name)s".') % {'name': import_name})
- ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE187", String.format(
- "MissingRequiredFieldError: Import of template \"%s\" is missing field %s",importName,FILE)));
- }
- for(String key: importUri.keySet()) {
- boolean bFound = false;
- for(String is: IMPORTS_SECTION) {
- if(is.equals(key)) {
- bFound = true;
- break;
- }
- }
- if(!bFound) {
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE187", String.format(
+ "MissingRequiredFieldError: Import of template \"%s\" is missing field %s", importName, FILE)));
+ }
+ for (String key : importUri.keySet()) {
+ boolean bFound = false;
+ for (String is : IMPORTS_SECTION) {
+ if (is.equals(key)) {
+ bFound = true;
+ break;
+ }
+ }
+ if (!bFound) {
//log.warning(_('Unknown keyname "%(key)s" error in '
// 'imported definition "%(def)s".')
// % {'key': key, 'def': import_name})
- ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE188", String.format(
- "UnknownFieldError: Import of template \"%s\" has unknown fiels %s",importName,key)));
- }
- }
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE188", String.format(
+ "UnknownFieldError: Import of template \"%s\" has unknown fiels %s", importName, key)));
+ }
+ }
}
@SuppressWarnings("unchecked")
- private Object[] _loadImportTemplate(String importName, Object importUriDef) {
+ private Object[] _loadImportTemplate(String importName, Object importUriDef) {
/*
This method loads the custom type definitions referenced in "imports"
section of the TOSCA YAML template by determining whether each import
@@ -251,251 +246,237 @@ public class ImportsLoader {
| URL | URL | OK |
+----------+--------+------------------------------+
*/
- Object al[] = new Object[2];
+ Object al[] = new Object[2];
boolean shortImportNotation = false;
String fileName;
String repository;
- if(importUriDef instanceof LinkedHashMap) {
- _validateImportKeys(importName, (LinkedHashMap<String,Object>)importUriDef);
- fileName = (String)((LinkedHashMap<String,Object>)importUriDef).get(FILE);
- repository = (String)((LinkedHashMap<String,Object>)importUriDef).get(REPOSITORY);
- if(repository != null) {
- if(!repositories.keySet().contains(repository)) {
+ if (importUriDef instanceof LinkedHashMap) {
+ _validateImportKeys(importName, (LinkedHashMap<String, Object>) importUriDef);
+ fileName = (String) ((LinkedHashMap<String, Object>) importUriDef).get(FILE);
+ repository = (String) ((LinkedHashMap<String, Object>) importUriDef).get(REPOSITORY);
+ if (repository != null) {
+ if (!repositories.keySet().contains(repository)) {
ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE189", String.format(
- "InvalidPropertyValueError: Repository \"%s\" not found in \"%s\"",
- repository,repositories.keySet().toString())));
- }
+ "InvalidPropertyValueError: Repository \"%s\" not found in \"%s\"",
+ repository, repositories.keySet().toString())));
+ }
}
- }
- else {
- fileName = (String)importUriDef;
+ } else {
+ fileName = (String) importUriDef;
repository = null;
shortImportNotation = true;
}
- if(fileName == null || fileName.isEmpty()) {
- //msg = (_('A template file name is not provided with import '
- // 'definition "%(import_name)s".')
- // % {'import_name': import_name})
- //log.error(msg)
- ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE190", String.format(
- "ValidationError: A template file name is not provided with import definition \"%s\"",importName)));
- al[0] = al[1] = null;
- return al;
+ if (fileName == null || fileName.isEmpty()) {
+ //msg = (_('A template file name is not provided with import '
+ // 'definition "%(import_name)s".')
+ // % {'import_name': import_name})
+ //log.error(msg)
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE190", String.format(
+ "ValidationError: A template file name is not provided with import definition \"%s\"", importName)));
+ al[0] = al[1] = null;
+ return al;
}
- if(UrlUtils.validateUrl(fileName)) {
- try (InputStream input = new URL(fileName).openStream();) {
- al[0] = fileName;
- Yaml yaml = new Yaml();
- al[1] = yaml.load(input);
- return al;
- }
- catch(IOException e) {
- ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE191", String.format(
- "ImportError: \"%s\" loading YAML import from \"%s\"",e.getClass().getSimpleName(),fileName)));
- al[0] = al[1] = null;
- return al;
- }
- }
- else if(repository == null || repository.isEmpty()) {
- boolean aFile = false;
+ if (UrlUtils.validateUrl(fileName)) {
+ try (InputStream input = new URL(fileName).openStream();) {
+ al[0] = fileName;
+ Yaml yaml = new Yaml();
+ al[1] = yaml.load(input);
+ return al;
+ } catch (IOException e) {
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE191", String.format(
+ "ImportError: \"%s\" loading YAML import from \"%s\"", e.getClass().getSimpleName(), fileName)));
+ al[0] = al[1] = null;
+ return al;
+ }
+ } else if (repository == null || repository.isEmpty()) {
+ boolean aFile = false;
String importTemplate = null;
- if(path != null && !path.isEmpty()) {
- if(UrlUtils.validateUrl(path)) {
- File fp = new File(path);
- if(fp.isAbsolute()) {
- String msg = String.format(
- "ImportError: Absolute file name \"%s\" cannot be used in the URL-based input template \"%s\"",
- fileName,path);
- ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE192", msg));
+ if (path != null && !path.isEmpty()) {
+ if (UrlUtils.validateUrl(path)) {
+ File fp = new File(path);
+ if (fp.isAbsolute()) {
+ String msg = String.format(
+ "ImportError: Absolute file name \"%s\" cannot be used in the URL-based input template \"%s\"",
+ fileName, path);
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE192", msg));
al[0] = al[1] = null;
return al;
- }
- importTemplate = UrlUtils.joinUrl(path,fileName);
- aFile = false;
- }
- else {
-
+ }
+ importTemplate = UrlUtils.joinUrl(path, fileName);
+ aFile = false;
+ } else {
+
aFile = true;
- File fp = new File(path);
- if(fp.isFile()) {
+ File fp = new File(path);
+ if (fp.isFile()) {
File fn = new File(fileName);
- if(fn.isFile()) {
+ if (fn.isFile()) {
importTemplate = fileName;
- }
- else {
- String fullPath = Paths.get(path).toAbsolutePath().getParent().toString() + File.separator + fileName;
- File ffp = new File(fullPath);
- if(ffp.isFile()) {
+ } else {
+ String fullPath = Paths.get(path).toAbsolutePath().getParent().toString() + File.separator + fileName;
+ File ffp = new File(fullPath);
+ if (ffp.isFile()) {
importTemplate = fullPath;
- }
- else {
- String dirPath = Paths.get(path).toAbsolutePath().getParent().toString();
- String filePath;
- if(Paths.get(fileName).getParent() != null) {
- filePath = Paths.get(fileName).getParent().toString();
- }
- else {
- filePath = "";
- }
- if(!filePath.isEmpty() && dirPath.endsWith(filePath)) {
- String sFileName = Paths.get(fileName).getFileName().toString();
- importTemplate = dirPath + File.separator + sFileName;
- File fit = new File(importTemplate);
- if(!fit.isFile()) {
+ } else {
+ String dirPath = Paths.get(path).toAbsolutePath().getParent().toString();
+ String filePath;
+ if (Paths.get(fileName).getParent() != null) {
+ filePath = Paths.get(fileName).getParent().toString();
+ } else {
+ filePath = "";
+ }
+ if (!filePath.isEmpty() && dirPath.endsWith(filePath)) {
+ String sFileName = Paths.get(fileName).getFileName().toString();
+ importTemplate = dirPath + File.separator + sFileName;
+ File fit = new File(importTemplate);
+ if (!fit.isFile()) {
//msg = (_('"%(import_template)s" is'
// 'not a valid file')
// % {'import_template':
// import_template})
//log.error(msg)
- String msg = String.format(
- "ValueError: \"%s\" is not a valid file",importTemplate);
- ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE193", msg));
+ String msg = String.format(
+ "ValueError: \"%s\" is not a valid file", importTemplate);
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE193", msg));
log.debug("ImportsLoader - _loadImportTemplate - {}", msg);
- }
- }
+ }
+ }
}
}
- }
- }
+ }
+ }
+ } else { // template is pre-parsed
+ File fn = new File(fileName);
+ if (fn.isAbsolute() && fn.isFile()) {
+ aFile = true;
+ importTemplate = fileName;
+ } else {
+ String msg = String.format(
+ "Relative file name \"%s\" cannot be used in a pre-parsed input template", fileName);
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE194", "ImportError: " + msg));
+ al[0] = al[1] = null;
+ return al;
+ }
}
- else { // template is pre-parsed
- File fn = new File(fileName);
- if(fn.isAbsolute() && fn.isFile()) {
- aFile = true;
- importTemplate = fileName;
- }
- else {
- String msg = String.format(
- "Relative file name \"%s\" cannot be used in a pre-parsed input template",fileName);
- ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE194", "ImportError: " + msg));
- al[0] = al[1] = null;
- return al;
- }
- }
-
- if(importTemplate == null || importTemplate.isEmpty()) {
+
+ if (importTemplate == null || importTemplate.isEmpty()) {
//log.error(_('Import "%(name)s" is not valid.') %
// {'name': import_uri_def})
ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE195", String.format(
- "ImportError: Import \"%s\" is not valid",importUriDef)));
- al[0] = al[1] = null;
- return al;
+ "ImportError: Import \"%s\" is not valid", importUriDef)));
+ al[0] = al[1] = null;
+ return al;
}
-
+
// for now, this must be a file
- if(!aFile) {
- log.error("ImportsLoader - _loadImportTemplate - Error!! Expected a file. importUriDef = {}, importTemplate = {}", importUriDef, importTemplate);
+ if (!aFile) {
+ log.error("ImportsLoader - _loadImportTemplate - Error!! Expected a file. importUriDef = {}, importTemplate = {}", importUriDef, importTemplate);
ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE196", String.format(
- "ImportError: Import \"%s\" is not a file",importName)));
- al[0] = al[1] = null;
- return al;
+ "ImportError: Import \"%s\" is not a file", importName)));
+ al[0] = al[1] = null;
+ return al;
}
try (BufferedReader br = new BufferedReader(new FileReader(importTemplate));) {
- al[0] = importTemplate;
+ al[0] = importTemplate;
- Yaml yaml = new Yaml();
- al[1] = yaml.load(br);
- return al;
- }
- catch(FileNotFoundException e) {
+ Yaml yaml = new Yaml();
+ al[1] = yaml.load(br);
+ return al;
+ } catch (FileNotFoundException e) {
ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE197", String.format(
- "ImportError: Failed to load YAML from \"%s\"" + e,importName)));
- al[0] = al[1] = null;
- return al;
- }
- catch(Exception e) {
+ "ImportError: Failed to load YAML from \"%s\"" + e, importName)));
+ al[0] = al[1] = null;
+ return al;
+ } catch (Exception e) {
ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE198", String.format(
- "ImportError: Exception from SnakeYAML file = \"%s\"" + e,importName)));
- al[0] = al[1] = null;
- return al;
+ "ImportError: Exception from SnakeYAML file = \"%s\"" + e, importName)));
+ al[0] = al[1] = null;
+ return al;
}
}
-
- if(shortImportNotation) {
+
+ if (shortImportNotation) {
//log.error(_('Import "%(name)s" is not valid.') % import_uri_def)
ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE199", String.format(
- "ImportError: Import \"%s\" is not valid",importName)));
- al[0] = al[1] = null;
- return al;
+ "ImportError: Import \"%s\" is not valid", importName)));
+ al[0] = al[1] = null;
+ return al;
}
-
+
String fullUrl = "";
- String repoUrl = "";
- if(repository != null && !repository.isEmpty()) {
- if(repositories != null) {
- for(String repoName: repositories.keySet()) {
- if(repoName.equals(repository)) {
- Object repoDef = repositories.get(repoName);
- if(repoDef instanceof String) {
- repoUrl = (String)repoDef;
- }
- else if(repoDef instanceof LinkedHashMap) {
- repoUrl = (String)((LinkedHashMap<String,Object>)repoDef).get("url");
- }
- // Remove leading, ending spaces and strip
- // the last character if "/"
- repoUrl = repoUrl.trim();
- if(repoUrl.endsWith("/")) {
- repoUrl = repoUrl.substring(0,repoUrl.length()-1);
- }
- fullUrl = repoUrl + "/" + fileName;
- break;
- }
- }
- }
- if(fullUrl.isEmpty()) {
+ String repoUrl = "";
+ if (repository != null && !repository.isEmpty()) {
+ if (repositories != null) {
+ for (String repoName : repositories.keySet()) {
+ if (repoName.equals(repository)) {
+ Object repoDef = repositories.get(repoName);
+ if (repoDef instanceof String) {
+ repoUrl = (String) repoDef;
+ } else if (repoDef instanceof LinkedHashMap) {
+ repoUrl = (String) ((LinkedHashMap<String, Object>) repoDef).get("url");
+ }
+ // Remove leading, ending spaces and strip
+ // the last character if "/"
+ repoUrl = repoUrl.trim();
+ if (repoUrl.endsWith("/")) {
+ repoUrl = repoUrl.substring(0, repoUrl.length() - 1);
+ }
+ fullUrl = repoUrl + "/" + fileName;
+ break;
+ }
+ }
+ }
+ if (fullUrl.isEmpty()) {
String msg = String.format(
- "referenced repository \"%s\" in import definition \"%s\" not found",
- repository,importName);
- ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE200", "ImportError: " + msg));
- al[0] = al[1] = null;
- return al;
- }
- }
- if(UrlUtils.validateUrl(fullUrl)) {
- try (InputStream input = new URL(fullUrl).openStream();) {
- al[0] = fullUrl;
- Yaml yaml = new Yaml();
- al[1] = yaml.load(input);
- return al;
- }
- catch(IOException e) {
- ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE201", String.format(
- "ImportError: Exception loading YAML import from \"%s\"",fullUrl)));
- al[0] = al[1] = null;
- return al;
- }
+ "referenced repository \"%s\" in import definition \"%s\" not found",
+ repository, importName);
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE200", "ImportError: " + msg));
+ al[0] = al[1] = null;
+ return al;
+ }
}
- else {
+ if (UrlUtils.validateUrl(fullUrl)) {
+ try (InputStream input = new URL(fullUrl).openStream();) {
+ al[0] = fullUrl;
+ Yaml yaml = new Yaml();
+ al[1] = yaml.load(input);
+ return al;
+ } catch (IOException e) {
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE201", String.format(
+ "ImportError: Exception loading YAML import from \"%s\"", fullUrl)));
+ al[0] = al[1] = null;
+ return al;
+ }
+ } else {
String msg = String.format(
- "repository URL \"%s\" in import definition \"%s\" is not valid",
- repoUrl,importName);
- ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE202", "ImportError: " + msg));
+ "repository URL \"%s\" in import definition \"%s\" is not valid",
+ repoUrl, importName);
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE202", "ImportError: " + msg));
}
-
+
// if we got here something is wrong with the flow...
log.error("ImportsLoader - _loadImportTemplate - got to dead end (importName {})", importName);
ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE203", String.format(
- "ImportError: _loadImportTemplate got to dead end (importName %s)\n",importName)));
+ "ImportError: _loadImportTemplate got to dead end (importName %s)\n", importName)));
al[0] = al[1] = null;
return al;
}
- @Override
- public String toString() {
- return "ImportsLoader{" +
- "IMPORTS_SECTION=" + Arrays.toString(IMPORTS_SECTION) +
- ", importslist=" + importslist +
- ", path='" + path + '\'' +
- ", typeDefinitionList=" + typeDefinitionList +
- ", customDefs=" + customDefs +
- ", nestedToscaTpls=" + nestedToscaTpls +
- ", repositories=" + repositories +
- '}';
- }
+ @Override
+ public String toString() {
+ return "ImportsLoader{" +
+ "IMPORTS_SECTION=" + Arrays.toString(IMPORTS_SECTION) +
+ ", importslist=" + importslist +
+ ", path='" + path + '\'' +
+ ", typeDefinitionList=" + typeDefinitionList +
+ ", customDefs=" + customDefs +
+ ", nestedToscaTpls=" + nestedToscaTpls +
+ ", repositories=" + repositories +
+ '}';
+ }
}
/*python