2 * ================================================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ================================================================================
20 package org.openecomp.portalapp.portal.controller;
22 import java.util.HashMap;
25 import javax.servlet.http.HttpServletRequest;
27 import org.json.JSONObject;
28 import org.openecomp.portalapp.portal.domain.EPUser;
29 import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
30 import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
31 import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
32 import org.openecomp.portalapp.portal.service.AdminRolesService;
33 import org.openecomp.portalapp.portal.service.EPAppService;
34 import org.openecomp.portalapp.portal.service.PersUserAppService;
35 import org.openecomp.portalapp.portal.service.UserService;
36 import org.openecomp.portalapp.util.EPUserUtils;
37 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.context.annotation.EnableAspectJAutoProxy;
40 import org.springframework.web.bind.annotation.PathVariable;
41 import org.springframework.web.bind.annotation.RequestBody;
42 import org.springframework.web.bind.annotation.RequestMapping;
43 import org.springframework.web.bind.annotation.RequestMethod;
44 import org.springframework.web.bind.annotation.RestController;
47 @org.springframework.context.annotation.Configuration
48 @EnableAspectJAutoProxy
50 public class AppsOSController extends AppsController {
52 static final String FAILURE = "failure";
53 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AppsOSController.class);
56 AdminRolesService adminRolesService;
58 EPAppService appService;
60 PersUserAppService persUserAppService;
62 UserService userService;
67 * Create new application's contact us details.
72 @RequestMapping(value = "/portalApi/saveNewUser", method = RequestMethod.POST, produces = "application/json")
73 public PortalRestResponse<String> saveNewUser(HttpServletRequest request,@RequestBody EPUser newUser) {
74 EPUser user = EPUserUtils.getUserSession(request);
76 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, FAILURE,
77 "New User cannot be null or empty");
79 if (!(adminRolesService.isSuperAdmin(user) || adminRolesService.isAccountAdmin(user))){
80 if(!user.getLoginId().equalsIgnoreCase(newUser.getLoginId()))
81 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, FAILURE,
85 String checkDuplicate = request.getParameter("isCheck");
86 String saveNewUser = FAILURE;
88 saveNewUser = userService.saveNewUser(newUser,checkDuplicate);
89 } catch (Exception e) {
90 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, saveNewUser, e.getMessage());
92 return new PortalRestResponse<String>(PortalRestStatusEnum.OK, saveNewUser, "");
95 @RequestMapping(value = { "/portalApi/currentUserProfile/{loginId}" }, method = RequestMethod.GET, produces = "application/json")
96 public String getCurrentUserProfile(HttpServletRequest request, @PathVariable("loginId") String loginId) {
98 Map<String,String> map = new HashMap<String,String>();
101 user = (EPUser) userService.getUserByUserId(loginId).get(0);
102 map.put("firstName", user.getFirstName());
103 map.put("lastName", user.getLastName());
104 map.put("email", user.getEmail());
105 map.put("loginId", user.getLoginId());
106 map.put("loginPwd",user.getLoginPwd());
107 map.put("middleInitial",user.getMiddleInitial());
108 } catch (Exception e) {
109 logger.error(EELFLoggerDelegate.errorLogger, "Failed to get user info", e);
112 JSONObject j = new JSONObject(map);;