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.vendorsoftwareproduct.utils;
19 import org.apache.commons.collections4.CollectionUtils;
20 import org.apache.commons.collections4.MapUtils;
21 import org.openecomp.core.enrichment.types.MonitoringUploadType;
22 import org.openecomp.core.utilities.file.FileContentHandler;
23 import org.openecomp.sdc.common.errors.ErrorCode;
24 import org.openecomp.sdc.common.errors.Messages;
25 import org.openecomp.sdc.common.utils.SdcCommon;
26 import org.openecomp.sdc.datatypes.error.ErrorLevel;
27 import org.openecomp.sdc.datatypes.error.ErrorMessage;
28 import org.openecomp.sdc.logging.api.Logger;
29 import org.openecomp.sdc.logging.api.LoggerFactory;
30 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentMonitoringUploadEntity;
31 import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse;
36 public class VendorSoftwareProductUtils {
38 private static final Logger LOGGER = LoggerFactory.getLogger(VendorSoftwareProductUtils.class);
40 private VendorSoftwareProductUtils(){
45 * Add file names to upload file response.
47 * @param fileContentMap the file content map
48 * @param uploadFileResponse the upload file response
50 public static void addFileNamesToUploadFileResponse(FileContentHandler fileContentMap,
51 OrchestrationTemplateActionResponse uploadFileResponse) {
52 uploadFileResponse.setFileNames(new ArrayList<>());
53 for (String filename : fileContentMap.getFileList()) {
54 if (!new File(filename).isDirectory()) {
55 uploadFileResponse.addNewFileToList(filename);
58 uploadFileResponse.removeFileFromList(SdcCommon.MANIFEST_NAME);
61 * Validate content zip data.
63 * @param contentMap the content map
64 * @param errors the errors
66 public static void validateContentZipData(FileContentHandler contentMap,
67 Map<String, List<ErrorMessage>> errors) {
68 if (contentMap.getFileList().isEmpty()) {
69 ErrorMessage.ErrorMessageUtil.addMessage(SdcCommon.UPLOAD_FILE, errors)
70 .add(new ErrorMessage(ErrorLevel.ERROR, Messages.INVALID_ZIP_FILE.getErrorMessage()));
76 * Maps all artifacts by type.
78 * @param artifacts the artifacts
81 public static Map<MonitoringUploadType, String> mapArtifactsByType(
82 Collection<ComponentMonitoringUploadEntity> artifacts) {
83 Map<MonitoringUploadType, String> artifactTypeToFilename
84 = new EnumMap<>(MonitoringUploadType.class);
86 for (ComponentMonitoringUploadEntity entity : artifacts) {
87 artifactTypeToFilename.put(entity.getType(), entity.getArtifactName());
90 return artifactTypeToFilename;
95 * Sets errors into logger.
96 * @param errors the errors
98 public static void setErrorsIntoLogger(Map<String, List<ErrorMessage>> errors) {
99 if (MapUtils.isEmpty(errors)) {
103 for (Map.Entry<String, List<ErrorMessage>> listEntry : errors.entrySet()) {
104 List<ErrorMessage> errorList = listEntry.getValue();
105 for (ErrorMessage message : errorList) {
106 LOGGER.error(message.getMessage());
112 * Sets errors into logger.
113 * @param errors the errors
115 public static void setErrorsIntoLogger(Collection<ErrorCode> errors) {
117 if (CollectionUtils.isEmpty(errors)) {
121 for (ErrorCode error : errors) {
122 LOGGER.error(error.message());