Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / java / org / openecomp / portalapp / service / AdminAuthExtension.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP Policy Engine
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.portalapp.service;
22
23
24 import org.openecomp.policy.dao.RolesDao;
25 import org.openecomp.policy.model.Roles;
26 import org.openecomp.policy.rest.dao.UserInfoDao;
27 import org.openecomp.policy.rest.jpa.UserInfo;
28 import org.openecomp.portalsdk.core.domain.Role;
29 import org.openecomp.portalsdk.core.domain.User;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.stereotype.Service;
32 import org.springframework.transaction.annotation.Transactional;
33
34 import org.openecomp.policy.common.logging.flexlogger.FlexLogger; 
35 import org.openecomp.policy.common.logging.flexlogger.Logger;
36
37 @Service("adminAuthExtension")
38 @Transactional
39 public class AdminAuthExtension {
40         
41         @Autowired
42         RolesDao rolesDAO;
43         
44         @Autowired
45         UserInfoDao  userInfoDao;
46         
47         private static Logger logger = FlexLogger.getLogger(AdminAuthExtension.class);
48         public void saveUserExtension(User user){
49                 System.out.println("User Object Recieved");
50                 try{
51                         Roles roles = new Roles();
52                         roles.setName(user.getFullName());
53                         roles.setLoginId(user.getLoginId());
54                         if(user.getRoles() != null){
55                                 rolesDAO.delete(roles);
56                                 for(Role role : user.getRoles()){ 
57                                         if(role.getName().trim().equalsIgnoreCase("Policy Super Admin") || role.getName().trim().equalsIgnoreCase("System Administrator") || role.getName().trim().equalsIgnoreCase("Standard User") ){
58                                                 roles.setRole("super-admin");
59                                         }else if(role.getName().trim().equalsIgnoreCase("Policy Super Editor")){
60                                                 roles.setRole("super-editor");
61                                         }else if(role.getName().trim().equalsIgnoreCase("Policy Super Guest")){
62                                                 roles.setRole("super-guest");
63                                         }else if(role.getName().trim().equalsIgnoreCase("Policy Admin")){
64                                                 roles.setRole("admin");
65                                         }else if(role.getName().trim().equalsIgnoreCase("Policy Editor")){
66                                                 roles.setRole("editor");
67                                         }else if(role.getName().trim().equalsIgnoreCase("Policy Guest")){
68                                                 roles.setRole("guest");
69                                         }       
70                                         rolesDAO.save(roles);
71                                 }       
72                         }
73                         
74                         UserInfo userInfo = new UserInfo();
75                         userInfo.setUserLoginId(user.getLoginId());
76                         userInfo.setUserName(user.getFullName());
77                         userInfoDao.save(userInfo);
78                 }
79                 catch(Exception e){
80                         logger.error("Exception caused while Setting role to Policy DB"+e);
81                 }
82         }
83
84 }