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.annotations.*;
26 import javax.inject.Inject;
27 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
28 import org.openecomp.sdc.be.components.impl.ElementBusinessLogic;
29 import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
30 import org.openecomp.sdc.be.components.scheduledtasks.ComponentsCleanBusinessLogic;
31 import org.openecomp.sdc.be.config.BeEcompErrorManager;
32 import org.openecomp.sdc.be.config.ConfigurationManager;
33 import org.openecomp.sdc.be.dao.api.ActionStatus;
34 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
35 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
36 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
37 import org.openecomp.sdc.be.impl.ComponentsUtils;
38 import org.openecomp.sdc.be.info.ArtifactTypesInfo;
39 import org.openecomp.sdc.be.model.*;
40 import org.openecomp.sdc.be.model.Tag;
41 import org.openecomp.sdc.be.model.catalog.CatalogComponent;
42 import org.openecomp.sdc.be.model.category.CategoryDefinition;
43 import org.openecomp.sdc.be.model.category.GroupingDefinition;
44 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
45 import org.openecomp.sdc.be.ui.model.UiCategories;
46 import org.openecomp.sdc.be.user.UserBusinessLogic;
47 import org.openecomp.sdc.common.api.Constants;
48 import org.openecomp.sdc.common.log.wrappers.Logger;
49 import org.openecomp.sdc.exception.ResponseFormat;
51 import javax.inject.Singleton;
52 import javax.servlet.ServletContext;
53 import javax.servlet.http.HttpServletRequest;
55 import javax.ws.rs.core.Context;
56 import javax.ws.rs.core.MediaType;
57 import javax.ws.rs.core.Response;
58 import java.util.ArrayList;
59 import java.util.HashMap;
60 import java.util.List;
67 * UI oriented servlet - to return elements in specific format UI needs
71 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
72 @Api(value = "Element Servlet", description = "Element Servlet")
74 public class ElementServlet extends BeGenericServlet {
76 private static final Logger log = Logger.getLogger(ElementServlet.class);
77 private final ComponentsCleanBusinessLogic componentsCleanBusinessLogic;
78 private final ElementBusinessLogic elementBusinessLogic;
79 private final UserBusinessLogic userBusinessLogic;
82 public ElementServlet(UserBusinessLogic userBusinessLogic,
83 ComponentsUtils componentsUtils,
84 ComponentsCleanBusinessLogic componentsCleanBusinessLogic,
85 ElementBusinessLogic elementBusinessLogic) {
86 super(userBusinessLogic, componentsUtils);
87 this.componentsCleanBusinessLogic = componentsCleanBusinessLogic;
88 this.elementBusinessLogic = elementBusinessLogic;
89 this.userBusinessLogic = userBusinessLogic;
93 ******************************************************************************
94 * NEW CATEGORIES category / \ subcategory subcategory / grouping
95 ******************************************************************************/
102 /////////////////////////////////////////////////////////////////////////////////////////////////////
103 // retrieve all component categories
105 @Path("/categories/{componentType}")
106 @Consumes(MediaType.APPLICATION_JSON)
107 @Produces(MediaType.APPLICATION_JSON)
108 @ApiOperation(value = "Retrieve the list of all resource/service/product categories/sub-categories/groupings", httpMethod = "GET", notes = "Retrieve the list of all resource/service/product categories/sub-categories/groupings.", response = Response.class)
109 @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns categories Ok"), @ApiResponse(code = 403, message = "Missing information"), @ApiResponse(code = 400, message = "Invalid component type"),
110 @ApiResponse(code = 409, message = "Restricted operation"), @ApiResponse(code = 500, message = "Internal Server Error") })
111 public Response getComponentCategories(@ApiParam(value = "allowed values are resources / services/ products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
112 + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam(value = "componentType") final String componentType, @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
115 Either<List<CategoryDefinition>, ResponseFormat> either = elementBusinessLogic.getAllCategories(componentType, userId);
116 if (either.isRight()) {
117 log.debug("No categories were found for type {}", componentType);
118 return buildErrorResponse(either.right().value());
120 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
122 } catch (Exception e) {
123 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Component Categories");
124 log.debug("getComponentCategories failed with exception", e);
125 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
131 @Consumes(MediaType.APPLICATION_JSON)
132 @Produces(MediaType.APPLICATION_JSON)
133 @ApiOperation(value = "Retrieve the all resource, service and product categories", httpMethod = "GET", notes = "Retrieve the all resource, service and product categories", response = Response.class)
134 @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns categories Ok"), @ApiResponse(code = 403, message = "Missing information"),
135 @ApiResponse(code = 409, message = "Restricted operation"), @ApiResponse(code = 500, message = "Internal Server Error") })
136 public Response getAllCategories(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
139 Either<UiCategories, ResponseFormat> either = elementBusinessLogic
140 .getAllCategories(userId);
141 if (either.isRight()) {
142 log.debug("No categories were found");
143 return buildErrorResponse(either.right().value());
145 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
147 } catch (Exception e) {
148 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get All Categories");
149 log.debug("getAllCategories failed with exception", e);
150 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
156 @Path("/category/{componentType}")
157 @Consumes(MediaType.APPLICATION_JSON)
158 @Produces(MediaType.APPLICATION_JSON)
159 @ApiOperation(value = "Create new component category", httpMethod = "POST", notes = "Create new component category")
160 @ApiResponses(value = { @ApiResponse(code = 201, message = "Category created"), @ApiResponse(code = 400, message = "Invalid category data"), @ApiResponse(code = 403, message = "USER_ID header is missing"),
161 @ApiResponse(code = 409, message = "Category already exists / User not permitted to perform the action"), @ApiResponse(code = 500, message = "General Error") })
162 public Response createComponentCategory(
163 @ApiParam(value = "allowed values are resources /services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
164 + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam(value = "componentType") final String componentType,
165 @ApiParam(value = "Category to be created", required = true) String data, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
167 CategoryDefinition category = RepresentationUtils.fromRepresentation(data, CategoryDefinition.class);
169 Either<CategoryDefinition, ResponseFormat> createResourceCategory =
170 elementBusinessLogic.createCategory(category, componentType, userId);
171 if (createResourceCategory.isRight()) {
172 return buildErrorResponse(createResourceCategory.right().value());
175 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
176 return buildOkResponse(responseFormat, createResourceCategory.left().value());
178 } catch (Exception e) {
179 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create resource category");
180 log.debug("createResourceCategory failed with exception", e);
181 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
187 @Path("/category/{componentType}/{categoryUniqueId}")
188 @Consumes(MediaType.APPLICATION_JSON)
189 @Produces(MediaType.APPLICATION_JSON)
190 @ApiOperation(value = "Delete component category", httpMethod = "DELETE", notes = "Delete component category", response = Category.class)
191 @ApiResponses(value = { @ApiResponse(code = 204, message = "Category deleted"), @ApiResponse(code = 403, message = "USER_ID header is missing"), @ApiResponse(code = 409, message = "User not permitted to perform the action"),
192 @ApiResponse(code = 404, message = "Category not found"), @ApiResponse(code = 500, message = "General Error") })
193 public Response deleteComponentCategory(@PathParam(value = "categoryUniqueId") final String categoryUniqueId, @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
194 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
197 Either<CategoryDefinition, ResponseFormat> createResourceCategory =
198 elementBusinessLogic.deleteCategory(categoryUniqueId, componentType, userId);
200 if (createResourceCategory.isRight()) {
201 return buildErrorResponse(createResourceCategory.right().value());
203 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
204 return buildOkResponse(responseFormat, null);
206 } catch (Exception e) {
207 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create resource category");
208 log.debug("createResourceCategory failed with exception", e);
209 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
222 @Path("/category/{componentType}/{categoryId}/subCategory")
223 @Consumes(MediaType.APPLICATION_JSON)
224 @Produces(MediaType.APPLICATION_JSON)
225 @ApiOperation(value = "Create new component sub-category", httpMethod = "POST", notes = "Create new component sub-category for existing category")
226 @ApiResponses(value = { @ApiResponse(code = 201, message = "Subcategory created"), @ApiResponse(code = 400, message = "Invalid subcategory data"), @ApiResponse(code = 403, message = "USER_ID header is missing"),
227 @ApiResponse(code = 404, message = "Parent category wasn't found"), @ApiResponse(code = 409, message = "Subcategory already exists / User not permitted to perform the action"), @ApiResponse(code = 500, message = "General Error") })
228 public Response createComponentSubCategory(
229 @ApiParam(value = "allowed values are resources / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + ","
230 + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam(value = "componentType") final String componentType,
231 @ApiParam(value = "Parent category unique ID", required = true) @PathParam(value = "categoryId") final String categoryId, @ApiParam(value = "Subcategory to be created. \ne.g. {\"name\":\"Resource-subcat\"}", required = true) String data,
232 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
235 SubCategoryDefinition subCategory = RepresentationUtils.fromRepresentation(data, SubCategoryDefinition.class);
237 Either<SubCategoryDefinition, ResponseFormat> createSubcategory = elementBusinessLogic
238 .createSubCategory(subCategory, componentType, categoryId, userId);
239 if (createSubcategory.isRight()) {
240 return buildErrorResponse(createSubcategory.right().value());
242 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
243 return buildOkResponse(responseFormat, createSubcategory.left().value());
245 } catch (Exception e) {
246 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create sub-category");
247 log.debug("createComponentSubCategory failed with exception", e);
248 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
254 @Path("/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}")
255 @Consumes(MediaType.APPLICATION_JSON)
256 @Produces(MediaType.APPLICATION_JSON)
257 @ApiOperation(value = "Delete component category", httpMethod = "DELETE", notes = "Delete component category", response = Category.class)
258 @ApiResponses(value = { @ApiResponse(code = 204, message = "Category deleted"), @ApiResponse(code = 403, message = "USER_ID header is missing"), @ApiResponse(code = 409, message = "User not permitted to perform the action"),
259 @ApiResponse(code = 404, message = "Category not found"), @ApiResponse(code = 500, message = "General Error") })
260 public Response deleteComponentSubCategory(@PathParam(value = "categoryUniqueId") final String categoryUniqueId, @PathParam(value = "subCategoryUniqueId") final String subCategoryUniqueId,
261 @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
264 Either<SubCategoryDefinition, ResponseFormat> deleteSubResourceCategory =
265 elementBusinessLogic.deleteSubCategory(subCategoryUniqueId, componentType, userId);
266 if (deleteSubResourceCategory.isRight()) {
267 return buildErrorResponse(deleteSubResourceCategory.right().value());
269 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
270 return buildOkResponse(responseFormat, null);
272 } catch (Exception e) {
273 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete component category");
274 log.debug("deleteComponentSubCategory failed with exception", e);
275 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
284 @Path("/category/{componentType}/{categoryId}/subCategory/{subCategoryId}/grouping")
285 @Consumes(MediaType.APPLICATION_JSON)
286 @Produces(MediaType.APPLICATION_JSON)
287 @ApiOperation(value = "Create new component grouping", httpMethod = "POST", notes = "Create new component grouping for existing sub-category")
288 @ApiResponses(value = { @ApiResponse(code = 201, message = "Grouping created"), @ApiResponse(code = 400, message = "Invalid grouping data"), @ApiResponse(code = 403, message = "USER_ID header is missing"),
289 @ApiResponse(code = 404, message = "Parent category or subcategory were not found"), @ApiResponse(code = 409, message = "Grouping already exists / User not permitted to perform the action"),
290 @ApiResponse(code = 500, message = "General Error") })
291 public Response createComponentGrouping(@ApiParam(value = "allowed values are products", allowableValues = ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam(value = "componentType") final String componentType,
292 @ApiParam(value = "Parent category unique ID", required = true) @PathParam(value = "categoryId") final String grandParentCategoryId,
293 @ApiParam(value = "Parent sub-category unique ID", required = true) @PathParam(value = "subCategoryId") final String parentSubCategoryId, @ApiParam(value = "Subcategory to be created", required = true) String data,
294 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
296 GroupingDefinition grouping = RepresentationUtils.fromRepresentation(data, GroupingDefinition.class);
298 Either<GroupingDefinition, ResponseFormat> createGrouping = elementBusinessLogic
299 .createGrouping(grouping, componentType, grandParentCategoryId, parentSubCategoryId, userId);
300 if (createGrouping.isRight()) {
301 return buildErrorResponse(createGrouping.right().value());
303 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
304 return buildOkResponse(responseFormat, createGrouping.left().value());
306 } catch (Exception e) {
307 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create grouping");
308 log.debug("createComponentGrouping failed with exception", e);
309 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
315 @Path("/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}/grouping/{groupingUniqueId}")
316 @Consumes(MediaType.APPLICATION_JSON)
317 @Produces(MediaType.APPLICATION_JSON)
318 @ApiOperation(value = "Delete component category", httpMethod = "DELETE", notes = "Delete component category", response = Category.class)
319 @ApiResponses(value = { @ApiResponse(code = 204, message = "Category deleted"), @ApiResponse(code = 403, message = "USER_ID header is missing"), @ApiResponse(code = 409, message = "User not permitted to perform the action"),
320 @ApiResponse(code = 404, message = "Category not found"), @ApiResponse(code = 500, message = "General Error") })
321 public Response deleteComponentGrouping(@PathParam(value = "categoryUniqueId") final String grandParentCategoryUniqueId, @PathParam(value = "subCategoryUniqueId") final String parentSubCategoryUniqueId,
322 @PathParam(value = "groupingUniqueId") final String groupingUniqueId, @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
323 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
326 Either<GroupingDefinition, ResponseFormat> deleteGrouping = elementBusinessLogic
327 .deleteGrouping(groupingUniqueId, componentType, userId);
328 if (deleteGrouping.isRight()) {
329 return buildErrorResponse(deleteGrouping.right().value());
331 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
332 return buildOkResponse(responseFormat, null);
334 } catch (Exception e) {
335 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete component grouping");
336 log.debug("deleteGrouping failed with exception", e);
337 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
342 /////////////////////////////////////////////////////////////////////////////////////////////////////
346 @Consumes(MediaType.APPLICATION_JSON)
347 @Produces(MediaType.APPLICATION_JSON)
348 @ApiOperation(value = "Retrieve all tags", httpMethod = "GET", notes = "Retrieve all tags", response = User.class)
349 @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns tags Ok"), @ApiResponse(code = 404, message = "No tags were found"), @ApiResponse(code = 500, message = "Internal Server Error") })
350 public Response getTags(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
351 String url = request.getMethod() + " " + request.getRequestURI();
352 log.debug("(getTags) Start handle request of {}", url);
355 Either<List<Tag>, ActionStatus> either = elementBusinessLogic.getAllTags(userId);
356 if (either.isRight() || either.left().value() == null) {
357 log.debug("No tags were found");
358 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
360 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
362 } catch (Exception e) {
363 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get All Tags");
364 log.debug("getAllTags failed with exception", e);
365 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
369 /////////////////////////////////////////////////////////////////////////////////////////////////////
370 // retrieve all property scopes
372 @Path("/propertyScopes")
373 @Consumes(MediaType.APPLICATION_JSON)
374 @Produces(MediaType.APPLICATION_JSON)
375 @ApiOperation(value = "Retrieve all propertyScopes", httpMethod = "GET", notes = "Retrieve all propertyScopes", response = User.class)
376 @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns propertyScopes Ok"), @ApiResponse(code = 404, message = "No propertyScopes were found"), @ApiResponse(code = 500, message = "Internal Server Error") })
377 public Response getPropertyScopes(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
378 String url = request.getMethod() + " " + request.getRequestURI();
379 log.debug("(getPropertyScopes) Start handle request of {}", url);
382 Either<List<PropertyScope>, ActionStatus> either = elementBusinessLogic.getAllPropertyScopes(userId);
383 if (either.isRight() || either.left().value() == null) {
384 log.debug("No property scopes were found");
385 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
387 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
389 } catch (Exception e) {
390 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Property Scopes Categories");
391 log.debug("getPropertyScopes failed with exception", e);
392 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
396 /////////////////////////////////////////////////////////////////////////////////////////////////////
397 // retrieve all artifact types
399 @Path("/artifactTypes")
400 @Consumes(MediaType.APPLICATION_JSON)
401 @Produces(MediaType.APPLICATION_JSON)
402 @ApiOperation(value = "Retrieve all artifactTypes", httpMethod = "GET", notes = "Retrieve all artifactTypes", response = User.class)
403 @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns artifactTypes Ok"), @ApiResponse(code = 404, message = "No artifactTypes were found"), @ApiResponse(code = 500, message = "Internal Server Error") })
404 public Response getArtifactTypes(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
405 String url = request.getMethod() + " " + request.getRequestURI();
406 log.debug("(GET - getArtifactTypes) Start handle request of {}", url);
409 Either<List<ArtifactType>, ActionStatus> either = elementBusinessLogic.getAllArtifactTypes(userId);
410 if (either.isRight() || either.left().value() == null) {
411 log.debug("No artifact types were found");
412 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
415 Integer defaultHeatTimeout = ConfigurationManager.getConfigurationManager().getConfiguration().getDefaultHeatArtifactTimeoutMinutes();
416 ArtifactTypesInfo typesResponse = new ArtifactTypesInfo();
417 typesResponse.setArtifactTypes(either.left().value());
418 typesResponse.setHeatDefaultTimeout(defaultHeatTimeout);
420 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), typesResponse);
422 } catch (Exception e) {
423 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Artifact Types");
424 log.debug("getArtifactTypes failed with exception", e);
425 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
429 /////////////////////////////////////////////////////////////////////////////////////////////////////
430 // retrieve all artifact types
432 @Path("/configuration/ui")
433 @Consumes(MediaType.APPLICATION_JSON)
434 @Produces(MediaType.APPLICATION_JSON)
435 @ApiOperation(value = "Retrieve all artifactTypes", httpMethod = "GET", notes = "Retrieve all artifactTypes", response = User.class)
436 @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns artifactTypes Ok"), @ApiResponse(code = 404, message = "No artifactTypes were found"), @ApiResponse(code = 500, message = "Internal Server Error") })
437 public Response getConfiguration(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
438 String url = request.getMethod() + " " + request.getRequestURI();
439 log.debug("(getConfiguration) Start handle request of {}", url);
442 Either<List<ArtifactType>, ActionStatus> otherEither = elementBusinessLogic.getAllArtifactTypes(userId);
443 Either<Integer, ActionStatus> defaultHeatTimeout = elementBusinessLogic.getDefaultHeatTimeout();
444 Either<Map<String, Object>, ActionStatus> deploymentEither = elementBusinessLogic.getAllDeploymentArtifactTypes();
445 Either<Map<String, String>, ActionStatus> resourceTypesMap = elementBusinessLogic.getResourceTypesMap();
447 if (otherEither.isRight() || otherEither.left().value() == null) {
448 log.debug("No other artifact types were found");
449 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
450 } else if (deploymentEither.isRight() || deploymentEither.left().value() == null) {
451 log.debug("No deployment artifact types were found");
452 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
453 } else if (defaultHeatTimeout.isRight() || defaultHeatTimeout.left().value() == null) {
454 log.debug("heat default timeout was not found");
455 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
456 } else if (resourceTypesMap.isRight() || resourceTypesMap.left().value() == null) {
457 log.debug("No resource types were found");
458 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
460 Map<String, Object> artifacts = new HashMap<>();
461 Map<String, Object> configuration = new HashMap<>();
463 artifacts.put("other", otherEither.left().value());
464 artifacts.put("deployment", deploymentEither.left().value());
465 configuration.put("artifacts", artifacts);
466 configuration.put("defaultHeatTimeout", defaultHeatTimeout.left().value());
467 configuration.put("componentTypes", elementBusinessLogic.getAllComponentTypesParamNames());
468 configuration.put("roles", elementBusinessLogic.getAllSupportedRoles());
469 configuration.put("resourceTypes", resourceTypesMap.left().value());
470 configuration.put("environmentContext", ConfigurationManager.getConfigurationManager().getConfiguration().getEnvironmentContext());
471 configuration.put("gab", ConfigurationManager.getConfigurationManager().getConfiguration().getGabConfig());
473 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), configuration);
476 } catch (Exception e) {
477 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Artifact Types");
478 log.debug("getArtifactTypes failed with exception", e);
479 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
483 /////////////////////////////////////////////////////////////////////////////////////////////////////
484 // retrieve all followed resources and services
487 @Consumes(MediaType.APPLICATION_JSON)
488 @Produces(MediaType.APPLICATION_JSON)
489 @ApiOperation(value = "Retrieve all followed", httpMethod = "GET", notes = "Retrieve all followed", response = User.class)
490 @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns followed Ok"), @ApiResponse(code = 404, message = "No followed were found"), @ApiResponse(code = 404, message = "User not found"),
491 @ApiResponse(code = 500, message = "Internal Server Error") })
492 public Response getFollowedResourcesServices(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
495 User userData = null;
497 String url = request.getMethod() + " " + request.getRequestURI();
498 log.debug("Start handle request of {}", url);
501 Either<User, ActionStatus> either = userBusinessLogic.getUser(userId, false);
502 if (either.isRight()) {
503 // Couldn't find or otherwise fetch the user
504 return buildErrorResponse(getComponentsUtils().getResponseFormatByUserId(either.right().value(), userId));
507 if (either.left().value() != null) {
508 userData = either.left().value();
509 Either<Map<String, List<? extends Component>>, ResponseFormat> followedResourcesServices =
510 elementBusinessLogic.getFollowed(userData);
511 if (followedResourcesServices.isRight()) {
512 log.debug("failed to get followed resources services ");
513 return buildErrorResponse(followedResourcesServices.right().value());
515 Object data = RepresentationUtils.toRepresentation(followedResourcesServices.left().value());
516 res = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), data);
518 res = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
520 } catch (Exception e) {
521 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Followed Resources / Services Categories");
522 log.debug("Getting followed resources/services failed with exception", e);
523 res = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
528 /////////////////////////////////////////////////////////////////////////////////////////////////////
529 // retrieve all certified resources and services and their last version
532 @Consumes(MediaType.APPLICATION_JSON)
533 @Produces(MediaType.APPLICATION_JSON)
534 @ApiOperation(value = "Retrieve catalog resources and services", httpMethod = "GET", notes = "Retrieve catalog resources and services", response = User.class)
535 @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns resources and services Ok"), @ApiResponse(code = 404, message = "No resources and services were found"), @ApiResponse(code = 404, message = "User not found"),
536 @ApiResponse(code = 500, message = "Internal Server Error") })
537 public Response getCatalogComponents(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @QueryParam("excludeTypes") List<OriginTypeEnum> excludeTypes) {
541 String url = request.getMethod() + " " + request.getRequestURI();
542 log.debug("Start handle request of {}", url);
544 Either<Map<String, List<CatalogComponent>>, ResponseFormat> catalogData = elementBusinessLogic
545 .getCatalogComponents(userId, excludeTypes);
547 if (catalogData.isRight()) {
548 log.debug("failed to get catalog data");
549 return buildErrorResponse(catalogData.right().value());
551 Object data = RepresentationUtils.toRepresentation(catalogData.left().value());
552 res = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), data);
554 } catch (Exception e) {
555 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Catalog Components");
556 log.debug("Getting catalog components failed with exception", e);
557 res = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
563 @Path("/inactiveComponents/{componentType}")
564 public Response deleteMarkedResources(@PathParam("componentType") final String componentType, @Context final HttpServletRequest request) {
565 String url = request.getMethod() + " " + request.getRequestURI();
566 log.debug("Start handle request of {}", url);
569 String userId = request.getHeader(Constants.USER_ID_HEADER);
570 User modifier = new User();
571 modifier.setUserId(userId);
572 log.debug("modifier id is {}", userId);
574 Response response = null;
576 NodeTypeEnum nodeType = NodeTypeEnum.getByNameIgnoreCase(componentType);
577 if (nodeType == null) {
578 log.info("componentType is not valid: {}", componentType);
579 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
582 List<NodeTypeEnum> componentsList = new ArrayList<>();
583 componentsList.add(nodeType);
585 Map<NodeTypeEnum, Either<List<String>, ResponseFormat>> cleanComponentsResult = componentsCleanBusinessLogic.cleanComponents(componentsList);
586 Either<List<String>, ResponseFormat> cleanResult = cleanComponentsResult.get(nodeType);
588 if (cleanResult.isRight()) {
589 log.debug("failed to delete marked components of type {}", nodeType);
590 response = buildErrorResponse(cleanResult.right().value());
593 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), cleanResult.left().value());
596 } catch (Exception e) {
597 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Marked Components");
598 log.debug("delete marked components failed with exception", e);
599 response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
606 @Path("/ecompPortalMenu")
607 @Consumes(MediaType.APPLICATION_JSON)
608 @Produces(MediaType.APPLICATION_JSON)
609 @ApiOperation(value = "Retrieve ecomp portal menu - MOC", httpMethod = "GET", notes = "Retrieve ecomp portal menu", response = User.class)
610 @ApiResponses(value = { @ApiResponse(code = 200, message = "Retrieve ecomp portal menu") })
611 public Response getListOfCsars(@Context final HttpServletRequest request) {
612 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
613 "[{\"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}]}]}]");