summaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-validation-manager/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-validation-manager/src/main')
-rw-r--r--openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/UploadValidationManager.java13
-rw-r--r--openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/impl/UploadValidationManagerImpl.java111
-rw-r--r--openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/types/ValidationFileResponse.java20
-rw-r--r--openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/types/ValidationFileStatus.java8
-rw-r--r--openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/util/ValidationManagerUtil.java65
5 files changed, 95 insertions, 122 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/UploadValidationManager.java b/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/UploadValidationManager.java
index 88aceeb87d..22f014742c 100644
--- a/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/UploadValidationManager.java
+++ b/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/UploadValidationManager.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.
@@ -17,21 +17,16 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.validation;
-import org.openecomp.sdc.validation.types.ValidationFileResponse;
-
import java.io.IOException;
import java.io.InputStream;
+import org.openecomp.sdc.validation.types.ValidationFileResponse;
/**
* Created by TALIO on 4/20/2016.
*/
public interface UploadValidationManager {
-
- ValidationFileResponse validateFile(String type, InputStream heatFileToUpload) throws IOException;
-
-
+ ValidationFileResponse validateFile(String type, InputStream heatFileToUpload) throws IOException;
}
diff --git a/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/impl/UploadValidationManagerImpl.java b/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/impl/UploadValidationManagerImpl.java
index 90f8ad369b..6a9015489b 100644
--- a/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/impl/UploadValidationManagerImpl.java
+++ b/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/impl/UploadValidationManagerImpl.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.
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.validation.impl;
import java.io.IOException;
@@ -44,76 +43,60 @@ import org.openecomp.sdc.validation.UploadValidationManager;
import org.openecomp.sdc.validation.types.ValidationFileResponse;
import org.openecomp.sdc.validation.util.ValidationManagerUtil;
-
/**
* Created by TALIO on 4/20/2016.
*/
public class UploadValidationManagerImpl implements UploadValidationManager {
- private static FileContentHandler getFileContentMapFromZip(byte[] uploadFileData) throws IOException {
- final Map<String, byte[]> zipFileAndByteMap;
- try {
- zipFileAndByteMap = ZipUtils.readZip(uploadFileData, true);
- } catch (final ZipException e) {
- throw new IOException(e);
+ private static FileContentHandler getFileContentMapFromZip(byte[] uploadFileData) throws IOException {
+ final Map<String, byte[]> zipFileAndByteMap;
+ try {
+ zipFileAndByteMap = ZipUtils.readZip(uploadFileData, true);
+ } catch (final ZipException e) {
+ throw new IOException(e);
+ }
+ final boolean zipHasFolders = zipFileAndByteMap.values().stream().anyMatch(Objects::isNull);
+ if (zipHasFolders) {
+ throw new CoreException((new ErrorCode.ErrorCodeBuilder()).withMessage(Messages.ZIP_SHOULD_NOT_CONTAIN_FOLDERS.getErrorMessage())
+ .withId(Messages.ZIP_SHOULD_NOT_CONTAIN_FOLDERS.getErrorMessage()).withCategory(ErrorCategory.APPLICATION).build());
+ }
+ final FileContentHandler mapFileContent = new FileContentHandler();
+ zipFileAndByteMap.entrySet().stream().filter(entry -> entry.getValue() != null)
+ .forEach(zipEntry -> mapFileContent.addFile(zipEntry.getKey(), zipEntry.getValue()));
+ return mapFileContent;
}
- final boolean zipHasFolders = zipFileAndByteMap.values().stream().anyMatch(Objects::isNull);
- if (zipHasFolders) {
- throw new CoreException((new ErrorCode.ErrorCodeBuilder())
- .withMessage(Messages.ZIP_SHOULD_NOT_CONTAIN_FOLDERS.getErrorMessage())
- .withId(Messages.ZIP_SHOULD_NOT_CONTAIN_FOLDERS.getErrorMessage())
- .withCategory(ErrorCategory.APPLICATION).build());
+ @Override
+ public ValidationFileResponse validateFile(String type, InputStream fileToValidate) throws IOException {
+ ValidationFileResponse validationFileResponse = new ValidationFileResponse();
+ HeatTreeManager tree;
+ ValidationStructureList validationStructureList = new ValidationStructureList();
+ if (type.equalsIgnoreCase("heat")) {
+ FileContentHandler content = getFileContent(fileToValidate);
+ if (!content.containsFile(SdcCommon.MANIFEST_NAME)) {
+ throw new CoreException((new ErrorCode.ErrorCodeBuilder()).withMessage(Messages.MANIFEST_NOT_EXIST.getErrorMessage())
+ .withId(Messages.ZIP_SHOULD_NOT_CONTAIN_FOLDERS.getErrorMessage()).withCategory(ErrorCategory.APPLICATION).build());
+ }
+ Map<String, List<ErrorMessage>> errors = validateHeatUploadData(content);
+ tree = HeatTreeManagerUtil.initHeatTreeManager(content);
+ tree.createTree();
+ if (MapUtils.isNotEmpty(errors)) {
+ tree.addErrors(errors);
+ validationStructureList.setImportStructure(tree.getTree());
+ }
+ } else {
+ throw new RuntimeException("invalid type:" + type);
+ }
+ validationFileResponse.setValidationData(validationStructureList);
+ return validationFileResponse;
}
- final FileContentHandler mapFileContent = new FileContentHandler();
- zipFileAndByteMap.entrySet().stream()
- .filter(entry -> entry.getValue() != null)
- .forEach(zipEntry -> mapFileContent.addFile(zipEntry.getKey(), zipEntry.getValue()));
-
- return mapFileContent;
- }
-
- @Override
- public ValidationFileResponse validateFile(String type, InputStream fileToValidate)
- throws IOException {
- ValidationFileResponse validationFileResponse = new ValidationFileResponse();
-
- HeatTreeManager tree;
- ValidationStructureList validationStructureList = new ValidationStructureList();
- if (type.equalsIgnoreCase("heat")) {
- FileContentHandler content = getFileContent(fileToValidate);
- if (!content.containsFile(SdcCommon.MANIFEST_NAME)) {
- throw new CoreException((new ErrorCode.ErrorCodeBuilder())
- .withMessage(Messages.MANIFEST_NOT_EXIST.getErrorMessage())
- .withId(Messages.ZIP_SHOULD_NOT_CONTAIN_FOLDERS.getErrorMessage())
- .withCategory(ErrorCategory.APPLICATION).build());
- }
- Map<String, List<ErrorMessage>> errors = validateHeatUploadData(content);
- tree = HeatTreeManagerUtil.initHeatTreeManager(content);
- tree.createTree();
-
- if (MapUtils.isNotEmpty(errors)) {
- tree.addErrors(errors);
- validationStructureList.setImportStructure(tree.getTree());
- }
- } else {
- throw new RuntimeException("invalid type:" + type);
+ private Map<String, List<ErrorMessage>> validateHeatUploadData(FileContentHandler fileContentMap) {
+ ValidationManager validationManager = ValidationManagerUtil.initValidationManager(fileContentMap);
+ return validationManager.validate();
}
- validationFileResponse.setValidationData(validationStructureList);
- return validationFileResponse;
- }
-
- private Map<String, List<ErrorMessage>> validateHeatUploadData(FileContentHandler fileContentMap) {
- ValidationManager validationManager =
- ValidationManagerUtil.initValidationManager(fileContentMap);
- return validationManager.validate();
- }
-
- private FileContentHandler getFileContent(InputStream is) throws IOException {
- return getFileContentMapFromZip(FileUtils.toByteArray(is));
-
-
- }
+ private FileContentHandler getFileContent(InputStream is) throws IOException {
+ return getFileContentMapFromZip(FileUtils.toByteArray(is));
+ }
}
diff --git a/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/types/ValidationFileResponse.java b/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/types/ValidationFileResponse.java
index bf6923d3de..41de2b73a3 100644
--- a/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/types/ValidationFileResponse.java
+++ b/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/types/ValidationFileResponse.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.
@@ -17,19 +17,19 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.validation.types;
import org.openecomp.sdc.heat.datatypes.structure.ValidationStructureList;
public class ValidationFileResponse {
- private ValidationStructureList validationData;
- public ValidationStructureList getValidationData() {
- return validationData;
- }
+ private ValidationStructureList validationData;
+
+ public ValidationStructureList getValidationData() {
+ return validationData;
+ }
- public void setValidationData(ValidationStructureList validationData) {
- this.validationData = validationData;
- }
+ public void setValidationData(ValidationStructureList validationData) {
+ this.validationData = validationData;
+ }
}
diff --git a/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/types/ValidationFileStatus.java b/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/types/ValidationFileStatus.java
index 4bf7be8b79..2ed4520f2a 100644
--- a/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/types/ValidationFileStatus.java
+++ b/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/types/ValidationFileStatus.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.
@@ -17,10 +17,8 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.validation.types;
public enum ValidationFileStatus {
- Success,
- Failure
+ Success, Failure
}
diff --git a/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/util/ValidationManagerUtil.java b/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/util/ValidationManagerUtil.java
index 6a7466d20d..3117082419 100644
--- a/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/util/ValidationManagerUtil.java
+++ b/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/util/ValidationManagerUtil.java
@@ -13,9 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.validation.util;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
import org.openecomp.core.utilities.file.FileContentHandler;
import org.openecomp.core.utilities.file.FileUtils;
import org.openecomp.core.validation.api.ValidationManager;
@@ -25,42 +28,36 @@ import org.openecomp.sdc.common.utils.SdcCommon;
import org.openecomp.sdc.datatypes.error.ErrorLevel;
import org.openecomp.sdc.datatypes.error.ErrorMessage;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.List;
-import java.util.Map;
-
-
public class ValidationManagerUtil {
- private ValidationManagerUtil(){}
+ private ValidationManagerUtil() {
+ }
- /**
- * Handle missing manifest.
- *
- * @param fileContentMap the file content map
- * @param errors the errors
- */
- public static void handleMissingManifest(FileContentHandler fileContentMap,
- Map<String, List<ErrorMessage>> errors) throws IOException {
- try (InputStream manifest = fileContentMap.getFileContentAsStream(SdcCommon.MANIFEST_NAME)) {
- if (manifest == null) {
- ErrorMessage.ErrorMessageUtil.addMessage(SdcCommon.MANIFEST_NAME, errors)
- .add(new ErrorMessage(ErrorLevel.ERROR, Messages.MANIFEST_NOT_EXIST.getErrorMessage()));
- }
+ /**
+ * Handle missing manifest.
+ *
+ * @param fileContentMap the file content map
+ * @param errors the errors
+ */
+ public static void handleMissingManifest(FileContentHandler fileContentMap, Map<String, List<ErrorMessage>> errors) throws IOException {
+ try (InputStream manifest = fileContentMap.getFileContentAsStream(SdcCommon.MANIFEST_NAME)) {
+ if (manifest == null) {
+ ErrorMessage.ErrorMessageUtil.addMessage(SdcCommon.MANIFEST_NAME, errors)
+ .add(new ErrorMessage(ErrorLevel.ERROR, Messages.MANIFEST_NOT_EXIST.getErrorMessage()));
+ }
+ }
}
- }
- /**
- * Init validation manager validation manager.
- *
- * @param fileContentMap the file content map
- * @return the validation manager
- */
- public static ValidationManager initValidationManager(FileContentHandler fileContentMap) {
- ValidationManager validationManager = ValidationManagerFactory.getInstance().createInterface();
- fileContentMap.getFileList().forEach(fileName -> validationManager
- .addFile(fileName, FileUtils.toByteArray(fileContentMap.getFileContentAsStream(fileName))));
- return validationManager;
- }
+ /**
+ * Init validation manager validation manager.
+ *
+ * @param fileContentMap the file content map
+ * @return the validation manager
+ */
+ public static ValidationManager initValidationManager(FileContentHandler fileContentMap) {
+ ValidationManager validationManager = ValidationManagerFactory.getInstance().createInterface();
+ fileContentMap.getFileList()
+ .forEach(fileName -> validationManager.addFile(fileName, FileUtils.toByteArray(fileContentMap.getFileContentAsStream(fileName))));
+ return validationManager;
+ }
}