2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.sdc.be.servlets;
\r
23 import java.util.ArrayList;
\r
24 import java.util.HashMap;
\r
25 import java.util.List;
\r
26 import java.util.Map;
\r
27 import javax.inject.Inject;
\r
28 import javax.inject.Singleton;
\r
29 import javax.servlet.http.HttpServletRequest;
\r
30 import javax.ws.rs.Consumes;
\r
31 import javax.ws.rs.DELETE;
\r
32 import javax.ws.rs.GET;
\r
33 import javax.ws.rs.HeaderParam;
\r
34 import javax.ws.rs.POST;
\r
35 import javax.ws.rs.Path;
\r
36 import javax.ws.rs.PathParam;
\r
37 import javax.ws.rs.Produces;
\r
38 import javax.ws.rs.QueryParam;
\r
39 import javax.ws.rs.core.Context;
\r
40 import javax.ws.rs.core.MediaType;
\r
41 import javax.ws.rs.core.Response;
\r
42 import org.openecomp.sdc.be.components.impl.ElementBusinessLogic;
\r
43 import org.openecomp.sdc.be.components.scheduledtasks.ComponentsCleanBusinessLogic;
\r
44 import org.openecomp.sdc.be.config.BeEcompErrorManager;
\r
45 import org.openecomp.sdc.be.config.ConfigurationManager;
\r
46 import org.openecomp.sdc.be.dao.api.ActionStatus;
\r
47 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
\r
48 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
\r
49 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
\r
50 import org.openecomp.sdc.be.impl.ComponentsUtils;
\r
51 import org.openecomp.sdc.be.info.ArtifactTypesInfo;
\r
52 import org.openecomp.sdc.be.model.ArtifactType;
\r
53 import org.openecomp.sdc.be.model.Category;
\r
54 import org.openecomp.sdc.be.model.Component;
\r
55 import org.openecomp.sdc.be.model.PropertyScope;
\r
56 import org.openecomp.sdc.be.model.Tag;
\r
57 import org.openecomp.sdc.be.model.User;
\r
58 import org.openecomp.sdc.be.model.catalog.CatalogComponent;
\r
59 import org.openecomp.sdc.be.model.category.CategoryDefinition;
\r
60 import org.openecomp.sdc.be.model.category.GroupingDefinition;
\r
61 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
\r
62 import org.openecomp.sdc.be.ui.model.UiCategories;
\r
63 import org.openecomp.sdc.be.user.UserBusinessLogic;
\r
64 import org.openecomp.sdc.common.api.Constants;
\r
65 import org.openecomp.sdc.common.log.wrappers.Logger;
\r
66 import org.openecomp.sdc.exception.ResponseFormat;
\r
67 import com.jcabi.aspects.Loggable;
\r
68 import fj.data.Either;
\r
69 import io.swagger.v3.oas.annotations.OpenAPIDefinition;
\r
70 import io.swagger.v3.oas.annotations.Operation;
\r
71 import io.swagger.v3.oas.annotations.Parameter;
\r
72 import io.swagger.v3.oas.annotations.info.Info;
\r
73 import io.swagger.v3.oas.annotations.media.ArraySchema;
\r
74 import io.swagger.v3.oas.annotations.media.Content;
\r
75 import io.swagger.v3.oas.annotations.media.Schema;
\r
76 import io.swagger.v3.oas.annotations.responses.ApiResponse;
\r
77 import io.swagger.v3.oas.annotations.responses.ApiResponses;
\r
83 * UI oriented servlet - to return elements in specific format UI needs
\r
87 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
\r
88 @OpenAPIDefinition(info = @Info(title = "Element Servlet",description = "Element Servlet"))
\r
90 public class ElementServlet extends BeGenericServlet {
\r
92 private static final Logger log = Logger.getLogger(ElementServlet.class);
\r
93 private final ComponentsCleanBusinessLogic componentsCleanBusinessLogic;
\r
94 private final ElementBusinessLogic elementBusinessLogic;
\r
95 private final UserBusinessLogic userBusinessLogic;
\r
98 public ElementServlet(UserBusinessLogic userBusinessLogic,
\r
99 ComponentsUtils componentsUtils,
\r
100 ComponentsCleanBusinessLogic componentsCleanBusinessLogic,
\r
101 ElementBusinessLogic elementBusinessLogic) {
\r
102 super(userBusinessLogic, componentsUtils);
\r
103 this.componentsCleanBusinessLogic = componentsCleanBusinessLogic;
\r
104 this.elementBusinessLogic = elementBusinessLogic;
\r
105 this.userBusinessLogic = userBusinessLogic;
\r
109 ******************************************************************************
\r
110 * NEW CATEGORIES category / \ subcategory subcategory / grouping
\r
111 ******************************************************************************/
\r
118 /////////////////////////////////////////////////////////////////////////////////////////////////////
\r
119 // retrieve all component categories
\r
121 @Path("/categories/{componentType}")
\r
122 @Consumes(MediaType.APPLICATION_JSON)
\r
123 @Produces(MediaType.APPLICATION_JSON)
\r
124 @Operation(description = "Retrieve the list of all resource/service/product categories/sub-categories/groupings",
\r
126 summary = "Retrieve the list of all resource/service/product categories/sub-categories/groupings.",
\r
127 responses = @ApiResponse(
\r
128 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
\r
129 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns categories Ok"),
\r
130 @ApiResponse(responseCode = "403", description = "Missing information"),
\r
131 @ApiResponse(responseCode = "400", description = "Invalid component type"),
\r
132 @ApiResponse(responseCode = "409", description = "Restricted operation"),
\r
133 @ApiResponse(responseCode = "500", description = "Internal Server Error")})
\r
134 public Response getComponentCategories(
\r
135 @Parameter(description = "allowed values are resources / services/ products", schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
\r
136 ComponentTypeEnum.SERVICE_PARAM_NAME,ComponentTypeEnum.PRODUCT_PARAM_NAME}),required = true)
\r
137 @PathParam(value = "componentType") final String componentType,
\r
138 @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
\r
141 Either<List<CategoryDefinition>, ResponseFormat> either =
\r
142 elementBusinessLogic.getAllCategories(componentType, userId);
\r
143 if (either.isRight()) {
\r
144 log.debug("No categories were found for type {}", componentType);
\r
145 return buildErrorResponse(either.right().value());
\r
147 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
\r
149 } catch (Exception e) {
\r
150 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Component Categories");
\r
151 log.debug("getComponentCategories failed with exception", e);
\r
152 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
\r
157 @Path("/categories")
\r
158 @Consumes(MediaType.APPLICATION_JSON)
\r
159 @Produces(MediaType.APPLICATION_JSON)
\r
160 @Operation(description = "Retrieve the all resource, service and product categories", method = "GET",
\r
161 summary = "Retrieve the all resource, service and product categories", responses = @ApiResponse(
\r
162 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
\r
163 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns categories Ok"),
\r
164 @ApiResponse(responseCode = "403", description = "Missing information"),
\r
165 @ApiResponse(responseCode = "409", description = "Restricted operation"),
\r
166 @ApiResponse(responseCode = "500", description = "Internal Server Error")})
\r
167 public Response getAllCategories(@Context final HttpServletRequest request,
\r
168 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
\r
171 Either<UiCategories, ResponseFormat> either = elementBusinessLogic.getAllCategories(userId);
\r
172 if (either.isRight()) {
\r
173 log.debug("No categories were found");
\r
174 return buildErrorResponse(either.right().value());
\r
176 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
\r
178 } catch (Exception e) {
\r
179 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get All Categories");
\r
180 log.debug("getAllCategories failed with exception", e);
\r
181 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
\r
187 @Path("/category/{componentType}")
\r
188 @Consumes(MediaType.APPLICATION_JSON)
\r
189 @Produces(MediaType.APPLICATION_JSON)
\r
190 @Operation(description = "Create new component category", method = "POST",
\r
191 summary = "Create new component category")
\r
192 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Category created"),
\r
193 @ApiResponse(responseCode = "400", description = "Invalid category data"),
\r
194 @ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
\r
195 @ApiResponse(responseCode = "409",
\r
196 description = "Category already exists / User not permitted to perform the action"),
\r
197 @ApiResponse(responseCode = "500", description = "General Error")})
\r
198 public Response createComponentCategory(
\r
199 @Parameter(description = "allowed values are resources /services / products",
\r
200 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
\r
201 ComponentTypeEnum.SERVICE_PARAM_NAME,ComponentTypeEnum.PRODUCT_PARAM_NAME}),
\r
202 required = true) @PathParam(value = "componentType") final String componentType,
\r
203 @Parameter(description = "Category to be created", required = true) String data,
\r
204 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
\r
206 CategoryDefinition category = RepresentationUtils.fromRepresentation(data, CategoryDefinition.class);
\r
208 Either<CategoryDefinition, ResponseFormat> createResourceCategory =
\r
209 elementBusinessLogic.createCategory(category, componentType, userId);
\r
210 if (createResourceCategory.isRight()) {
\r
211 return buildErrorResponse(createResourceCategory.right().value());
\r
214 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
\r
215 return buildOkResponse(responseFormat, createResourceCategory.left().value());
\r
217 } catch (Exception e) {
\r
218 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create resource category");
\r
219 log.debug("createResourceCategory failed with exception", e);
\r
220 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
\r
226 @Path("/category/{componentType}/{categoryUniqueId}")
\r
227 @Consumes(MediaType.APPLICATION_JSON)
\r
228 @Produces(MediaType.APPLICATION_JSON)
\r
229 @Operation(description = "Delete component category", method = "DELETE", summary = "Delete component category",
\r
230 responses = @ApiResponse(
\r
231 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Category.class)))))
\r
232 @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Category deleted"),
\r
233 @ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
\r
234 @ApiResponse(responseCode = "409", description = "User not permitted to perform the action"),
\r
235 @ApiResponse(responseCode = "404", description = "Category not found"),
\r
236 @ApiResponse(responseCode = "500", description = "General Error")})
\r
237 public Response deleteComponentCategory(@PathParam(value = "categoryUniqueId") final String categoryUniqueId,
\r
238 @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
\r
239 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
\r
242 Either<CategoryDefinition, ResponseFormat> createResourceCategory =
\r
243 elementBusinessLogic.deleteCategory(categoryUniqueId, componentType, userId);
\r
245 if (createResourceCategory.isRight()) {
\r
246 return buildErrorResponse(createResourceCategory.right().value());
\r
248 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
\r
249 return buildOkResponse(responseFormat, null);
\r
251 } catch (Exception e) {
\r
252 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create resource category");
\r
253 log.debug("createResourceCategory failed with exception", e);
\r
254 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
\r
267 @Path("/category/{componentType}/{categoryId}/subCategory")
\r
268 @Consumes(MediaType.APPLICATION_JSON)
\r
269 @Produces(MediaType.APPLICATION_JSON)
\r
270 @Operation(description = "Create new component sub-category", method = "POST",
\r
271 summary = "Create new component sub-category for existing category")
\r
272 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Subcategory created"),
\r
273 @ApiResponse(responseCode = "400", description = "Invalid subcategory data"),
\r
274 @ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
\r
275 @ApiResponse(responseCode = "404", description = "Parent category wasn't found"),
\r
276 @ApiResponse(responseCode = "409",
\r
277 description = "Subcategory already exists / User not permitted to perform the action"),
\r
278 @ApiResponse(responseCode = "500", description = "General Error")})
\r
279 public Response createComponentSubCategory(
\r
280 @Parameter(description = "allowed values are resources / products",
\r
281 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
\r
282 ComponentTypeEnum.PRODUCT_PARAM_NAME}),
\r
283 required = true) @PathParam(value = "componentType") final String componentType,
\r
284 @Parameter(description = "Parent category unique ID",
\r
285 required = true) @PathParam(value = "categoryId") final String categoryId,
\r
286 @Parameter(description = "Subcategory to be created. \ne.g. {\"name\":\"Resource-subcat\"}",
\r
287 required = true) String data,
\r
288 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
\r
291 SubCategoryDefinition subCategory =
\r
292 RepresentationUtils.fromRepresentation(data, SubCategoryDefinition.class);
\r
294 Either<SubCategoryDefinition, ResponseFormat> createSubcategory =
\r
295 elementBusinessLogic.createSubCategory(subCategory, componentType, categoryId, userId);
\r
296 if (createSubcategory.isRight()) {
\r
297 return buildErrorResponse(createSubcategory.right().value());
\r
299 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
\r
300 return buildOkResponse(responseFormat, createSubcategory.left().value());
\r
302 } catch (Exception e) {
\r
303 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create sub-category");
\r
304 log.debug("createComponentSubCategory failed with exception", e);
\r
305 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
\r
311 @Path("/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}")
\r
312 @Consumes(MediaType.APPLICATION_JSON)
\r
313 @Produces(MediaType.APPLICATION_JSON)
\r
314 @Operation(description = "Delete component category", method = "DELETE", summary = "Delete component category",
\r
315 responses = @ApiResponse(
\r
316 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Category.class)))))
\r
317 @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Category deleted"),
\r
318 @ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
\r
319 @ApiResponse(responseCode = "409", description = "User not permitted to perform the action"),
\r
320 @ApiResponse(responseCode = "404", description = "Category not found"),
\r
321 @ApiResponse(responseCode = "500", description = "General Error")})
\r
322 public Response deleteComponentSubCategory(@PathParam(value = "categoryUniqueId") final String categoryUniqueId,
\r
323 @PathParam(value = "subCategoryUniqueId") final String subCategoryUniqueId,
\r
324 @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
\r
325 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
\r
328 Either<SubCategoryDefinition, ResponseFormat> deleteSubResourceCategory =
\r
329 elementBusinessLogic.deleteSubCategory(subCategoryUniqueId, componentType, userId);
\r
330 if (deleteSubResourceCategory.isRight()) {
\r
331 return buildErrorResponse(deleteSubResourceCategory.right().value());
\r
333 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
\r
334 return buildOkResponse(responseFormat, null);
\r
336 } catch (Exception e) {
\r
337 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete component category");
\r
338 log.debug("deleteComponentSubCategory failed with exception", e);
\r
339 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
\r
348 @Path("/category/{componentType}/{categoryId}/subCategory/{subCategoryId}/grouping")
\r
349 @Consumes(MediaType.APPLICATION_JSON)
\r
350 @Produces(MediaType.APPLICATION_JSON)
\r
351 @Operation(description = "Create new component grouping", method = "POST",
\r
352 summary = "Create new component grouping for existing sub-category")
\r
353 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Grouping created"),
\r
354 @ApiResponse(responseCode = "400", description = "Invalid grouping data"),
\r
355 @ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
\r
356 @ApiResponse(responseCode = "404", description = "Parent category or subcategory were not found"),
\r
357 @ApiResponse(responseCode = "409",
\r
358 description = "Grouping already exists / User not permitted to perform the action"),
\r
359 @ApiResponse(responseCode = "500", description = "General Error")})
\r
360 public Response createComponentGrouping(
\r
361 @Parameter(description = "allowed values are products",
\r
362 schema = @Schema(allowableValues = {ComponentTypeEnum.PRODUCT_PARAM_NAME}),
\r
363 required = true) @PathParam(value = "componentType") final String componentType,
\r
364 @Parameter(description = "Parent category unique ID",
\r
365 required = true) @PathParam(value = "categoryId") final String grandParentCategoryId,
\r
366 @Parameter(description = "Parent sub-category unique ID",
\r
367 required = true) @PathParam(value = "subCategoryId") final String parentSubCategoryId,
\r
368 @Parameter(description = "Subcategory to be created", required = true) String data,
\r
369 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
\r
371 GroupingDefinition grouping = RepresentationUtils.fromRepresentation(data, GroupingDefinition.class);
\r
373 Either<GroupingDefinition, ResponseFormat> createGrouping = elementBusinessLogic.createGrouping(grouping,
\r
374 componentType, grandParentCategoryId, parentSubCategoryId, userId);
\r
375 if (createGrouping.isRight()) {
\r
376 return buildErrorResponse(createGrouping.right().value());
\r
378 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
\r
379 return buildOkResponse(responseFormat, createGrouping.left().value());
\r
381 } catch (Exception e) {
\r
382 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create grouping");
\r
383 log.debug("createComponentGrouping failed with exception", e);
\r
384 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
\r
390 @Path("/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}/grouping/{groupingUniqueId}")
\r
391 @Consumes(MediaType.APPLICATION_JSON)
\r
392 @Produces(MediaType.APPLICATION_JSON)
\r
393 @Operation(description = "Delete component category", method = "DELETE", summary = "Delete component category",
\r
394 responses = @ApiResponse(
\r
395 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Category.class)))))
\r
396 @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Category deleted"),
\r
397 @ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
\r
398 @ApiResponse(responseCode = "409", description = "User not permitted to perform the action"),
\r
399 @ApiResponse(responseCode = "404", description = "Category not found"),
\r
400 @ApiResponse(responseCode = "500", description = "General Error")})
\r
401 public Response deleteComponentGrouping(
\r
402 @PathParam(value = "categoryUniqueId") final String grandParentCategoryUniqueId,
\r
403 @PathParam(value = "subCategoryUniqueId") final String parentSubCategoryUniqueId,
\r
404 @PathParam(value = "groupingUniqueId") final String groupingUniqueId,
\r
405 @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
\r
406 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
\r
409 Either<GroupingDefinition, ResponseFormat> deleteGrouping =
\r
410 elementBusinessLogic.deleteGrouping(groupingUniqueId, componentType, userId);
\r
411 if (deleteGrouping.isRight()) {
\r
412 return buildErrorResponse(deleteGrouping.right().value());
\r
414 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
\r
415 return buildOkResponse(responseFormat, null);
\r
417 } catch (Exception e) {
\r
418 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete component grouping");
\r
419 log.debug("deleteGrouping failed with exception", e);
\r
420 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
\r
425 /////////////////////////////////////////////////////////////////////////////////////////////////////
\r
426 // retrieve all tags
\r
429 @Consumes(MediaType.APPLICATION_JSON)
\r
430 @Produces(MediaType.APPLICATION_JSON)
\r
431 @Operation(description = "Retrieve all tags", method = "GET", summary = "Retrieve all tags",responses = @ApiResponse(
\r
432 content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
\r
433 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns tags Ok"),
\r
434 @ApiResponse(responseCode = "404", description = "No tags were found"),
\r
435 @ApiResponse(responseCode = "500", description = "Internal Server Error")})
\r
436 public Response getTags(@Context final HttpServletRequest request,
\r
437 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
\r
438 String url = request.getMethod() + " " + request.getRequestURI();
\r
439 log.debug("(getTags) Start handle request of {}", url);
\r
442 Either<List<Tag>, ActionStatus> either = elementBusinessLogic.getAllTags(userId);
\r
443 if (either.isRight() || either.left().value() == null) {
\r
444 log.debug("No tags were found");
\r
445 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
\r
447 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
\r
449 } catch (Exception e) {
\r
450 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get All Tags");
\r
451 log.debug("getAllTags failed with exception", e);
\r
452 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
\r
456 /////////////////////////////////////////////////////////////////////////////////////////////////////
\r
457 // retrieve all property scopes
\r
459 @Path("/propertyScopes")
\r
460 @Consumes(MediaType.APPLICATION_JSON)
\r
461 @Produces(MediaType.APPLICATION_JSON)
\r
462 @Operation(description = "Retrieve all propertyScopes", method = "GET", summary = "Retrieve all propertyScopes",
\r
463 responses = @ApiResponse(
\r
464 content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
\r
465 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns propertyScopes Ok"),
\r
466 @ApiResponse(responseCode = "404", description = "No propertyScopes were found"),
\r
467 @ApiResponse(responseCode = "500", description = "Internal Server Error")})
\r
468 public Response getPropertyScopes(@Context final HttpServletRequest request,
\r
469 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
\r
470 String url = request.getMethod() + " " + request.getRequestURI();
\r
471 log.debug("(getPropertyScopes) Start handle request of {}", url);
\r
474 Either<List<PropertyScope>, ActionStatus> either = elementBusinessLogic.getAllPropertyScopes(userId);
\r
475 if (either.isRight() || either.left().value() == null) {
\r
476 log.debug("No property scopes were found");
\r
477 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
\r
479 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
\r
481 } catch (Exception e) {
\r
482 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Property Scopes Categories");
\r
483 log.debug("getPropertyScopes failed with exception", e);
\r
484 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
\r
488 /////////////////////////////////////////////////////////////////////////////////////////////////////
\r
489 // retrieve all artifact types
\r
491 @Path("/artifactTypes")
\r
492 @Consumes(MediaType.APPLICATION_JSON)
\r
493 @Produces(MediaType.APPLICATION_JSON)
\r
494 @Operation(description = "Retrieve all artifactTypes", method = "GET", summary = "Retrieve all artifactTypes",
\r
495 responses = @ApiResponse(
\r
496 content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
\r
497 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns artifactTypes Ok"),
\r
498 @ApiResponse(responseCode = "404", description = "No artifactTypes were found"),
\r
499 @ApiResponse(responseCode = "500", description = "Internal Server Error")})
\r
500 public Response getArtifactTypes(@Context final HttpServletRequest request,
\r
501 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
\r
502 String url = request.getMethod() + " " + request.getRequestURI();
\r
503 log.debug("(GET - getArtifactTypes) Start handle request of {}", url);
\r
506 Either<List<ArtifactType>, ActionStatus> either = elementBusinessLogic.getAllArtifactTypes(userId);
\r
507 if (either.isRight() || either.left().value() == null) {
\r
508 log.debug("No artifact types were found");
\r
509 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
\r
512 Integer defaultHeatTimeout = ConfigurationManager.getConfigurationManager().getConfiguration()
\r
513 .getDefaultHeatArtifactTimeoutMinutes();
\r
514 ArtifactTypesInfo typesResponse = new ArtifactTypesInfo();
\r
515 typesResponse.setArtifactTypes(either.left().value());
\r
516 typesResponse.setHeatDefaultTimeout(defaultHeatTimeout);
\r
518 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), typesResponse);
\r
520 } catch (Exception e) {
\r
521 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Artifact Types");
\r
522 log.debug("getArtifactTypes failed with exception", e);
\r
523 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
\r
527 /////////////////////////////////////////////////////////////////////////////////////////////////////
\r
528 // retrieve all artifact types
\r
530 @Path("/configuration/ui")
\r
531 @Consumes(MediaType.APPLICATION_JSON)
\r
532 @Produces(MediaType.APPLICATION_JSON)
\r
533 @Operation(description = "Retrieve all artifactTypes", method = "GET", summary = "Retrieve all artifactTypes",
\r
534 responses = @ApiResponse(
\r
535 content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
\r
536 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns artifactTypes Ok"),
\r
537 @ApiResponse(responseCode = "404", description = "No artifactTypes were found"),
\r
538 @ApiResponse(responseCode = "500", description = "Internal Server Error")})
\r
539 public Response getConfiguration(@Context final HttpServletRequest request,
\r
540 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
\r
541 String url = request.getMethod() + " " + request.getRequestURI();
\r
542 log.debug("(getConfiguration) Start handle request of {}", url);
\r
545 Either<List<ArtifactType>, ActionStatus> otherEither = elementBusinessLogic.getAllArtifactTypes(userId);
\r
546 Either<Integer, ActionStatus> defaultHeatTimeout = elementBusinessLogic.getDefaultHeatTimeout();
\r
547 Either<Map<String, Object>, ActionStatus> deploymentEither =
\r
548 elementBusinessLogic.getAllDeploymentArtifactTypes();
\r
549 Either<Map<String, String>, ActionStatus> resourceTypesMap = elementBusinessLogic.getResourceTypesMap();
\r
551 if (otherEither.isRight() || otherEither.left().value() == null) {
\r
552 log.debug("No other artifact types were found");
\r
553 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
\r
554 } else if (deploymentEither.isRight() || deploymentEither.left().value() == null) {
\r
555 log.debug("No deployment artifact types were found");
\r
556 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
\r
557 } else if (defaultHeatTimeout.isRight() || defaultHeatTimeout.left().value() == null) {
\r
558 log.debug("heat default timeout was not found");
\r
559 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
\r
560 } else if (resourceTypesMap.isRight() || resourceTypesMap.left().value() == null) {
\r
561 log.debug("No resource types were found");
\r
562 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
\r
564 Map<String, Object> artifacts = new HashMap<>();
\r
565 Map<String, Object> configuration = new HashMap<>();
\r
567 artifacts.put("other", otherEither.left().value());
\r
568 artifacts.put("deployment", deploymentEither.left().value());
\r
569 configuration.put("artifacts", artifacts);
\r
570 configuration.put("defaultHeatTimeout", defaultHeatTimeout.left().value());
\r
571 configuration.put("componentTypes", elementBusinessLogic.getAllComponentTypesParamNames());
\r
572 configuration.put("roles", elementBusinessLogic.getAllSupportedRoles());
\r
573 configuration.put("resourceTypes", resourceTypesMap.left().value());
\r
574 configuration.put("environmentContext",
\r
575 ConfigurationManager.getConfigurationManager().getConfiguration().getEnvironmentContext());
\r
576 configuration.put("gab",
\r
577 ConfigurationManager.getConfigurationManager().getConfiguration().getGabConfig());
\r
579 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), configuration);
\r
582 } catch (Exception e) {
\r
583 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Artifact Types");
\r
584 log.debug("getArtifactTypes failed with exception", e);
\r
585 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
\r
589 /////////////////////////////////////////////////////////////////////////////////////////////////////
\r
590 // retrieve all followed resources and services
\r
593 @Consumes(MediaType.APPLICATION_JSON)
\r
594 @Produces(MediaType.APPLICATION_JSON)
\r
595 @Operation(description = "Retrieve all followed", method = "GET", summary = "Retrieve all followed",
\r
596 responses = @ApiResponse(
\r
597 content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
\r
598 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns followed Ok"),
\r
599 @ApiResponse(responseCode = "404", description = "No followed were found"),
\r
600 @ApiResponse(responseCode = "404", description = "User not found"),
\r
601 @ApiResponse(responseCode = "500", description = "Internal Server Error")})
\r
602 public Response getFollowedResourcesServices(@Context final HttpServletRequest request,
\r
603 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
\r
605 Response res = null;
\r
606 User userData = null;
\r
608 String url = request.getMethod() + " " + request.getRequestURI();
\r
609 log.debug("Start handle request of {}", url);
\r
611 // Getting the user
\r
612 Either<User, ActionStatus> either = userBusinessLogic.getUser(userId, false);
\r
613 if (either.isRight()) {
\r
614 // Couldn't find or otherwise fetch the user
\r
615 return buildErrorResponse(
\r
616 getComponentsUtils().getResponseFormatByUserId(either.right().value(), userId));
\r
619 if (either.left().value() != null) {
\r
620 userData = either.left().value();
\r
621 Either<Map<String, List<? extends Component>>, ResponseFormat> followedResourcesServices =
\r
622 elementBusinessLogic.getFollowed(userData);
\r
623 if (followedResourcesServices.isRight()) {
\r
624 log.debug("failed to get followed resources services ");
\r
625 return buildErrorResponse(followedResourcesServices.right().value());
\r
627 Object data = RepresentationUtils.toRepresentation(followedResourcesServices.left().value());
\r
628 res = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), data);
\r
630 res = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
\r
632 } catch (Exception e) {
\r
633 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Followed Resources / Services Categories");
\r
634 log.debug("Getting followed resources/services failed with exception", e);
\r
635 res = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
\r
640 /////////////////////////////////////////////////////////////////////////////////////////////////////
\r
641 // retrieve all certified resources and services and their last version
\r
644 @Consumes(MediaType.APPLICATION_JSON)
\r
645 @Produces(MediaType.APPLICATION_JSON)
\r
646 @Operation(description = "Retrieve catalog resources and services", method = "GET",
\r
647 summary = "Retrieve catalog resources and services", responses = @ApiResponse(
\r
648 content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
\r
649 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns resources and services Ok"),
\r
650 @ApiResponse(responseCode = "404", description = "No resources and services were found"),
\r
651 @ApiResponse(responseCode = "404", description = "User not found"),
\r
652 @ApiResponse(responseCode = "500", description = "Internal Server Error")})
\r
653 public Response getCatalogComponents(@Context final HttpServletRequest request,
\r
654 @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
\r
655 @QueryParam("excludeTypes") List<OriginTypeEnum> excludeTypes) {
\r
657 Response res = null;
\r
659 String url = request.getMethod() + " " + request.getRequestURI();
\r
660 log.debug("Start handle request of {}", url);
\r
662 Either<Map<String, List<CatalogComponent>>, ResponseFormat> catalogData =
\r
663 elementBusinessLogic.getCatalogComponents(userId, excludeTypes);
\r
665 if (catalogData.isRight()) {
\r
666 log.debug("failed to get catalog data");
\r
667 return buildErrorResponse(catalogData.right().value());
\r
669 Object data = RepresentationUtils.toRepresentation(catalogData.left().value());
\r
670 res = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), data);
\r
672 } catch (Exception e) {
\r
673 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Catalog Components");
\r
674 log.debug("Getting catalog components failed with exception", e);
\r
675 res = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
\r
681 @Path("/inactiveComponents/{componentType}")
\r
682 public Response deleteMarkedResources(@PathParam("componentType") final String componentType, @Context final HttpServletRequest request) {
\r
683 String url = request.getMethod() + " " + request.getRequestURI();
\r
684 log.debug("Start handle request of {}", url);
\r
687 String userId = request.getHeader(Constants.USER_ID_HEADER);
\r
688 User modifier = new User();
\r
689 modifier.setUserId(userId);
\r
690 log.debug("modifier id is {}", userId);
\r
692 Response response = null;
\r
694 NodeTypeEnum nodeType = NodeTypeEnum.getByNameIgnoreCase(componentType);
\r
695 if (nodeType == null) {
\r
696 log.info("componentType is not valid: {}", componentType);
\r
697 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
\r
700 List<NodeTypeEnum> componentsList = new ArrayList<>();
\r
701 componentsList.add(nodeType);
\r
703 Map<NodeTypeEnum, Either<List<String>, ResponseFormat>> cleanComponentsResult = componentsCleanBusinessLogic.cleanComponents(componentsList);
\r
704 Either<List<String>, ResponseFormat> cleanResult = cleanComponentsResult.get(nodeType);
\r
706 if (cleanResult.isRight()) {
\r
707 log.debug("failed to delete marked components of type {}", nodeType);
\r
708 response = buildErrorResponse(cleanResult.right().value());
\r
711 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), cleanResult.left().value());
\r
714 } catch (Exception e) {
\r
715 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Marked Components");
\r
716 log.debug("delete marked components failed with exception", e);
\r
717 response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
\r
724 @Path("/ecompPortalMenu")
\r
725 @Consumes(MediaType.APPLICATION_JSON)
\r
726 @Produces(MediaType.APPLICATION_JSON)
\r
727 @Operation(description = "Retrieve ecomp portal menu - MOC", method = "GET", summary = "Retrieve ecomp portal menu", responses = @ApiResponse(
\r
728 content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
\r
729 @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Retrieve ecomp portal menu") })
\r
730 public Response getListOfCsars(@Context final HttpServletRequest request) {
\r
731 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
\r
732 "[{\"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}]}]}]");
\r