Updated DB scrip and EPUesrApp
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / portal / domain / EPUserApp.java
index 424a915..2b23568 100644 (file)
@@ -64,13 +64,12 @@ public class EPUserApp extends DomainVo implements java.io.Serializable, Compara
        }
        
        public Long getAppRoleId() {
-               return (role.getAppRoleId() == null) ? null : role.getAppRoleId();
+               return this.role.getAppRoleId();
        }
                
        @Override 
        public String toString() {
-               String str = "[u: "+getUserId()+"; a: "+getAppId()+", r: "+getRoleId()+"; appRoleId: "+getAppRoleId()+"]";
-               return str;
+               return "[u: "+getUserId()+"; a: "+getAppId()+", r: "+getRoleId()+"; appRoleId: "+getAppRoleId()+"]";
        }
        
        public Long getUserId() {
@@ -105,6 +104,7 @@ public class EPUserApp extends DomainVo implements java.io.Serializable, Compara
                this.priority = priority;
        }
 
+       @Override
        public boolean equals(Object other) {
                if ((this == other))
                        return true;
@@ -114,10 +114,9 @@ public class EPUserApp extends DomainVo implements java.io.Serializable, Compara
                        return false;
                EPUserApp castOther = (EPUserApp) other;
 
-               return (this.getUserId().equals(castOther.getUserId()))
-                               && (this.getApp().getId().equals(castOther.getApp().getId()))
-                               && (this.getRole().getId().equals(castOther.getRole().getId()))
-                               && ((this.priority==null && castOther.getPriority()==null) || this.getPriority().equals(castOther.getPriority()));
+               return (otherUserIdIsSameAsThisUserId(castOther))
+                               && (otherAppIdIsSameAsThis(castOther))
+                               && (otherRoleIsSameAsThis(castOther));
        }
 
        public int hashCode() {
@@ -126,16 +125,27 @@ public class EPUserApp extends DomainVo implements java.io.Serializable, Compara
                result = 37 * result + (int) (this.getUserId()==null ? 0 : this.getUserId().intValue());
                result = 37 * result + (int) (this.getApp().getId()==null ? 0 : this.getApp().getId().intValue());
                result = 37 * result + (int) (this.getRole().getId()==null ? 0 : this.getRole().getId().intValue());
-               result = 37 * result + (int) (this.priority==null ? 0 : this.priority);
                return result;
        }
 
        public int compareTo(Object other){
            EPUserApp castOther = (EPUserApp) other;
 
-           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);
-           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);
+           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());
+           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());
 
            return c1.compareTo(c2);
        }
+       
+       private boolean otherRoleIsSameAsThis(EPUserApp other){
+               return this.getRole().getId().equals(other.getRole().getId());
+       }
+
+       private boolean otherAppIdIsSameAsThis(EPUserApp other){
+               return this.getApp().getId().equals(other.getApp().getId());
+       }
+
+       private boolean otherUserIdIsSameAsThisUserId(EPUserApp other){
+               return this.getUserId().equals(other.getUserId());
+       }
 }