7e659948fe08eedb267b6aac93414b4ea1ece9fe
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / servlets / ConfigMgrServlet.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.openecomp.sdc.be.servlets;
21
22 import com.jcabi.aspects.Loggable;
23 import io.swagger.v3.oas.annotations.servers.Server;
24 import io.swagger.v3.oas.annotations.servers.Servers;
25 import io.swagger.v3.oas.annotations.tags.Tag;
26 import io.swagger.v3.oas.annotations.tags.Tags;
27 import javax.servlet.ServletContext;
28 import javax.servlet.http.HttpServletRequest;
29 import javax.ws.rs.Consumes;
30 import javax.ws.rs.GET;
31 import javax.ws.rs.POST;
32 import javax.ws.rs.PUT;
33 import javax.ws.rs.Path;
34 import javax.ws.rs.Produces;
35 import javax.ws.rs.QueryParam;
36 import javax.ws.rs.core.Context;
37 import javax.ws.rs.core.MediaType;
38 import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
39 import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
40 import org.openecomp.sdc.be.config.Configuration;
41 import org.openecomp.sdc.be.config.ConfigurationManager;
42 import org.openecomp.sdc.common.api.Constants;
43 import org.openecomp.sdc.common.log.wrappers.Logger;
44 import org.openecomp.sdc.common.servlets.BasicServlet;
45
46 /**
47  * Root resource (exposed at "/" path)
48  */
49 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
50 @Tags({@Tag(name = "SDCE-2 APIs")})
51 @Servers({@Server(url = "/sdc2/rest")})
52 @Path("/configmgr")
53 public class ConfigMgrServlet extends BasicServlet {
54
55     private static final Logger log = Logger.getLogger(ConfigMgrServlet.class);
56
57     @GET
58     @Path("/get")
59     @Produces(MediaType.APPLICATION_JSON)
60     @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
61     public String getConfig(@Context final HttpServletRequest request, @QueryParam("type") String type) {
62         String result = null;
63         ServletContext context = request.getSession().getServletContext();
64         ConfigurationManager configurationManager = (ConfigurationManager) context.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR);
65         if (type == null || type.equals("configuration")) {
66             Configuration configuration = configurationManager.getConfiguration();
67             if (configuration == null) {
68                 log.warn("Configuration of type {} was not found", Configuration.class);
69             } else {
70                 log.info("The value returned from getConfig is {}", configuration);
71                 result = gson.toJson(configuration);
72             }
73         }
74         return result;
75     }
76
77     @POST
78     @Path("/set1")
79     @Produces(MediaType.TEXT_PLAIN)
80     @Consumes(MediaType.APPLICATION_JSON)
81     @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
82     public String setConfig1(@Context final HttpServletRequest request, Configuration configuration) {
83         log.debug("{}", configuration);
84         return "ok";
85     }
86
87     @POST
88     @Path("/set2")
89     @Produces(MediaType.TEXT_PLAIN)
90     @Consumes(MediaType.APPLICATION_JSON)
91     @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
92     public void setConfig2(@Context final HttpServletRequest request, Configuration configuration) {
93         log.debug("{}", configuration);
94     }
95
96     @PUT
97     @Path("/setput1")
98     @Produces(MediaType.TEXT_PLAIN)
99     @Consumes(MediaType.APPLICATION_JSON)
100     @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
101     public String setConfig3(@Context final HttpServletRequest request, Configuration configuration) {
102         log.debug("{}", configuration);
103         return "ok";
104     }
105
106     @PUT
107     @Path("/setput2")
108     @Produces(MediaType.TEXT_PLAIN)
109     @Consumes(MediaType.APPLICATION_JSON)
110     @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
111     public void setConfig4(@Context final HttpServletRequest request, Configuration configuration) {
112         log.debug("{}", configuration);
113     }
114 }