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.log.wrappers.Logger;
45 import org.openecomp.sdc.exception.ResponseFormat;
47 import javax.inject.Singleton;
48 import javax.servlet.ServletContext;
49 import javax.servlet.http.HttpServletRequest;
51 import javax.ws.rs.core.Context;
52 import javax.ws.rs.core.MediaType;
53 import javax.ws.rs.core.Response;
54 import java.util.ArrayList;
55 import java.util.HashMap;
56 import java.util.List;
63 * UI oriented servlet - to return elements in specific format UI needs
67 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
68 @Api(value = "Element Servlet", description = "Element Servlet")
70 public class ElementServlet extends BeGenericServlet {
72 private static final Logger log = Logger.getLogger(ElementServlet.class);
75 ******************************************************************************
76 * NEW CATEGORIES category / \ subcategory subcategory / grouping
77 ******************************************************************************/
84 /////////////////////////////////////////////////////////////////////////////////////////////////////
85 // retrieve all component categories
87 @Path("/categories/{componentType}")
88 @Consumes(MediaType.APPLICATION_JSON)
89 @Produces(MediaType.APPLICATION_JSON)
90 @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)
91 @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns categories Ok"), @ApiResponse(code = 403, message = "Missing information"), @ApiResponse(code = 400, message = "Invalid component type"),
92 @ApiResponse(code = 409, message = "Restricted operation"), @ApiResponse(code = 500, message = "Internal Server Error") })
93 public Response getComponentCategories(@ApiParam(value = "allowed values are resources / services/ products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
94 + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam(value = "componentType") final String componentType, @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
97 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
98 Either<List<CategoryDefinition>, ResponseFormat> either = elementBL .getAllCategories(componentType, userId);
99 if (either.isRight()) {
100 log.debug("No categories were found for type {}", componentType);
101 return buildErrorResponse(either.right().value());
103 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
105 } catch (Exception e) {
106 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Component Categories");
107 log.debug("getComponentCategories failed with exception", e);
108 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
114 @Consumes(MediaType.APPLICATION_JSON)
115 @Produces(MediaType.APPLICATION_JSON)
116 @ApiOperation(value = "Retrieve the all resource, service and product categories", httpMethod = "GET", notes = "Retrieve the all resource, service and product categories", response = Response.class)
117 @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns categories Ok"), @ApiResponse(code = 403, message = "Missing information"),
118 @ApiResponse(code = 409, message = "Restricted operation"), @ApiResponse(code = 500, message = "Internal Server Error") })
119 public Response getAllCategories(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
122 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
123 Either<UiCategories, ResponseFormat> either = elementBL.getAllCategories(userId);
124 if (either.isRight()) {
125 log.debug("No categories were found");
126 return buildErrorResponse(either.right().value());
128 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
130 } catch (Exception e) {
131 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get All Categories");
132 log.debug("getAllCategories failed with exception", e);
133 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
139 @Path("/category/{componentType}")
140 @Consumes(MediaType.APPLICATION_JSON)
141 @Produces(MediaType.APPLICATION_JSON)
142 @ApiOperation(value = "Create new component category", httpMethod = "POST", notes = "Create new component category")
143 @ApiResponses(value = { @ApiResponse(code = 201, message = "Category created"), @ApiResponse(code = 400, message = "Invalid category data"), @ApiResponse(code = 403, message = "USER_ID header is missing"),
144 @ApiResponse(code = 409, message = "Category already exists / User not permitted to perform the action"), @ApiResponse(code = 500, message = "General Error") })
145 public Response createComponentCategory(
146 @ApiParam(value = "allowed values are resources /services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
147 + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam(value = "componentType") final String componentType,
148 @ApiParam(value = "Category to be created", required = true) String data, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
150 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
151 CategoryDefinition category = RepresentationUtils.fromRepresentation(data, CategoryDefinition.class);
153 Either<CategoryDefinition, ResponseFormat> createResourceCategory = elementBL.createCategory(category, componentType, userId);
154 if (createResourceCategory.isRight()) {
155 return buildErrorResponse(createResourceCategory.right().value());
158 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
159 return buildOkResponse(responseFormat, createResourceCategory.left().value());
161 } catch (Exception e) {
162 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create resource category");
163 log.debug("createResourceCategory failed with exception", e);
164 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
170 @Path("/category/{componentType}/{categoryUniqueId}")
171 @Consumes(MediaType.APPLICATION_JSON)
172 @Produces(MediaType.APPLICATION_JSON)
173 @ApiOperation(value = "Delete component category", httpMethod = "DELETE", notes = "Delete component category", response = Category.class)
174 @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"),
175 @ApiResponse(code = 404, message = "Category not found"), @ApiResponse(code = 500, message = "General Error") })
176 public Response deleteComponentCategory(@PathParam(value = "categoryUniqueId") final String categoryUniqueId, @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
177 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
180 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
181 Either<CategoryDefinition, ResponseFormat> createResourceCategory = elementBL.deleteCategory(categoryUniqueId, componentType, userId);
183 if (createResourceCategory.isRight()) {
184 return buildErrorResponse(createResourceCategory.right().value());
186 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
187 return buildOkResponse(responseFormat, null);
189 } catch (Exception e) {
190 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create resource category");
191 log.debug("createResourceCategory failed with exception", e);
192 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
205 @Path("/category/{componentType}/{categoryId}/subCategory")
206 @Consumes(MediaType.APPLICATION_JSON)
207 @Produces(MediaType.APPLICATION_JSON)
208 @ApiOperation(value = "Create new component sub-category", httpMethod = "POST", notes = "Create new component sub-category for existing category")
209 @ApiResponses(value = { @ApiResponse(code = 201, message = "Subcategory created"), @ApiResponse(code = 400, message = "Invalid subcategory data"), @ApiResponse(code = 403, message = "USER_ID header is missing"),
210 @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") })
211 public Response createComponentSubCategory(
212 @ApiParam(value = "allowed values are resources / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + ","
213 + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam(value = "componentType") final String componentType,
214 @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,
215 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
218 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
219 SubCategoryDefinition subCategory = RepresentationUtils.fromRepresentation(data, SubCategoryDefinition.class);
221 Either<SubCategoryDefinition, ResponseFormat> createSubcategory = elementBL.createSubCategory(subCategory, componentType, categoryId, userId);
222 if (createSubcategory.isRight()) {
223 return buildErrorResponse(createSubcategory.right().value());
225 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
226 return buildOkResponse(responseFormat, createSubcategory.left().value());
228 } catch (Exception e) {
229 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create sub-category");
230 log.debug("createComponentSubCategory failed with exception", e);
231 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
237 @Path("/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}")
238 @Consumes(MediaType.APPLICATION_JSON)
239 @Produces(MediaType.APPLICATION_JSON)
240 @ApiOperation(value = "Delete component category", httpMethod = "DELETE", notes = "Delete component category", response = Category.class)
241 @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"),
242 @ApiResponse(code = 404, message = "Category not found"), @ApiResponse(code = 500, message = "General Error") })
243 public Response deleteComponentSubCategory(@PathParam(value = "categoryUniqueId") final String categoryUniqueId, @PathParam(value = "subCategoryUniqueId") final String subCategoryUniqueId,
244 @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
247 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
248 Either<SubCategoryDefinition, ResponseFormat> deleteSubResourceCategory = elementBL.deleteSubCategory(subCategoryUniqueId, componentType, userId);
249 if (deleteSubResourceCategory.isRight()) {
250 return buildErrorResponse(deleteSubResourceCategory.right().value());
252 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
253 return buildOkResponse(responseFormat, null);
255 } catch (Exception e) {
256 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete component category");
257 log.debug("deleteComponentSubCategory failed with exception", e);
258 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
267 @Path("/category/{componentType}/{categoryId}/subCategory/{subCategoryId}/grouping")
268 @Consumes(MediaType.APPLICATION_JSON)
269 @Produces(MediaType.APPLICATION_JSON)
270 @ApiOperation(value = "Create new component grouping", httpMethod = "POST", notes = "Create new component grouping for existing sub-category")
271 @ApiResponses(value = { @ApiResponse(code = 201, message = "Grouping created"), @ApiResponse(code = 400, message = "Invalid grouping data"), @ApiResponse(code = 403, message = "USER_ID header is missing"),
272 @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"),
273 @ApiResponse(code = 500, message = "General Error") })
274 public Response createComponentGrouping(@ApiParam(value = "allowed values are products", allowableValues = ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam(value = "componentType") final String componentType,
275 @ApiParam(value = "Parent category unique ID", required = true) @PathParam(value = "categoryId") final String grandParentCategoryId,
276 @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,
277 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
279 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
280 GroupingDefinition grouping = RepresentationUtils.fromRepresentation(data, GroupingDefinition.class);
282 Either<GroupingDefinition, ResponseFormat> createGrouping = elementBL.createGrouping(grouping, componentType, grandParentCategoryId, parentSubCategoryId, userId);
283 if (createGrouping.isRight()) {
284 return buildErrorResponse(createGrouping.right().value());
286 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
287 return buildOkResponse(responseFormat, createGrouping.left().value());
289 } catch (Exception e) {
290 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create grouping");
291 log.debug("createComponentGrouping failed with exception", e);
292 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
298 @Path("/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}/grouping/{groupingUniqueId}")
299 @Consumes(MediaType.APPLICATION_JSON)
300 @Produces(MediaType.APPLICATION_JSON)
301 @ApiOperation(value = "Delete component category", httpMethod = "DELETE", notes = "Delete component category", response = Category.class)
302 @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"),
303 @ApiResponse(code = 404, message = "Category not found"), @ApiResponse(code = 500, message = "General Error") })
304 public Response deleteComponentGrouping(@PathParam(value = "categoryUniqueId") final String grandParentCategoryUniqueId, @PathParam(value = "subCategoryUniqueId") final String parentSubCategoryUniqueId,
305 @PathParam(value = "groupingUniqueId") final String groupingUniqueId, @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
306 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
309 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
310 Either<GroupingDefinition, ResponseFormat> deleteGrouping = elementBL.deleteGrouping(groupingUniqueId, componentType, userId);
311 if (deleteGrouping.isRight()) {
312 return buildErrorResponse(deleteGrouping.right().value());
314 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
315 return buildOkResponse(responseFormat, null);
317 } catch (Exception e) {
318 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete component grouping");
319 log.debug("deleteGrouping failed with exception", e);
320 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
325 /////////////////////////////////////////////////////////////////////////////////////////////////////
329 @Consumes(MediaType.APPLICATION_JSON)
330 @Produces(MediaType.APPLICATION_JSON)
331 @ApiOperation(value = "Retrieve all tags", httpMethod = "GET", notes = "Retrieve all tags", response = User.class)
332 @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns tags Ok"), @ApiResponse(code = 404, message = "No tags were found"), @ApiResponse(code = 500, message = "Internal Server Error") })
333 public Response getTags(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
334 String url = request.getMethod() + " " + request.getRequestURI();
335 log.debug("(getTags) Start handle request of {}", url);
338 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
339 Either<List<Tag>, ActionStatus> either = elementBL.getAllTags(userId);
340 if (either.isRight() || either.left().value() == null) {
341 log.debug("No tags were found");
342 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
344 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
346 } catch (Exception e) {
347 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get All Tags");
348 log.debug("getAllTags failed with exception", e);
349 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
353 /////////////////////////////////////////////////////////////////////////////////////////////////////
354 // retrieve all property scopes
356 @Path("/propertyScopes")
357 @Consumes(MediaType.APPLICATION_JSON)
358 @Produces(MediaType.APPLICATION_JSON)
359 @ApiOperation(value = "Retrieve all propertyScopes", httpMethod = "GET", notes = "Retrieve all propertyScopes", response = User.class)
360 @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns propertyScopes Ok"), @ApiResponse(code = 404, message = "No propertyScopes were found"), @ApiResponse(code = 500, message = "Internal Server Error") })
361 public Response getPropertyScopes(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
362 String url = request.getMethod() + " " + request.getRequestURI();
363 log.debug("(getPropertyScopes) Start handle request of {}", url);
366 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
367 Either<List<PropertyScope>, ActionStatus> either = elementBL.getAllPropertyScopes(userId);
368 if (either.isRight() || either.left().value() == null) {
369 log.debug("No property scopes were found");
370 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
372 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
374 } catch (Exception e) {
375 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Property Scopes Categories");
376 log.debug("getPropertyScopes failed with exception", e);
377 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
381 /////////////////////////////////////////////////////////////////////////////////////////////////////
382 // retrieve all artifact types
384 @Path("/artifactTypes")
385 @Consumes(MediaType.APPLICATION_JSON)
386 @Produces(MediaType.APPLICATION_JSON)
387 @ApiOperation(value = "Retrieve all artifactTypes", httpMethod = "GET", notes = "Retrieve all artifactTypes", response = User.class)
388 @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns artifactTypes Ok"), @ApiResponse(code = 404, message = "No artifactTypes were found"), @ApiResponse(code = 500, message = "Internal Server Error") })
389 public Response getArtifactTypes(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
390 String url = request.getMethod() + " " + request.getRequestURI();
391 log.debug("(GET - getArtifactTypes) Start handle request of {}", url);
394 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
395 Either<List<ArtifactType>, ActionStatus> either = elementBL.getAllArtifactTypes(userId);
396 if (either.isRight() || either.left().value() == null) {
397 log.debug("No artifact types were found");
398 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
401 Integer defaultHeatTimeout = ConfigurationManager.getConfigurationManager().getConfiguration().getDefaultHeatArtifactTimeoutMinutes();
402 ArtifactTypesInfo typesResponse = new ArtifactTypesInfo();
403 typesResponse.setArtifactTypes(either.left().value());
404 typesResponse.setHeatDefaultTimeout(defaultHeatTimeout);
406 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), typesResponse);
408 } catch (Exception e) {
409 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Artifact Types");
410 log.debug("getArtifactTypes failed with exception", e);
411 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
415 /////////////////////////////////////////////////////////////////////////////////////////////////////
416 // retrieve all artifact types
418 @Path("/configuration/ui")
419 @Consumes(MediaType.APPLICATION_JSON)
420 @Produces(MediaType.APPLICATION_JSON)
421 @ApiOperation(value = "Retrieve all artifactTypes", httpMethod = "GET", notes = "Retrieve all artifactTypes", response = User.class)
422 @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns artifactTypes Ok"), @ApiResponse(code = 404, message = "No artifactTypes were found"), @ApiResponse(code = 500, message = "Internal Server Error") })
423 public Response getConfiguration(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
424 String url = request.getMethod() + " " + request.getRequestURI();
425 log.debug("(getConfiguration) Start handle request of {}", url);
428 ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
429 Either<List<ArtifactType>, ActionStatus> otherEither = elementBL.getAllArtifactTypes(userId);
430 Either<Integer, ActionStatus> defaultHeatTimeout = elementBL.getDefaultHeatTimeout();
431 Either<Map<String, Object>, ActionStatus> deploymentEither = elementBL.getAllDeploymentArtifactTypes();
432 Either<Map<String, String>, ActionStatus> resourceTypesMap = elementBL.getResourceTypesMap();
434 if (otherEither.isRight() || otherEither.left().value() == null) {
435 log.debug("No other artifact types were found");
436 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
437 } else if (deploymentEither.isRight() || deploymentEither.left().value() == null) {
438 log.debug("No deployment artifact types were found");
439 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
440 } else if (defaultHeatTimeout.isRight() || defaultHeatTimeout.left().value() == null) {
441 log.debug("heat default timeout was not found");
442 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
443 } else if (resourceTypesMap.isRight() || resourceTypesMap.left().value() == null) {
444 log.debug("No resource types were found");
445 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
447 Map<String, Object> artifacts = new HashMap<>();
448 Map<String, Object> configuration = new HashMap<>();
450 artifacts.put("other", otherEither.left().value());
451 artifacts.put("deployment", deploymentEither.left().value());
452 configuration.put("artifacts", artifacts);
453 configuration.put("defaultHeatTimeout", defaultHeatTimeout.left().value());
454 configuration.put("componentTypes", elementBL.getAllComponentTypesParamNames());
455 configuration.put("roles", elementBL.getAllSupportedRoles());
456 configuration.put("resourceTypes", resourceTypesMap.left().value());
457 configuration.put("environmentContext", ConfigurationManager.getConfigurationManager().getConfiguration().getEnvironmentContext());
458 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), configuration);
461 } catch (Exception e) {
462 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Artifact Types");
463 log.debug("getArtifactTypes failed with exception", e);
464 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
468 /////////////////////////////////////////////////////////////////////////////////////////////////////
469 // retrieve all followed resources and services
472 @Consumes(MediaType.APPLICATION_JSON)
473 @Produces(MediaType.APPLICATION_JSON)
474 @ApiOperation(value = "Retrieve all followed", httpMethod = "GET", notes = "Retrieve all followed", response = User.class)
475 @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns followed Ok"), @ApiResponse(code = 404, message = "No followed were found"), @ApiResponse(code = 404, message = "User not found"),
476 @ApiResponse(code = 500, message = "Internal Server Error") })
477 public Response getFollowedResourcesServices(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
480 User userData = null;
482 String url = request.getMethod() + " " + request.getRequestURI();
483 log.debug("Start handle request of {}", url);
484 UserBusinessLogic userAdminManager = getUserAdminManager(request.getSession().getServletContext());
487 Either<User, ActionStatus> either = userAdminManager.getUser(userId, false);
488 if (either.isRight()) {
489 // Couldn't find or otherwise fetch the user
490 return buildErrorResponse(getComponentsUtils().getResponseFormatByUserId(either.right().value(), userId));
493 if (either.left().value() != null) {
494 userData = either.left().value();
495 Either<Map<String, List<? extends Component>>, ResponseFormat> followedResourcesServices = getElementBL(request.getSession().getServletContext()).getFollowed(userData);
496 if (followedResourcesServices.isRight()) {
497 log.debug("failed to get followed resources services ");
498 return buildErrorResponse(followedResourcesServices.right().value());
500 Object data = RepresentationUtils.toRepresentation(followedResourcesServices.left().value());
501 res = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), data);
503 res = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
505 } catch (Exception e) {
506 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Followed Resources / Services Categories");
507 log.debug("Getting followed resources/services failed with exception", e);
508 res = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
513 /////////////////////////////////////////////////////////////////////////////////////////////////////
514 // retrieve all certified resources and services and their last version
517 @Consumes(MediaType.APPLICATION_JSON)
518 @Produces(MediaType.APPLICATION_JSON)
519 @ApiOperation(value = "Retrieve catalog resources and services", httpMethod = "GET", notes = "Retrieve catalog resources and services", response = User.class)
520 @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"),
521 @ApiResponse(code = 500, message = "Internal Server Error") })
522 public Response getCatalogComponents(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @QueryParam("excludeTypes") List<OriginTypeEnum> excludeTypes) {
526 String url = request.getMethod() + " " + request.getRequestURI();
527 log.debug("Start handle request of {}", url);
529 Either<Map<String, List<CatalogComponent>>, ResponseFormat> catalogData = getElementBL(request.getSession().getServletContext()).getCatalogComponents(userId, excludeTypes);
531 if (catalogData.isRight()) {
532 log.debug("failed to get catalog data");
533 return buildErrorResponse(catalogData.right().value());
535 Object data = RepresentationUtils.toRepresentation(catalogData.left().value());
536 res = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), data);
538 } catch (Exception e) {
539 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Catalog Components");
540 log.debug("Getting catalog components failed with exception", e);
541 res = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
547 @Path("/inactiveComponents/{componentType}")
548 public Response deleteMarkedResources(@PathParam("componentType") final String componentType, @Context final HttpServletRequest request) {
550 ServletContext context = request.getSession().getServletContext();
552 String url = request.getMethod() + " " + request.getRequestURI();
553 log.debug("Start handle request of {}", url);
556 String userId = request.getHeader(Constants.USER_ID_HEADER);
557 User modifier = new User();
558 modifier.setUserId(userId);
559 log.debug("modifier id is {}", userId);
561 Response response = null;
563 NodeTypeEnum nodeType = NodeTypeEnum.getByNameIgnoreCase(componentType);
564 if (nodeType == null) {
565 log.info("componentType is not valid: {}", componentType);
566 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
569 List<NodeTypeEnum> componentsList = new ArrayList<>();
570 componentsList.add(nodeType);
572 ComponentsCleanBusinessLogic businessLogic = getComponentCleanerBL(context);
573 Map<NodeTypeEnum, Either<List<String>, ResponseFormat>> cleanComponentsResult = businessLogic.cleanComponents(componentsList);
574 Either<List<String>, ResponseFormat> cleanResult = cleanComponentsResult.get(nodeType);
576 if (cleanResult.isRight()) {
577 log.debug("failed to delete marked components of type {}", nodeType);
578 response = buildErrorResponse(cleanResult.right().value());
581 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), cleanResult.left().value());
584 } catch (Exception e) {
585 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Marked Components");
586 log.debug("delete marked components failed with exception", e);
587 response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
594 @Path("/ecompPortalMenu")
595 @Consumes(MediaType.APPLICATION_JSON)
596 @Produces(MediaType.APPLICATION_JSON)
597 @ApiOperation(value = "Retrieve ecomp portal menu - MOC", httpMethod = "GET", notes = "Retrieve ecomp portal menu", response = User.class)
598 @ApiResponses(value = { @ApiResponse(code = 200, message = "Retrieve ecomp portal menu") })
599 public Response getListOfCsars(@Context final HttpServletRequest request) {
600 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
601 "[{\"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}]}]}]");