a7374d0c28c656206858229deba7e2feb1029bb6
[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.portalsdk.core.service;
21 /*package org.openecomp.portalsdk.core.service;
22
23 import java.util.Iterator;
24 import java.util.List;
25 import java.util.Set;
26 import java.util.TreeSet;
27
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.stereotype.Service;
30 import org.springframework.transaction.annotation.Transactional;
31
32 import org.openecomp.portalsdk.core.domain.Role;
33 import org.openecomp.portalsdk.core.domain.RoleFunction;
34
35 @Service("roleService")
36 @Transactional
37 public class RoleServiceNonSpringImpl implements RoleService{
38
39         @Autowired
40         private DataAccessService  dataAccessService;
41         
42         @SuppressWarnings("unchecked")  
43         public List<RoleFunction> getRoleFunctions() {
44                 //List msgDB = getDataAccessService().getList(Profile.class, null);
45                 return getDataAccessService().getList(RoleFunction.class, null);
46         }
47         
48         @SuppressWarnings("unchecked")
49         public List<Role> getAvailableChildRoles(Long roleId) {
50                 List<Role> availableChildRoles = (List<Role>)getDataAccessService().getList(Role.class,null);
51                 if(roleId==null || roleId==0){
52                         return availableChildRoles;
53                 }
54                 
55                 Role currentRole = (Role)getDataAccessService().getDomainObject(Role.class,roleId,null);
56                 Set<Role> allParentRoles = new TreeSet<Role>();
57                 allParentRoles = getAllParentRolesAsList(currentRole, allParentRoles);
58
59                 
60                 Iterator<Role> availableChildRolesIterator = availableChildRoles.iterator();
61                 while (availableChildRolesIterator.hasNext()) {
62                         Role role = availableChildRolesIterator.next(); 
63                         if(!role.getActive() || allParentRoles.contains(role) || role.getId().equals(roleId)){
64                                 availableChildRolesIterator.remove();
65                         }
66                 }
67                 return availableChildRoles;
68         }
69         
70         @SuppressWarnings("unchecked")
71         private Set<Role> getAllParentRolesAsList(Role role, Set<Role> allParentRoles) {
72                 Set<Role> parentRoles = role.getParentRoles();
73                 allParentRoles.addAll(parentRoles);
74                 Iterator<Role> parentRolesIterator = parentRoles.iterator();
75                 while (parentRolesIterator.hasNext()) {
76                         getAllParentRolesAsList(parentRolesIterator.next(),allParentRoles);
77                 }
78                 return allParentRoles;
79         }
80         
81         public RoleFunction getRoleFunction(String code) {
82                 return (RoleFunction)getDataAccessService().getDomainObject(RoleFunction.class, code, null);
83         }
84         
85         public void saveRoleFunction(RoleFunction domainRoleFunction) {
86                 getDataAccessService().saveDomainObject(domainRoleFunction, null);
87         }
88         
89         public void deleteRoleFunction(RoleFunction domainRoleFunction) {
90                 getDataAccessService().deleteDomainObject(domainRoleFunction, null);
91         }
92         
93         public Role getRole(Long id) {
94                 return (Role)getDataAccessService().getDomainObject(Role.class, id, null);
95         }
96         
97         public void saveRole(Role domainRole) {
98                 getDataAccessService().saveDomainObject(domainRole, null);
99         }
100         
101         public void deleteRole(Role domainRole) {
102                 getDataAccessService().deleteDomainObject(domainRole, null);
103         }
104         
105         @SuppressWarnings("unchecked")
106         public List<Role> getAvailableRoles() {
107                 return getDataAccessService().getList(Role.class, null);
108         }
109
110         public DataAccessService getDataAccessService() {
111                 return dataAccessService;
112         }
113
114
115         public void setDataAccessService(DataAccessService dataAccessService) {
116                 this.dataAccessService = dataAccessService;
117         }
118         
119         
120
121 }
122 */