[PORTAL-7] Rebase
[portal.git] / ecomp-portal-BE-common / src / main / java / org / openecomp / portalapp / portal / domain / EPUserApp.java
1 /*-\r
2  * ================================================================================\r
3  * ECOMP Portal\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ================================================================================\r
19  */\r
20 package org.openecomp.portalapp.portal.domain;\r
21 \r
22 \r
23 @SuppressWarnings("rawtypes")\r
24 public class EPUserApp implements java.io.Serializable, Comparable {\r
25 \r
26         private static final long serialVersionUID = 1L;\r
27         \r
28         private Long userId;\r
29         private EPApp app;\r
30         private EPRole role;\r
31         private Short priority;\r
32         \r
33         public EPUserApp() {\r
34         }\r
35         \r
36         public Long getAppId() {\r
37                 return this.getApp().getId();\r
38         }\r
39         \r
40         public Long getRoleId() {\r
41                 return (role == null) ? null : role.getId();\r
42         }\r
43         \r
44         public Long getAppRoleId() {\r
45                 return (role.getAppRoleId() == null) ? null : role.getAppRoleId();\r
46         }\r
47                 \r
48         @Override \r
49         public String toString() {\r
50                 String str = "[u: "+getUserId()+"; a: "+getAppId()+", r: "+getRoleId()+"; appRoleId: "+getAppRoleId()+"]";\r
51                 return str;\r
52         }\r
53         \r
54         public Long getUserId() {\r
55                 return userId;\r
56         }\r
57 \r
58         public void setUserId(Long id) {\r
59                 this.userId = id;\r
60         }\r
61 \r
62         public EPApp getApp() {\r
63                 return app;\r
64         }\r
65 \r
66         public void setApp(EPApp app) {\r
67                 this.app = app;\r
68         }\r
69 \r
70         public EPRole getRole() {\r
71                 return role;\r
72         }\r
73 \r
74         public void setRole(EPRole role) {\r
75                 this.role = role;\r
76         }\r
77                 \r
78         public Short getPriority() {\r
79                 return this.priority;\r
80         }\r
81 \r
82         public void setPriority(Short priority) {\r
83                 this.priority = priority;\r
84         }\r
85 \r
86         public boolean equals(Object other) {\r
87                 if ((this == other))\r
88                         return true;\r
89                 if ((other == null))\r
90                         return false;\r
91                 if (!(other instanceof EPUserApp))\r
92                         return false;\r
93                 EPUserApp castOther = (EPUserApp) other;\r
94 \r
95                 return (this.getUserId().equals(castOther.getUserId()))\r
96                                 && (this.getApp().getId().equals(castOther.getApp().getId()))\r
97                                 && (this.getRole().getId().equals(castOther.getRole().getId()))\r
98                                 && ((this.priority==null && castOther.getPriority()==null) || this.getPriority().equals(castOther.getPriority()));\r
99         }\r
100 \r
101         public int hashCode() {\r
102                 int result = 17;\r
103 \r
104                 result = 37 * result + (int) (this.getUserId()==null ? 0 : this.getUserId().intValue());\r
105                 result = 37 * result + (int) (this.getApp().getId()==null ? 0 : this.getApp().getId().intValue());\r
106                 result = 37 * result + (int) (this.getRole().getId()==null ? 0 : this.getRole().getId().intValue());\r
107                 result = 37 * result + (int) (this.priority==null ? 0 : this.priority);\r
108                 return result;\r
109         }\r
110 \r
111         public int compareTo(Object other){\r
112             EPUserApp castOther = (EPUserApp) other;\r
113 \r
114             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);\r
115             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);\r
116 \r
117             return c1.compareTo(c2);\r
118         }\r
119 }\r