From b7594ee217d0fd4c724fd64dd48d2e154fdd6e90 Mon Sep 17 00:00:00 2001 From: Ankitkumar Patel Date: Wed, 7 Feb 2018 11:12:27 -0500 Subject: [PATCH] Fixed the sonar issues in ONAP-REST. Minor Sonar issues are fixed in the ONAP_REST module. The copyright headers of the changed files are also updated. Issue-ID: POLICY-476 Change-Id: I920d8bcdd7b855e3e1660a002fb0e4e8d1674e44 Signed-off-by: Ankitkumar Patel --- .../org/onap/policy/rest/jpa/ConstraintValue.java | 5 +++-- .../main/java/org/onap/policy/rest/jpa/Obadvice.java | 3 ++- .../org/onap/policy/rest/jpa/ObadviceExpression.java | 3 ++- .../org/onap/policy/rest/jpa/PIPConfiguration.java | 10 +++++----- .../java/org/onap/policy/rest/jpa/PIPResolver.java | 14 +++++++------- .../java/org/onap/policy/rest/util/MSModelUtils.java | 20 ++++++-------------- .../org/onap/policy/rest/util/PolicyValidation.java | 4 ++-- .../rest/util/PolicyValidationRequestWrapper.java | 8 ++++---- 8 files changed, 31 insertions(+), 36 deletions(-) diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/jpa/ConstraintValue.java b/ONAP-REST/src/main/java/org/onap/policy/rest/jpa/ConstraintValue.java index 4943a41c8..f2cdbf179 100644 --- a/ONAP-REST/src/main/java/org/onap/policy/rest/jpa/ConstraintValue.java +++ b/ONAP-REST/src/main/java/org/onap/policy/rest/jpa/ConstraintValue.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-REST * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -104,7 +104,8 @@ public class ConstraintValue implements Serializable { public void setAttribute(Attribute attribute) { this.attribute = attribute; } - + + @Override public ConstraintValue clone() { ConstraintValue constraint = new ConstraintValue(); diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/jpa/Obadvice.java b/ONAP-REST/src/main/java/org/onap/policy/rest/jpa/Obadvice.java index b3b52cdd4..1b2fc3ada 100644 --- a/ONAP-REST/src/main/java/org/onap/policy/rest/jpa/Obadvice.java +++ b/ONAP-REST/src/main/java/org/onap/policy/rest/jpa/Obadvice.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-REST * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -209,6 +209,7 @@ public class Obadvice implements Serializable { } @Transient + @Override public Obadvice clone() { Obadvice obadvice = new Obadvice(); diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/jpa/ObadviceExpression.java b/ONAP-REST/src/main/java/org/onap/policy/rest/jpa/ObadviceExpression.java index 7b0db3f72..6992843db 100644 --- a/ONAP-REST/src/main/java/org/onap/policy/rest/jpa/ObadviceExpression.java +++ b/ONAP-REST/src/main/java/org/onap/policy/rest/jpa/ObadviceExpression.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-REST * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -105,6 +105,7 @@ public class ObadviceExpression implements Serializable { this.obadvice = obadvice; } + @Override public ObadviceExpression clone() { ObadviceExpression expression = new ObadviceExpression(); diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/jpa/PIPConfiguration.java b/ONAP-REST/src/main/java/org/onap/policy/rest/jpa/PIPConfiguration.java index 01f5cfcff..a921a0c35 100644 --- a/ONAP-REST/src/main/java/org/onap/policy/rest/jpa/PIPConfiguration.java +++ b/ONAP-REST/src/main/java/org/onap/policy/rest/jpa/PIPConfiguration.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-REST * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -248,7 +248,7 @@ public class PIPConfiguration implements Serializable { @Transient public void clearConfigParams() { - while (this.pipconfigParams.isEmpty() == false) { + while (!this.pipconfigParams.isEmpty()) { this.removePipconfigParam(this.pipconfigParams.iterator().next()); } } @@ -392,7 +392,7 @@ public class PIPConfiguration implements Serializable { // Go through each property // for (Object nme : properties.keySet()) { - if (nme.toString().startsWith(id) == false) { + if (!nme.toString().startsWith(id)) { continue; } if (nme.equals(id + ".classname")) { @@ -450,7 +450,7 @@ public class PIPConfiguration implements Serializable { } else { prefix = name; } - if (prefix.endsWith(".") == false) { + if (!prefix.endsWith(".")) { prefix = prefix + "."; } Map map = new HashMap<>(); @@ -501,7 +501,7 @@ public class PIPConfiguration implements Serializable { if (this.description != null) { props.setProperty(prefix + "description", this.description); } - if (this.issuer != null && this.issuer.isEmpty() == false) { + if (this.issuer != null && !this.issuer.isEmpty()) { props.setProperty(prefix + "issuer", this.issuer); } diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/jpa/PIPResolver.java b/ONAP-REST/src/main/java/org/onap/policy/rest/jpa/PIPResolver.java index 4838639f9..a5e9ef824 100644 --- a/ONAP-REST/src/main/java/org/onap/policy/rest/jpa/PIPResolver.java +++ b/ONAP-REST/src/main/java/org/onap/policy/rest/jpa/PIPResolver.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-REST * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -254,7 +254,7 @@ public class PIPResolver implements Serializable { @Transient public void clearParams() { - while (this.pipresolverParams.isEmpty() == false) { + while (!this.pipresolverParams.isEmpty()) { this.removePipresolverParam(this.pipresolverParams.iterator().next()); } } @@ -295,7 +295,7 @@ public class PIPResolver implements Serializable { // Go through each property // for (Object nme : properties.keySet()) { - if (nme.toString().startsWith(prefix) == false) { + if (!nme.toString().startsWith(prefix)) { continue; } if (nme.equals(prefix + ".classname")) { @@ -319,7 +319,7 @@ public class PIPResolver implements Serializable { public Map getConfiguration(String prefix) { String pref = prefix; Map map = new HashMap<>(); - if (prefix.endsWith(".") == false) { + if (!prefix.endsWith(".")) { pref = prefix + "."; } map.put(pref + "classname", this.classname); @@ -327,7 +327,7 @@ public class PIPResolver implements Serializable { if (this.description != null) { map.put(pref + "description", this.description); } - if (this.issuer != null && this.issuer.isEmpty() != false) { + if (this.issuer != null && this.issuer.isEmpty()) { map.put(pref + "issuer", this.issuer); } for (PIPResolverParam param : this.pipresolverParams) { @@ -339,7 +339,7 @@ public class PIPResolver implements Serializable { @Transient public void generateProperties(Properties props, String prefix) { String pref = prefix; - if (prefix.endsWith(".") == false) { + if (!prefix.endsWith(".")) { pref = prefix + "."; } props.setProperty(pref + "classname", this.classname); @@ -347,7 +347,7 @@ public class PIPResolver implements Serializable { if (this.description != null) { props.setProperty(pref + "description", this.description); } - if (this.issuer != null && this.issuer.isEmpty() != false) { + if (this.issuer != null && this.issuer.isEmpty()) { props.setProperty(pref + "issuer", this.issuer); } for (PIPResolverParam param : this.pipresolverParams) { diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/util/MSModelUtils.java b/ONAP-REST/src/main/java/org/onap/policy/rest/util/MSModelUtils.java index e96396e0c..18fd80c63 100644 --- a/ONAP-REST/src/main/java/org/onap/policy/rest/util/MSModelUtils.java +++ b/ONAP-REST/src/main/java/org/onap/policy/rest/util/MSModelUtils.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-REST * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -102,7 +102,7 @@ public class MSModelUtils { // Pulling out dependency from file while (treeItr.hasNext()) { - EObject obj = (EObject) treeItr.next(); + EObject obj = treeItr.next(); if (obj instanceof EClassifier) { EClassifier eClassifier = (EClassifier) obj; className = eClassifier.getName(); @@ -184,9 +184,7 @@ public class MSModelUtils { logger.error("Error loading Encore Resource for new Model" + e); } - EPackage root = (EPackage) resource.getContents().get(0); - - return root; + return (EPackage) resource.getContents().get(0); } private HashMap getEEnum(EObject obj) { @@ -352,10 +350,7 @@ public class MSModelUtils { public JSONObject buildJavaObject(Map map){ - JSONObject returnValue = new JSONObject(map); - - return returnValue; - + return new JSONObject(map); } public Map getRefAttributeList(EPackage root, String className, String superClass){ @@ -651,9 +646,7 @@ public class MSModelUtils { } Gson gson = new Gson(); - String json = gson.toJson(myObject); - - return json; + return gson.toJson(myObject); } public Map getRefclass(Map classMap, String className){ @@ -687,8 +680,7 @@ public class MSModelUtils { } } - String returnValue = createJson(workingMap, classMap, modelName); - return returnValue; + return createJson(workingMap, classMap, modelName); } public List getFullDependencyList(List dependency, Map classMap) { diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java b/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java index 77dcbdc1d..446073d40 100644 --- a/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java +++ b/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy Engine * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -306,7 +306,7 @@ public class PolicyValidation { valid = false; } } else if ("PROPERTIES".equals(configType)) { - if (!PolicyUtils.isPropValid(configBodyData)||configBodyData.equals("")) { + if (!PolicyUtils.isPropValid(configBodyData) || "".equals(configBodyData)) { responseString.append("Config Body: Property data is not valid" + HTML_ITALICS_LNBREAK); valid = false; } diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidationRequestWrapper.java b/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidationRequestWrapper.java index 4267ff9fc..f19773964 100644 --- a/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidationRequestWrapper.java +++ b/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidationRequestWrapper.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy Engine * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -231,10 +231,10 @@ public class PolicyValidationRequestWrapper { ArrayList attributeList = new ArrayList<>(); if (matching != null) { - for (String keyField : matching.keySet()) { + for (Map.Entry entry : matching.entrySet()) { LinkedHashMap attributeMap = new LinkedHashMap<>(); - String key = keyField; - String value = matching.get(keyField); + String key = entry.getKey(); + String value = entry.getValue(); attributeMap.put("key", key); attributeMap.put("value", value); attributeList.add(attributeMap); -- 2.16.6