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 org.openecomp.sdc.be.components.impl.ElementBusinessLogic;
27 import org.openecomp.sdc.be.components.scheduledtasks.ComponentsCleanBusinessLogic;
28 import org.openecomp.sdc.be.config.BeEcompErrorManager;
29 import org.openecomp.sdc.be.config.ConfigurationManager;
30 import org.openecomp.sdc.be.dao.api.ActionStatus;
31 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
32 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
33 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
34 import org.openecomp.sdc.be.info.ArtifactTypesInfo;
35 import org.openecomp.sdc.be.model.*;
36 import org.openecomp.sdc.be.model.Tag;
37 import org.openecomp.sdc.be.model.catalog.CatalogComponent;
38 import org.openecomp.sdc.be.model.category.CategoryDefinition;
39 import org.openecomp.sdc.be.model.category.GroupingDefinition;
40 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
41 import org.openecomp.sdc.be.ui.model.UiCategories;
42 import org.openecomp.sdc.be.user.UserBusinessLogic;
43 import org.openecomp.sdc.common.api.Constants;
44 import org.openecomp.sdc.common.config.EcompErrorName;
45 import org.openecomp.sdc.exception.ResponseFormat;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
49 import javax.inject.Singleton;
50 import javax.servlet.ServletContext;
51 import javax.servlet.http.HttpServletRequest;
53 import javax.ws.rs.core.Context;
54 import javax.ws.rs.core.MediaType;
55 import javax.ws.rs.core.Response;
56 import java.util.ArrayList;
57 import java.util.HashMap;
58 import java.util.List;
65 * UI oriented servlet - to return elements in specific format UI needs
69 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
70 @Api(value = "Element Servlet", description = "Element Servlet")
72 public class ElementServlet extends BeGenericServlet {
74 private static final Logger log = LoggerFactory.getLogger(ElementServlet.class);
77 ******************************************************************************
78 * NEW CATEGORIES category / \ subcategory subcategory / grouping
79 ******************************************************************************/
86 /////////////////////////////////////////////////////////////////////////////////////////////////////
87 // retrieve all component categories
89 @Path("/categories/{componentType}")
90 @Consumes(MediaType.APPLICATION_JSON)
91 @Produces(MediaType.APPLICATION_JSON)
92 @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)
93 @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns categories Ok"), @ApiResponse(code = 403, message = "Missing information"), @ApiResponse(code = 400, message = "Invalid component type"),
94 @ApiResponse(code = 409, message = "Restricted operation"), @ApiResponse(code = 500, message = "Internal Server Error") })
95 public Response getComponentCategories(@ApiParam(value = "allowed values are resources / services/ products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
96 + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam(value = "componentType") final String componentType, @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
99 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
100 Either<List<CategoryDefinition>, ResponseFormat> either = elementBL.getAllCategories(componentType, userId);
101 if (either.isRight()) {
102 log.debug("No categories were found for type {}", componentType);
103 return buildErrorResponse(either.right().value());
105 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
107 } catch (Exception e) {
108 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Component Categories");
109 log.debug("getComponentCategories failed with exception", e);
110 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
116 @Consumes(MediaType.APPLICATION_JSON)
117 @Produces(MediaType.APPLICATION_JSON)
118 @ApiOperation(value = "Retrieve the all resource, service and product categories", httpMethod = "GET", notes = "Retrieve the all resource, service and product categories", response = Response.class)
119 @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns categories Ok"), @ApiResponse(code = 403, message = "Missing information"),
120 @ApiResponse(code = 409, message = "Restricted operation"), @ApiResponse(code = 500, message = "Internal Server Error") })
121 public Response getAllCategories(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
124 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
125 Either<UiCategories, ResponseFormat> either = elementBL.getAllCategories(userId);
126 if (either.isRight()) {
127 log.debug("No categories were found");
128 return buildErrorResponse(either.right().value());
130 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
132 } catch (Exception e) {
133 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get All Categories");
134 log.debug("getAllCategories failed with exception", e);
135 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
141 @Path("/category/{componentType}")
142 @Consumes(MediaType.APPLICATION_JSON)
143 @Produces(MediaType.APPLICATION_JSON)
144 @ApiOperation(value = "Create new component category", httpMethod = "POST", notes = "Create new component category")
145 @ApiResponses(value = { @ApiResponse(code = 201, message = "Category created"), @ApiResponse(code = 400, message = "Invalid category data"), @ApiResponse(code = 403, message = "USER_ID header is missing"),
146 @ApiResponse(code = 409, message = "Category already exists / User not permitted to perform the action"), @ApiResponse(code = 500, message = "General Error") })
147 public Response createComponentCategory(
148 @ApiParam(value = "allowed values are resources /services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
149 + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam(value = "componentType") final String componentType,
150 @ApiParam(value = "Category to be created", required = true) String data, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
152 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
153 CategoryDefinition category = RepresentationUtils.fromRepresentation(data, CategoryDefinition.class);
155 Either<CategoryDefinition, ResponseFormat> createResourceCategory = elementBL.createCategory(category, componentType, userId);
156 if (createResourceCategory.isRight()) {
157 return buildErrorResponse(createResourceCategory.right().value());
160 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
161 return buildOkResponse(responseFormat, createResourceCategory.left().value());
163 } catch (Exception e) {
164 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create resource category");
165 log.debug("createResourceCategory failed with exception", e);
166 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
172 @Path("/category/{componentType}/{categoryUniqueId}")
173 @Consumes(MediaType.APPLICATION_JSON)
174 @Produces(MediaType.APPLICATION_JSON)
175 @ApiOperation(value = "Delete component category", httpMethod = "DELETE", notes = "Delete component category", response = Category.class)
176 @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"),
177 @ApiResponse(code = 404, message = "Category not found"), @ApiResponse(code = 500, message = "General Error") })
178 public Response deleteComponentCategory(@PathParam(value = "categoryUniqueId") final String categoryUniqueId, @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
179 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
182 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
183 Either<CategoryDefinition, ResponseFormat> createResourceCategory = elementBL.deleteCategory(categoryUniqueId, componentType, userId);
185 if (createResourceCategory.isRight()) {
186 return buildErrorResponse(createResourceCategory.right().value());
188 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
189 return buildOkResponse(responseFormat, null);
191 } catch (Exception e) {
192 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create resource category");
193 log.debug("createResourceCategory failed with exception", e);
194 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
207 @Path("/category/{componentType}/{categoryId}/subCategory")
208 @Consumes(MediaType.APPLICATION_JSON)
209 @Produces(MediaType.APPLICATION_JSON)
210 @ApiOperation(value = "Create new component sub-category", httpMethod = "POST", notes = "Create new component sub-category for existing category")
211 @ApiResponses(value = { @ApiResponse(code = 201, message = "Subcategory created"), @ApiResponse(code = 400, message = "Invalid subcategory data"), @ApiResponse(code = 403, message = "USER_ID header is missing"),
212 @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") })
213 public Response createComponentSubCategory(
214 @ApiParam(value = "allowed values are resources / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + ","
215 + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam(value = "componentType") final String componentType,
216 @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,
217 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
220 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
221 SubCategoryDefinition subCategory = RepresentationUtils.fromRepresentation(data, SubCategoryDefinition.class);
223 Either<SubCategoryDefinition, ResponseFormat> createSubcategory = elementBL.createSubCategory(subCategory, componentType, categoryId, userId);
224 if (createSubcategory.isRight()) {
225 return buildErrorResponse(createSubcategory.right().value());
227 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
228 return buildOkResponse(responseFormat, createSubcategory.left().value());
230 } catch (Exception e) {
231 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create sub-category");
232 log.debug("createComponentSubCategory failed with exception", e);
233 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
239 @Path("/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}")
240 @Consumes(MediaType.APPLICATION_JSON)
241 @Produces(MediaType.APPLICATION_JSON)
242 @ApiOperation(value = "Delete component category", httpMethod = "DELETE", notes = "Delete component category", response = Category.class)
243 @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"),
244 @ApiResponse(code = 404, message = "Category not found"), @ApiResponse(code = 500, message = "General Error") })
245 public Response deleteComponentSubCategory(@PathParam(value = "categoryUniqueId") final String categoryUniqueId, @PathParam(value = "subCategoryUniqueId") final String subCategoryUniqueId,
246 @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
249 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
250 Either<SubCategoryDefinition, ResponseFormat> deleteSubResourceCategory = elementBL.deleteSubCategory(categoryUniqueId, subCategoryUniqueId, componentType, userId);
251 if (deleteSubResourceCategory.isRight()) {
252 return buildErrorResponse(deleteSubResourceCategory.right().value());
254 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
255 return buildOkResponse(responseFormat, null);
257 } catch (Exception e) {
258 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete component category");
259 log.debug("deleteComponentSubCategory failed with exception", e);
260 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
269 @Path("/category/{componentType}/{categoryId}/subCategory/{subCategoryId}/grouping")
270 @Consumes(MediaType.APPLICATION_JSON)
271 @Produces(MediaType.APPLICATION_JSON)
272 @ApiOperation(value = "Create new component grouping", httpMethod = "POST", notes = "Create new component grouping for existing sub-category")
273 @ApiResponses(value = { @ApiResponse(code = 201, message = "Grouping created"), @ApiResponse(code = 400, message = "Invalid grouping data"), @ApiResponse(code = 403, message = "USER_ID header is missing"),
274 @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"),
275 @ApiResponse(code = 500, message = "General Error") })
276 public Response createComponentGrouping(@ApiParam(value = "allowed values are products", allowableValues = ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam(value = "componentType") final String componentType,
277 @ApiParam(value = "Parent category unique ID", required = true) @PathParam(value = "categoryId") final String grandParentCategoryId,
278 @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,
279 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
281 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
282 GroupingDefinition grouping = RepresentationUtils.fromRepresentation(data, GroupingDefinition.class);
284 Either<GroupingDefinition, ResponseFormat> createGrouping = elementBL.createGrouping(grouping, componentType, grandParentCategoryId, parentSubCategoryId, userId);
285 if (createGrouping.isRight()) {
286 return buildErrorResponse(createGrouping.right().value());
288 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
289 return buildOkResponse(responseFormat, createGrouping.left().value());
291 } catch (Exception e) {
292 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create grouping");
293 log.debug("createComponentGrouping failed with exception", e);
294 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
300 @Path("/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}/grouping/{groupingUniqueId}")
301 @Consumes(MediaType.APPLICATION_JSON)
302 @Produces(MediaType.APPLICATION_JSON)
303 @ApiOperation(value = "Delete component category", httpMethod = "DELETE", notes = "Delete component category", response = Category.class)
304 @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"),
305 @ApiResponse(code = 404, message = "Category not found"), @ApiResponse(code = 500, message = "General Error") })
306 public Response deleteComponentGrouping(@PathParam(value = "categoryUniqueId") final String grandParentCategoryUniqueId, @PathParam(value = "subCategoryUniqueId") final String parentSubCategoryUniqueId,
307 @PathParam(value = "groupingUniqueId") final String groupingUniqueId, @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
308 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
311 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
312 Either<GroupingDefinition, ResponseFormat> deleteGrouping = elementBL.deleteGrouping(grandParentCategoryUniqueId, parentSubCategoryUniqueId, groupingUniqueId, componentType, userId);
313 if (deleteGrouping.isRight()) {
314 return buildErrorResponse(deleteGrouping.right().value());
316 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
317 return buildOkResponse(responseFormat, null);
319 } catch (Exception e) {
320 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete component grouping");
321 log.debug("deleteGrouping failed with exception", e);
322 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
327 /////////////////////////////////////////////////////////////////////////////////////////////////////
331 @Consumes(MediaType.APPLICATION_JSON)
332 @Produces(MediaType.APPLICATION_JSON)
333 @ApiOperation(value = "Retrieve all tags", httpMethod = "GET", notes = "Retrieve all tags", response = User.class)
334 @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns tags Ok"), @ApiResponse(code = 404, message = "No tags were found"), @ApiResponse(code = 500, message = "Internal Server Error") })
335 public Response getTags(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
336 String url = request.getMethod() + " " + request.getRequestURI();
337 log.debug("(getTags) Start handle request of {}", url);
340 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
341 Either<List<Tag>, ActionStatus> either = elementBL.getAllTags(userId);
342 if (either.isRight() || either.left().value() == null) {
343 log.debug("No tags were found");
344 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
346 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
348 } catch (Exception e) {
349 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get All Tags");
350 log.debug("getAllTags failed with exception", e);
351 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
355 /////////////////////////////////////////////////////////////////////////////////////////////////////
356 // retrieve all property scopes
358 @Path("/propertyScopes")
359 @Consumes(MediaType.APPLICATION_JSON)
360 @Produces(MediaType.APPLICATION_JSON)
361 @ApiOperation(value = "Retrieve all propertyScopes", httpMethod = "GET", notes = "Retrieve all propertyScopes", response = User.class)
362 @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns propertyScopes Ok"), @ApiResponse(code = 404, message = "No propertyScopes were found"), @ApiResponse(code = 500, message = "Internal Server Error") })
363 public Response getPropertyScopes(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
364 String url = request.getMethod() + " " + request.getRequestURI();
365 log.debug("(getPropertyScopes) Start handle request of {}", url);
368 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
369 Either<List<PropertyScope>, ActionStatus> either = elementBL.getAllPropertyScopes(userId);
370 if (either.isRight() || either.left().value() == null) {
371 log.debug("No property scopes were found");
372 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
374 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
376 } catch (Exception e) {
377 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Property Scopes Categories");
378 log.debug("getPropertyScopes failed with exception", e);
379 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
383 /////////////////////////////////////////////////////////////////////////////////////////////////////
384 // retrieve all artifact types
386 @Path("/artifactTypes")
387 @Consumes(MediaType.APPLICATION_JSON)
388 @Produces(MediaType.APPLICATION_JSON)
389 @ApiOperation(value = "Retrieve all artifactTypes", httpMethod = "GET", notes = "Retrieve all artifactTypes", response = User.class)
390 @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns artifactTypes Ok"), @ApiResponse(code = 404, message = "No artifactTypes were found"), @ApiResponse(code = 500, message = "Internal Server Error") })
391 public Response getArtifactTypes(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
392 String url = request.getMethod() + " " + request.getRequestURI();
393 log.debug("(GET - getArtifactTypes) Start handle request of {}", url);
396 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
397 Either<List<ArtifactType>, ActionStatus> either = elementBL.getAllArtifactTypes(userId);
398 if (either.isRight() || either.left().value() == null) {
399 log.debug("No artifact types were found");
400 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
403 Integer defaultHeatTimeout = ConfigurationManager.getConfigurationManager().getConfiguration().getDefaultHeatArtifactTimeoutMinutes();
404 ArtifactTypesInfo typesResponse = new ArtifactTypesInfo();
405 typesResponse.setArtifactTypes(either.left().value());
406 typesResponse.setHeatDefaultTimeout(defaultHeatTimeout);
408 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), typesResponse);
410 } catch (Exception e) {
411 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Artifact Types");
412 log.debug("getArtifactTypes failed with exception", e);
413 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
417 /////////////////////////////////////////////////////////////////////////////////////////////////////
418 // retrieve all artifact types
420 @Path("/configuration/ui")
421 @Consumes(MediaType.APPLICATION_JSON)
422 @Produces(MediaType.APPLICATION_JSON)
423 @ApiOperation(value = "Retrieve all artifactTypes", httpMethod = "GET", notes = "Retrieve all artifactTypes", response = User.class)
424 @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns artifactTypes Ok"), @ApiResponse(code = 404, message = "No artifactTypes were found"), @ApiResponse(code = 500, message = "Internal Server Error") })
425 public Response getConfiguration(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
426 String url = request.getMethod() + " " + request.getRequestURI();
427 log.debug("(getConfiguration) Start handle request of {}", url);
430 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
431 Either<List<ArtifactType>, ActionStatus> otherEither = elementBL.getAllArtifactTypes(userId);
432 Either<Integer, ActionStatus> defaultHeatTimeout = elementBL.getDefaultHeatTimeout();
433 Either<Map<String, Object>, ActionStatus> deploymentEither = elementBL.getAllDeploymentArtifactTypes();
434 Either<Map<String, String>, ActionStatus> resourceTypesMap = elementBL.getResourceTypesMap();
436 if (otherEither.isRight() || otherEither.left().value() == null) {
437 log.debug("No other artifact types were found");
438 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
439 } else if (deploymentEither.isRight() || deploymentEither.left().value() == null) {
440 log.debug("No deployment artifact types were found");
441 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
442 } else if (defaultHeatTimeout.isRight() || defaultHeatTimeout.left().value() == null) {
443 log.debug("heat default timeout was not found");
444 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
445 } else if (resourceTypesMap.isRight() || resourceTypesMap.left().value() == null) {
446 log.debug("No resource types were found");
447 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
449 Map<String, Object> artifacts = new HashMap<String, Object>();
450 Map<String, Object> configuration = new HashMap<String, Object>();
452 artifacts.put("other", otherEither.left().value());
453 artifacts.put("deployment", deploymentEither.left().value());
454 configuration.put("artifacts", artifacts);
455 configuration.put("defaultHeatTimeout", defaultHeatTimeout.left().value());
456 configuration.put("componentTypes", elementBL.getAllComponentTypesParamNames());
457 configuration.put("roles", elementBL.getAllSupportedRoles());
458 configuration.put("resourceTypes", resourceTypesMap.left().value());
459 configuration.put("environmentContext", ConfigurationManager.getConfigurationManager().getConfiguration().getEnvironmentContext());
460 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), configuration);
463 } catch (Exception e) {
464 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Artifact Types");
465 log.debug("getArtifactTypes failed with exception", e);
466 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
470 /////////////////////////////////////////////////////////////////////////////////////////////////////
471 // retrieve all followed resources and services
474 @Consumes(MediaType.APPLICATION_JSON)
475 @Produces(MediaType.APPLICATION_JSON)
476 @ApiOperation(value = "Retrieve all followed", httpMethod = "GET", notes = "Retrieve all followed", response = User.class)
477 @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns followed Ok"), @ApiResponse(code = 404, message = "No followed were found"), @ApiResponse(code = 404, message = "User not found"),
478 @ApiResponse(code = 500, message = "Internal Server Error") })
479 public Response getFollowedResourcesServices(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
482 User userData = null;
484 String url = request.getMethod() + " " + request.getRequestURI();
485 log.debug("Start handle request of {}", url);
486 UserBusinessLogic userAdminManager = getUserAdminManager(request.getSession().getServletContext());
489 Either<User, ActionStatus> either = userAdminManager.getUser(userId, false);
490 if (either.isRight()) {
491 // Couldn't find or otherwise fetch the user
492 return buildErrorResponse(getComponentsUtils().getResponseFormatByUserId(either.right().value(), userId));
495 if (either.left().value() != null) {
496 userData = either.left().value();
497 Either<Map<String, List<? extends Component>>, ResponseFormat> followedResourcesServices = getElementBL(request.getSession().getServletContext()).getFollowed(userData);
498 if (followedResourcesServices.isRight()) {
499 log.debug("failed to get followed resources services ");
500 return buildErrorResponse(followedResourcesServices.right().value());
502 Object data = RepresentationUtils.toRepresentation(followedResourcesServices.left().value());
503 res = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), data);
505 res = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
507 } catch (Exception e) {
508 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Followed Resources / Services Categories");
509 log.debug("Getting followed resources/services failed with exception", e);
510 res = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
515 /////////////////////////////////////////////////////////////////////////////////////////////////////
516 // retrieve all certified resources and services and their last version
519 @Consumes(MediaType.APPLICATION_JSON)
520 @Produces(MediaType.APPLICATION_JSON)
521 @ApiOperation(value = "Retrieve catalog resources and services", httpMethod = "GET", notes = "Retrieve catalog resources and services", response = User.class)
522 @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"),
523 @ApiResponse(code = 500, message = "Internal Server Error") })
524 public Response getCatalogComponents(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @QueryParam("excludeTypes") List<OriginTypeEnum> excludeTypes) {
528 String url = request.getMethod() + " " + request.getRequestURI();
529 log.debug("Start handle request of {}", url);
531 Either<Map<String, List<CatalogComponent>>, ResponseFormat> catalogData = getElementBL(request.getSession().getServletContext()).getCatalogComponents(userId);
533 if (catalogData.isRight()) {
534 log.debug("failed to get catalog data");
535 return buildErrorResponse(catalogData.right().value());
537 Object data = RepresentationUtils.toRepresentation(catalogData.left().value());
538 res = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), data);
540 } catch (Exception e) {
541 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Catalog Components");
542 log.debug("Getting catalog components failed with exception", e);
543 res = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
549 @Path("/inactiveComponents/{componentType}")
550 public Response deleteMarkedResources(@PathParam("componentType") final String componentType, @Context final HttpServletRequest request) {
552 ServletContext context = request.getSession().getServletContext();
554 String url = request.getMethod() + " " + request.getRequestURI();
555 log.debug("Start handle request of {}", url);
558 String userId = request.getHeader(Constants.USER_ID_HEADER);
559 User modifier = new User();
560 modifier.setUserId(userId);
561 log.debug("modifier id is {}", userId);
563 Response response = null;
565 NodeTypeEnum nodeType = NodeTypeEnum.getByNameIgnoreCase(componentType);
566 if (nodeType == null) {
567 log.info("componentType is not valid: {]", componentType);
568 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
571 List<NodeTypeEnum> componentsList = new ArrayList<NodeTypeEnum>();
572 componentsList.add(nodeType);
574 ComponentsCleanBusinessLogic businessLogic = getComponentCleanerBL(context);
575 Map<NodeTypeEnum, Either<List<String>, ResponseFormat>> cleanComponentsResult = businessLogic.cleanComponents(componentsList);
576 Either<List<String>, ResponseFormat> cleanResult = cleanComponentsResult.get(nodeType);
578 if (cleanResult.isRight()) {
579 log.debug("failed to delete marked components of type {}", nodeType);
580 response = buildErrorResponse(cleanResult.right().value());
583 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), cleanResult.left().value());
586 } catch (Exception e) {
587 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Marked Components");
588 log.debug("delete marked components failed with exception", e);
589 response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
596 @Path("/ecompPortalMenu")
597 @Consumes(MediaType.APPLICATION_JSON)
598 @Produces(MediaType.APPLICATION_JSON)
599 @ApiOperation(value = "Retrieve ecomp portal menu - MOC", httpMethod = "GET", notes = "Retrieve ecomp portal menu", response = User.class)
600 @ApiResponses(value = { @ApiResponse(code = 200, message = "Retrieve ecomp portal menu") })
601 public Response getListOfCsars(@Context final HttpServletRequest request) {
602 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
603 "[{\"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}]}]}]");