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/sdnr | |
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/sdnr')
7 files changed, 21 insertions, 299 deletions
diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciCommonHeader.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciCommonHeader.java index cdafa6858..0b3e98795 100644 --- a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciCommonHeader.java +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciCommonHeader.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,11 +29,13 @@ import java.time.Instant; import java.util.HashMap; import java.util.Map; import java.util.UUID; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @Getter @Setter +@EqualsAndHashCode public class PciCommonHeader implements Serializable { private static final long serialVersionUID = 5435363539127062114L; @@ -85,71 +87,4 @@ public class PciCommonHeader 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 + ((requestTrack == null) ? 0 : requestTrack.hashCode()); - result = prime * result + ((requestId == null) ? 0 : requestId.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; - } - PciCommonHeader other = (PciCommonHeader) 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 (requestTrack == null) { - if (other.requestTrack != null) { - return false; - } - } else if (!requestTrack.equals(other.requestTrack)) { - return false; - } - if (requestId == null) { - if (other.requestId != null) { - return false; - } - } else if (!requestId.equals(other.requestId)) { - 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/sdnr/src/main/java/org/onap/policy/sdnr/PciRequest.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequest.java index d1430a7dc..03fdfc1e4 100644 --- a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequest.java +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequest.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,11 +25,13 @@ package org.onap.policy.sdnr; import com.google.gson.annotations.SerializedName; import java.io.Serializable; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @Getter @Setter +@EqualsAndHashCode public class PciRequest implements Serializable { private static final long serialVersionUID = 323235565922846624L; @@ -99,47 +101,4 @@ public class PciRequest implements Serializable { public String toString() { return "PciRequest[commonHeader=" + commonHeader + ", action=" + action + ", payload=" + payload + "]"; } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((commonHeader == null) ? 0 : commonHeader.hashCode()); - result = prime * result + ((action == null) ? 0 : action.hashCode()); - result = prime * result + ((payload == null) ? 0 : payload.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; - } - PciRequest other = (PciRequest) obj; - if (commonHeader == null) { - if (other.commonHeader != null) { - return false; - } - } else if (!commonHeader.equals(other.commonHeader)) { - return false; - } - if (action == null) { - if (other.action != null) { - return false; - } - } else if (!action.equals(other.action)) { - return false; - } - if (payload == null) { - return other.payload == null; - } else { - return payload.equals(other.payload); - } - } } diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequestWrapper.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequestWrapper.java index 4de3a0d30..b4453ad93 100644 --- a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequestWrapper.java +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequestWrapper.java @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,11 +23,13 @@ package org.onap.policy.sdnr; import java.io.Serializable; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @Getter @Setter +@EqualsAndHashCode(callSuper = true) public class PciRequestWrapper extends PciWrapper implements Serializable { private static final long serialVersionUID = 879766924715980798L; @@ -45,31 +48,4 @@ public class PciRequestWrapper extends PciWrapper implements Serializable { public String toString() { return "RequestWrapper [body=" + body + ", toString()=" + super.toString() + "]"; } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + ((body == null) ? 0 : body.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; - } - PciRequestWrapper other = (PciRequestWrapper) obj; - if (body == null) { - return other.body == null; - } else { - return body.equals(other.body); - } - } } diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponse.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponse.java index 0bc2eb4cf..5d7697eed 100644 --- a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponse.java +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponse.java @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,11 +25,13 @@ package org.onap.policy.sdnr; import com.google.gson.annotations.SerializedName; import java.io.Serializable; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @Getter @Setter +@EqualsAndHashCode public class PciResponse implements Serializable { private static final long serialVersionUID = 8375708697287669750L; @@ -62,47 +65,4 @@ public class PciResponse implements Serializable { return "PciResponse[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; - } - PciResponse other = (PciResponse) 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); - } - } } diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseWrapper.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseWrapper.java index e1613645d..a41ec90bc 100644 --- a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseWrapper.java +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseWrapper.java @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,11 +23,13 @@ package org.onap.policy.sdnr; import java.io.Serializable; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @Getter @Setter +@EqualsAndHashCode(callSuper = true) public class PciResponseWrapper extends PciWrapper implements Serializable { private static final long serialVersionUID = 109837814781086802L; @@ -41,31 +44,4 @@ public class PciResponseWrapper extends PciWrapper implements Serializable { public String toString() { return "ResponseWrapper [body=" + body + ", toString()=" + super.toString() + "]"; } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + ((body == null) ? 0 : body.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; - } - PciResponseWrapper other = (PciResponseWrapper) obj; - if (body == null) { - return other.body == null; - } else { - return body.equals(other.body); - } - } } diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciWrapper.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciWrapper.java index cf0a8a711..a3bffdadd 100644 --- a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciWrapper.java +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciWrapper.java @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,11 +25,13 @@ package org.onap.policy.sdnr; import com.google.gson.annotations.SerializedName; import java.io.Serializable; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @Getter @Setter +@EqualsAndHashCode public class PciWrapper implements Serializable { private static final long serialVersionUID = 375215806432396532L; @@ -55,63 +58,4 @@ public class PciWrapper implements Serializable { return "Wrapper [version=" + version + ", cambriaPartition=" + cambriaPartition + ", rpcName=" + rpcName + ", correlationId=" + correlationId + ", type=" + type + "]"; } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((cambriaPartition == null) ? 0 : cambriaPartition.hashCode()); - result = prime * result + ((correlationId == null) ? 0 : correlationId.hashCode()); - result = prime * result + ((rpcName == null) ? 0 : rpcName.hashCode()); - result = prime * result + ((type == null) ? 0 : type.hashCode()); - result = prime * result + ((version == null) ? 0 : version.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; - } - PciWrapper other = (PciWrapper) obj; - if (cambriaPartition == null) { - if (other.cambriaPartition != null) { - return false; - } - } else if (!cambriaPartition.equals(other.cambriaPartition)) { - return false; - } - if (correlationId == null) { - if (other.correlationId != null) { - return false; - } - } else if (!correlationId.equals(other.correlationId)) { - return false; - } - if (rpcName == null) { - if (other.rpcName != null) { - return false; - } - } else if (!rpcName.equals(other.rpcName)) { - return false; - } - if (type == null) { - if (other.type != null) { - return false; - } - } else if (!type.equals(other.type)) { - return false; - } - if (version == null) { - return other.version == null; - } else { - return version.equals(other.version); - } - } } diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/Status.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/Status.java index a8fe379e7..cdbe9dcb0 100644 --- a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/Status.java +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/Status.java @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,11 +25,13 @@ package org.onap.policy.sdnr; import com.google.gson.annotations.SerializedName; import java.io.Serializable; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @Getter @Setter +@EqualsAndHashCode public class Status implements Serializable { private static final long serialVersionUID = 877641506135467199L; @@ -57,35 +60,4 @@ public class Status implements Serializable { public String toString() { return "Status [code = " + code + ", value = " + value + "]"; } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + code; - result = prime * result + ((value == null) ? 0 : value.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; - } - Status other = (Status) obj; - if (code != other.code) { - return false; - } - if (value == null) { - return other.value == null; - } else { - return value.equals(other.value); - } - } } |