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