2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.vendorsoftwareproduct.utils;
23 import org.apache.commons.collections4.CollectionUtils;
24 import org.apache.commons.collections4.MapUtils;
25 import org.openecomp.core.enrichment.types.MonitoringUploadType;
26 import org.openecomp.core.utilities.file.FileContentHandler;
27 import org.openecomp.sdc.common.errors.ErrorCode;
28 import org.openecomp.sdc.common.errors.Messages;
29 import org.openecomp.sdc.common.utils.SdcCommon;
30 import org.openecomp.sdc.datatypes.error.ErrorLevel;
31 import org.openecomp.sdc.datatypes.error.ErrorMessage;
32 import org.openecomp.sdc.logging.api.Logger;
33 import org.openecomp.sdc.logging.api.LoggerFactory;
34 import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
35 import org.openecomp.sdc.logging.types.LoggerConstants;
36 import org.openecomp.sdc.logging.types.LoggerErrorDescription;
37 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentMonitoringUploadEntity;
38 import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse;
42 import java.util.ArrayList;
43 import java.util.Collection;
44 import java.util.HashMap;
45 import java.util.List;
48 public class VendorSoftwareProductUtils {
50 protected static Logger logger =
51 LoggerFactory.getLogger(VendorSoftwareProductUtils.class);
54 * Add file names to upload file response.
56 * @param fileContentMap the file content map
57 * @param uploadFileResponse the upload file response
59 public static void addFileNamesToUploadFileResponse(FileContentHandler fileContentMap,
60 OrchestrationTemplateActionResponse uploadFileResponse) {
61 uploadFileResponse.setFileNames(new ArrayList<>());
62 for (String filename : fileContentMap.getFileList()) {
63 if (!new File(filename).isDirectory()) {
64 uploadFileResponse.addNewFileToList(filename);
67 uploadFileResponse.removeFileFromList(SdcCommon.MANIFEST_NAME);
72 * Validate content zip data.
74 * @param contentMap the content map
75 * @param errors the errors
77 public static void validateContentZipData(FileContentHandler contentMap,
78 Map<String, List<ErrorMessage>> errors) {
79 MDC.put(LoggerConstants.ERROR_DESCRIPTION, LoggerErrorDescription.INVALID_ZIP);
80 if (contentMap.getFileList().isEmpty()) {
81 ErrorMessage.ErrorMessageUtil.addMessage(SdcCommon.UPLOAD_FILE, errors)
82 .add(new ErrorMessage(ErrorLevel.ERROR, Messages.INVALID_ZIP_FILE.getErrorMessage()));
88 * Maps all artifacts by type.
90 * @param artifacts the artifacts
93 public static Map<MonitoringUploadType, String> mapArtifactsByType(
94 Collection<ComponentMonitoringUploadEntity> artifacts) {
95 Map<MonitoringUploadType, String> artifactTypeToFilename = new HashMap<>();
97 for (ComponentMonitoringUploadEntity entity : artifacts) {
98 artifactTypeToFilename.put(entity.getType(), entity.getArtifactName());
101 return artifactTypeToFilename;
106 * Sets errors into logger.
107 * @param errors the errors
108 * @param targetServiceName the target service name
110 public static void setErrorsIntoLogger(Map<String, List<ErrorMessage>> errors,
111 String targetServiceName) {
112 MdcDataErrorMessage mdcDataErrorMessage =
113 new MdcDataErrorMessage(targetServiceName, LoggerConstants.TARGET_ENTITY_DB,
114 ErrorLevel.ERROR.name(), null, null);
115 mdcDataErrorMessage.setMdcValues();
117 if (MapUtils.isEmpty(errors)) {
121 for (Map.Entry<String, List<ErrorMessage>> listEntry : errors.entrySet()) {
122 List<ErrorMessage> errorList = listEntry.getValue();
123 for (ErrorMessage message : errorList) {
124 logger.error(message.getMessage());
130 * Sets errors into logger.
131 * @param errors the errors
132 * @param targetServiceName the target service name
134 public static void setErrorsIntoLogger(Collection<ErrorCode> errors,
135 String targetServiceName) {
136 MdcDataErrorMessage mdcDataErrorMessage =
137 new MdcDataErrorMessage(targetServiceName, LoggerConstants.TARGET_ENTITY_DB,
138 ErrorLevel.ERROR.name(), null, null);
139 mdcDataErrorMessage.setMdcValues();
141 if (CollectionUtils.isEmpty(errors)) {
145 for (ErrorCode error : errors) {
146 logger.error(error.message());