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