diff options
author | Jim Hahn <jrh3@att.com> | 2020-04-07 13:58:09 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-04-07 17:15:07 -0400 |
commit | 9b3ff5f270572a6760ff07dda9577cdadb53b088 (patch) | |
tree | eacd325199fbb72fddaba94a057178a19e9c3360 /models-interactions/model-impl/appc | |
parent | 3000fdca611c32b7001c553621660b8ea0d2eb49 (diff) |
Address sonar issues in models
Addressed the following sonar issues:
- use RE2 instead of java.util Pattern for "+" and "*"
- don't use deprecated methods
- for Date(long), sonar appeared not to parse the argument's
type correctly. Modified the code slightly to make sonar happy
- duplicate blocks of code
- either log or throw
- missing assert in junit
- for SDNR & VFC, eliminated threads, as they are unnecessary
- duplicate code block in different branches
- useless assignments
- redeclaring abstract methods
- cyclomatic complexity
- used lombok in some cases (e.g., EqualsAndHashCode)
- assert argument order
- actually deleted ControlLoopTargetType, because it is not needed
and sonar complains regardless of which order is used
- add private constructor to utility classes
- use StandardCharsets instead of literals
Also:
- added logback-test.xml to SO to eliminate the voluminous output
from the junit test
Issue-ID: POLICY-2305
Change-Id: I586c331781bedbd54a115a71847d04d293689445
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-impl/appc')
3 files changed, 9 insertions, 190 deletions
diff --git a/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/CommonHeader.java b/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/CommonHeader.java index f0419efe9..058323412 100644 --- a/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/CommonHeader.java +++ b/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/CommonHeader.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * appc * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,12 +29,13 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Map; import java.util.UUID; - +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @Getter @Setter +@EqualsAndHashCode public class CommonHeader implements Serializable { private static final long serialVersionUID = -3581658269910980336L; @@ -88,79 +89,4 @@ public class CommonHeader implements Serializable { + ", RequestId=" + requestId + ", SubrequestId=" + subRequestId + ", RequestTrack=" + requestTrack + ", Flags=" + flags + "]"; } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((apiVer == null) ? 0 : apiVer.hashCode()); - result = prime * result + ((flags == null) ? 0 : flags.hashCode()); - result = prime * result + ((originatorId == null) ? 0 : originatorId.hashCode()); - result = prime * result + ((requestId == null) ? 0 : requestId.hashCode()); - result = prime * result + ((requestTrack == null) ? 0 : requestTrack.hashCode()); - result = prime * result + ((subRequestId == null) ? 0 : subRequestId.hashCode()); - result = prime * result + ((timeStamp == null) ? 0 : timeStamp.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - CommonHeader other = (CommonHeader) obj; - if (apiVer == null) { - if (other.apiVer != null) { - return false; - } - } else if (!apiVer.equals(other.apiVer)) { - return false; - } - if (flags == null) { - if (other.flags != null) { - return false; - } - } else if (!flags.equals(other.flags)) { - return false; - } - if (originatorId == null) { - if (other.originatorId != null) { - return false; - } - } else if (!originatorId.equals(other.originatorId)) { - return false; - } - if (requestId == null) { - if (other.requestId != null) { - return false; - } - } else if (!requestId.equals(other.requestId)) { - return false; - } - if (requestTrack == null) { - if (other.requestTrack != null) { - return false; - } - } else if (!requestTrack.equals(other.requestTrack)) { - return false; - } - if (subRequestId == null) { - if (other.subRequestId != null) { - return false; - } - } else if (!subRequestId.equals(other.subRequestId)) { - return false; - } - if (timeStamp == null) { - return other.timeStamp == null; - } else { - return timeStamp.equals(other.timeStamp); - } - } } diff --git a/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/Request.java b/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/Request.java index e340360af..08cc163c0 100644 --- a/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/Request.java +++ b/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/Request.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * appc * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,11 +26,13 @@ import com.google.gson.annotations.SerializedName; import java.io.Serializable; import java.util.HashMap; import java.util.Map; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @Getter @Setter +@EqualsAndHashCode public class Request implements Serializable { private static final long serialVersionUID = -3912323643990646431L; @@ -54,74 +56,6 @@ public class Request implements Serializable { } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((action == null) ? 0 : action.hashCode()); - result = prime * result + ((commonHeader == null) ? 0 : commonHeader.hashCode()); - result = prime * result + ((objectId == null) ? 0 : objectId.hashCode()); - result = prime * result + ((payload == null) ? 0 : payload.hashCode()); - result = prime * result + ((targetId == null) ? 0 : targetId.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - - Request other = (Request) obj; - if (action == null) { - if (other.action != null) { - return false; - } - } else if (!action.equals(other.action)) { - return false; - } - - if (commonHeader == null) { - if (other.commonHeader != null) { - return false; - } - } else if (!commonHeader.equals(other.commonHeader)) { - return false; - } - - if (objectId == null) { - if (other.objectId != null) { - return false; - } - } else if (!objectId.equals(other.objectId)) { - return false; - } - - if (payload == null) { - if (other.payload != null) { - return false; - } - } else if (!payload.equals(other.payload)) { - return false; - } - - if (targetId == null) { - if (other.targetId != null) { - return false; - } - } else if (!targetId.equals(other.targetId)) { - return false; - } - - return true; - } - - @Override public String toString() { return "Request [CommonHeader=" + commonHeader + ", Action=" + action + ", TargetId=" + targetId + ", ObjectId=" + objectId + ", Payload=" + payload + "]"; diff --git a/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/Response.java b/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/Response.java index fb70151f6..368876f93 100644 --- a/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/Response.java +++ b/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/Response.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * appc * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,11 +26,13 @@ import com.google.gson.annotations.SerializedName; import java.io.Serializable; import java.util.HashMap; import java.util.Map; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @Getter @Setter +@EqualsAndHashCode public class Response implements Serializable { private static final long serialVersionUID = 434953706339865151L; @@ -71,47 +73,4 @@ public class Response implements Serializable { public String toString() { return "Response [CommonHeader=" + commonHeader + ", Status=" + status + ", Payload=" + payload + "]"; } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((commonHeader == null) ? 0 : commonHeader.hashCode()); - result = prime * result + ((payload == null) ? 0 : payload.hashCode()); - result = prime * result + ((status == null) ? 0 : status.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - Response other = (Response) obj; - if (commonHeader == null) { - if (other.commonHeader != null) { - return false; - } - } else if (!commonHeader.equals(other.commonHeader)) { - return false; - } - if (payload == null) { - if (other.payload != null) { - return false; - } - } else if (!payload.equals(other.payload)) { - return false; - } - if (status == null) { - return other.status == null; - } else { - return status.equals(other.status); - } - } } |