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.be.servlets;
23 import com.jcabi.aspects.Loggable;
24 import fj.data.Either;
25 import io.swagger.v3.oas.annotations.Operation;
26 import io.swagger.v3.oas.annotations.Parameter;
27 import io.swagger.v3.oas.annotations.media.ArraySchema;
28 import io.swagger.v3.oas.annotations.media.Content;
29 import io.swagger.v3.oas.annotations.media.Schema;
30 import io.swagger.v3.oas.annotations.responses.ApiResponse;
31 import io.swagger.v3.oas.annotations.servers.Server;
32 import io.swagger.v3.oas.annotations.servers.Servers;
33 import io.swagger.v3.oas.annotations.tags.Tags;
34 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
35 import org.openecomp.sdc.be.components.impl.ElementBusinessLogic;
36 import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
37 import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
38 import org.openecomp.sdc.be.components.scheduledtasks.ComponentsCleanBusinessLogic;
39 import org.openecomp.sdc.be.config.BeEcompErrorManager;
40 import org.openecomp.sdc.be.config.Configuration;
41 import org.openecomp.sdc.be.config.ConfigurationManager;
42 import org.openecomp.sdc.be.dao.api.ActionStatus;
43 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
44 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
45 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
46 import org.openecomp.sdc.be.impl.ComponentsUtils;
47 import org.openecomp.sdc.be.info.ArtifactTypesInfo;
48 import org.openecomp.sdc.be.model.ArtifactType;
49 import org.openecomp.sdc.be.model.CatalogUpdateTimestamp;
50 import org.openecomp.sdc.be.model.Category;
51 import org.openecomp.sdc.be.model.Component;
52 import org.openecomp.sdc.be.model.PropertyScope;
53 import org.openecomp.sdc.be.model.Tag;
54 import org.openecomp.sdc.be.model.User;
55 import org.openecomp.sdc.be.model.catalog.CatalogComponent;
56 import org.openecomp.sdc.be.model.category.CategoryDefinition;
57 import org.openecomp.sdc.be.model.category.GroupingDefinition;
58 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
59 import org.openecomp.sdc.be.ui.model.UiCategories;
60 import org.openecomp.sdc.be.user.UserBusinessLogic;
61 import org.openecomp.sdc.common.api.Constants;
62 import org.openecomp.sdc.common.log.wrappers.Logger;
63 import org.openecomp.sdc.exception.ResponseFormat;
64 import org.springframework.stereotype.Controller;
66 import javax.inject.Inject;
67 import javax.servlet.ServletContext;
68 import javax.servlet.http.HttpServletRequest;
69 import javax.ws.rs.Consumes;
70 import javax.ws.rs.DELETE;
71 import javax.ws.rs.GET;
72 import javax.ws.rs.HeaderParam;
73 import javax.ws.rs.POST;
74 import javax.ws.rs.Path;
75 import javax.ws.rs.PathParam;
76 import javax.ws.rs.Produces;
77 import javax.ws.rs.QueryParam;
78 import javax.ws.rs.core.Context;
79 import javax.ws.rs.core.MediaType;
80 import javax.ws.rs.core.Response;
81 import java.io.IOException;
82 import java.util.ArrayList;
83 import java.util.HashMap;
84 import java.util.List;
91 * UI oriented servlet - to return elements in specific format UI needs
95 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
96 @Tags({@io.swagger.v3.oas.annotations.tags.Tag(name = "SDC Internal APIs")})
97 @Servers({@Server(url = "/sdc2/rest")})
99 public class ElementServlet extends BeGenericServlet {
101 private static final Logger log = Logger.getLogger(ElementServlet.class);
102 private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
103 private final ComponentsCleanBusinessLogic componentsCleanBusinessLogic;
104 private final ElementBusinessLogic elementBusinessLogic;
105 private final ArtifactsBusinessLogic artifactsBusinessLogic;
108 public ElementServlet(final UserBusinessLogic userBusinessLogic,
109 final ComponentsUtils componentsUtils,
110 final ComponentsCleanBusinessLogic componentsCleanBusinessLogic,
111 final ElementBusinessLogic elementBusinessLogic,
112 final ArtifactsBusinessLogic artifactsBusinessLogic) {
113 super(userBusinessLogic, componentsUtils);
114 this.componentsCleanBusinessLogic = componentsCleanBusinessLogic;
115 this.elementBusinessLogic = elementBusinessLogic;
116 this.artifactsBusinessLogic = artifactsBusinessLogic;
120 ******************************************************************************
121 * NEW CATEGORIES category / \ subcategory subcategory / grouping
122 ******************************************************************************/
129 /////////////////////////////////////////////////////////////////////////////////////////////////////
130 // retrieve all component categories
132 @Path("/categories/{componentType}")
133 @Consumes(MediaType.APPLICATION_JSON)
134 @Produces(MediaType.APPLICATION_JSON)
135 @Operation(description = "Retrieve the list of all resource/service/product categories/sub-categories/groupings",
137 summary = "Retrieve the list of all resource/service/product categories/sub-categories/groupings.",
138 responses = {@ApiResponse(
139 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
140 @ApiResponse(responseCode = "200", description = "Returns categories Ok"),
141 @ApiResponse(responseCode = "403", description = "Missing information"),
142 @ApiResponse(responseCode = "400", description = "Invalid component type"),
143 @ApiResponse(responseCode = "409", description = "Restricted operation"),
144 @ApiResponse(responseCode = "500", description = "Internal Server Error")})
145 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
146 public Response getComponentCategories(
147 @Parameter(description = "allowed values are resources / services/ products", schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
148 ComponentTypeEnum.SERVICE_PARAM_NAME,ComponentTypeEnum.PRODUCT_PARAM_NAME}),required = true)
149 @PathParam(value = "componentType") final String componentType,
150 @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
153 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
154 Either<List<CategoryDefinition>, ResponseFormat> either = elementBL.getAllCategories(componentType, userId);
155 if (either.isRight()) {
156 log.debug("No categories were found for type {}", componentType);
157 return buildErrorResponse(either.right().value());
159 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
161 } catch (Exception e) {
162 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Component Categories");
163 log.debug("getComponentCategories failed with exception", e);
169 @Path("/category/{componentType}")
170 @Consumes(MediaType.APPLICATION_JSON)
171 @Produces(MediaType.APPLICATION_JSON)
172 @Operation(description = "Create new component category", method = "POST",
173 summary = "Create new component category",
174 responses = {@ApiResponse(responseCode = "201", description = "Category created"),
175 @ApiResponse(responseCode = "400", description = "Invalid category data"),
176 @ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
177 @ApiResponse(responseCode = "409",
178 description = "Category already exists / User not permitted to perform the action"),
179 @ApiResponse(responseCode = "500", description = "General Error")})
180 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
181 public Response createComponentCategory(
182 @Parameter(description = "allowed values are resources /services / products",
183 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
184 ComponentTypeEnum.SERVICE_PARAM_NAME,ComponentTypeEnum.PRODUCT_PARAM_NAME}),
185 required = true) @PathParam(value = "componentType") final String componentType,
186 @Parameter(description = "Category to be created", required = true) String data,
187 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
189 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
190 CategoryDefinition category = RepresentationUtils.fromRepresentation(data, CategoryDefinition.class);
192 Either<CategoryDefinition, ResponseFormat> createResourceCategory = elementBL.createCategory(category, componentType, userId);
193 if (createResourceCategory.isRight()) {
194 return buildErrorResponse(createResourceCategory.right().value());
197 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
198 return buildOkResponse(responseFormat, createResourceCategory.left().value());
200 } catch (Exception e) {
201 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create resource category");
202 log.debug("createResourceCategory failed with exception", e);
208 @Path("/category/{componentType}/{categoryUniqueId}")
209 @Consumes(MediaType.APPLICATION_JSON)
210 @Produces(MediaType.APPLICATION_JSON)
211 @Operation(description = "Delete component category", method = "DELETE", summary = "Delete component category",
212 responses = {@ApiResponse(
213 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Category.class)))),
214 @ApiResponse(responseCode = "204", description = "Category deleted"),
215 @ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
216 @ApiResponse(responseCode = "409", description = "User not permitted to perform the action"),
217 @ApiResponse(responseCode = "404", description = "Category not found"),
218 @ApiResponse(responseCode = "500", description = "General Error")})
219 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
220 public Response deleteComponentCategory(@PathParam(value = "categoryUniqueId") final String categoryUniqueId,
221 @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
222 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
225 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
226 Either<CategoryDefinition, ResponseFormat> createResourceCategory = elementBL.deleteCategory(categoryUniqueId, componentType, userId);
228 if (createResourceCategory.isRight()) {
229 return buildErrorResponse(createResourceCategory.right().value());
231 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
232 return buildOkResponse(responseFormat, null);
234 } catch (Exception e) {
235 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create resource category");
236 log.debug("createResourceCategory failed with exception", e);
249 @Path("/category/{componentType}/{categoryId}/subCategory")
250 @Consumes(MediaType.APPLICATION_JSON)
251 @Produces(MediaType.APPLICATION_JSON)
252 @Operation(description = "Create new component sub-category", method = "POST",
253 summary = "Create new component sub-category for existing category",
254 responses = {@ApiResponse(responseCode = "201", description = "Subcategory created"),
255 @ApiResponse(responseCode = "400", description = "Invalid subcategory data"),
256 @ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
257 @ApiResponse(responseCode = "404", description = "Parent category wasn't found"),
258 @ApiResponse(responseCode = "409",
259 description = "Subcategory already exists / User not permitted to perform the action"),
260 @ApiResponse(responseCode = "500", description = "General Error")})
261 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
262 public Response createComponentSubCategory(
263 @Parameter(description = "allowed values are resources / products",
264 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
265 ComponentTypeEnum.PRODUCT_PARAM_NAME}),
266 required = true) @PathParam(value = "componentType") final String componentType,
267 @Parameter(description = "Parent category unique ID",
268 required = true) @PathParam(value = "categoryId") final String categoryId,
269 @Parameter(description = "Subcategory to be created. \ne.g. {\"name\":\"Resource-subcat\"}",
270 required = true) String data,
271 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
274 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
275 SubCategoryDefinition subCategory = RepresentationUtils.fromRepresentation(data, SubCategoryDefinition.class);
277 Either<SubCategoryDefinition, ResponseFormat> createSubcategory = elementBL.createSubCategory(subCategory, componentType, categoryId, userId);
278 if (createSubcategory.isRight()) {
279 return buildErrorResponse(createSubcategory.right().value());
281 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
282 return buildOkResponse(responseFormat, createSubcategory.left().value());
284 } catch (Exception e) {
285 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create sub-category");
286 log.debug("createComponentSubCategory failed with exception", e);
292 @Path("/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}")
293 @Consumes(MediaType.APPLICATION_JSON)
294 @Produces(MediaType.APPLICATION_JSON)
295 @Operation(description = "Delete component category", method = "DELETE", summary = "Delete component category",
296 responses = {@ApiResponse(
297 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Category.class)))),
298 @ApiResponse(responseCode = "204", description = "Category deleted"),
299 @ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
300 @ApiResponse(responseCode = "409", description = "User not permitted to perform the action"),
301 @ApiResponse(responseCode = "404", description = "Category not found"),
302 @ApiResponse(responseCode = "500", description = "General Error")})
303 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
304 public Response deleteComponentSubCategory(@PathParam(value = "categoryUniqueId") final String categoryUniqueId,
305 @PathParam(value = "subCategoryUniqueId") final String subCategoryUniqueId,
306 @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
307 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
310 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
311 Either<SubCategoryDefinition, ResponseFormat> deleteSubResourceCategory = elementBL.deleteSubCategory(subCategoryUniqueId, componentType, userId);
312 if (deleteSubResourceCategory.isRight()) {
313 return buildErrorResponse(deleteSubResourceCategory.right().value());
315 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
316 return buildOkResponse(responseFormat, null);
318 } catch (Exception e) {
319 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete component subcategory");
320 log.debug("deleteComponentSubCategory failed with exception", e);
329 @Path("/category/{componentType}/{categoryId}/subCategory/{subCategoryId}/grouping")
330 @Consumes(MediaType.APPLICATION_JSON)
331 @Produces(MediaType.APPLICATION_JSON)
332 @Operation(description = "Create new component grouping", method = "POST",
333 summary = "Create new component grouping for existing sub-category",
334 responses = {@ApiResponse(responseCode = "201", description = "Grouping created"),
335 @ApiResponse(responseCode = "400", description = "Invalid grouping data"),
336 @ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
337 @ApiResponse(responseCode = "404", description = "Parent category or subcategory were not found"),
338 @ApiResponse(responseCode = "409",
339 description = "Grouping already exists / User not permitted to perform the action"),
340 @ApiResponse(responseCode = "500", description = "General Error")})
341 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
342 public Response createComponentGrouping(
343 @Parameter(description = "allowed values are products",
344 schema = @Schema(allowableValues = {ComponentTypeEnum.PRODUCT_PARAM_NAME}),
345 required = true) @PathParam(value = "componentType") final String componentType,
346 @Parameter(description = "Parent category unique ID",
347 required = true) @PathParam(value = "categoryId") final String grandParentCategoryId,
348 @Parameter(description = "Parent sub-category unique ID",
349 required = true) @PathParam(value = "subCategoryId") final String parentSubCategoryId,
350 @Parameter(description = "Subcategory to be created", required = true) String data,
351 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
353 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
354 GroupingDefinition grouping = RepresentationUtils.fromRepresentation(data, GroupingDefinition.class);
356 Either<GroupingDefinition, ResponseFormat> createGrouping = elementBL.createGrouping(grouping, componentType, grandParentCategoryId, parentSubCategoryId, userId);
357 if (createGrouping.isRight()) {
358 return buildErrorResponse(createGrouping.right().value());
360 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
361 return buildOkResponse(responseFormat, createGrouping.left().value());
363 } catch (Exception e) {
364 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create grouping");
365 log.debug("createComponentGrouping failed with exception", e);
371 @Path("/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}/grouping/{groupingUniqueId}")
372 @Consumes(MediaType.APPLICATION_JSON)
373 @Produces(MediaType.APPLICATION_JSON)
374 @Operation(description = "Delete component category", method = "DELETE", summary = "Delete component category",
375 responses = {@ApiResponse(
376 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Category.class)))),
377 @ApiResponse(responseCode = "204", description = "Category deleted"),
378 @ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
379 @ApiResponse(responseCode = "409", description = "User not permitted to perform the action"),
380 @ApiResponse(responseCode = "404", description = "Category not found"),
381 @ApiResponse(responseCode = "500", description = "General Error")})
382 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
383 public Response deleteComponentGrouping(
384 @PathParam(value = "categoryUniqueId") final String grandParentCategoryUniqueId,
385 @PathParam(value = "subCategoryUniqueId") final String parentSubCategoryUniqueId,
386 @PathParam(value = "groupingUniqueId") final String groupingUniqueId,
387 @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
388 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
391 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
392 Either<GroupingDefinition, ResponseFormat> deleteGrouping = elementBL.deleteGrouping(groupingUniqueId, componentType, userId);
393 if (deleteGrouping.isRight()) {
394 return buildErrorResponse(deleteGrouping.right().value());
396 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
397 return buildOkResponse(responseFormat, null);
399 } catch (Exception e) {
400 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete component grouping");
401 log.debug("deleteGrouping failed with exception", e);
406 /////////////////////////////////////////////////////////////////////////////////////////////////////
410 @Consumes(MediaType.APPLICATION_JSON)
411 @Produces(MediaType.APPLICATION_JSON)
412 @Operation(description = "Retrieve all tags", method = "GET", summary = "Retrieve all tags", responses = {
413 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))),
414 @ApiResponse(responseCode = "200", description = "Returns tags Ok"),
415 @ApiResponse(responseCode = "404", description = "No tags were found"),
416 @ApiResponse(responseCode = "500", description = "Internal Server Error")})
417 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
418 public Response getTags(@Context final HttpServletRequest request,
419 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
420 String url = request.getMethod() + " " + request.getRequestURI();
421 log.debug("(getTags) Start handle request of {}", url);
424 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
425 Either<List<Tag>, ActionStatus> either = elementBL.getAllTags(userId);
426 if (either.isRight() || either.left().value() == null) {
427 log.debug("No tags were found");
428 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
430 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
432 } catch (Exception e) {
433 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get All Tags");
434 log.debug("getAllTags failed with exception", e);
439 /////////////////////////////////////////////////////////////////////////////////////////////////////
440 // retrieve all property scopes
442 @Path("/propertyScopes")
443 @Consumes(MediaType.APPLICATION_JSON)
444 @Produces(MediaType.APPLICATION_JSON)
445 @Operation(description = "Retrieve all propertyScopes", method = "GET", summary = "Retrieve all propertyScopes",
446 responses = {@ApiResponse(
447 content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))),
448 @ApiResponse(responseCode = "200", description = "Returns propertyScopes Ok"),
449 @ApiResponse(responseCode = "404", description = "No propertyScopes were found"),
450 @ApiResponse(responseCode = "500", description = "Internal Server Error")})
451 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
452 public Response getPropertyScopes(@Context final HttpServletRequest request,
453 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
454 String url = request.getMethod() + " " + request.getRequestURI();
455 log.debug("(getPropertyScopes) Start handle request of {}", url);
458 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
459 Either<List<PropertyScope>, ActionStatus> either = elementBL.getAllPropertyScopes(userId);
460 if (either.isRight() || either.left().value() == null) {
461 log.debug("No property scopes were found");
462 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
464 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
466 } catch (Exception e) {
467 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Property Scopes Categories");
468 log.debug("getPropertyScopes failed with exception", e);
473 /////////////////////////////////////////////////////////////////////////////////////////////////////
474 // retrieve all artifact types
476 @Path("/artifactTypes")
477 @Consumes(MediaType.APPLICATION_JSON)
478 @Produces(MediaType.APPLICATION_JSON)
479 @Operation(description = "Retrieve all artifactTypes", method = "GET", summary = "Retrieve all artifactTypes",
480 responses = {@ApiResponse(
481 content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))),
482 @ApiResponse(responseCode = "200", description = "Returns artifactTypes Ok"),
483 @ApiResponse(responseCode = "404", description = "No artifactTypes were found"),
484 @ApiResponse(responseCode = "500", description = "Internal Server Error")})
485 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
486 public Response getArtifactTypes(@Context final HttpServletRequest request,
487 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
488 String url = request.getMethod() + " " + request.getRequestURI();
489 log.debug("(GET - getArtifactTypes) Start handle request of {}", url);
492 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
493 Either<List<ArtifactType>, ActionStatus> either = elementBL.getAllArtifactTypes(userId);
494 if (either.isRight() || either.left().value() == null) {
495 log.debug("No artifact types were found");
496 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
499 Integer defaultHeatTimeout = ConfigurationManager.getConfigurationManager().getConfiguration().getHeatArtifactDeploymentTimeout().getDefaultMinutes();
500 ArtifactTypesInfo typesResponse = new ArtifactTypesInfo();
501 typesResponse.setArtifactTypes(either.left().value());
502 typesResponse.setHeatDefaultTimeout(defaultHeatTimeout);
504 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), typesResponse);
506 } catch (Exception e) {
507 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Artifact Types");
508 log.debug("getArtifactTypes failed with exception", e);
514 /////////////////////////////////////////////////////////////////////////////////////////////////////
515 // retrieve all followed resources and services
518 @Consumes(MediaType.APPLICATION_JSON)
519 @Produces(MediaType.APPLICATION_JSON)
520 @Operation(description = "Retrieve all followed", method = "GET", summary = "Retrieve all followed", responses = {
521 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))),
522 @ApiResponse(responseCode = "200", description = "Returns followed Ok"),
523 @ApiResponse(responseCode = "404", description = "No followed were found"),
524 @ApiResponse(responseCode = "404", description = "User not found"),
525 @ApiResponse(responseCode = "500", description = "Internal Server Error")})
526 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
527 public Response getFollowedResourcesServices(@Context final HttpServletRequest request,
528 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
531 String url = request.getMethod() + " " + request.getRequestURI();
532 log.debug(START_HANDLE_REQUEST_OF, url);
533 UserBusinessLogic userAdminManager = getUserAdminManager(request.getSession().getServletContext());
534 User userData = userAdminManager.getUser(userId, false);
535 Either<Map<String, List<? extends Component>>, ResponseFormat> followedResourcesServices = getElementBL(request.getSession().getServletContext()).getFollowed(userData);
536 if (followedResourcesServices.isRight()) {
537 log.debug("failed to get followed resources services ");
538 return buildErrorResponse(followedResourcesServices.right().value());
540 Object data = RepresentationUtils.toRepresentation(followedResourcesServices.left().value());
541 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), data);
542 } catch (Exception e) {
543 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Followed Resources / Services Categories");
544 log.debug("Getting followed resources/services failed with exception", e);
549 /////////////////////////////////////////////////////////////////////////////////////////////////////
550 // retrieve all certified resources and services and their last version
553 @Consumes(MediaType.APPLICATION_JSON)
554 @Produces(MediaType.APPLICATION_JSON)
555 @Operation(description = "Retrieve catalog resources and services", method = "GET",
556 summary = "Retrieve catalog resources and services", responses = {
557 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))),
558 @ApiResponse(responseCode = "200", description = "Returns resources and services Ok"),
559 @ApiResponse(responseCode = "404", description = "No resources and services were found"),
560 @ApiResponse(responseCode = "404", description = "User not found"),
561 @ApiResponse(responseCode = "500", description = "Internal Server Error")})
562 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
563 public Response getCatalogComponents(@Context final HttpServletRequest request,
564 @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
565 @QueryParam("excludeTypes") List<OriginTypeEnum> excludeTypes) throws IOException {
568 String url = request.getMethod() + " " + request.getRequestURI();
569 log.debug(START_HANDLE_REQUEST_OF, url);
571 Either<Map<String, List<CatalogComponent>>, ResponseFormat> catalogData = getElementBL(request.getSession().getServletContext()).getCatalogComponents(userId, excludeTypes);
573 if (catalogData.isRight()) {
574 log.debug("failed to get catalog data");
575 return buildErrorResponse(catalogData.right().value());
577 Object data = RepresentationUtils.toRepresentation(catalogData.left().value());
578 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), data);
580 } catch (Exception e) {
581 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Catalog Components");
582 log.debug("Getting catalog components failed with exception", e);
588 @Path("/inactiveComponents/{componentType}")
589 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
590 public Response deleteMarkedResources(@PathParam("componentType") final String componentType, @Context final HttpServletRequest request) {
591 String url = request.getMethod() + " " + request.getRequestURI();
592 log.debug(START_HANDLE_REQUEST_OF, url);
595 String userId = request.getHeader(Constants.USER_ID_HEADER);
596 User modifier = new User();
597 modifier.setUserId(userId);
598 log.debug("modifier id is {}", userId);
600 NodeTypeEnum nodeType = NodeTypeEnum.getByNameIgnoreCase(componentType);
601 if (nodeType == null) {
602 log.info("componentType is not valid: {}", componentType);
603 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
606 List<NodeTypeEnum> componentsList = new ArrayList<>();
607 componentsList.add(nodeType);
609 Map<NodeTypeEnum, Either<List<String>, ResponseFormat>> cleanComponentsResult = componentsCleanBusinessLogic.cleanComponents(componentsList);
610 Either<List<String>, ResponseFormat> cleanResult = cleanComponentsResult.get(nodeType);
612 if (cleanResult.isRight()) {
613 log.debug("failed to delete marked components of type {}", nodeType);
614 return buildErrorResponse(cleanResult.right().value());
616 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), cleanResult.left().value());
618 } catch (Exception e) {
619 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Marked Components");
620 log.debug("delete marked components failed with exception", e);
626 @Path("/ecompPortalMenu")
627 @Consumes(MediaType.APPLICATION_JSON)
628 @Produces(MediaType.APPLICATION_JSON)
629 @Operation(description = "Retrieve ecomp portal menu - MOC", method = "GET", summary = "Retrieve ecomp portal menu",
630 responses = {@ApiResponse(
631 content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))),
632 @ApiResponse(responseCode = "200", description = "Retrieve ecomp portal menu")})
633 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
634 public Response getListOfCsars(@Context final HttpServletRequest request) {
635 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
636 "[{\"menuId\":1,\"column\":2,\"text\":\"Design\",\"parentMenuId\":null,\"url\":\"\",\"appid\":null,\"roles\":null,\"children\":[{\"menuId\":11,\"column\":1,\"text\":\"ProductDesign\",\"parentMenuId\":1,\"url\":\"\",\"appid\":null,\"roles\":null},{\"menuId\":12,\"column\":2,\"text\":\"Service\",\"parentMenuId\":1,\"url\":\"\",\"appid\":null,\"roles\":null,\"children\":[{\"menuId\":21,\"column\":1,\"text\":\"ViewPolicies\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null,\"children\":[{\"menuId\":90,\"column\":1,\"text\":\"4thLevelApp1aR16\",\"parentMenuId\":21,\"url\":\"http://google.com\",\"appid\":null,\"roles\":null}]},{\"menuId\":22,\"column\":2,\"text\":\"UpdatePolicies\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null,\"children\":[{\"menuId\":91,\"column\":1,\"text\":\"4thLevelApp1bR16\",\"parentMenuId\":22,\"url\":\"http://jsonlint.com/\",\"appid\":null,\"roles\":null}]},{\"menuId\":23,\"column\":3,\"text\":\"UpdateRules\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null},{\"menuId\":24,\"column\":4,\"text\":\"CreateSignatures?\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null},{\"menuId\":25,\"column\":5,\"text\":\"Definedata\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null}]}]}]");
640 @Path("/catalogUpdateTime")
641 @Consumes(MediaType.APPLICATION_JSON)
642 @Produces(MediaType.APPLICATION_JSON)
643 @Operation(description = "Retrieve previus and current catalog update time", method = "GET",
644 summary = "Retrieve previus and current catalog update time", responses = {
645 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
646 @ApiResponse(responseCode = "200", description = "Retrieve previus and current catalog update time")})
647 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
648 public Response getCatalogUpdateTime(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
651 String url = request.getMethod() + " " + request.getRequestURI();
652 log.debug("(post) Start handle request of {}", url);
653 CatalogUpdateTimestamp catalogUpdateTimestamp = getElementBL(request.getSession().getServletContext()).getCatalogUpdateTime(userId);
655 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
656 catalogUpdateTimestamp);
660 // retrieve all artifact types, ui configuration and sdc version
663 @Consumes(MediaType.APPLICATION_JSON)
664 @Produces(MediaType.APPLICATION_JSON)
665 @Operation(description = "Retrieve all artifactTypes, ui configuration and sdc version", method = "GET",
666 summary = "Retrieve all artifactTypes, ui configuration and sdc version", responses = {
667 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))),
668 @ApiResponse(responseCode = "200",
669 description = "Returns artifactTypes, ui configuration and sdc version Ok"),
670 @ApiResponse(responseCode = "404",
671 description = "No artifactTypes were found/no ui configuration were found/no sdc version were found"),
672 @ApiResponse(responseCode = "500", description = "Internal Server Error")})
673 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
674 public Response getConfCategoriesAndVersion(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
675 String url = request.getMethod() + " " + request.getRequestURI();
676 log.debug("(getConsolidated) Start handle request of {}", url);
678 Map<String, Object> consolidatedObject = new HashMap<>();
681 ServletContext servletContext = request.getSession().getServletContext();
682 Map<String, Object> configuration = getConfigurationUi(elementBusinessLogic);
683 if (!configuration.isEmpty()) {
684 consolidatedObject.put("configuration", configuration);
686 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
689 Either<UiCategories, ResponseFormat> either = elementBusinessLogic.getAllCategories(userId);
690 if (either.isRight()) {
691 log.debug("No categories were found");
692 return buildErrorResponse(either.right().value());
694 consolidatedObject.put("categories", either.left().value());
696 consolidatedObject.put("version", getVersion(servletContext));
698 } catch (Exception e) {
699 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("getSDCVersion");
700 log.debug("method getConfCategoriesAndVersion failed with unexpected exception", e);
704 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), consolidatedObject);
707 private String getVersion(ServletContext servletContext) {
708 String version = (String) servletContext.getAttribute(Constants.ASDC_RELEASE_VERSION_ATTR);
709 log.debug("sdc version from manifest is: {}", version);
713 private Map<String, Object> getConfigurationUi(final ElementBusinessLogic elementBL) {
714 Either<Configuration.HeatDeploymentArtifactTimeout, ActionStatus> defaultHeatTimeout = elementBL.getDefaultHeatTimeout();
715 Either<Map<String, String>, ActionStatus> resourceTypesMap = elementBL.getResourceTypesMap();
717 Map<String, Object> configuration = new HashMap<>();
719 if (defaultHeatTimeout.isRight() || defaultHeatTimeout.left().value() == null) {
720 log.debug("heat default timeout was not found");
721 return configuration;
723 if (resourceTypesMap.isRight() || resourceTypesMap.left().value() == null) {
724 log.debug("No resource types were found");
725 return configuration;
727 configuration.put("artifact", artifactsBusinessLogic.getConfiguration());
728 configuration.put("heatDeploymentTimeout", defaultHeatTimeout.left().value());
729 configuration.put("componentTypes", elementBL.getAllComponentTypesParamNames());
730 configuration.put("roles", elementBL.getAllSupportedRoles());
731 configuration.put("resourceTypes", resourceTypesMap.left().value());
732 configuration.put("environmentContext", ConfigurationManager.getConfigurationManager().getConfiguration().getEnvironmentContext());
733 configuration.put("gab", ConfigurationManager.getConfigurationManager().getConfiguration().getGabConfig());
735 return configuration;