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.portalsdk.core.service;
21 /*package org.openecomp.portalsdk.core.service;
23 import java.util.Iterator;
24 import java.util.List;
26 import java.util.TreeSet;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.stereotype.Service;
30 import org.springframework.transaction.annotation.Transactional;
32 import org.openecomp.portalsdk.core.domain.Role;
33 import org.openecomp.portalsdk.core.domain.RoleFunction;
35 @Service("roleService")
37 public class RoleServiceNonSpringImpl implements RoleService{
40 private DataAccessService dataAccessService;
42 @SuppressWarnings("unchecked")
43 public List<RoleFunction> getRoleFunctions() {
44 //List msgDB = getDataAccessService().getList(Profile.class, null);
45 return getDataAccessService().getList(RoleFunction.class, null);
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;
55 Role currentRole = (Role)getDataAccessService().getDomainObject(Role.class,roleId,null);
56 Set<Role> allParentRoles = new TreeSet<Role>();
57 allParentRoles = getAllParentRolesAsList(currentRole, allParentRoles);
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();
67 return availableChildRoles;
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);
78 return allParentRoles;
81 public RoleFunction getRoleFunction(String code) {
82 return (RoleFunction)getDataAccessService().getDomainObject(RoleFunction.class, code, null);
85 public void saveRoleFunction(RoleFunction domainRoleFunction) {
86 getDataAccessService().saveDomainObject(domainRoleFunction, null);
89 public void deleteRoleFunction(RoleFunction domainRoleFunction) {
90 getDataAccessService().deleteDomainObject(domainRoleFunction, null);
93 public Role getRole(Long id) {
94 return (Role)getDataAccessService().getDomainObject(Role.class, id, null);
97 public void saveRole(Role domainRole) {
98 getDataAccessService().saveDomainObject(domainRole, null);
101 public void deleteRole(Role domainRole) {
102 getDataAccessService().deleteDomainObject(domainRole, null);
105 @SuppressWarnings("unchecked")
106 public List<Role> getAvailableRoles() {
107 return getDataAccessService().getList(Role.class, null);
110 public DataAccessService getDataAccessService() {
111 return dataAccessService;
115 public void setDataAccessService(DataAccessService dataAccessService) {
116 this.dataAccessService = dataAccessService;