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=========================================================
20 package org.openecomp.sdc.be.servlets;
22 import com.jcabi.aspects.Loggable;
23 import fj.data.Either;
24 import io.swagger.v3.oas.annotations.Operation;
25 import io.swagger.v3.oas.annotations.Parameter;
26 import io.swagger.v3.oas.annotations.media.ArraySchema;
27 import io.swagger.v3.oas.annotations.media.Content;
28 import io.swagger.v3.oas.annotations.media.Schema;
29 import io.swagger.v3.oas.annotations.responses.ApiResponse;
30 import io.swagger.v3.oas.annotations.servers.Server;
31 import io.swagger.v3.oas.annotations.tags.Tag;
32 import java.util.ArrayList;
33 import java.util.HashMap;
34 import java.util.List;
36 import java.util.Optional;
37 import java.util.stream.Collectors;
38 import javax.inject.Inject;
39 import javax.servlet.http.HttpServletRequest;
40 import javax.ws.rs.Consumes;
41 import javax.ws.rs.DefaultValue;
42 import javax.ws.rs.GET;
43 import javax.ws.rs.HeaderParam;
44 import javax.ws.rs.Path;
45 import javax.ws.rs.Produces;
46 import javax.ws.rs.QueryParam;
47 import javax.ws.rs.core.Context;
48 import javax.ws.rs.core.MediaType;
49 import javax.ws.rs.core.Response;
50 import org.apache.commons.codec.binary.Base64;
51 import org.apache.commons.collections4.ListUtils;
52 import org.openecomp.sdc.be.components.impl.ArtifactTypeBusinessLogic;
53 import org.openecomp.sdc.be.components.impl.CapabilitiesBusinessLogic;
54 import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
55 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
56 import org.openecomp.sdc.be.components.impl.InterfaceOperationBusinessLogic;
57 import org.openecomp.sdc.be.components.impl.RelationshipTypeBusinessLogic;
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.exceptions.ByActionStatusComponentException;
61 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
62 import org.openecomp.sdc.be.config.BeEcompErrorManager;
63 import org.openecomp.sdc.be.dao.api.ActionStatus;
64 import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;
65 import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
66 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
67 import org.openecomp.sdc.be.exception.BusinessException;
68 import org.openecomp.sdc.be.impl.ComponentsUtils;
69 import org.openecomp.sdc.be.impl.ServletUtils;
70 import org.openecomp.sdc.be.model.ArtifactUiDownloadData;
71 import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
72 import org.openecomp.sdc.be.model.Component;
73 import org.openecomp.sdc.be.model.DataTypeDefinition;
74 import org.openecomp.sdc.be.model.InterfaceDefinition;
75 import org.openecomp.sdc.be.model.Model;
76 import org.openecomp.sdc.be.model.RelationshipTypeDefinition;
77 import org.openecomp.sdc.be.model.User;
78 import org.openecomp.sdc.be.model.operations.impl.DataTypeOperation;
79 import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
80 import org.openecomp.sdc.be.tosca.ToscaExportHandler;
81 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
82 import org.openecomp.sdc.common.api.Constants;
83 import org.openecomp.sdc.common.datastructure.Wrapper;
84 import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
85 import org.openecomp.sdc.common.log.wrappers.Logger;
86 import org.openecomp.sdc.common.util.ValidationUtils;
87 import org.openecomp.sdc.exception.ResponseFormat;
88 import org.springframework.stereotype.Controller;
90 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
92 @Tag(name = "SDCE-2 APIs")
93 @Server(url = "/sdc2/rest")
95 public class TypesFetchServlet extends AbstractValidationsServlet {
97 private static final Logger log = Logger.getLogger(TypesFetchServlet.class);
98 private static final String FAILED_TO_GET_ALL_NON_ABSTRACT = "failed to get all non abstract {}";
99 private static final String START_HANDLE_REQUEST_OF_MODIFIER_ID_IS = "Start handle request of {} | modifier id is {}";
100 private static final String DATATYPE_FILE_TYPE = ".yml";
101 private final RelationshipTypeBusinessLogic relationshipTypeBusinessLogic;
102 private final CapabilitiesBusinessLogic capabilitiesBusinessLogic;
103 private final InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
104 private final ResourceBusinessLogic resourceBusinessLogic;
105 private final ArtifactTypeBusinessLogic artifactTypeBusinessLogic;
106 private final ModelOperation modelOperation;
107 private final DataTypeOperation dataTypeOperation;
108 private final ToscaExportHandler toscaExportUtils;
111 public TypesFetchServlet(
112 ComponentInstanceBusinessLogic componentInstanceBL,
113 ComponentsUtils componentsUtils,
114 ServletUtils servletUtils,
115 ResourceImportManager resourceImportManager,
116 RelationshipTypeBusinessLogic relationshipTypeBusinessLogic,
117 CapabilitiesBusinessLogic capabilitiesBusinessLogic,
118 InterfaceOperationBusinessLogic interfaceOperationBusinessLogic,
119 ResourceBusinessLogic resourceBusinessLogic,
120 ArtifactTypeBusinessLogic artifactTypeBusinessLogic,
121 ModelOperation modelOperation,
122 DataTypeOperation dataTypeOperation,
123 ToscaExportHandler toscaExportUtils
129 resourceImportManager
131 this.relationshipTypeBusinessLogic = relationshipTypeBusinessLogic;
132 this.capabilitiesBusinessLogic = capabilitiesBusinessLogic;
133 this.interfaceOperationBusinessLogic = interfaceOperationBusinessLogic;
134 this.resourceBusinessLogic = resourceBusinessLogic;
135 this.artifactTypeBusinessLogic = artifactTypeBusinessLogic;
136 this.modelOperation = modelOperation;
137 this.dataTypeOperation = dataTypeOperation;
138 this.toscaExportUtils = toscaExportUtils;
143 @Consumes(MediaType.APPLICATION_JSON)
144 @Produces(MediaType.APPLICATION_JSON)
145 @Operation(description = "Get data types", method = "GET", summary = "Returns data types", responses = {
146 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
147 @ApiResponse(responseCode = "200", description = "datatypes"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
148 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
149 @ApiResponse(responseCode = "404", description = "Data types not found")})
150 public Response getAllDataTypesServlet(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
151 @Parameter(description = "model") @QueryParam("model") String modelName) {
152 Wrapper<Response> responseWrapper = new Wrapper<>();
153 Wrapper<User> userWrapper = new Wrapper<>();
155 validateUserExist(responseWrapper, userWrapper, userId);
156 if (responseWrapper.isEmpty()) {
157 String url = request.getMethod() + " " + request.getRequestURI();
158 log.debug("Start handle request of {} - modifier id is {}", url, userId);
159 resourceBusinessLogic.getApplicationDataTypeCache().refreshDataTypesCacheIfStale();
160 final Map<String, DataTypeDefinition> dataTypes = resourceBusinessLogic.getComponentsUtils()
161 .getAllDataTypes(resourceBusinessLogic.getApplicationDataTypeCache(), modelName);
162 String dataTypeJson = gson.toJson(dataTypes);
163 Response okResponse = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), dataTypeJson);
164 responseWrapper.setInnerElement(okResponse);
166 return responseWrapper.getInnerElement();
170 @Path("allDataTypes")
171 @Consumes(MediaType.APPLICATION_JSON)
172 @Produces(MediaType.APPLICATION_JSON)
173 @Operation(description = "Get data types", method = "GET", summary = "Returns all data types from all models", responses = {
174 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
175 @ApiResponse(responseCode = "200", description = "allDataTypes"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
176 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
177 @ApiResponse(responseCode = "404", description = "Data types not found")})
178 public Response getAllDataTypesFromAllModels(@Context final HttpServletRequest request,
179 @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
180 @QueryParam("excludePrimitives") @DefaultValue("false") String excludePrimitives) {
181 Wrapper<Response> responseWrapper = new Wrapper<>();
182 Wrapper<User> userWrapper = new Wrapper<>();
184 validateUserExist(responseWrapper, userWrapper, userId);
185 if (responseWrapper.isEmpty()) {
186 final boolean exclude = Boolean.parseBoolean(excludePrimitives);
187 String url = request.getMethod() + " " + request.getRequestURI();
188 log.debug("Start handle request of {} - modifier id is {}", url, userId);
189 resourceBusinessLogic.getApplicationDataTypeCache().refreshDataTypesCacheIfStale();
190 final List<Map<String, DataTypeDefinition>> dataTypesList = new ArrayList<>();
191 List<Model> models = modelOperation.findAllModels();
192 models.add(new Model(null));
193 models.forEach(model -> {
194 final Map<String, DataTypeDefinition> dataTypes = resourceBusinessLogic.getComponentsUtils()
195 .getAllDataTypes(resourceBusinessLogic.getApplicationDataTypeCache(), model.getName());
197 dataTypesList.add(dataTypes.entrySet().stream().filter(entry -> !ToscaPropertyType.isScalarType(entry.getKey()))
198 .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
200 dataTypesList.add(dataTypes);
203 String dataTypeJson = gson.toJson(dataTypesList);
204 Response okResponse = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), dataTypeJson);
205 responseWrapper.setInnerElement(okResponse);
207 return responseWrapper.getInnerElement();
211 @Path("downloadDataType")
212 @Consumes(MediaType.APPLICATION_JSON)
213 @Produces(MediaType.APPLICATION_JSON)
214 @Operation(description = "Get data types", method = "GET", summary = "Returns all data types from all models", responses = {
215 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
216 @ApiResponse(responseCode = "200", description = "allDataTypes"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
217 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
218 @ApiResponse(responseCode = "404", description = "Data types not found")})
219 public Response downloadDataType(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
220 @Parameter(description = "dataTypeId") @QueryParam("dataTypeId") String dataTypeId) {
221 Wrapper<Response> responseWrapper = new Wrapper<>();
222 Wrapper<User> userWrapper = new Wrapper<>();
224 validateUserExist(responseWrapper, userWrapper, userId);
227 String url = request.getMethod() + " " + request.getRequestURI();
228 log.info(START_HANDLE_REQUEST_OF_MODIFIER_ID_IS, url, userId);
229 response = handleDataTypeDownloadRequest(dataTypeId);
230 } catch (Exception e) {
231 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("downloadResourceArtifactBase64");
232 log.debug("downloadResourceArtifactBase64 unexpected exception", e);
239 @Path("interfaceLifecycleTypes")
240 @Consumes(MediaType.APPLICATION_JSON)
241 @Produces(MediaType.APPLICATION_JSON)
242 @Operation(description = "Get interface lifecycle types", method = "GET", summary = "Returns interface lifecycle types", responses = {
243 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
244 @ApiResponse(responseCode = "200", description = "Interface lifecycle types"),
245 @ApiResponse(responseCode = "403", description = "Restricted operation"),
246 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
247 @ApiResponse(responseCode = "404", description = "Interface lifecycle types not found")})
248 public Response getInterfaceLifecycleTypes(@Context final HttpServletRequest request,
249 @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
250 @Parameter(description = "model") @QueryParam("model") String modelName) {
251 Wrapper<Response> responseWrapper = new Wrapper<>();
252 Wrapper<User> userWrapper = new Wrapper<>();
254 validateUserExist(responseWrapper, userWrapper, userId);
255 if (responseWrapper.isEmpty()) {
256 String url = request.getMethod() + " " + request.getRequestURI();
257 log.info(START_HANDLE_REQUEST_OF_MODIFIER_ID_IS, url, userId);
258 Either<Map<String, InterfaceDefinition>, ResponseFormat> allInterfaceLifecycleTypes = interfaceOperationBusinessLogic
259 .getAllInterfaceLifecycleTypes(modelName);
260 if (allInterfaceLifecycleTypes.isRight()) {
261 log.info("Failed to get all interface lifecycle types. Reason - {}", allInterfaceLifecycleTypes.right().value());
262 Response errorResponse = buildErrorResponse(allInterfaceLifecycleTypes.right().value());
263 responseWrapper.setInnerElement(errorResponse);
265 String interfaceLifecycleTypeJson = gson.toJson(allInterfaceLifecycleTypes.left().value());
266 Response okResponse = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), interfaceLifecycleTypeJson);
267 responseWrapper.setInnerElement(okResponse);
270 return responseWrapper.getInnerElement();
271 } catch (Exception e) {
272 log.debug("get all interface lifecycle types failed with exception", e);
273 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
274 return buildErrorResponse(responseFormat);
279 @Path("capabilityTypes")
280 @Consumes(MediaType.APPLICATION_JSON)
281 @Produces(MediaType.APPLICATION_JSON)
282 @Operation(description = "Get capability types", method = "GET", summary = "Returns capability types", responses = {
283 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
284 @ApiResponse(responseCode = "200", description = "capabilityTypes"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
285 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
286 @ApiResponse(responseCode = "404", description = "Capability types not found")})
287 public Response getAllCapabilityTypesServlet(@Context final HttpServletRequest request,
288 @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
289 @Parameter(description = "model") @QueryParam("model") String modelName) {
290 Wrapper<Response> responseWrapper = new Wrapper<>();
291 Wrapper<User> userWrapper = new Wrapper<>();
294 validateUserExist(responseWrapper, userWrapper, userId);
295 modelName = ValidationUtils.sanitizeInputString(modelName);
296 if (responseWrapper.isEmpty()) {
297 String url = request.getMethod() + " " + request.getRequestURI();
298 log.debug(START_HANDLE_REQUEST_OF_MODIFIER_ID_IS, url, userId);
299 Either<Map<String, CapabilityTypeDefinition>, ResponseFormat> allDataTypes = capabilitiesBusinessLogic.getAllCapabilityTypes(
301 if (allDataTypes.isRight()) {
302 log.info("Failed to get all capability types. Reason - {}", allDataTypes.right().value());
303 Response errorResponse = buildErrorResponse(allDataTypes.right().value());
304 responseWrapper.setInnerElement(errorResponse);
306 Map<String, CapabilityTypeDefinition> dataTypes = allDataTypes.left().value();
307 String dataTypeJson = gson.toJson(dataTypes);
308 Response okResponse = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), dataTypeJson);
309 responseWrapper.setInnerElement(okResponse);
312 return responseWrapper.getInnerElement();
313 } catch (Exception e) {
314 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Capability Types");
315 log.debug("get all capability types failed with exception", e);
316 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
317 return buildErrorResponse(responseFormat);
322 @Path("relationshipTypes")
323 @Consumes(MediaType.APPLICATION_JSON)
324 @Produces(MediaType.APPLICATION_JSON)
325 @Operation(description = "Get relationship types", method = "GET", summary = "Returns relationship types", responses = {
326 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
327 @ApiResponse(responseCode = "200", description = "relationshipTypes"),
328 @ApiResponse(responseCode = "403", description = "Restricted operation"),
329 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
330 @ApiResponse(responseCode = "404", description = "Relationship types not found")})
331 public Response getAllRelationshipTypesServlet(@Context final HttpServletRequest request,
332 @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
333 @Parameter(description = "model") @QueryParam("model") String modelName) {
334 Wrapper<Response> responseWrapper = new Wrapper<>();
335 Wrapper<User> userWrapper = new Wrapper<>();
338 validateUserExist(responseWrapper, userWrapper, userId);
339 modelName = ValidationUtils.sanitizeInputString(modelName);
340 if (responseWrapper.isEmpty()) {
341 String url = request.getMethod() + " " + request.getRequestURI();
342 log.debug(START_HANDLE_REQUEST_OF_MODIFIER_ID_IS, url, userId);
343 Either<Map<String, RelationshipTypeDefinition>, ResponseFormat> allDataTypes = relationshipTypeBusinessLogic
344 .getAllRelationshipTypes(modelName);
345 if (allDataTypes.isRight()) {
346 log.info("Failed to get all relationship types. Reason - {}", allDataTypes.right().value());
347 Response errorResponse = buildErrorResponse(allDataTypes.right().value());
348 responseWrapper.setInnerElement(errorResponse);
350 Map<String, RelationshipTypeDefinition> dataTypes = allDataTypes.left().value();
351 String dataTypeJson = gson.toJson(dataTypes);
352 Response okResponse = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), dataTypeJson);
353 responseWrapper.setInnerElement(okResponse);
356 return responseWrapper.getInnerElement();
357 } catch (Exception e) {
358 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Relationship Types");
359 log.debug("get all relationship types failed with exception", e);
360 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
361 return buildErrorResponse(responseFormat);
367 @Consumes(MediaType.APPLICATION_JSON)
368 @Produces(MediaType.APPLICATION_JSON)
369 @Operation(description = "Get node types", method = "GET", summary = "Returns node types", responses = {
370 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
371 @ApiResponse(responseCode = "200", description = "nodeTypes"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
372 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
373 @ApiResponse(responseCode = "404", description = "Node types not found")})
374 public Response getAllNodeTypesServlet(
375 @Context final HttpServletRequest request,
376 @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
377 @Parameter(description = "model") @QueryParam("model") String modelName
379 Wrapper<Response> responseWrapper = new Wrapper<>();
380 Wrapper<User> userWrapper = new Wrapper<>();
381 Either<Map<String, Component>, Response> response;
382 Map<String, Component> componentMap;
385 validateUserExist(responseWrapper, userWrapper, userId);
386 modelName = ValidationUtils.sanitizeInputString(modelName);
387 if (responseWrapper.isEmpty()) {
388 String url = request.getMethod() + " " + request.getRequestURI();
389 log.debug(START_HANDLE_REQUEST_OF_MODIFIER_ID_IS, url, userId);
390 response = getComponent(resourceBusinessLogic, true, userId, modelName);
391 if (response.isRight()) {
392 return response.right().value();
394 componentMap = new HashMap<>(response.left().value());
395 response = getComponent(resourceBusinessLogic, false, userId, modelName);
396 if (response.isRight()) {
397 return response.right().value();
399 componentMap.putAll(response.left().value());
400 String nodeTypesJson = gson.toJson(componentMap);
401 Response okResponse = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), nodeTypesJson);
402 responseWrapper.setInnerElement(okResponse);
404 return responseWrapper.getInnerElement();
405 } catch (Exception e) {
406 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Node Types");
407 log.debug("get all node types failed with exception", e);
408 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
409 return buildErrorResponse(responseFormat);
414 @Path("/artifactTypes")
415 @Operation(description = "Get Tosca ArtifactTypes", method = "GET", summary = "Returns tosca artifact types", responses = {
416 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
417 @ApiResponse(responseCode = "200", description = "Listing successful"),
418 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
419 @ApiResponse(responseCode = "403", description = "Restricted operation"),
420 @ApiResponse(responseCode = "404", description = "Tosca Artifact Types not found")})
421 public Response getAllToscaArtifactTypes(@Parameter(description = "Model name") @QueryParam("model") String model,
422 @Context final HttpServletRequest request, @HeaderParam(Constants.USER_ID_HEADER) String creator) {
424 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
425 artifactTypeBusinessLogic.getAllToscaArtifactTypes(model));
426 } catch (final BusinessException e) {
428 } catch (final Exception e) {
429 final var errorMsg = "Unexpected error while listing the Tosca Artifact types";
430 BeEcompErrorManager.getInstance().logBeRestApiGeneralError(errorMsg);
431 log.error(EcompLoggerErrorCode.UNKNOWN_ERROR, this.getClass().getName(), errorMsg, e);
432 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
437 private Either<Map<String, Component>, Response> getComponent(
438 ComponentBusinessLogic resourceBL,
439 boolean isAbstract, String userId,
440 final String modelName
442 Either<List<Component>, ResponseFormat> actionResponse;
443 List<Component> componentList;
444 actionResponse = resourceBL
445 .getLatestVersionNotAbstractComponentsMetadata(isAbstract, HighestFilterEnum.HIGHEST_ONLY, ComponentTypeEnum.RESOURCE, null, userId,
447 if (actionResponse.isRight()) {
448 log.debug(FAILED_TO_GET_ALL_NON_ABSTRACT, ComponentTypeEnum.RESOURCE.getValue());
449 return Either.right(buildErrorResponse(actionResponse.right().value()));
451 componentList = actionResponse.left().value();
452 return Either.left(ListUtils.emptyIfNull(componentList).stream().filter(component ->
453 ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition()).getToscaResourceName() != null)
454 .collect(Collectors.toMap(
455 component -> ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition())
456 .getToscaResourceName(), component -> component, (component1, component2) -> component1)));
459 private Response handleDataTypeDownloadRequest(final String dataTypeId) {
460 Optional<DataTypeDefinition> dataTypeDefinition = dataTypeOperation.handleDataTypeDownloadRequestById(dataTypeId);
461 Either<byte[], ComponentException> toscaExportDataType = toscaExportUtils.exportDataType(dataTypeDefinition.get()).left()
462 .map(toscaRepresentation -> {
463 log.debug("Tosca yaml exported for Datatype {} ", dataTypeDefinition.get().getUniqueId());
464 return toscaRepresentation.getMainYaml();
465 }).right().map(toscaError -> {
466 log.debug("Failed export tosca yaml for DataType {} error {}", dataTypeDefinition.get().getUniqueId(), toscaError);
467 return new ByActionStatusComponentException(componentsUtils.convertFromToscaError(toscaError));
469 byte[] file = toscaExportDataType.left().value();
470 String base64Contents = new String(Base64.encodeBase64(file));
471 String artifactName = dataTypeDefinition.get().getName() + DATATYPE_FILE_TYPE;
472 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
473 ArtifactUiDownloadData artifactUiDownloadData = new ArtifactUiDownloadData();
474 artifactUiDownloadData.setArtifactName(artifactName);
475 artifactUiDownloadData.setBase64Contents(base64Contents);
476 return buildOkResponse(responseFormat, artifactUiDownloadData);