2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the “License”);
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.openecomp.portalapp.portal.controller;
40 import java.util.HashMap;
43 import javax.servlet.http.HttpServletRequest;
45 import org.json.JSONObject;
46 import org.openecomp.portalapp.portal.domain.EPUser;
47 import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
48 import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
49 import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
50 import org.openecomp.portalapp.portal.service.AdminRolesService;
51 import org.openecomp.portalapp.portal.service.EPAppService;
52 import org.openecomp.portalapp.portal.service.PersUserAppService;
53 import org.openecomp.portalapp.portal.service.UserService;
54 import org.openecomp.portalapp.util.EPUserUtils;
55 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
56 import org.springframework.beans.factory.annotation.Autowired;
57 import org.springframework.context.annotation.EnableAspectJAutoProxy;
58 import org.springframework.web.bind.annotation.PathVariable;
59 import org.springframework.web.bind.annotation.RequestBody;
60 import org.springframework.web.bind.annotation.RequestMapping;
61 import org.springframework.web.bind.annotation.RequestMethod;
62 import org.springframework.web.bind.annotation.RestController;
65 @org.springframework.context.annotation.Configuration
66 @EnableAspectJAutoProxy
68 public class AppsOSController extends AppsController {
70 static final String FAILURE = "failure";
71 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AppsOSController.class);
74 AdminRolesService adminRolesService;
76 EPAppService appService;
78 PersUserAppService persUserAppService;
80 UserService userService;
85 * Create new application's contact us details.
90 @RequestMapping(value = "/portalApi/saveNewUser", method = RequestMethod.POST, produces = "application/json")
91 public PortalRestResponse<String> saveNewUser(HttpServletRequest request,@RequestBody EPUser newUser) {
92 EPUser user = EPUserUtils.getUserSession(request);
94 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, FAILURE,
95 "New User cannot be null or empty");
97 if (!(adminRolesService.isSuperAdmin(user) || adminRolesService.isAccountAdmin(user))){
98 if(!user.getLoginId().equalsIgnoreCase(newUser.getLoginId()))
99 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, FAILURE,
103 String checkDuplicate = request.getParameter("isCheck");
104 String saveNewUser = FAILURE;
106 saveNewUser = userService.saveNewUser(newUser,checkDuplicate);
107 } catch (Exception e) {
108 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, saveNewUser, e.getMessage());
110 return new PortalRestResponse<String>(PortalRestStatusEnum.OK, saveNewUser, "");
113 @RequestMapping(value = { "/portalApi/currentUserProfile/{loginId}" }, method = RequestMethod.GET, produces = "application/json")
114 public String getCurrentUserProfile(HttpServletRequest request, @PathVariable("loginId") String loginId) {
116 Map<String,String> map = new HashMap<String,String>();
119 user = (EPUser) userService.getUserByUserId(loginId).get(0);
120 map.put("firstName", user.getFirstName());
121 map.put("lastName", user.getLastName());
122 map.put("email", user.getEmail());
123 map.put("loginId", user.getLoginId());
124 map.put("loginPwd",user.getLoginPwd());
125 map.put("middleInitial",user.getMiddleInitial());
126 } catch (Exception e) {
127 logger.error(EELFLoggerDelegate.errorLogger, "Failed to get user info", e);
130 JSONObject j = new JSONObject(map);;