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