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