52bc5c4f2c445efddbf39ab0b34d67b081b58383
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / externalapi / servlet / AssetsDataServlet.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.openecomp.sdc.be.externalapi.servlet;
21
22 import static org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum.RESOURCE;
23
24 import com.jcabi.aspects.Loggable;
25 import fj.data.Either;
26 import io.swagger.v3.oas.annotations.Operation;
27 import io.swagger.v3.oas.annotations.Parameter;
28 import io.swagger.v3.oas.annotations.media.ArraySchema;
29 import io.swagger.v3.oas.annotations.media.Content;
30 import io.swagger.v3.oas.annotations.media.ExampleObject;
31 import io.swagger.v3.oas.annotations.media.Schema;
32 import io.swagger.v3.oas.annotations.responses.ApiResponse;
33 import io.swagger.v3.oas.annotations.servers.Server;
34 import io.swagger.v3.oas.annotations.tags.Tag;
35 import java.io.ByteArrayInputStream;
36 import java.io.IOException;
37 import java.io.InputStream;
38 import java.util.Comparator;
39 import java.util.EnumMap;
40 import java.util.HashMap;
41 import java.util.List;
42 import java.util.Map;
43 import javax.inject.Inject;
44 import javax.servlet.http.HttpServletRequest;
45 import javax.ws.rs.GET;
46 import javax.ws.rs.HeaderParam;
47 import javax.ws.rs.Path;
48 import javax.ws.rs.PathParam;
49 import javax.ws.rs.Produces;
50 import javax.ws.rs.QueryParam;
51 import javax.ws.rs.core.Context;
52 import javax.ws.rs.core.MediaType;
53 import javax.ws.rs.core.Response;
54 import org.apache.commons.collections4.CollectionUtils;
55 import org.apache.commons.lang3.tuple.ImmutablePair;
56 import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
57 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
58 import org.openecomp.sdc.be.components.impl.ElementBusinessLogic;
59 import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
60 import org.openecomp.sdc.be.components.impl.ResourceImportManager;
61 import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
62 import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
63 import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
64 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
65 import org.openecomp.sdc.be.config.BeEcompErrorManager;
66 import org.openecomp.sdc.be.dao.api.ActionStatus;
67 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
68 import org.openecomp.sdc.be.datatypes.enums.FilterKeyEnum;
69 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
70 import org.openecomp.sdc.be.ecomp.converters.AssetMetadataConverter;
71 import org.openecomp.sdc.be.externalapi.servlet.representation.AssetMetadata;
72 import org.openecomp.sdc.be.externalapi.servlet.representation.ServiceAssetMetadata;
73 import org.openecomp.sdc.be.impl.ComponentsUtils;
74 import org.openecomp.sdc.be.impl.ServletUtils;
75 import org.openecomp.sdc.be.model.Component;
76 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
77 import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData;
78 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
79 import org.openecomp.sdc.be.servlets.AbstractValidationsServlet;
80 import org.openecomp.sdc.be.servlets.RepresentationUtils;
81 import org.openecomp.sdc.common.api.Constants;
82 import org.openecomp.sdc.common.log.wrappers.Logger;
83 import org.openecomp.sdc.common.util.GeneralUtility;
84 import org.openecomp.sdc.exception.ResponseFormat;
85 import org.springframework.stereotype.Controller;
86
87 /**
88  * This Servlet serves external users for retrieving component metadata.
89  *
90  * @author tgitelman
91  */
92 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
93 @Path("/v1/catalog")
94 @Tag(name = "SDCE-7 APIs")
95 @Server(url = "/sdc")
96 @Controller
97 public class AssetsDataServlet extends AbstractValidationsServlet {
98
99     private static final Logger log = Logger.getLogger(AssetsDataServlet.class);
100     private final ElementBusinessLogic elementBL;
101     private final AssetMetadataConverter assetMetadataConverter;
102     private final ServiceBusinessLogic serviceBL;
103     private final ResourceBusinessLogic resourceBL;
104     @Context
105     private HttpServletRequest request;
106
107     @Inject
108     public AssetsDataServlet(ComponentInstanceBusinessLogic componentInstanceBL, ComponentsUtils componentsUtils, ServletUtils servletUtils,
109                              ResourceImportManager resourceImportManager, ElementBusinessLogic elementBL,
110                              AssetMetadataConverter assetMetadataConverter, ServiceBusinessLogic serviceBL,
111                              ResourceBusinessLogic resourceBL) {
112         super(componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
113         this.elementBL = elementBL;
114         this.assetMetadataConverter = assetMetadataConverter;
115         this.serviceBL = serviceBL;
116         this.resourceBL = resourceBL;
117     }
118
119     @GET
120     @Path("/{assetType}")
121     @Produces(MediaType.APPLICATION_JSON)
122     @Operation(description = "Fetch list of assets", method = "GET", summary = "Returns list of assets", responses = {
123         @ApiResponse(responseCode = "200", description = "ECOMP component is authenticated and list of Catalog Assets Metadata is returned", content = @Content(array = @ArraySchema(schema = @Schema(implementation = AssetMetadata.class)))),
124         @ApiResponse(responseCode = "400", description = "Missing  'X-ECOMP-InstanceID'  HTTP header - POL5001"),
125         @ApiResponse(responseCode = "401", description = "ECOMP component  should authenticate itself  and  to  re-send  again  HTTP  request  with its Basic Authentication credentials - POL5002"),
126         @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
127         @ApiResponse(responseCode = "405", description = "Method  Not Allowed  :  Invalid HTTP method type used ( PUT,DELETE,POST will be rejected) - POL4050"),
128         @ApiResponse(responseCode = "500", description = "The GET request failed either due to internal SDC problem. ECOMP Component should continue the attempts to get the needed information - POL5000")})
129     @PermissionAllowed(AafPermission.PermNames.READ_VALUE)
130     public Response getAssetListExternal(
131         @Parameter(description = "X-ECOMP-RequestID header") @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
132         @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
133         @Parameter(description = "Determines the format of the body of the response") @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
134         @Parameter(description = "The username and password", required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
135         @Parameter(description = "The requested asset type", schema = @Schema(allowableValues = {"resources",
136             "services"}), required = true) @PathParam("assetType") final String assetType,
137
138         @Parameter(description = "The category to filter the result set on") @QueryParam("category") String category,
139         @Parameter(description = "The sub category to filter the result set on. Only applicable when assetType = resources") @QueryParam("subCategory") String subCategory,
140         @Parameter(description = "The distribution status to filter the result set on") @QueryParam("distributionStatus") String distributionStatus,
141         @Parameter(description = "The resource type to filter the result set on. Only applicable when assetType = resources") @QueryParam("resourceType") String resourceType,
142         @Parameter(description = "Additional metadata keys to include in the response, not all keys are supported.\nSupported keys: lastUpdateDate, creationDate, description, uniqueId and category specific metadata keys")
143         @QueryParam("include") List<String> additionalMetadataKeysToInclude,
144         @Parameter(description = "The version(s) to filter the result set on\n" +
145             "Syntax: /services?version=(highestMatchingVersionOnly|lessThan|greaterThan|equals)(:=)(value)",
146             examples = {
147                 @ExampleObject(
148                     name = "An example request to get each service with highest version",
149                     value = "highestMatchingVersionOnly:true"),
150                 @ExampleObject(
151                     name = "An example request to get all services with version less than 2.1",
152                     value = "lessThan:2.1"),
153                 @ExampleObject(
154                     name = "An example request to get all services with version equal 2.0",
155                     value = "equals:2.0"),
156                 @ExampleObject(
157                     name = "An example request to get all services with version greater than 1.1",
158                     value = "greaterThan:1.1")})
159         @QueryParam("version") String version,
160         @Parameter(description = "The keys of the metadata to include in the entries in the result set. Only applicable when assetType = services\n" +
161             "Only category specific metadata keys are supported\n" +
162             "Syntax: /services?metadata=<KEY1>(:=)<VALUE1>&metadata=<KEY2>(:=)<VALUE2> ...",
163             examples = {
164                 @ExampleObject(
165                     name = "An example request to get all services matching following Category Specific Metadata condition 'ETSI Version=3.3.1'",
166                     value = "ETSI Version:3.3.1")})
167         @QueryParam("metadata") List<String> metadata) throws IOException {
168         ResponseFormat responseFormat;
169         final String query = request.getQueryString();
170         final String requestURI =
171             request.getRequestURI().endsWith("/") ? removeDuplicateSlashSeparator(request.getRequestURI()) : request.getRequestURI();
172         final String url = request.getMethod() + " " + requestURI;
173         log.debug("Start handle request of {}", url);
174         final AuditingActionEnum auditingActionEnum = query == null ? AuditingActionEnum.GET_ASSET_LIST : AuditingActionEnum.GET_FILTERED_ASSET_LIST;
175         final String resourceUrl = query == null ? requestURI : requestURI + "?" + query;
176         final DistributionData distributionData = new DistributionData(instanceIdHeader, resourceUrl);
177         // Mandatory
178         if (instanceIdHeader == null || instanceIdHeader.isEmpty()) {
179             log.debug("getAssetList: Missing X-ECOMP-InstanceID header");
180             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
181             getComponentsUtils().auditExternalGetAssetList(responseFormat, auditingActionEnum, distributionData, requestId);
182             return buildErrorResponse(responseFormat);
183         }
184         try {
185             final Map<FilterKeyEnum, Object> filters = new EnumMap<>(FilterKeyEnum.class);
186             if (category != null) {
187                 filters.put(FilterKeyEnum.CATEGORY, category);
188             }
189             if (subCategory != null) {
190                 filters.put(FilterKeyEnum.SUB_CATEGORY, subCategory);
191             }
192             if (distributionStatus != null) {
193                 filters.put(FilterKeyEnum.DISTRIBUTION_STATUS, distributionStatus);
194             }
195             if (version != null) {
196                 filters.put(FilterKeyEnum.VERSION, version);
197             }
198             if (CollectionUtils.isNotEmpty(metadata)) {
199                 filters.put(FilterKeyEnum.METADATA, metadata);
200             }
201             if (resourceType != null) {
202                 ResourceTypeEnum resourceTypeEnum = ResourceTypeEnum.getTypeIgnoreCase(resourceType);
203                 if (resourceTypeEnum == null) {
204                     log.debug("getAssetList: Asset Fetching Failed. Invalid resource type was received");
205                     responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
206                     getComponentsUtils().auditExternalGetAssetList(responseFormat, auditingActionEnum, distributionData, requestId);
207                     return buildErrorResponse(responseFormat);
208                 }
209                 filters.put(FilterKeyEnum.RESOURCE_TYPE, resourceTypeEnum.name());
210             }
211             final Either<List<? extends Component>, ResponseFormat> componentList = elementBL.getFilteredCatalogComponents(assetType, filters, query);
212             if (componentList.isRight()) {
213                 log.debug("getAssetList: Asset Fetching Failed");
214                 responseFormat = componentList.right().value();
215                 getComponentsUtils().auditExternalGetAssetList(responseFormat, auditingActionEnum, distributionData, requestId);
216                 return buildErrorResponse(responseFormat);
217             } else {
218                 log.debug("getAssetList: Asset Fetching Success");
219                 final Either<List<? extends AssetMetadata>, ResponseFormat> resMetadata = assetMetadataConverter
220                     .convertToAssetMetadata(componentList.left().value(), requestURI, false, additionalMetadataKeysToInclude);
221                 if (resMetadata.isRight()) {
222                     log.debug("getAssetList: Asset conversion Failed");
223                     responseFormat = resMetadata.right().value();
224                     getComponentsUtils().auditExternalGetAssetList(responseFormat, auditingActionEnum, distributionData, requestId);
225                     return buildErrorResponse(responseFormat);
226                 }
227                 final Object result = RepresentationUtils.toRepresentation(sortIfNeed(resMetadata.left().value(), additionalMetadataKeysToInclude));
228                 responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
229                 getComponentsUtils().auditExternalGetAssetList(responseFormat, auditingActionEnum, distributionData, requestId);
230                 return buildOkResponse(responseFormat, result);
231             }
232         } catch (Exception e) {
233             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Fetch filtered list of assets");
234             log.debug("getAssetList: Fetch list of assets failed with exception", e);
235             throw e;
236         }
237     }
238
239     /**
240      * @param requestId
241      * @param instanceIdHeader
242      * @param accept
243      * @param authorization
244      * @param assetType
245      * @param uuid
246      * @return
247      */
248     @GET
249     @Path("/{assetType}/{uuid}/metadata")
250     @Produces(MediaType.APPLICATION_JSON)
251     @Operation(description = "Detailed metadata of asset by uuid", method = "GET", summary = "Returns detailed metadata of an asset by uuid", responses = {
252         @ApiResponse(responseCode = "200", description = "ECOMP component is authenticated and list of Catalog Assets Metadata is returned", content = @Content(array = @ArraySchema(schema = @Schema(implementation = AssetMetadata.class)))),
253         @ApiResponse(responseCode = "400", description = "Missing  'X-ECOMP-InstanceID'  HTTP header - POL5001"),
254         @ApiResponse(responseCode = "401", description = "ECOMP component  should authenticate itself  and  to  re-send  again  HTTP  request  with its Basic Authentication credentials - POL5002"),
255         @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
256         @ApiResponse(responseCode = "404", description = "Error: Requested '%1' (uuid) resource was not found - SVC4063"),
257         @ApiResponse(responseCode = "405", description = "Method  Not Allowed  :  Invalid HTTP method type used ( PUT,DELETE,POST will be rejected) - POL4050"),
258         @ApiResponse(responseCode = "500", description = "The GET request failed either due to internal SDC problem. ECOMP Component should continue the attempts to get the needed information - POL5000")})
259     @PermissionAllowed(AafPermission.PermNames.READ_VALUE)
260     public Response getAssetSpecificMetadataByUuidExternal(
261         @Parameter(description = "X-ECOMP-RequestID header") @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
262         @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
263         @Parameter(description = "Determines the format of the body of the response") @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
264         @Parameter(description = "The username and password", required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
265         @Parameter(description = "The requested asset type", schema = @Schema(allowableValues = {"resources",
266             "services"}), required = true) @PathParam("assetType") final String assetType,
267         @Parameter(description = "The requested asset uuid", required = true) @PathParam("uuid") final String uuid) throws IOException {
268         ResponseFormat responseFormat = null;
269         AuditingActionEnum auditingActionEnum = AuditingActionEnum.GET_ASSET_METADATA;
270         String requestURI = request.getRequestURI();
271         String url = request.getMethod() + " " + requestURI;
272         log.debug("Start handle request of {}", url);
273         ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
274         ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentType.getValue());
275         DistributionData distributionData = new DistributionData(instanceIdHeader, requestURI);
276         // Mandatory
277         if (instanceIdHeader == null || instanceIdHeader.isEmpty()) {
278             log.debug("getAssetList: Missing X-ECOMP-InstanceID header");
279             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
280             getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData, resourceCommonInfo, requestId, uuid);
281             return buildErrorResponse(responseFormat);
282         }
283         try {
284             final Either<List<? extends Component>, ResponseFormat> assetTypeData = elementBL.getCatalogComponentsByUuidAndAssetType(assetType, uuid);
285             if (assetTypeData.isRight()) {
286                 log.debug("getAssetList: Asset Fetching Failed");
287                 responseFormat = assetTypeData.right().value();
288                 getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData, resourceCommonInfo, requestId, uuid);
289                 return buildErrorResponse(responseFormat);
290             }
291             resourceCommonInfo.setResourceName(assetTypeData.left().value().iterator().next().getName());
292             log.debug("getAssetList: Asset Fetching Success");
293             Either<List<? extends AssetMetadata>, ResponseFormat> resMetadata = assetMetadataConverter
294                 .convertToAssetMetadata(assetTypeData.left().value(), requestURI, true, null);
295             if (resMetadata.isRight()) {
296                 log.debug("getAssetList: Asset conversion Failed");
297                 responseFormat = resMetadata.right().value();
298                 getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData, resourceCommonInfo, requestId, uuid);
299                 return buildErrorResponse(responseFormat);
300             }
301             Object result = RepresentationUtils.toRepresentation(resMetadata.left().value().iterator().next());
302             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
303             getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData, resourceCommonInfo, requestId, uuid);
304             return buildOkResponse(responseFormat, result);
305         } catch (Exception e) {
306             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Fetch filtered list of assets");
307             log.debug("getAssetList: Fetch list of assets failed with exception", e);
308             throw e;
309         }
310     }
311
312     private ComponentBusinessLogic getComponentBLByType(ComponentTypeEnum componentTypeEnum) {
313         if (componentTypeEnum.equals(RESOURCE)) {
314             return resourceBL;
315         } else {
316             // Implementation is the same for any ComponentBusinessLogic
317             return serviceBL;
318         }
319     }
320
321     /**
322      * @param requestId
323      * @param instanceIdHeader
324      * @param accept
325      * @param authorization
326      * @param assetType
327      * @param uuid
328      * @return
329      */
330     @GET
331     @Path("/{assetType}/{uuid}/toscaModel")
332     @Produces(MediaType.APPLICATION_OCTET_STREAM)
333     @Operation(description = "Fetch assets CSAR", method = "GET", summary = "Returns asset csar", responses = {
334         @ApiResponse(description = "default response", content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
335         @ApiResponse(responseCode = "200", description = "ECOMP component is authenticated and list of Catalog Assets Metadata is returned", content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
336         @ApiResponse(responseCode = "400", description = "Missing  'X-ECOMP-InstanceID'  HTTP header - POL5001"),
337         @ApiResponse(responseCode = "401", description = "ECOMP component  should authenticate itself  and  to  re-send  again  HTTP  request  with its Basic Authentication credentials - POL5002"),
338         @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
339         @ApiResponse(responseCode = "404", description = "Error: Requested '%1' (uuid) resource was not found - SVC4063"),
340         @ApiResponse(responseCode = "405", description = "Method  Not Allowed  :  Invalid HTTP method type used ( PUT,DELETE,POST will be rejected) - POL4050"),
341         @ApiResponse(responseCode = "500", description = "The GET request failed either due to internal SDC problem. ECOMP Component should continue the attempts to get the needed information - POL5000")})
342     @PermissionAllowed(AafPermission.PermNames.READ_VALUE)
343     public Response getToscaModelExternal(
344         @Parameter(description = "X-ECOMP-RequestID header") @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
345         @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
346         @Parameter(description = "Determines the format of the body of the response") @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
347         @Parameter(description = "The username and password", required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
348         @Parameter(description = "The requested asset type", schema = @Schema(allowableValues = {"resources",
349             "services"}), required = true) @PathParam("assetType") final String assetType,
350         @Parameter(description = "The requested asset uuid", required = true) @PathParam("uuid") final String uuid) {
351         String url = request.getRequestURI();
352         log.debug("Start handle request of {} {}", request.getMethod(), url);
353         ResponseFormat responseFormat = null;
354         ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
355         AuditingActionEnum auditingActionEnum = AuditingActionEnum.GET_TOSCA_MODEL;
356         ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentType.getValue());
357         DistributionData distributionData = new DistributionData(instanceIdHeader, url);
358         if (instanceIdHeader == null || instanceIdHeader.isEmpty()) {
359             log.debug("getToscaModel: Missing X-ECOMP-InstanceID header");
360             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
361             getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData, resourceCommonInfo, requestId, uuid);
362             return buildErrorResponse(responseFormat);
363         }
364         try {
365             ComponentBusinessLogic componentBusinessLogic = getComponentBLByType(componentType);
366             ImmutablePair<String, byte[]> csarArtifact = componentBusinessLogic.getToscaModelByComponentUuid(componentType, uuid, resourceCommonInfo);
367             byte[] value = csarArtifact.getRight();
368             InputStream is = new ByteArrayInputStream(value);
369             String contenetMD5 = GeneralUtility.calculateMD5Base64EncodedByByteArray(value);
370             Map<String, String> headers = new HashMap<>();
371             headers.put(Constants.CONTENT_DISPOSITION_HEADER, getContentDispositionValue(csarArtifact.getLeft()));
372             headers.put(Constants.MD5_HEADER, contenetMD5);
373             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
374             getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData, resourceCommonInfo, requestId, uuid);
375             return buildOkResponse(responseFormat, is, headers);
376         } catch (ComponentException e) {
377             responseFormat = e.getResponseFormat();
378             getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData, resourceCommonInfo, requestId, uuid);
379             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get asset tosca model");
380             log.debug("failed to get asset tosca model", e);
381             Response response = buildErrorResponse(responseFormat);
382             getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData, resourceCommonInfo, requestId, uuid);
383             return response;
384         }
385     }
386
387     private String removeDuplicateSlashSeparator(String requestUri) {
388         return requestUri.substring(0, requestUri.length() - 1);
389     }
390
391     private List<? extends AssetMetadata> sortIfNeed(final List<? extends AssetMetadata> assetMetadataList,
392                                                      final List<String> additionalMetadataKeysToInclude) {
393         if (additionalMetadataKeysToInclude.contains("creationDate")) {
394             assetMetadataList.sort(
395                 Comparator.comparing((AssetMetadata am) -> ((ServiceAssetMetadata) am).getAdditionalRequestedMetadata().get("creationDate")));
396         }
397         return assetMetadataList;
398     }
399
400 }