2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ===================================================================
10 * Unless otherwise specified, all software contained herein is licensed
11 * under the Apache License, Version 2.0 (the "License");
12 * you may not use this software except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * Unless otherwise specified, all documentation contained herein is licensed
24 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25 * you may not use this documentation except in compliance with the License.
26 * You may obtain a copy of the License at
28 * https://creativecommons.org/licenses/by/4.0/
30 * Unless required by applicable law or agreed to in writing, documentation
31 * distributed under the License is distributed on an "AS IS" BASIS,
32 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 * See the License for the specific language governing permissions and
34 * limitations under the License.
36 * ============LICENSE_END============================================
41 package org.onap.portal.domain.dto.ecomp;
43 import com.fasterxml.jackson.annotation.JsonIgnore;
44 import java.util.SortedSet;
45 import java.util.TreeSet;
46 import javax.validation.Valid;
47 import lombok.AllArgsConstructor;
49 import lombok.NoArgsConstructor;
51 import org.hibernate.validator.constraints.SafeHtml;
52 import org.onap.portalsdk.core.domain.RoleFunction;
53 import org.onap.portal.domain.db.DomainVo;
59 public class EPRole extends DomainVo {
61 private static final long serialVersionUID = 1L;
64 private boolean active;
65 private Integer priority;
66 private Long appId; // used by ONAP only
67 private Long appRoleId; // used by ONAP only
68 private SortedSet<RoleFunction> roleFunctions = new TreeSet<>();
70 private SortedSet<EPRole> childRoles = new TreeSet<>();
72 private SortedSet<EPRole> parentRoles = new TreeSet<>();
75 public void addRoleFunction(RoleFunction roleFunction) {
76 this.roleFunctions.add(roleFunction);
79 public void addChildRole(EPRole role) {
80 this.childRoles.add(role);
83 public void addParentRole(EPRole role) {
84 this.parentRoles.add(role);
87 public String getEditUrl() {
88 return "/role.htm?role_id=" + getId();
91 public String getToggleActiveImage() {
92 return "/static/fusion/images/" + (isActive() ? "active.png" : "inactive.png");
95 public String getToggleActiveAltText() {
96 return isActive() ? "Click to Deactivate Role" : "Click to Activate Role";
99 public void removeChildRole(Long roleId) {
101 for (EPRole childRole : this.childRoles) {
102 if (childRole.getId().equals(roleId)) {
103 this.childRoles.remove(childRole);
109 public void removeParentRole(Long roleId) {
111 for (EPRole parentRole : this.parentRoles) {
112 if (parentRole.getId().equals(roleId)) {
113 this.parentRoles.remove(parentRole);
119 public void removeRoleFunction(String roleFunctionCd) {
121 for (RoleFunction roleFunction : this.roleFunctions) {
122 if (roleFunction.getCode().equals(roleFunctionCd)) {
123 this.roleFunctions.remove(roleFunction);
129 public int compareTo(Object obj) {
130 EPRole other = (EPRole) obj;
132 if (this.appId == null) {
133 if (other.getAppId() == null) {
134 return compareByName(other); //equal
138 } else if (other.getAppId() == null) {
141 int appIdCompareResult = appId.compareTo(other.getAppId());
142 return appIdCompareResult == 0 ? compareByName(other) : appIdCompareResult;
146 private int compareByName(EPRole other) {
147 String c1 = getName();
148 String c2 = other.getName();
150 return (c1 == null || c2 == null) ? 1 : c1.compareTo(c2);
154 public String toString() {
155 return "[Id = " + super.getId() + ", name = " + name + "]";