Merge "Fix null pointer exception"
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / portal / controller / LanguageController.java
1 /**
2  * Copyright (C) 2019 CMCC, Inc. and others. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.portalapp.portal.controller;
17
18 import javax.servlet.http.HttpServletRequest;
19 import javax.servlet.http.HttpServletResponse;
20 import org.onap.portalapp.portal.service.LanguageService;
21 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.web.bind.annotation.PathVariable;
23 import org.springframework.web.bind.annotation.RequestBody;
24 import org.springframework.web.bind.annotation.RequestMapping;
25 import org.springframework.web.bind.annotation.RequestMethod;
26 import org.springframework.web.bind.annotation.RestController;
27 import com.alibaba.fastjson.JSONObject;
28
29 @RestController
30 @RequestMapping("/auxapi")
31 public class LanguageController {
32
33     @Autowired
34     private LanguageService languageService;
35
36     @RequestMapping(value = "/language",method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
37     public JSONObject getLanguageList() {
38         return languageService.getLanguages();
39     }
40
41     @RequestMapping(value = "/languageSetting/user/{loginId}",method = RequestMethod.POST)
42     public void setUpUserLanguage(@RequestBody JSONObject jsonLanguageId,
43                                   @PathVariable("loginId") String loginId) throws Exception {
44         Integer languageId = jsonLanguageId.getInteger("languageId");
45         languageService.setUpUserLanguage(languageId,loginId);
46     }
47
48     @RequestMapping(value = "/languageSetting/user/{loginId}",method = RequestMethod.GET)
49     public JSONObject getUserLanguage(HttpServletRequest request, HttpServletResponse response,
50                                       @PathVariable("loginId") String loginId) {
51         return languageService.getUserLanguage(loginId);
52     }
53
54 }