re base code
[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 org.openecomp.sdc.be.config.Configuration;
25 import org.openecomp.sdc.be.config.ConfigurationManager;
26 import org.openecomp.sdc.common.api.Constants;
27 import org.openecomp.sdc.common.log.wrappers.Logger;
28 import org.openecomp.sdc.common.servlets.BasicServlet;
29
30 import javax.servlet.ServletContext;
31 import javax.servlet.http.HttpServletRequest;
32 import javax.ws.rs.*;
33 import javax.ws.rs.core.Context;
34 import javax.ws.rs.core.MediaType;
35
36 /**
37  * Root resource (exposed at "/" path)
38  */
39 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
40 @Path("/configmgr")
41 public class ConfigMgrServlet extends BasicServlet {
42
43     private static final Logger log = Logger.getLogger(ConfigMgrServlet.class);
44
45     @GET
46     @Path("/get")
47     @Produces(MediaType.APPLICATION_JSON)
48     public String getConfig(@Context final HttpServletRequest request, @QueryParam("type") String type) {
49
50         String result = null;
51
52         ServletContext context = request.getSession().getServletContext();
53
54         ConfigurationManager configurationManager = (ConfigurationManager) context.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR);
55
56         if (type == null || type.equals("configuration")) {
57
58             Configuration configuration = configurationManager.getConfiguration();
59             if (configuration == null) {
60                 log.warn("Configuration of type {} was not found", Configuration.class);
61             } else {
62                 log.info("The value returned from getConfig is {}", configuration);
63
64                 result = gson.toJson(configuration);
65
66             }
67         }
68
69         return result;
70
71     }
72
73     @POST
74     @Path("/set1")
75     @Produces(MediaType.TEXT_PLAIN)
76     @Consumes(MediaType.APPLICATION_JSON)
77     public String setConfig1(@Context final HttpServletRequest request, Configuration configuration) {
78
79         log.debug("{}", configuration);
80
81         return "ok";
82
83     }
84
85     @POST
86     @Path("/set2")
87     @Produces(MediaType.TEXT_PLAIN)
88     @Consumes(MediaType.APPLICATION_JSON)
89     public void setConfig2(@Context final HttpServletRequest request, Configuration configuration) {
90
91         log.debug("{}", configuration);
92
93     }
94
95     @PUT
96     @Path("/setput1")
97     @Produces(MediaType.TEXT_PLAIN)
98     @Consumes(MediaType.APPLICATION_JSON)
99     public String setConfig3(@Context final HttpServletRequest request, Configuration configuration) {
100
101         log.debug("{}", configuration);
102
103         return "ok";
104
105     }
106
107     @PUT
108     @Path("/setput2")
109     @Produces(MediaType.TEXT_PLAIN)
110     @Consumes(MediaType.APPLICATION_JSON)
111     public void setConfig4(@Context final HttpServletRequest request, Configuration configuration) {
112
113         log.debug("{}", configuration);
114
115     }
116
117 }