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;
34 import java.util.ArrayList;
35 import java.util.Collection;
36 import java.util.EnumMap;
37 import java.util.List;
40 public class VendorSoftwareProductUtils {
42 private static final Logger LOGGER = LoggerFactory.getLogger(VendorSoftwareProductUtils.class);
44 private VendorSoftwareProductUtils(){
49 * Add file names to upload file response.
51 * @param fileContentMap the file content map
52 * @param uploadFileResponse the upload file response
54 public static void addFileNamesToUploadFileResponse(FileContentHandler fileContentMap,
55 OrchestrationTemplateActionResponse uploadFileResponse) {
56 uploadFileResponse.setFileNames(new ArrayList<>());
57 for (String filename : fileContentMap.getFileList()) {
58 if (!new File(filename).isDirectory()) {
59 uploadFileResponse.addNewFileToList(filename);
62 uploadFileResponse.removeFileFromList(SdcCommon.MANIFEST_NAME);
65 * Validate content zip data.
67 * @param contentMap the content map
68 * @param errors the errors
70 public static void validateContentZipData(FileContentHandler contentMap,
71 Map<String, List<ErrorMessage>> errors) {
72 if (contentMap.getFileList().isEmpty()) {
73 ErrorMessage.ErrorMessageUtil.addMessage(SdcCommon.UPLOAD_FILE, errors)
74 .add(new ErrorMessage(ErrorLevel.ERROR, Messages.INVALID_ZIP_FILE.getErrorMessage()));
80 * Maps all artifacts by type.
82 * @param artifacts the artifacts
85 public static Map<MonitoringUploadType, String> mapArtifactsByType(
86 Collection<ComponentMonitoringUploadEntity> artifacts) {
87 Map<MonitoringUploadType, String> artifactTypeToFilename
88 = new EnumMap<>(MonitoringUploadType.class);
90 for (ComponentMonitoringUploadEntity entity : artifacts) {
91 artifactTypeToFilename.put(entity.getType(), entity.getArtifactName());
94 return artifactTypeToFilename;
99 * Sets errors into logger.
100 * @param errors the errors
102 public static void setErrorsIntoLogger(Map<String, List<ErrorMessage>> errors) {
103 if (MapUtils.isEmpty(errors)) {
107 for (Map.Entry<String, List<ErrorMessage>> listEntry : errors.entrySet()) {
108 List<ErrorMessage> errorList = listEntry.getValue();
109 for (ErrorMessage message : errorList) {
110 LOGGER.error(message.getMessage());
116 * Sets errors into logger.
117 * @param errors the errors
119 public static void setErrorsIntoLogger(Collection<ErrorCode> errors) {
121 if (CollectionUtils.isEmpty(errors)) {
125 for (ErrorCode error : errors) {
126 LOGGER.error(error.message());