1449af765675b6a1ffd0992ee37c2ddf58c8e5ed
[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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.onap.portalapp.portal.domain;
39
40
41 @SuppressWarnings("rawtypes")
42 public class EPUserApp implements java.io.Serializable, Comparable {
43
44         private static final long serialVersionUID = 1L;
45         
46         private Long userId;
47         private EPApp app;
48         private EPRole role;
49         private Short priority;
50         
51         public EPUserApp() {
52         }
53         
54         public Long getAppId() {
55                 return this.getApp().getId();
56         }
57         
58         public Long getRoleId() {
59                 return (role == null) ? null : role.getId();
60         }
61         
62         public Long getAppRoleId() {
63                 return (role.getAppRoleId() == null) ? null : role.getAppRoleId();
64         }
65                 
66         @Override 
67         public String toString() {
68                 String str = "[u: "+getUserId()+"; a: "+getAppId()+", r: "+getRoleId()+"; appRoleId: "+getAppRoleId()+"]";
69                 return str;
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 Short getPriority() {
97                 return this.priority;
98         }
99
100         public void setPriority(Short priority) {
101                 this.priority = priority;
102         }
103
104         public boolean equals(Object other) {
105                 if ((this == other))
106                         return true;
107                 if ((other == null))
108                         return false;
109                 if (!(other instanceof EPUserApp))
110                         return false;
111                 EPUserApp castOther = (EPUserApp) other;
112
113                 return (this.getUserId().equals(castOther.getUserId()))
114                                 && (this.getApp().getId().equals(castOther.getApp().getId()))
115                                 && (this.getRole().getId().equals(castOther.getRole().getId()))
116                                 && ((this.priority==null && castOther.getPriority()==null) || this.getPriority().equals(castOther.getPriority()));
117         }
118
119         public int hashCode() {
120                 int result = 17;
121
122                 result = 37 * result + (int) (this.getUserId()==null ? 0 : this.getUserId().intValue());
123                 result = 37 * result + (int) (this.getApp().getId()==null ? 0 : this.getApp().getId().intValue());
124                 result = 37 * result + (int) (this.getRole().getId()==null ? 0 : this.getRole().getId().intValue());
125                 result = 37 * result + (int) (this.priority==null ? 0 : this.priority);
126                 return result;
127         }
128
129         public int compareTo(Object other){
130             EPUserApp castOther = (EPUserApp) other;
131
132             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);
133             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);
134
135             return c1.compareTo(c2);
136         }
137 }