From 55b2eae0abb1a5b1985ac54694e5a2c54c2e76e5 Mon Sep 17 00:00:00 2001 From: Parshad Patel Date: Wed, 14 Aug 2019 14:58:35 +0900 Subject: Sonar fix in ecomp-portal-BE-common Override "equals(Object obj)" to comply with the contract of the "compareTo(T o)" method Make "auditTrail" transient or serializable Reduce the number of conditional operators (4) used in the expression (maximum allowed 3) Issue-ID: PORTAL-562 Change-Id: Ic867eca2d2f57d68bbc902f27bf0eb9753aeeaa1 Signed-off-by: Parshad Patel --- .../portal/domain/CentralV2RoleFunction.java | 32 +++++++++-- .../portal/domain/ExternalRoleDetails.java | 18 +++--- .../portal/transport/CentralRoleFunction.java | 2 +- .../portal/transport/CentralV2UserApp.java | 64 ++++++++++------------ 4 files changed, 67 insertions(+), 49 deletions(-) diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/CentralV2RoleFunction.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/CentralV2RoleFunction.java index a761103f..be565799 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/CentralV2RoleFunction.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/CentralV2RoleFunction.java @@ -186,8 +186,32 @@ public class CentralV2RoleFunction extends DomainVo implements Serializable, Com String c2 = ((CentralV2RoleFunction)obj).getName(); return (c1 == null || c2 == null) ? 1 : c1.compareTo(c2); - } - - - + } + + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + CentralV2RoleFunction other = (CentralV2RoleFunction) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } } diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/ExternalRoleDetails.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/ExternalRoleDetails.java index bb902786..34b2c509 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/ExternalRoleDetails.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/ExternalRoleDetails.java @@ -47,18 +47,16 @@ import lombok.Setter; @EqualsAndHashCode public class ExternalRoleDetails implements Comparable { - private String name; + private String name; private boolean active; private Integer priority; - private Long appId; // used by ONAP only + private Long appId; // used by ONAP only private Long appRoleId; // used by ONAP only - private List perms; - - @Override - public int compareTo(Object obj) { - EPRole other = (EPRole)obj; - return (this.getName() == null || other.getName() == null) ? 1 : getName().equals(other.getName()) ? 0 : 1; - } - + private List perms; + @Override + public int compareTo(Object obj) { + EPRole other = (EPRole) obj; + return (this.getName() == null || other.getName() == null) ? 1 : getName().equals(other.getName()) ? 0 : 1; + } } diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralRoleFunction.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralRoleFunction.java index a2086331..004f9557 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralRoleFunction.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralRoleFunction.java @@ -50,7 +50,7 @@ public class CentralRoleFunction implements Serializable, Comparable { private Long createdId; private Long modifiedId; private Serializable auditUserId; - private Set auditTrail; + private transient Set auditTrail; private Long rowNum; private String code; private String name; diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralV2UserApp.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralV2UserApp.java index 17007a5f..1e2ca315 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralV2UserApp.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralV2UserApp.java @@ -42,7 +42,7 @@ import java.util.Objects; @SuppressWarnings("rawtypes") public class CentralV2UserApp implements Serializable, Comparable{ - + /** * */ @@ -51,77 +51,73 @@ public class CentralV2UserApp implements Serializable, Comparable{ private CentralApp app; private CentralV2Role role; private Integer priority; - - - + public Long getUserId() { return userId; } - - public void setUserId(Long userId) { this.userId = userId; } - - public CentralApp getApp() { return app; } - - public void setApp(CentralApp app) { this.app = app; } - - public CentralV2Role getRole() { return role; } - - public void setRole(CentralV2Role role) { this.role = role; } - - public Integer getPriority() { return priority; } - - public void setPriority(Integer priority) { this.priority = priority; } @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - if (!(other instanceof CentralV2UserApp)) { - return false; - } - CentralV2UserApp castOther = (CentralV2UserApp) other; - return Objects.equals(this.userId, castOther.userId) && - Objects.equals(this.app, castOther.app) && - Objects.equals(this.role, castOther.role) && - Objects.equals(this.priority, castOther.priority); - } + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((app == null) ? 0 : app.hashCode()); + result = prime * result + ((priority == null) ? 0 : priority.hashCode()); + result = prime * result + ((role == null) ? 0 : role.hashCode()); + result = prime * result + ((userId == null) ? 0 : userId.hashCode()); + return result; + } + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + if (!(other instanceof CentralV2UserApp)) { + return false; + } + CentralV2UserApp castOther = (CentralV2UserApp) other; + return Objects.equals(this.userId, castOther.userId) && + Objects.equals(this.app, castOther.app) && + Objects.equals(this.role, castOther.role) && + Objects.equals(this.priority, castOther.priority); + } public int compareTo(Object other){ CentralV2UserApp castOther = (CentralV2UserApp) other; - Long c1 = (this.getUserId()==null ? 0 : this.getUserId()) + (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.priority==null ? 0 : castOther.priority); + Long c1 = (this.getUserId() == null ? 0 : this.getUserId()) + (this.priority == null ? 0 : this.priority); + Long c2 = (castOther.getUserId() == null ? 0 : castOther.getUserId()); + c2 += (castOther.getApp() == null || castOther.getApp().getId() == null ? 0 : castOther.getApp().getId()); + c2 += (castOther.priority == null ? 0 : castOther.priority); return c1.compareTo(c2); } - } -- cgit 1.2.3-korg