03aaab5f4704875a06199ba27382e2ef438fca3e
[portal/sdk.git] /
1 /*-
2  * ================================================================================
3  * ECOMP Portal SDK
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
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  * ================================================================================
19  */
20 package org.openecomp.portalapp.controller.sample;
21
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28
29 import org.json.JSONObject;
30 import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
31 import org.openecomp.portalsdk.core.domain.User;
32 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
33 import org.openecomp.portalsdk.core.service.UserProfileService;
34 import org.openecomp.portalsdk.core.web.support.JsonMessage;
35 import org.openecomp.portalsdk.core.web.support.UserUtils;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.stereotype.Controller;
38 import org.springframework.web.bind.annotation.RequestMapping;
39 import org.springframework.web.bind.annotation.RequestMethod;
40 import org.springframework.web.servlet.ModelAndView;
41
42 import com.fasterxml.jackson.databind.ObjectMapper;
43
44 @Controller
45 @RequestMapping("/")  
46 public class CollaborateListController  extends RestrictedBaseController{
47         @Autowired
48         UserProfileService service;
49         EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CollaborateListController.class);
50         
51         @RequestMapping(value = {"/collaborate_list" }, method = RequestMethod.GET)
52         public ModelAndView ProfileSearch(HttpServletRequest request) {
53                 Map<String, Object> model = new HashMap<String, Object>();
54                 ObjectMapper mapper = new ObjectMapper();
55                 User user = UserUtils.getUserSession(request);
56                 
57                 List<User> profileList =null;
58                 try {
59                         profileList = service.findAllUserWithOnOffline(user.getOrgUserId());
60                         model.put("profileList", mapper.writeValueAsString(profileList));
61                 } catch (Exception e) {
62                         logger.error(EELFLoggerDelegate.errorLogger, "Error happened during collaborate list search" + e.getMessage());
63
64                 } 
65                 return new ModelAndView(getViewName(),"model", model);
66         }
67         
68         @RequestMapping(value = {"/get_collaborate_list" }, method = RequestMethod.GET)
69         public void getCollaborateList(HttpServletRequest request,HttpServletResponse response) {
70                 
71                 ObjectMapper mapper = new ObjectMapper();
72                 User user = UserUtils.getUserSession(request);
73                 
74                 List<User> profileList =null;
75                 try {
76                         profileList = service.findAllUserWithOnOffline(user.getOrgUserId());
77                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(profileList));
78                         JSONObject j = new JSONObject(msg);
79                         response.getWriter().write(j.toString());       
80                 } catch (Exception e) {
81                         logger.error(EELFLoggerDelegate.errorLogger, "Error happened during get collaborate list" + e.getMessage());
82
83                 } 
84         }
85 }