2 * Copyright © 2016-2017 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.validation.util;
19 import org.openecomp.core.utilities.file.FileContentHandler;
20 import org.openecomp.core.utilities.file.FileUtils;
21 import org.openecomp.core.validation.api.ValidationManager;
22 import org.openecomp.core.validation.factory.ValidationManagerFactory;
23 import org.openecomp.sdc.common.errors.Messages;
24 import org.openecomp.sdc.common.utils.SdcCommon;
25 import org.openecomp.sdc.datatypes.error.ErrorLevel;
26 import org.openecomp.sdc.datatypes.error.ErrorMessage;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.util.List;
34 public class ValidationManagerUtil {
36 private ValidationManagerUtil(){}
39 * Handle missing manifest.
41 * @param fileContentMap the file content map
42 * @param errors the errors
44 public static void handleMissingManifest(FileContentHandler fileContentMap,
45 Map<String, List<ErrorMessage>> errors) throws IOException {
46 try (InputStream manifest = fileContentMap.getFileContentAsStream(SdcCommon.MANIFEST_NAME)) {
47 if (manifest == null) {
48 ErrorMessage.ErrorMessageUtil.addMessage(SdcCommon.MANIFEST_NAME, errors)
49 .add(new ErrorMessage(ErrorLevel.ERROR, Messages.MANIFEST_NOT_EXIST.getErrorMessage()));
55 * Init validation manager validation manager.
57 * @param fileContentMap the file content map
58 * @return the validation manager
60 public static ValidationManager initValidationManager(FileContentHandler fileContentMap) {
61 ValidationManager validationManager = ValidationManagerFactory.getInstance().createInterface();
62 fileContentMap.getFileList().forEach(fileName -> validationManager
63 .addFile(fileName, FileUtils.toByteArray(fileContentMap.getFileContentAsStream(fileName))));
64 return validationManager;