diff options
author | 2021-02-11 15:55:33 -0500 | |
---|---|---|
committer | 2021-02-19 18:38:01 +0000 | |
commit | 13a50bb9b035c6408019ef58297009f7e3fe2779 (patch) | |
tree | 8f773bef932f1e1cc1d04d32741c70788b50c2c7 /gui-editors/gui-editor-apex | |
parent | b3982731bc994a0de656e36905ae42ea5246595d (diff) |
Fix sonars in gui
Addressed the following issues (java only):
- assignment to static field
- expression is always true
- duplicate character in regex
- duplicate code
- remove Thread.sleep() from junit test
Issue-ID: POLICY-3063
Change-Id: I70951ed47defad5baa6c957852663688e51fa88a
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'gui-editors/gui-editor-apex')
9 files changed, 46 insertions, 136 deletions
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorMain.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorMain.java index d8a4030..53d94c8 100644 --- a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorMain.java +++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorMain.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2021 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,6 +23,7 @@ package org.onap.policy.gui.editors.apex.rest; import java.io.PrintStream; +import java.util.concurrent.atomic.AtomicReference; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -59,7 +61,7 @@ public class ApexEditorMain { private ApexEditor apexEditor = null; // The parameters for the editor - private static ApexEditorParameters parameters = null; + private static AtomicReference<ApexEditorParameters> parameters = new AtomicReference<>(); // Output and error streams for messages private final PrintStream outStream; @@ -79,17 +81,17 @@ public class ApexEditorMain { try { // Get and check the parameters - parameters = parser.parse(args); + parameters.set(parser.parse(args)); } catch (final ApexEditorParameterException e) { throw new ApexEditorParameterException(REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, " + e.getMessage() + '\n' + parser.getHelp(ApexEditorMain.class.getName()), e); } - if (parameters.isHelp()) { + if (parameters.get().isHelp()) { throw new ApexEditorParameterException(parser.getHelp(ApexEditorMain.class.getName())); } // Validate the parameters - final String validationMessage = parameters.validate(); + final String validationMessage = parameters.get().validate(); if (validationMessage.length() > 0) { throw new ApexEditorParameterException(REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + validationMessage + '\n' + parser.getHelp(ApexEditorMain.class.getName())); @@ -102,29 +104,29 @@ public class ApexEditorMain { * Initialize the Apex editor. */ public void init() { - outStream.println( - REST_ENDPOINT_PREFIX + this.toString() + ") starting at " + parameters.getBaseUri().toString() + " . . ."); + outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at " + + parameters.get().getBaseUri().toString() + " . . ."); try { state = EditorState.INITIALIZING; // Start the editor - apexEditor = new ApexEditor(parameters); + apexEditor = new ApexEditor(parameters.get()); // Add a shutdown hook to shut down the editor when the process is exiting Runtime.getRuntime().addShutdownHook(new Thread(new ApexEditorShutdownHook())); state = EditorState.RUNNING; - if (parameters.getTimeToLive() == ApexEditorParameters.INFINITY_TIME_TO_LIVE) { - outStream.println( - REST_ENDPOINT_PREFIX + this.toString() + ") started at " + parameters.getBaseUri().toString()); + if (parameters.get().getTimeToLive() == ApexEditorParameters.INFINITY_TIME_TO_LIVE) { + outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started at " + + parameters.get().getBaseUri().toString()); } else { outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started"); } // Find out how long is left to wait - long timeRemaining = parameters.getTimeToLive(); + long timeRemaining = parameters.get().getTimeToLive(); while (timeRemaining == ApexEditorParameters.INFINITY_TIME_TO_LIVE || timeRemaining > 0) { // decrement the time to live in the non-infinity case if (timeRemaining > 0) { @@ -185,7 +187,7 @@ public class ApexEditorMain { * @return the parameters */ public static ApexEditorParameters getParameters() { - return parameters; + return parameters.get(); } /** diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ContextAlbumHandler.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ContextAlbumHandler.java index abf81b8..2b29367 100644 --- a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ContextAlbumHandler.java +++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ContextAlbumHandler.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2021 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. @@ -114,7 +115,7 @@ public class ContextAlbumHandler implements RestCommandHandler { session.finishSession(result.isOk()); - LOGGER.exit("ContextAlbum/Create" + (result != null && result.isOk() ? OK : NOT_OK)); + LOGGER.exit("ContextAlbum/Create" + (result.isOk() ? OK : NOT_OK)); return result; } @@ -142,7 +143,7 @@ public class ContextAlbumHandler implements RestCommandHandler { session.finishSession(result.isOk()); - LOGGER.exit("ContextAlbum/Update" + (result != null && result.isOk() ? OK : NOT_OK)); + LOGGER.exit("ContextAlbum/Update" + (result.isOk() ? OK : NOT_OK)); return result; } @@ -191,7 +192,7 @@ public class ContextAlbumHandler implements RestCommandHandler { session.finishSession(result.isOk()); - LOGGER.exit("ContextAlbum/Delete" + (result != null && result.isOk() ? OK : NOT_OK)); + LOGGER.exit("ContextAlbum/Delete" + (result.isOk() ? OK : NOT_OK)); return result; } diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ContextSchemaHandler.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ContextSchemaHandler.java index 65aa2fd..a9b856d 100644 --- a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ContextSchemaHandler.java +++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ContextSchemaHandler.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2021 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. @@ -107,7 +108,7 @@ public class ContextSchemaHandler implements RestCommandHandler { session.finishSession(result.isOk()); - LOGGER.exit("ContextSchema/create" + (result != null && result.isOk() ? OK : NOT_OK)); + LOGGER.exit("ContextSchema/create" + (result.isOk() ? OK : NOT_OK)); return result; } @@ -131,7 +132,7 @@ public class ContextSchemaHandler implements RestCommandHandler { session.finishSession(result.isOk()); - LOGGER.exit("ContextSchema/Update" + (result != null && result.isOk() ? OK : NOT_OK)); + LOGGER.exit("ContextSchema/Update" + (result.isOk() ? OK : NOT_OK)); return result; } @@ -169,7 +170,7 @@ public class ContextSchemaHandler implements RestCommandHandler { session.finishSession(result.isOk()); - LOGGER.exit("ContextSchema/Delete" + (result != null && result.isOk() ? OK : NOT_OK)); + LOGGER.exit("ContextSchema/Delete" + (result.isOk() ? OK : NOT_OK)); return result; } diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/EventHandler.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/EventHandler.java index a1e2ff9..debf99a 100644 --- a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/EventHandler.java +++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/EventHandler.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2021 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. @@ -119,7 +120,7 @@ public class EventHandler implements RestCommandHandler { session.finishSession(result.isOk()); - LOGGER.exit("Event/Create" + (result != null && result.isOk() ? OK : NOT_OK)); + LOGGER.exit("Event/Create" + (result.isOk() ? OK : NOT_OK)); return result; } @@ -199,7 +200,7 @@ public class EventHandler implements RestCommandHandler { session.finishSession(result.isOk()); - LOGGER.exit("Event/Update" + (result != null && result.isOk() ? OK : NOT_OK)); + LOGGER.exit("Event/Update" + (result.isOk() ? OK : NOT_OK)); return result; } @@ -248,7 +249,7 @@ public class EventHandler implements RestCommandHandler { session.finishSession(result.isOk()); - LOGGER.exit("Event/Delete" + (result != null && result.isOk() ? OK : NOT_OK)); + LOGGER.exit("Event/Delete" + (result.isOk() ? OK : NOT_OK)); return result; } diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/PolicyHandler.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/PolicyHandler.java index 19130aa..0ceee17 100644 --- a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/PolicyHandler.java +++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/PolicyHandler.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2021 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. @@ -130,7 +131,7 @@ public class PolicyHandler implements RestCommandHandler { session.finishSession(result.isOk()); - LOGGER.exit("Policy/Create" + (result != null && result.isOk() ? OK : NOT_OK)); + LOGGER.exit("Policy/Create" + (result.isOk() ? OK : NOT_OK)); return result; } @@ -528,7 +529,7 @@ public class PolicyHandler implements RestCommandHandler { session.finishSession(result.isOk()); - LOGGER.exit("Policy/Update" + (result != null && result.isOk() ? OK : NOT_OK)); + LOGGER.exit("Policy/Update" + (result.isOk() ? OK : NOT_OK)); return result; } @@ -582,7 +583,7 @@ public class PolicyHandler implements RestCommandHandler { session.finishSession(result.isOk()); - LOGGER.exit("Policy/Delete" + (result != null && result.isOk() ? OK : NOT_OK)); + LOGGER.exit("Policy/Delete" + (result.isOk() ? OK : NOT_OK)); return result; } diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestUtils.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestUtils.java index 819657f..0151aa5 100644 --- a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestUtils.java +++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestUtils.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2021 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. @@ -53,7 +54,7 @@ public abstract class RestUtils { * starts with some kind of bracket [ or ( or {, then has something, then has * bracket. */ - private static final String JSON_INPUT_TYPE_REGEXP = "^\\s*[\\(\\{\\[][\\s+\\S]*[\\)\\}\\]]"; + private static final String JSON_INPUT_TYPE_REGEXP = "^\\s*[\\(\\{\\[][\\s\\S]*[\\)\\}\\]]"; /** * Constructor, block inheritance. diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/TaskHandler.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/TaskHandler.java index 8a52a03..a5dd4cd 100644 --- a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/TaskHandler.java +++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/TaskHandler.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2021 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. @@ -123,7 +124,7 @@ public class TaskHandler implements RestCommandHandler { session.finishSession(result.isOk()); - LOGGER.exit("Task/Create" + (result != null && result.isOk() ? OK : NOT_OK)); + LOGGER.exit("Task/Create" + (result.isOk() ? OK : NOT_OK)); return result; } @@ -387,7 +388,7 @@ public class TaskHandler implements RestCommandHandler { session.finishSession(result.isOk()); - LOGGER.exit("Task/Update" + (result != null && result.isOk() ? OK : NOT_OK)); + LOGGER.exit("Task/Update" + (result.isOk() ? OK : NOT_OK)); return result; } @@ -440,7 +441,7 @@ public class TaskHandler implements RestCommandHandler { session.finishSession(result.isOk()); - LOGGER.exit("Task/Delete" + (result != null && result.isOk() ? OK : NOT_OK)); + LOGGER.exit("Task/Delete" + (result.isOk() ? OK : NOT_OK)); return result; } diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanContextSchema.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanContextSchema.java index bec3fcd..35987d5 100644 --- a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanContextSchema.java +++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanContextSchema.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2021 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,15 @@ package org.onap.policy.gui.editors.apex.rest.handling.bean; import javax.xml.bind.annotation.XmlType; +import lombok.Getter; +import lombok.ToString; /** * The ContextSchema Bean. */ @XmlType +@Getter +@ToString public class BeanContextSchema extends BeanBase { private String name = null; private String version = null; @@ -34,67 +39,4 @@ public class BeanContextSchema extends BeanBase { private String schemaDefinition = null; private String uuid = null; private String description = null; - - /** - * Gets the name. - * - * @return the name - */ - public String getName() { - return name; - } - - /** - * Gets the version. - * - * @return the version - */ - public String getVersion() { - return version; - } - - /** - * Gets the uuid. - * - * @return the uuid - */ - public String getUuid() { - return uuid; - } - - /** - * Gets the description. - * - * @return the description - */ - public String getDescription() { - return description; - } - - /** - * Gets the schema flavour. - * - * @return the schema flavour - */ - public String getSchemaFlavour() { - return schemaFlavour; - } - - /** - * Gets the schema definition. - * - * @return the schema definition - */ - public String getSchemaDefinition() { - return schemaDefinition; - } - - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - return "ContextSchema [name=" + name + ", version=" + version + ", schemaFlavour=" + schemaFlavour - + ", schemaDefinition=" + schemaDefinition + ", uuid=" + uuid + ", description=" + description + "]"; - } } diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanModel.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanModel.java index fdb3c9b..859a841 100644 --- a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanModel.java +++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanModel.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2021 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,60 +23,19 @@ package org.onap.policy.gui.editors.apex.rest.handling.bean; import javax.xml.bind.annotation.XmlType; +import lombok.Getter; +import lombok.ToString; /** * The Model Bean. */ @XmlType +@Getter +@ToString public class BeanModel extends BeanBase { private String name = null; private String version = null; private String uuid = null; private String description = null; - - /** - * Gets the name. - * - * @return the name - */ - public String getName() { - return name; - } - - /** - * Gets the version. - * - * @return the version - */ - public String getVersion() { - return version; - } - - /** - * Gets the uuid. - * - * @return the uuid - */ - public String getUuid() { - return uuid; - } - - /** - * Gets the description. - * - * @return the description - */ - public String getDescription() { - return description; - } - - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - return "Model [name=" + name + ", version=" + version + ", uuid=" + uuid + ", description=" + description + "]"; - } - } |