f0dd7b2b3dfa3ad4410c14e2ebecbb3fb9c7d707
[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 Short 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 (role.getAppRoleId() == null) ? null : role.getAppRoleId();
65         }
66                 
67         @Override 
68         public String toString() {
69                 String str = "[u: "+getUserId()+"; a: "+getAppId()+", r: "+getRoleId()+"; appRoleId: "+getAppRoleId()+"]";
70                 return str;
71         }
72         
73         public Long getUserId() {
74                 return userId;
75         }
76
77         public void setUserId(Long id) {
78                 this.userId = id;
79         }
80
81         public EPApp getApp() {
82                 return app;
83         }
84
85         public void setApp(EPApp app) {
86                 this.app = app;
87         }
88
89         public EPRole getRole() {
90                 return role;
91         }
92
93         public void setRole(EPRole role) {
94                 this.role = role;
95         }
96                 
97         public Short getPriority() {
98                 return this.priority;
99         }
100
101         public void setPriority(Short priority) {
102                 this.priority = priority;
103         }
104
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 (this.getUserId().equals(castOther.getUserId()))
115                                 && (this.getApp().getId().equals(castOther.getApp().getId()))
116                                 && (this.getRole().getId().equals(castOther.getRole().getId()))
117                                 && ((this.priority==null && castOther.getPriority()==null) || this.getPriority().equals(castOther.getPriority()));
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 }