From 280f8015d06af1f41a3ef12e8300801c7a5e0d54 Mon Sep 17 00:00:00 2001 From: AviZi Date: Fri, 9 Jun 2017 02:39:56 +0300 Subject: [SDC-29] Amdocs OnBoard 1707 initial commit. Change-Id: Ie4d12a3f574008b792899b368a0902a8b46b5370 Signed-off-by: AviZi --- .../sdc/validation/UploadValidationManager.java | 3 + .../validation/errors/ValidationErrorCodes.java | 3 + .../errors/ValidationInvalidErrorBuilder.java | 9 +-- .../impl/UploadValidationManagerImpl.java | 42 +++++++++++--- .../validation/types/ValidationFileResponse.java | 1 - .../sdc/validation/util/ValidationManagerUtil.java | 66 ++++++++++++++++++++++ 6 files changed, 108 insertions(+), 16 deletions(-) create mode 100644 openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/util/ValidationManagerUtil.java (limited to 'openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp') 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 734771f909..88aceeb87d 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 @@ -25,6 +25,9 @@ import org.openecomp.sdc.validation.types.ValidationFileResponse; import java.io.IOException; import java.io.InputStream; +/** + * Created by TALIO on 4/20/2016. + */ public interface UploadValidationManager { diff --git a/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/errors/ValidationErrorCodes.java b/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/errors/ValidationErrorCodes.java index 815517cdb8..6a7a010444 100644 --- a/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/errors/ValidationErrorCodes.java +++ b/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/errors/ValidationErrorCodes.java @@ -20,6 +20,9 @@ package org.openecomp.sdc.validation.errors; +/** + * Created by TALIO on 4/24/2016. + */ public class ValidationErrorCodes { public static final String VALIDATION_INVALID = "VALIDATION_INVALID"; diff --git a/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/errors/ValidationInvalidErrorBuilder.java b/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/errors/ValidationInvalidErrorBuilder.java index 5e4cb59ef3..b8015c0962 100644 --- a/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/errors/ValidationInvalidErrorBuilder.java +++ b/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/errors/ValidationInvalidErrorBuilder.java @@ -20,8 +20,6 @@ package org.openecomp.sdc.validation.errors; -import static org.openecomp.sdc.validation.errors.ValidationErrorCodes.VALIDATION_INVALID; - import org.openecomp.sdc.common.errors.BaseErrorBuilder; import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.datatypes.error.ErrorMessage; @@ -29,9 +27,6 @@ import org.openecomp.sdc.datatypes.error.ErrorMessage; import java.util.List; import java.util.Map; -/** - * The type Validation invalid error builder. - */ public class ValidationInvalidErrorBuilder extends BaseErrorBuilder { private static final String VALIDATION_INVALID_DETAILED_MSG = "File is invalid: %s"; private static final String VALIDATION_INVALID_MSG = "Validated file is invalid"; @@ -42,7 +37,7 @@ public class ValidationInvalidErrorBuilder extends BaseErrorBuilder { * @param errors the errors */ public ValidationInvalidErrorBuilder(Map> errors) { - getErrorCodeBuilder().withId(VALIDATION_INVALID); + getErrorCodeBuilder().withId(ValidationErrorCodes.VALIDATION_INVALID); getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION); getErrorCodeBuilder() .withMessage(String.format(VALIDATION_INVALID_DETAILED_MSG, toString(errors))); @@ -52,7 +47,7 @@ public class ValidationInvalidErrorBuilder extends BaseErrorBuilder { * Instantiates a new Validation invalid error builder. */ public ValidationInvalidErrorBuilder() { - getErrorCodeBuilder().withId(VALIDATION_INVALID); + getErrorCodeBuilder().withId(ValidationErrorCodes.VALIDATION_INVALID); getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION); getErrorCodeBuilder().withMessage(VALIDATION_INVALID_MSG); } 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 ce0d911082..ddb56ddbfc 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 @@ -25,17 +25,26 @@ import org.apache.commons.collections4.MapUtils; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.core.validation.api.ValidationManager; -import org.openecomp.core.validation.errors.Messages; +import org.openecomp.sdc.common.errors.Messages; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.common.errors.ErrorCode; -import org.openecomp.sdc.common.utils.AsdcCommon; +import org.openecomp.sdc.common.utils.SdcCommon; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.datatypes.error.ErrorMessage; import org.openecomp.sdc.heat.datatypes.structure.ValidationStructureList; import org.openecomp.sdc.heat.services.tree.HeatTreeManager; import org.openecomp.sdc.heat.services.tree.HeatTreeManagerUtil; +import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; +import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage; +import org.openecomp.sdc.logging.types.LoggerConstants; +import org.openecomp.sdc.logging.types.LoggerErrorCode; +import org.openecomp.sdc.logging.types.LoggerErrorDescription; +import org.openecomp.sdc.logging.types.LoggerTragetServiceName; import org.openecomp.sdc.validation.UploadValidationManager; import org.openecomp.sdc.validation.types.ValidationFileResponse; -import org.openecomp.sdc.validation.utils.ValidationManagerUtil; +import org.openecomp.sdc.validation.util.ValidationManagerUtil; +import org.slf4j.MDC; import java.io.ByteArrayInputStream; import java.io.File; @@ -47,8 +56,15 @@ import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; + +/** + * Created by TALIO on 4/20/2016. + */ public class UploadValidationManagerImpl implements UploadValidationManager { + private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + + private static FileContentHandler getFileContentMapFromZip(byte[] uploadFileData) throws IOException, CoreException { ZipEntry zipEntry; @@ -85,6 +101,7 @@ public class UploadValidationManagerImpl implements UploadValidationManager { } if (CollectionUtils.isNotEmpty(folderList)) { + MDC.put(LoggerConstants.ERROR_DESCRIPTION, LoggerErrorDescription.INVALID_ZIP); throw new CoreException((new ErrorCode.ErrorCodeBuilder()) .withMessage(Messages.ZIP_SHOULD_NOT_CONTAIN_FOLDERS.getErrorMessage()) .withId(Messages.ZIP_SHOULD_NOT_CONTAIN_FOLDERS.getErrorMessage()) @@ -112,20 +129,25 @@ public class UploadValidationManagerImpl implements UploadValidationManager { public ValidationFileResponse validateFile(String type, InputStream fileToValidate) throws IOException { + + mdcDataDebugMessage.debugEntryMessage(null, null); + ValidationFileResponse validationFileResponse = new ValidationFileResponse(); HeatTreeManager tree; ValidationStructureList validationStructureList = new ValidationStructureList(); if (type.toLowerCase().equals("heat")) { FileContentHandler content = getFileContent(fileToValidate); - if (!content.containsFile(AsdcCommon.MANIFEST_NAME)) { + if (!content.containsFile(SdcCommon.MANIFEST_NAME)) { + MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API, + LoggerTragetServiceName.VALIDATE_MANIFEST_CONTENT, ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ZIP); 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> errors = - validateHeatUploadData(content); + Map> errors = validateHeatUploadData(content); tree = HeatTreeManagerUtil.initHeatTreeManager(content); tree.createTree(); if (MapUtils.isNotEmpty(errors)) { @@ -138,14 +160,18 @@ public class UploadValidationManagerImpl implements UploadValidationManager { //validationFileResponse.setStatus(ValidationFileStatus.Success); } } else { + MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API, + LoggerTragetServiceName.VALIDATE_FILE_TYPE, ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_FILE_TYPE); throw new RuntimeException("invalid type:" + type); } validationFileResponse.setValidationData(validationStructureList); + + mdcDataDebugMessage.debugExitMessage(null, null); return validationFileResponse; } - private Map> validateHeatUploadData( - FileContentHandler fileContentMap) + private Map> validateHeatUploadData(FileContentHandler fileContentMap) throws IOException { ValidationManager validationManager = ValidationManagerUtil.initValidationManager(fileContentMap); 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 ff7f845252..bf6923d3de 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 @@ -20,7 +20,6 @@ package org.openecomp.sdc.validation.types; - import org.openecomp.sdc.heat.datatypes.structure.ValidationStructureList; public class ValidationFileResponse { 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 new file mode 100644 index 0000000000..924a956628 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/util/ValidationManagerUtil.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.validation.util; + +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.validation.api.ValidationManager; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.core.validation.factory.ValidationManagerFactory; +import org.openecomp.sdc.common.utils.SdcCommon; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.datatypes.error.ErrorMessage; + +import java.io.InputStream; +import java.util.List; +import java.util.Map; + + +public class ValidationManagerUtil { + + /** + * Handle missing manifest. + * + * @param fileContentMap the file content map + * @param errors the errors + */ + public static void handleMissingManifest(FileContentHandler fileContentMap, + Map> errors) { + InputStream manifest = fileContentMap.getFileContent(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.getFileContent(fileName)))); + return validationManager; + } +} -- cgit 1.2.3-korg