Catalog alignment
[sdc.git] / catalog-fe / src / main / java / org / openecomp / sdc / fe / 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.fe.servlets;
22
23 import org.openecomp.sdc.common.api.Constants;
24 import org.openecomp.sdc.common.log.wrappers.Logger;
25 import org.openecomp.sdc.common.rest.api.RestConfigurationInfo;
26 import org.openecomp.sdc.common.servlets.BasicServlet;
27 import org.openecomp.sdc.fe.config.Configuration;
28 import org.openecomp.sdc.fe.config.ConfigurationManager;
29
30 import javax.servlet.ServletContext;
31 import javax.servlet.http.HttpServletRequest;
32 import javax.ws.rs.GET;
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
39 /**
40  * Root resource (exposed at "/" path)
41  */
42 @Path("/configmgr")
43 public class ConfigMgrServlet extends BasicServlet {
44
45         private static Logger log = Logger.getLogger(ConfigMgrServlet.class.getName());
46
47     @GET
48     @Path("/get")
49     @Produces(MediaType.APPLICATION_JSON)
50     public String getConfig(@Context final HttpServletRequest request, @QueryParam("type") String type) {
51
52         String result = null;
53
54         ServletContext context = request.getSession().getServletContext();
55
56         ConfigurationManager configurationManager = (ConfigurationManager) context
57                 .getAttribute(Constants.CONFIGURATION_MANAGER_ATTR);
58
59         if (type == null || type.equals("configuration")) {
60
61             Configuration configuration = configurationManager.getConfiguration();
62             if (configuration == null) {
63                 log.warn("Configuration of type {} was not found", Configuration.class);
64             } else {
65                 log.info("The value returned from getConfig is {}", configuration);
66
67                 result = gson.toJson(configuration);
68
69             }
70         } else if (type.equals("rest")) {
71
72             RestConfigurationInfo configuration = configurationManager.getRestClientConfiguration();
73             if (configuration == null) {
74                 log.warn("Configuration of type {} was not found", RestConfigurationInfo.class);
75             } else {
76                 log.info("The value returned from getConfig is {}", configuration);
77
78                 result = gson.toJson(configuration);
79
80             }
81
82         }
83         return result;
84
85     }
86
87 }