c52bc3036f0ac0b0138c5e909e782ad18fb718a9
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / portal / domain / EPUserApp.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */
38 package org.onap.portalapp.portal.domain;
39
40 import org.onap.portalsdk.core.domain.support.DomainVo;
41
42 @SuppressWarnings("rawtypes")
43 public class EPUserApp extends DomainVo implements java.io.Serializable, Comparable {
44
45         private static final long serialVersionUID = 1L;
46         
47         private Long userId;
48         private EPApp app;
49         private EPRole role;
50         private Integer priority;
51         
52         public EPUserApp() {
53         }
54         
55         public Long getAppId() {
56                 return this.getApp().getId();
57         }
58         
59         public Long getRoleId() {
60                 return (role == null) ? null : role.getId();
61         }
62         
63         public Long getAppRoleId() {
64                 return this.role.getAppRoleId();
65         }
66                 
67         @Override 
68         public String toString() {
69                 return "[u: "+getUserId()+"; a: "+getAppId()+", r: "+getRoleId()+"; appRoleId: "+getAppRoleId()+"]";
70         }
71         
72         public Long getUserId() {
73                 return userId;
74         }
75
76         public void setUserId(Long id) {
77                 this.userId = id;
78         }
79
80         public EPApp getApp() {
81                 return app;
82         }
83
84         public void setApp(EPApp app) {
85                 this.app = app;
86         }
87
88         public EPRole getRole() {
89                 return role;
90         }
91
92         public void setRole(EPRole role) {
93                 this.role = role;
94         }
95                 
96         public Integer getPriority() {
97                 return (this.priority == null) ? 1 : priority;
98         }
99
100         public void setPriority(Integer priority) {
101                 this.priority = priority;
102         }
103
104         @Override
105         public boolean equals(Object other) {
106                 if ((this == other))
107                         return true;
108                 if ((other == null))
109                         return false;
110                 if (!(other instanceof EPUserApp))
111                         return false;
112                 EPUserApp castOther = (EPUserApp) other;
113
114                 return (otherUserIdIsSameAsThisUserId(castOther))
115                                 && (otherAppIdIsSameAsThis(castOther))
116                                 && (otherRoleIsSameAsThis(castOther))
117                                 && (otherPriorityIsSameAsThis(castOther));
118         }
119
120         public int hashCode() {
121                 int result = 17;
122
123                 result = 37 * result + (int) (this.getUserId()==null ? 0 : this.getUserId().intValue());
124                 result = 37 * result + (int) (this.getApp().getId()==null ? 0 : this.getApp().getId().intValue());
125                 result = 37 * result + (int) (this.getRole().getId()==null ? 0 : this.getRole().getId().intValue());
126                 result = 37 * result + (int) (this.priority==null ? 0 : this.priority);
127                 return result;
128         }
129
130         public int compareTo(Object other){
131             EPUserApp castOther = (EPUserApp) other;
132
133             Long c1 = (this.getUserId()==null ? 0 : this.getUserId()) + (this.getApp()==null||this.getApp().getId()==null ? 0 : this.getApp().getId()) + (this.getRole()==null||this.getRole().getId()==null ? 0 : this.getRole().getId()) + (this.priority==null ? 0 : this.priority);
134             Long c2 = (castOther.getUserId()==null ? 0 : castOther.getUserId()) + (castOther.getApp()==null||castOther.getApp().getId()==null ? 0 : castOther.getApp().getId()) + (castOther.getRole()==null||castOther.getRole().getId()==null ? 0 : castOther.getRole().getId()) + (castOther.priority==null ? 0 : castOther.priority);
135
136             return c1.compareTo(c2);
137         }
138         private boolean otherPriorityIsSameAsThis(EPUserApp other){
139                 return (this.priority==null && other.getPriority()==null) || this.getPriority().equals(other.getPriority());
140         }
141
142         private boolean otherRoleIsSameAsThis(EPUserApp other){
143                 return this.getRole().getId().equals(other.getRole().getId());
144         }
145
146         private boolean otherAppIdIsSameAsThis(EPUserApp other){
147                 return this.getApp().getId().equals(other.getApp().getId());
148         }
149
150         private boolean otherUserIdIsSameAsThisUserId(EPUserApp other){
151                 return this.getUserId().equals(other.getUserId());
152         }
153 }