Remove legacy certificate handling
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / servlets / DirectiveServlet.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Nordix Foundation
4  *  ================================================================================
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19 package org.openecomp.sdc.be.servlets;
20
21 import io.swagger.v3.oas.annotations.Operation;
22 import io.swagger.v3.oas.annotations.media.ArraySchema;
23 import io.swagger.v3.oas.annotations.media.Content;
24 import io.swagger.v3.oas.annotations.media.Schema;
25 import io.swagger.v3.oas.annotations.responses.ApiResponse;
26 import io.swagger.v3.oas.annotations.tags.Tag;
27 import io.swagger.v3.oas.annotations.tags.Tags;
28 import java.util.HashMap;
29 import java.util.List;
30 import java.util.Map;
31 import javax.inject.Inject;
32 import javax.inject.Singleton;
33 import javax.servlet.http.HttpServletRequest;
34 import javax.ws.rs.GET;
35 import javax.ws.rs.HeaderParam;
36 import javax.ws.rs.Path;
37 import javax.ws.rs.Produces;
38 import javax.ws.rs.core.Context;
39 import javax.ws.rs.core.MediaType;
40 import javax.ws.rs.core.Response;
41 import org.apache.commons.collections.CollectionUtils;
42 import org.openecomp.sdc.be.config.BeEcompErrorManager;
43 import org.openecomp.sdc.be.config.ConfigurationManager;
44 import org.openecomp.sdc.be.dao.api.ActionStatus;
45 import org.openecomp.sdc.be.impl.ComponentsUtils;
46 import org.openecomp.sdc.be.model.User;
47 import org.openecomp.sdc.common.api.Constants;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
50
51 @Path("/v1/catalog/directives")
52 @Tags({@Tag(name = "SDCE-2 APIs")})
53 @Singleton
54 public class DirectiveServlet extends BeGenericServlet {
55
56     private static final Logger LOGGER = LoggerFactory.getLogger(DirectiveServlet.class);
57
58     @Inject
59     public DirectiveServlet(final ComponentsUtils componentsUtils) {
60         super(componentsUtils);
61     }
62
63     @GET
64     @Path("/")
65     @Produces(MediaType.APPLICATION_JSON)
66     @Operation(description = "Retrieve all Directives values from configuration file", method = "GET", summary = "Retrieve all Directives", responses = {
67         @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))),
68         @ApiResponse(responseCode = "200", description = "Returns Directive values from configuration file Ok"),
69         @ApiResponse(responseCode = "404", description = "Directive not found"),
70         @ApiResponse(responseCode = "500", description = "Internal Server Error")})
71     public Response getConfCategoriesAndVersion(@Context final HttpServletRequest request,
72                                                 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
73         final String url = request.getMethod() + " " + request.getRequestURI();
74         LOGGER.debug("Start handle request of {}", url);
75         final Map<String, Object> directivesMap = new HashMap<>();
76         try {
77             final List<String> directives = getDirectiveValues();
78             if (CollectionUtils.isEmpty(directives)) {
79                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
80             }
81             directivesMap.put("directives", directives);
82         } catch (final Exception e) {
83             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("SDC Failed to retrieve all Directives");
84             LOGGER.debug("Method getDirectiveValues failed with unexpected exception", e);
85             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
86         }
87         return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), directivesMap);
88     }
89
90     private List<String> getDirectiveValues() {
91         return ConfigurationManager.getConfigurationManager().getConfiguration().getDirectives();
92     }
93 }