summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorJorge Hernandez <jh1730@att.com>2018-09-14 13:19:52 +0000
committerGerrit Code Review <gerrit@onap.org>2018-09-14 13:19:52 +0000
commitec351d2ee36a37af78476feaff401fac47afe524 (patch)
treeba9de9c01422f471c18120e5e5be618597f3d706 /client
parent330836ad1aa9c88dd3c308fcd750ccd1aaf3e4b9 (diff)
parentcd68fc9bae7d6258f77ff59c1431e4f925f61a4c (diff)
Merge "Address sonar/Checkstyle Issues"
Diffstat (limited to 'client')
-rw-r--r--client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRest.java4
-rw-r--r--client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestMain.java31
-rw-r--r--client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestParameterParser.java2
-rw-r--r--client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestParameters.java73
-rw-r--r--client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestResource.java5
-rw-r--r--client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditor.java4
-rw-r--r--client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorMain.java31
-rw-r--r--client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorParameterParser.java2
-rw-r--r--client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorParameters.java12
-rw-r--r--client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorRestResource.java888
-rw-r--r--client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/RestUtils.java25
-rw-r--r--client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/RestInterfaceTest.java16
-rw-r--r--client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/TestApexEditorStartup.java14
-rw-r--r--client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRest.java4
-rw-r--r--client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestMain.java31
-rw-r--r--client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameterParser.java2
-rw-r--r--client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameters.java21
-rw-r--r--client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRest.java4
-rw-r--r--client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestMain.java31
-rw-r--r--client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestParameterParser.java2
-rw-r--r--client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestParameters.java14
-rw-r--r--client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestResource.java103
22 files changed, 706 insertions, 613 deletions
diff --git a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRest.java b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRest.java
index 1fb7a2259..0ebeec446 100644
--- a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRest.java
+++ b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRest.java
@@ -59,14 +59,14 @@ public class ApexDeploymentRest {
// Create a resource configuration that scans for JAX-RS resources and providers
// in org.onap.policy.apex.client.deployment.rest package
- final ResourceConfig rc = new ResourceConfig().packages(parameters.getRESTPackages());
+ final ResourceConfig rc = new ResourceConfig().packages(parameters.getRestPackages());
// Add MultiPartFeature class for jersey-media-multipart
rc.register(MultiPartFeature.class);
// create and start a new instance of grizzly http server
// exposing the Jersey application at BASE_URI
- server = GrizzlyHttpServerFactory.createHttpServer(parameters.getBaseURI(), rc);
+ server = GrizzlyHttpServerFactory.createHttpServer(parameters.getBaseUri(), rc);
// Add static content
server.getServerConfiguration().addHttpHandler(new org.glassfish.grizzly.http.server.CLStaticHttpHandler(
diff --git a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestMain.java b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestMain.java
index a0e6641db..73374053f 100644
--- a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestMain.java
+++ b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestMain.java
@@ -22,12 +22,21 @@ package org.onap.policy.apex.client.deployment.rest;
import java.io.PrintStream;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
/**
* The main class for ApexDeploymentRest.
*
* @author Michael Watkins (michael.watkins@ericsson.com)
*/
public class ApexDeploymentRestMain {
+ // Logger for this class
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexDeploymentRestMain.class);
+
+ // Recurring string constants
+ private static final String REST_ENDPOINT_PREFIX = "Apex Services REST endpoint (";
+
// Services state
public enum ServicesState {
STOPPED, READY, INITIALIZING, RUNNING
@@ -54,7 +63,7 @@ public class ApexDeploymentRestMain {
final ApexDeploymentRestMain restMain = new ApexDeploymentRestMain(args, System.out);
restMain.init();
} catch (final Exception e) {
- System.err.println(e.getMessage());
+ LOGGER.error("start failed", e);
}
}
@@ -76,7 +85,7 @@ public class ApexDeploymentRestMain {
parameters = parser.parse(args);
} catch (final ApexDeploymentRestParameterException e) {
throw new ApexDeploymentRestParameterException(
- "Apex Services REST endpoint (" + this.toString() + ") parameter error, " + e.getMessage() + '\n'
+ REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, " + e.getMessage() + '\n'
+ parser.getHelp(ApexDeploymentRestMain.class.getCanonicalName()));
}
@@ -89,7 +98,7 @@ public class ApexDeploymentRestMain {
final String validationMessage = parameters.validate();
if (validationMessage.length() > 0) {
throw new ApexDeploymentRestParameterException(
- "Apex Services REST endpoint (" + this.toString() + ") parameters invalid, " + validationMessage
+ REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + validationMessage
+ '\n' + parser.getHelp(ApexDeploymentRestMain.class.getCanonicalName()));
}
@@ -100,8 +109,8 @@ public class ApexDeploymentRestMain {
* Initialize the rest service.
*/
public void init() {
- outStream.println("Apex Services REST endpoint (" + this.toString() + ") starting at "
- + parameters.getBaseURI().toString() + " . . .");
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at "
+ + parameters.getBaseUri().toString() + " . . .");
try {
state = ServicesState.INITIALIZING;
@@ -115,10 +124,10 @@ public class ApexDeploymentRestMain {
state = ServicesState.RUNNING;
if (parameters.getTimeToLive() == ApexDeploymentRestParameters.INFINITY_TIME_TO_LIVE) {
- outStream.println("Apex Services REST endpoint (" + this.toString() + ") started at "
- + parameters.getBaseURI().toString());
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started at "
+ + parameters.getBaseUri().toString());
} else {
- outStream.println("Apex Services REST endpoint (" + this.toString() + ") started");
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started");
}
// Find out how long is left to wait
@@ -134,7 +143,7 @@ public class ApexDeploymentRestMain {
}
} catch (final Exception e) {
outStream.println(
- "Apex Services REST endpoint (" + this.toString() + ") failed at with error: " + e.getMessage());
+ REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage());
} finally {
if (apexDeploymentRest != null) {
apexDeploymentRest.shutdown();
@@ -167,11 +176,11 @@ public class ApexDeploymentRestMain {
*/
public void shutdown() {
if (apexDeploymentRest != null) {
- outStream.println("Apex Services REST endpoint (" + this.toString() + ") shutting down");
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") shutting down");
apexDeploymentRest.shutdown();
}
state = ServicesState.STOPPED;
- outStream.println("Apex Services REST endpoint (" + this.toString() + ") shut down");
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") shut down");
}
/**
diff --git a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestParameterParser.java b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestParameterParser.java
index 564be435c..7e305788f 100644
--- a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestParameterParser.java
+++ b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestParameterParser.java
@@ -81,7 +81,7 @@ public class ApexDeploymentRestParameterParser {
}
try {
if (commandLine.hasOption('p')) {
- parameters.setRESTPort(((Number) commandLine.getParsedOptionValue("port")).intValue());
+ parameters.setRestPort(((Number) commandLine.getParsedOptionValue("port")).intValue());
}
} catch (final ParseException e) {
throw new ApexDeploymentRestParameterException("error parsing argument \"port\" :" + e.getMessage(), e);
diff --git a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestParameters.java b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestParameters.java
index af8cc5ab4..cadc3ef4e 100644
--- a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestParameters.java
+++ b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestParameters.java
@@ -44,6 +44,11 @@ public class ApexDeploymentRestParameters {
private int restPort = DEFAULT_REST_PORT;
private long timeToLive = INFINITY_TIME_TO_LIVE;
+ /**
+ * Validate the parameters.
+ *
+ * @return the result of the validation
+ */
public String validate() {
String validationMessage = "";
validationMessage += validatePort();
@@ -52,18 +57,38 @@ public class ApexDeploymentRestParameters {
return validationMessage;
}
- public URI getBaseURI() {
+ /**
+ * Gets the base uri.
+ *
+ * @return the base uri
+ */
+ public URI getBaseUri() {
return URI.create(DEFAULT_SERVER_URI_ROOT + restPort + DEFAULT_REST_PATH);
}
- public String[] getRESTPackages() {
+ /**
+ * Gets the rest packages.
+ *
+ * @return the rest packages
+ */
+ public String[] getRestPackages() {
return DEFAULT_PACKAGES;
}
+ /**
+ * Gets the static path.
+ *
+ * @return the static path
+ */
public String getStaticPath() {
return DEFAULT_STATIC_PATH;
}
+ /**
+ * Validate port.
+ *
+ * @return the string
+ */
private String validatePort() {
if (restPort < 1024 || restPort > 65535) {
return "port must be greater than 1023 and less than 65536\n";
@@ -72,6 +97,11 @@ public class ApexDeploymentRestParameters {
}
}
+ /**
+ * Validate time to live.
+ *
+ * @return the string
+ */
private String validateTimeToLive() {
if (timeToLive < -1) {
return "time to live must be greater than -1 (set to -1 to wait forever)\n";
@@ -80,34 +110,67 @@ public class ApexDeploymentRestParameters {
}
}
+ /**
+ * Checks if is help set.
+ *
+ * @return true, if is help set
+ */
public boolean isHelpSet() {
return helpSet;
}
+ /**
+ * Sets the help.
+ *
+ * @param helpSet the new help
+ */
public void setHelp(final boolean helpSet) {
this.helpSet = helpSet;
}
- public int getRESTPort() {
+ /**
+ * Gets the rest port.
+ *
+ * @return the rest port
+ */
+ public int getRestPort() {
return restPort;
}
- public void setRESTPort(final int restPort) {
+ /**
+ * Sets the rest port.
+ *
+ * @param restPort the new rest port
+ */
+ public void setRestPort(final int restPort) {
this.restPort = restPort;
}
+ /**
+ * Gets the time to live.
+ *
+ * @return the time to live
+ */
public long getTimeToLive() {
return timeToLive;
}
+ /**
+ * Sets the time to live.
+ *
+ * @param timeToLive the new time to live
+ */
public void setTimeToLive(final long timeToLive) {
this.timeToLive = timeToLive;
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
@Override
public String toString() {
final StringBuilder ret = new StringBuilder();
- ret.append(this.getClass().getSimpleName()).append(": URI=").append(this.getBaseURI()).append(", TTL=")
+ ret.append(this.getClass().getSimpleName()).append(": URI=").append(this.getBaseUri()).append(", TTL=")
.append(this.getTimeToLive()).append("sec");
return ret.toString();
}
diff --git a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestResource.java b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestResource.java
index 18aae5001..d3a7d654a 100644
--- a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestResource.java
+++ b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestResource.java
@@ -60,11 +60,6 @@ public class ApexDeploymentRestResource {
private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexDeploymentRestResource.class);
/**
- * Constructor, a new resource director is created for each request.
- */
- public ApexDeploymentRestResource() {}
-
- /**
* Query the engine service for data.
*
* @param hostName the host name of the engine service to connect to.
diff --git a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditor.java b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditor.java
index cb5e8f6b6..4ce73b750 100644
--- a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditor.java
+++ b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditor.java
@@ -56,11 +56,11 @@ public class ApexEditor {
// Create a resource configuration that scans for JAX-RS resources and providers
// in org.onap.policy.apex.client.editor.rest package
- final ResourceConfig rc = new ResourceConfig().packages(parameters.getRESTPackages());
+ final ResourceConfig rc = new ResourceConfig().packages(parameters.getRestPackages());
// create and start a new instance of grizzly http server
// exposing the Jersey application at BASE_URI
- server = GrizzlyHttpServerFactory.createHttpServer(parameters.getBaseURI(), rc);
+ server = GrizzlyHttpServerFactory.createHttpServer(parameters.getBaseUri(), rc);
// Add static content
server.getServerConfiguration().addHttpHandler(new org.glassfish.grizzly.http.server.CLStaticHttpHandler(
diff --git a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorMain.java b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorMain.java
index 0fa8011c5..3f54467cd 100644
--- a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorMain.java
+++ b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorMain.java
@@ -22,11 +22,20 @@ package org.onap.policy.apex.client.editor.rest;
import java.io.PrintStream;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
/**
* This class is the main class that is used to launch the Apex editor from the command line.
*
*/
public class ApexEditorMain {
+ // Logger for this class
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexEditorMain.class);
+
+ // Recurring string constants
+ private static final String REST_ENDPOINT_PREFIX = "Apex Editor REST endpoint (";
+
/**
* The Enum EditorState holds the current state of the editor.
*/
@@ -65,7 +74,7 @@ public class ApexEditorMain {
final ApexEditorMain editorMain = new ApexEditorMain(args, System.out);
editorMain.init();
} catch (final Exception e) {
- System.err.println(e.getMessage());
+ LOGGER.error("start failed", e);
}
}
@@ -87,7 +96,7 @@ public class ApexEditorMain {
parameters = parser.parse(args);
} catch (final ApexEditorParameterException e) {
throw new ApexEditorParameterException(
- "Apex Editor REST endpoint (" + this.toString() + ") parameter error, " + e.getMessage() + '\n'
+ REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, " + e.getMessage() + '\n'
+ parser.getHelp(ApexEditorMain.class.getCanonicalName()));
}
@@ -99,7 +108,7 @@ public class ApexEditorMain {
final String validationMessage = parameters.validate();
if (validationMessage.length() > 0) {
throw new ApexEditorParameterException(
- "Apex Editor REST endpoint (" + this.toString() + ") parameters invalid, " + validationMessage
+ REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + validationMessage
+ '\n' + parser.getHelp(ApexEditorMain.class.getCanonicalName()));
}
@@ -110,8 +119,8 @@ public class ApexEditorMain {
* Initialize the Apex editor.
*/
public void init() {
- outStream.println("Apex Editor REST endpoint (" + this.toString() + ") starting at "
- + parameters.getBaseURI().toString() + " . . .");
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at "
+ + parameters.getBaseUri().toString() + " . . .");
try {
state = EditorState.INITIALIZING;
@@ -125,10 +134,10 @@ public class ApexEditorMain {
state = EditorState.RUNNING;
if (parameters.getTimeToLive() == ApexEditorParameters.INFINITY_TIME_TO_LIVE) {
- outStream.println("Apex Editor REST endpoint (" + this.toString() + ") started at "
- + parameters.getBaseURI().toString());
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started at "
+ + parameters.getBaseUri().toString());
} else {
- outStream.println("Apex Editor REST endpoint (" + this.toString() + ") started");
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started");
}
// Find out how long is left to wait
@@ -144,7 +153,7 @@ public class ApexEditorMain {
}
} catch (final Exception e) {
outStream.println(
- "Apex Editor REST endpoint (" + this.toString() + ") failed at with error: " + e.getMessage());
+ REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage());
} finally {
if (apexEditor != null) {
apexEditor.shutdown();
@@ -181,11 +190,11 @@ public class ApexEditorMain {
*/
public void shutdown() {
if (apexEditor != null) {
- outStream.println("Apex Editor REST endpoint (" + this.toString() + ") shutting down");
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") shutting down");
apexEditor.shutdown();
}
state = EditorState.STOPPED;
- outStream.println("Apex Editor REST endpoint (" + this.toString() + ") shut down");
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") shut down");
}
/**
diff --git a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorParameterParser.java b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorParameterParser.java
index beb589dca..d67c6b1c6 100644
--- a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorParameterParser.java
+++ b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorParameterParser.java
@@ -88,7 +88,7 @@ public class ApexEditorParameterParser {
}
try {
if (commandLine.hasOption('p')) {
- parameters.setRESTPort(((Number) commandLine.getParsedOptionValue("port")).intValue());
+ parameters.setRestPort(((Number) commandLine.getParsedOptionValue("port")).intValue());
}
} catch (final ParseException e) {
throw new ApexEditorParameterException("error parsing argument \"port\" :" + e.getMessage(), e);
diff --git a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorParameters.java b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorParameters.java
index e0a2cf727..55d10c1a1 100644
--- a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorParameters.java
+++ b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorParameters.java
@@ -75,7 +75,7 @@ public class ApexEditorParameters {
*
* @return the base URI
*/
- public URI getBaseURI() {
+ public URI getBaseUri() {
return URI.create(DEFAULT_SERVER_URI_PREFIX + listenAddress + ':' + restPort + DEFAULT_REST_PATH);
}
@@ -84,7 +84,7 @@ public class ApexEditorParameters {
*
* @return the REST packages
*/
- public String[] getRESTPackages() {
+ public String[] getRestPackages() {
return DEFAULT_PACKAGES;
}
@@ -117,7 +117,7 @@ public class ApexEditorParameters {
*/
private String validateUrl() {
try {
- new URI(getBaseURI().toString()).parseServerAuthority();
+ new URI(getBaseUri().toString()).parseServerAuthority();
return "";
} catch (final URISyntaxException e) {
return "listen address is not valid. " + e.getMessage() + "\n";
@@ -160,7 +160,7 @@ public class ApexEditorParameters {
*
* @return the REST port
*/
- public int getRESTPort() {
+ public int getRestPort() {
return restPort;
}
@@ -169,7 +169,7 @@ public class ApexEditorParameters {
*
* @param incomingRestPort the REST port
*/
- public void setRESTPort(final int incomingRestPort) {
+ public void setRestPort(final int incomingRestPort) {
this.restPort = incomingRestPort;
}
@@ -199,7 +199,7 @@ public class ApexEditorParameters {
@Override
public String toString() {
final StringBuilder ret = new StringBuilder();
- ret.append(this.getClass().getSimpleName()).append(": URI=").append(this.getBaseURI()).append(", TTL=")
+ ret.append(this.getClass().getSimpleName()).append(": URI=").append(this.getBaseUri()).append(", TTL=")
.append(this.getTimeToLive()).append("sec");
return ret.toString();
}
diff --git a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorRestResource.java b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorRestResource.java
index cd52035a5..8bed63d28 100644
--- a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorRestResource.java
+++ b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorRestResource.java
@@ -70,40 +70,52 @@ import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
/**
- * The class represents the root resource exposed at the base URL<br>
- * The url to access this resource would be in the form {@code <baseURL>/rest/<session>/....} <br>
- * For example: a PUT request to the following URL
- * {@code http://localhost:8080/apex/rest/109/ContextSchema/Update}, with a JSON string payload
- * containing the new {@code Schema} in the body, can be explained as:
- * <ul>
- * <li>The server or servlet is running at the base URL {@code http://localhost:8080/apex}
- * <li>This resource {@code ApexRestEditorResource} is used because the path {@code rest/109}
- * matches the {@code Path} filter specification for this Resource
- * ({@code @Path("rest/{session}")}), where the {@code int} path parameter {@code session} is
- * assigned the {@code int} value {@code 109}
- * <li>The path {@code ContextSchema/Update} redirects this call to the method
- * {@link #updateContextSchema(String)}, which should be a {@link javax.ws.rs.PUT}, with a single
- * String in the body/payload which gets mapped to the single String parameter for the method.
- * <li>So, in summary, the REST request updates a {@code ContextSchema} as specified in the payload
- * for {@code session} number {@code 109}
- * </ul>
+ * The class represents the root resource exposed at the base URL<br> The url to access this resource would be in the
+ * form {@code <baseURL>/rest/<session>/....} <br> For example: a PUT request to the following URL
+ * {@code http://localhost:8080/apex/rest/109/ContextSchema/Update}, with a JSON string payload containing the new
+ * {@code Schema} in the body, can be explained as: <ul> <li>The server or servlet is running at the base URL
+ * {@code http://localhost:8080/apex} <li>This resource {@code ApexRestEditorResource} is used because the path
+ * {@code rest/109} matches the {@code Path} filter specification for this Resource ({@code @Path("rest/{session}")}),
+ * where the {@code int} path parameter {@code session} is assigned the {@code int} value {@code 109} <li>The path
+ * {@code ContextSchema/Update} redirects this call to the method {@link #updateContextSchema(String)}, which should be
+ * a {@link javax.ws.rs.PUT}, with a single String in the body/payload which gets mapped to the single String parameter
+ * for the method. <li>So, in summary, the REST request updates a {@code ContextSchema} as specified in the payload for
+ * {@code session} number {@code 109} </ul>
*
- * <b>Note:</b> An allocated {@code Session} identifier must be included in (almost) all requests.
- * Models for different {@code Session} identifiers are completely isolated from one another.
+ * <b>Note:</b> An allocated {@code Session} identifier must be included in (almost) all requests. Models for different
+ * {@code Session} identifiers are completely isolated from one another.
*
- * <b>Note:</b> To create a new {@code Session}, and have a new session ID allocated use
- * {@link javax.ws.rs.GET} request to {@code <baseURL>/rest/-1/Session/Create} (for example:
- * {@code http://localhost:8080/apex/rest/-1/Session/Create} )
+ * <b>Note:</b> To create a new {@code Session}, and have a new session ID allocated use {@link javax.ws.rs.GET} request
+ * to {@code <baseURL>/rest/-1/Session/Create} (for example: {@code http://localhost:8080/apex/rest/-1/Session/Create} )
*
*/
@Path("editor/{session}")
-@Produces({MediaType.APPLICATION_JSON})
-@Consumes({MediaType.APPLICATION_JSON})
+@Produces(
+ { MediaType.APPLICATION_JSON })
+@Consumes(
+ { MediaType.APPLICATION_JSON })
public class ApexEditorRestResource {
// Get a reference to the logger
private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexEditorRestResource.class);
+ // Recurring string constants
+ private static final String IN_TASK = "\" in task ";
+ private static final String POLICY_STATE_CREATED_OTHER_ERROR =
+ "\". The policy and state were created, but there was an error adding the";
+ private static final String IN_STATE = "\" in state \"";
+ private static final String POLICY_CREATED_STATE_ERROR =
+ "\". The policy was created, but there was an error adding the state.";
+ private static final String FOR_POLICY = "\" for policy \"";
+ private static final String NOT_OK = ": Not OK";
+ private static final String TASK_PARTIALLY_DEFINED = " The task has only been partially defined.";
+ private static final String POLICY_PARTIALLY_DEFINED = " The policy has only been partially defined.";
+ private static final String POLICY_WAS_CREATED = "\". The policy was created, ";
+ private static final String VERSION = "version";
+ private static final String POLICY_KEY = "policyKey";
+ private static final String DESCRIPTION = "description";
+ private static final String APEX_KEY_INFO = "apexKeyInfo";
+
// The next session will have this number, stating at 0
private static int nextSession = 0;
@@ -112,79 +124,77 @@ public class ApexEditorRestResource {
// The ID of this session. This gets injected from the URL.
@PathParam("session")
- private int sessionID = -1;
+ private int sessionId = -1;
// The Apex model for the session
private ApexModel sessionApexModel = null;
/**
- * This method sets the Apex model for the current editor session. Don't forget to call
- * {@link #commitChanges()} when finished! This makes requests atomic.
+ * This method sets the Apex model for the current editor session. Don't forget to call {@link #commitChanges()}
+ * when finished! This makes requests atomic.
*
* @return the result of finding the session Apex model and setting it
*/
private ApexApiResult initialiseSessionForChanges() {
- if (sessionID < 0) {
- return new ApexApiResult(Result.FAILED, "Session ID \"" + sessionID + "\" is negative");
+ if (sessionId < 0) {
+ return new ApexApiResult(Result.FAILED, "Session ID \"" + sessionId + "\" is negative");
}
- if (!SESSIONMODELMAP.containsKey(sessionID)) {
- return new ApexApiResult(Result.FAILED, "A session with session ID \"" + sessionID + "\" does not exist");
+ if (!SESSIONMODELMAP.containsKey(sessionId)) {
+ return new ApexApiResult(Result.FAILED, "A session with session ID \"" + sessionId + "\" does not exist");
}
if (sessionApexModel == null) {
- sessionApexModel = SESSIONMODELMAP.get(sessionID).clone();
+ sessionApexModel = SESSIONMODELMAP.get(sessionId).clone();
}
return new ApexApiResult();
}
/**
- * This method sets the Apex model for the current editor session. Don't make any changes to the
- * model.
+ * This method sets the Apex model for the current editor session. Don't make any changes to the model.
*
* @return the result of finding the session Apex model and setting it
*/
private ApexApiResult initialiseSessionForReadOnly() {
- if (sessionID < 0) {
- return new ApexApiResult(Result.FAILED, "Session ID \"" + sessionID + "\" is negative");
+ if (sessionId < 0) {
+ return new ApexApiResult(Result.FAILED, "Session ID \"" + sessionId + "\" is negative");
}
- if (!SESSIONMODELMAP.containsKey(sessionID)) {
- return new ApexApiResult(Result.FAILED, "A session with session ID \"" + sessionID + "\" does not exist");
+ if (!SESSIONMODELMAP.containsKey(sessionId)) {
+ return new ApexApiResult(Result.FAILED, "A session with session ID \"" + sessionId + "\" does not exist");
}
if (sessionApexModel == null) {
- sessionApexModel = SESSIONMODELMAP.get(sessionID);
+ sessionApexModel = SESSIONMODELMAP.get(sessionId);
}
return new ApexApiResult();
}
/**
- * This method commits changes to the Apex model for the current editor session. This should
- * only be called once, at the end of a successful change to the model for this session
+ * This method commits changes to the Apex model for the current editor session. This should only be called once, at
+ * the end of a successful change to the model for this session
*
* @return the result of committing the session Apex model
*/
private ApexApiResult commitChanges() {
if (sessionApexModel == null) {
- return new ApexApiResult(Result.FAILED, "Cannot commit a changes for Session ID \"" + sessionID
- + "\", because it has not been initialised / started");
+ return new ApexApiResult(Result.FAILED, "Cannot commit a changes for Session ID \"" + sessionId
+ + "\", because it has not been initialised / started");
}
- SESSIONMODELMAP.put(sessionID, sessionApexModel);
+ SESSIONMODELMAP.put(sessionId, sessionApexModel);
return new ApexApiResult();
}
/**
- * Creates a new session. Always call this method with sessionID -1, whereby a new sessionID
- * will be allocated. If successful the new sessionID will be available in the first message in
- * the result.
+ * Creates a new session. Always call this method with sessionID -1, whereby a new sessionID will be allocated. If
+ * successful the new sessionID will be available in the first message in the result.
*
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}.
- * This includes the session id for this session.
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}. This includes the session id
+ * for this session.
*/
@GET
@Path("Session/Create")
@@ -192,39 +202,39 @@ public class ApexEditorRestResource {
ApexApiResult ret = null;
LOGGER.entry();
try {
- if (sessionID != -1) {
- ret = new ApexApiResult(Result.FAILED, "Session ID must be set to -1 to create sessions: " + sessionID);
+ if (sessionId != -1) {
+ ret = new ApexApiResult(Result.FAILED, "Session ID must be set to -1 to create sessions: " + sessionId);
return ret;
}
- final int newSessionID = nextSession;
+ final int newSessionId = nextSession;
- if (SESSIONMODELMAP.containsKey(newSessionID)) {
- ret = new ApexApiResult(Result.FAILED, "Session already exists for session: " + newSessionID);
+ if (SESSIONMODELMAP.containsKey(newSessionId)) {
+ ret = new ApexApiResult(Result.FAILED, "Session already exists for session: " + newSessionId);
return ret;
}
- SESSIONMODELMAP.put(newSessionID, new ApexModelFactory().createApexModel(null, true));
- nextSession++;
+ SESSIONMODELMAP.put(newSessionId, new ApexModelFactory().createApexModel(null, true));
+ incrementNextSession();
- ret = new ApexApiResult(Result.SUCCESS, Integer.toString(newSessionID));
+ ret = new ApexApiResult(Result.SUCCESS, Integer.toString(newSessionId));
return ret;
} catch (final Exception e) {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Session/Create" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ String result = "Session/Create" + (ret != null && ret.isOk() ? ": OK" : NOT_OK);
+ LOGGER.exit(result);
}
}
/**
* Load the model from a JSON string for this session.
*
- * @param jsonString the JSON string to be parsed. The returned value(s) will be similar to
- * {@link AxPolicyModel}, with merged {@linkplain AxKeyInfo} for the root object.
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @param jsonString the JSON string to be parsed. The returned value(s) will be similar to {@link AxPolicyModel},
+ * with merged {@linkplain AxKeyInfo} for the root object.
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@PUT
@Path("/Model/Load")
@@ -246,17 +256,17 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Model/Load" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ String result = "Model/Load" + (ret != null && ret.isOk() ? ": OK" : NOT_OK);
+ LOGGER.exit(result);
}
}
/**
- * Analyse the model and return analysis results. If successful the analysis results will be
- * available in the messages in the result.
+ * Analyse the model and return analysis results. If successful the analysis results will be available in the
+ * messages in the result.
*
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@GET
@Path("Model/Analyse")
@@ -275,17 +285,16 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Model/Analyse" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("Model/Analyse" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
/**
- * Validate the model and return validation results. If successful the validation results will
- * be available in the messages in the result.
+ * Validate the model and return validation results. If successful the validation results will be available in the
+ * messages in the result.
*
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@GET
@Path("Model/Validate")
@@ -306,18 +315,16 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Model/Validate" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("Model/Validate" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
/**
* Creates the new model model for this session.
*
- * @param jsonString the JSON string to be parsed containing the new model. See
- * {@linkplain BeanModel}
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @param jsonString the JSON string to be parsed containing the new model. See {@linkplain BeanModel}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@POST
@Path("Model/Create")
@@ -330,9 +337,9 @@ public class ApexEditorRestResource {
return ret;
}
- final BeanModel jsonbean = RestUtils.getJSONParameters(jsonString, BeanModel.class);
+ final BeanModel jsonbean = RestUtils.getJsonParameters(jsonString, BeanModel.class);
ret = sessionApexModel.createModel(jsonbean.getName(), jsonbean.getVersion(), jsonbean.getUuid(),
- jsonbean.getDescription());
+ jsonbean.getDescription());
if (ret.isOk()) {
ret = addKeyInfo2Messages(ret);
@@ -345,18 +352,16 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Model/Create" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("Model/Create" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
/**
* Update the model for this session.
*
- * @param jsonString the JSON string to be parsed containing the updated model. See
- * {@linkplain BeanModel}
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @param jsonString the JSON string to be parsed containing the updated model. See {@linkplain BeanModel}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@PUT
@Path("Model/Update")
@@ -369,9 +374,9 @@ public class ApexEditorRestResource {
return ret;
}
- final BeanModel jsonbean = RestUtils.getJSONParameters(jsonString, BeanModel.class);
+ final BeanModel jsonbean = RestUtils.getJsonParameters(jsonString, BeanModel.class);
ret = sessionApexModel.updateModel(jsonbean.getName(), jsonbean.getVersion(), jsonbean.getUuid(),
- jsonbean.getDescription());
+ jsonbean.getDescription());
if (ret.isOk()) {
commitChanges();
}
@@ -380,17 +385,16 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Model/Update" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("Model/Update" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
/**
- * Gets the key for the model for this session. If successful the model key will be available in
- * the first message in the result. See {@linkplain AxKey}
+ * Gets the key for the model for this session. If successful the model key will be available in the first message
+ * in the result. See {@linkplain AxKey}
*
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@GET
@Path("Model/GetKey")
@@ -409,18 +413,17 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Model/GetKey" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("Model/GetKey" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
/**
- * Retrieve the model for this session. If successful the model will be available in the first
- * message in the result. The returned value will be similar to a {@link AxPolicyModel}, with
- * merged {@linkplain AxKeyInfo} for the root object.
+ * Retrieve the model for this session. If successful the model will be available in the first message in the
+ * result. The returned value will be similar to a {@link AxPolicyModel}, with merged {@linkplain AxKeyInfo} for the
+ * root object.
*
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@GET
@Path("Model/Get")
@@ -444,8 +447,7 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Model/Get" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("Model/Get" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
@@ -476,18 +478,16 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- if (ret != null) {
- LOGGER.exit(ret.isOk());
- }
- LOGGER.info("Model/Download" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ String result = "Model/Download" + (ret != null && ret.isOk() ? ": OK" : NOT_OK);
+ LOGGER.exit(result);
}
}
/**
* Delete the model for this session.
*
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@DELETE
@Path("Model/Delete")
@@ -509,24 +509,23 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Model/Delete" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("Model/Delete" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
/**
- * List key information with the given key names/versions. If successful the result(s) will be
- * available in the result messages. See {@linkplain AxKeyInfo}
+ * List key information with the given key names/versions. If successful the result(s) will be available in the
+ * result messages. See {@linkplain AxKeyInfo}
*
* @param name the name to search for. If null or empty, then all names will be queried
* @param version the version to search for. If null then all versions will be searched for.
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@GET
@Path("KeyInformation/Get")
public ApexApiResult listKeyInformation(@QueryParam("name") final String name,
- @QueryParam("version") final String version) {
+ @QueryParam(VERSION) final String version) {
ApexApiResult ret = null;
String name1 = name;
String version1 = version;
@@ -550,8 +549,7 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("KeyInformation/Get" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("KeyInformation/Get" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
@@ -559,8 +557,8 @@ public class ApexEditorRestResource {
* Creates a context schema with the information in the JSON string passed.
*
* @param jsonString the JSON string to be parsed. See {@linkplain BeanContextSchema}
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@POST
@Path("ContextSchema/Create")
@@ -573,10 +571,10 @@ public class ApexEditorRestResource {
return ret;
}
- final BeanContextSchema jsonbean = RestUtils.getJSONParameters(jsonString, BeanContextSchema.class);
+ final BeanContextSchema jsonbean = RestUtils.getJsonParameters(jsonString, BeanContextSchema.class);
ret = sessionApexModel.createContextSchema(jsonbean.getName(), jsonbean.getVersion(),
- jsonbean.getSchemaFlavour(), jsonbean.getSchemaDefinition(), jsonbean.getUuid(),
- jsonbean.getDescription());
+ jsonbean.getSchemaFlavour(), jsonbean.getSchemaDefinition(), jsonbean.getUuid(),
+ jsonbean.getDescription());
if (ret.isOk()) {
commitChanges();
}
@@ -585,8 +583,7 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("ContextSchema/Create" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("ContextSchema/Create" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
@@ -594,8 +591,8 @@ public class ApexEditorRestResource {
* Update a context schema with the information in the JSON string passed.
*
* @param jsonString the JSON string to be parsed. See {@linkplain BeanContextSchema}
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@PUT
@Path("ContextSchema/Update")
@@ -608,11 +605,11 @@ public class ApexEditorRestResource {
return ret;
}
- final BeanContextSchema jsonbean = RestUtils.getJSONParameters(jsonString, BeanContextSchema.class);
+ final BeanContextSchema jsonbean = RestUtils.getJsonParameters(jsonString, BeanContextSchema.class);
ret = sessionApexModel.updateContextSchema(jsonbean.getName(), jsonbean.getVersion(),
- jsonbean.getSchemaFlavour(), jsonbean.getSchemaDefinition(), jsonbean.getUuid(),
- jsonbean.getDescription());
+ jsonbean.getSchemaFlavour(), jsonbean.getSchemaDefinition(), jsonbean.getUuid(),
+ jsonbean.getDescription());
if (ret.isOk()) {
commitChanges();
}
@@ -621,25 +618,24 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("ContextSchema/Update" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("ContextSchema/Update" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
/**
- * List context schemas with the given key names/versions. If successful the result(s) will be
- * available in the result messages. The returned value(s) will be similar to
- * {@link AxContextSchema}, with merged {@linkplain AxKeyInfo} for the root object.
+ * List context schemas with the given key names/versions. If successful the result(s) will be available in the
+ * result messages. The returned value(s) will be similar to {@link AxContextSchema}, with merged
+ * {@linkplain AxKeyInfo} for the root object.
*
* @param name the name to search for. If null or empty, then all names will be queried
* @param version the version to search for. If null then all versions will be searched for.
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@GET
@Path("ContextSchema/Get")
public ApexApiResult listContextSchemas(@QueryParam("name") final String name,
- @QueryParam("version") final String version) {
+ @QueryParam(VERSION) final String version) {
ApexApiResult ret = null;
String name1 = name;
String version1 = version;
@@ -668,8 +664,7 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("ContextSchema/Get" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("ContextSchema/Get" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
@@ -678,13 +673,13 @@ public class ApexEditorRestResource {
*
* @param name the name to search for. If null or empty, then all names will be queried
* @param version the version to search for. If null then all versions will be searched for.
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@DELETE
@Path("ContextSchema/Delete")
public ApexApiResult deleteContextSchema(@QueryParam("name") final String name,
- @QueryParam("version") final String version) {
+ @QueryParam(VERSION) final String version) {
ApexApiResult ret = null;
String name1 = name;
String version1 = version;
@@ -711,24 +706,23 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("ContextSchema/Delete" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("ContextSchema/Delete" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
/**
- * Validate context schemas with the given key names/versions. The result(s) will be available
- * in the result messages.
+ * Validate context schemas with the given key names/versions. The result(s) will be available in the result
+ * messages.
*
* @param name the name to search for. If null or empty, then all names will be queried
* @param version the version to search for. If null then all versions will be searched for.
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@GET
@Path("Validate/ContextSchema")
public ApexApiResult validateContextSchemas(@QueryParam("name") final String name,
- @QueryParam("version") final String version) {
+ @QueryParam(VERSION) final String version) {
ApexApiResult ret = null;
String name1 = name;
String version1 = version;
@@ -757,8 +751,7 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Validate/ContextSchema" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("Validate/ContextSchema" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
@@ -766,8 +759,8 @@ public class ApexEditorRestResource {
* Creates a context album with the information in the JSON string passed.
*
* @param jsonString the JSON string to be parsed. See {@linkplain BeanContextAlbum}
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@POST
@Path("ContextAlbum/Create")
@@ -780,11 +773,11 @@ public class ApexEditorRestResource {
return ret;
}
- final BeanContextAlbum jsonbean = RestUtils.getJSONParameters(jsonString, BeanContextAlbum.class);
+ final BeanContextAlbum jsonbean = RestUtils.getJsonParameters(jsonString, BeanContextAlbum.class);
ret = sessionApexModel.createContextAlbum(jsonbean.getName(), jsonbean.getVersion(), jsonbean.getScope(),
- Boolean.toString(jsonbean.getWriteable()), jsonbean.getItemSchema().getName(),
- jsonbean.getItemSchema().getVersion(), jsonbean.getUuid(), jsonbean.getDescription());
+ Boolean.toString(jsonbean.getWriteable()), jsonbean.getItemSchema().getName(),
+ jsonbean.getItemSchema().getVersion(), jsonbean.getUuid(), jsonbean.getDescription());
if (ret.isOk()) {
commitChanges();
}
@@ -793,8 +786,7 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("ContextAlbum/Create" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("ContextAlbum/Create" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
@@ -802,8 +794,8 @@ public class ApexEditorRestResource {
* Update a context album with the information in the JSON string passed.
*
* @param jsonString the JSON string to be parsed. See {@linkplain BeanContextAlbum}
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@PUT
@Path("ContextAlbum/Update")
@@ -816,11 +808,11 @@ public class ApexEditorRestResource {
return ret;
}
- final BeanContextAlbum jsonbean = RestUtils.getJSONParameters(jsonString, BeanContextAlbum.class);
+ final BeanContextAlbum jsonbean = RestUtils.getJsonParameters(jsonString, BeanContextAlbum.class);
ret = sessionApexModel.updateContextAlbum(jsonbean.getName(), jsonbean.getVersion(), jsonbean.getScope(),
- Boolean.toString(jsonbean.getWriteable()), jsonbean.getItemSchema().getName(),
- jsonbean.getItemSchema().getVersion(), jsonbean.getUuid(), jsonbean.getDescription());
+ Boolean.toString(jsonbean.getWriteable()), jsonbean.getItemSchema().getName(),
+ jsonbean.getItemSchema().getVersion(), jsonbean.getUuid(), jsonbean.getDescription());
if (ret.isOk()) {
commitChanges();
}
@@ -829,25 +821,24 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("ContextAlbum/Update" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("ContextAlbum/Update" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
/**
- * List context albums with the given key names/versions. If successful the result(s) will be
- * available in the result messages. The returned value(s) will be similar to
- * {@link AxContextAlbum}, with merged {@linkplain AxKeyInfo} for the root object.
+ * List context albums with the given key names/versions. If successful the result(s) will be available in the
+ * result messages. The returned value(s) will be similar to {@link AxContextAlbum}, with merged
+ * {@linkplain AxKeyInfo} for the root object.
*
* @param name the name to search for. If null or empty, then all names will be queried
* @param version the version to search for. If null then all versions will be searched for.
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@GET
@Path("ContextAlbum/Get")
public ApexApiResult listContextAlbums(@QueryParam("name") final String name,
- @QueryParam("version") final String version) {
+ @QueryParam(VERSION) final String version) {
ApexApiResult ret = null;
String name1 = name;
String version1 = version;
@@ -876,8 +867,7 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("ContextAlbum/Get" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("ContextAlbum/Get" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
@@ -886,13 +876,13 @@ public class ApexEditorRestResource {
*
* @param name the name to search for. If null or empty, then all names will be queried
* @param version the version to search for. If null then all versions will be searched for.
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@DELETE
@Path("ContextAlbum/Delete")
public ApexApiResult deleteContextAlbum(@QueryParam("name") final String name,
- @QueryParam("version") final String version) {
+ @QueryParam(VERSION) final String version) {
ApexApiResult ret = null;
String name1 = name;
String version1 = version;
@@ -919,24 +909,23 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("ContextAlbum/Delete" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("ContextAlbum/Delete" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
/**
- * Validate context albums with the given key names/versions. The result(s) will be available in
- * the result messages.
+ * Validate context albums with the given key names/versions. The result(s) will be available in the result
+ * messages.
*
* @param name the name to search for. If null or empty, then all names will be queried
* @param version the version to search for. If null then all versions will be searched for.
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@GET
@Path("Validate/ContextAlbum")
public ApexApiResult validateContextAlbums(@QueryParam("name") final String name,
- @QueryParam("version") final String version) {
+ @QueryParam(VERSION) final String version) {
ApexApiResult ret = null;
String name1 = name;
String version1 = version;
@@ -965,8 +954,7 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Validate/ContextAlbum" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("Validate/ContextAlbum" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
@@ -974,8 +962,8 @@ public class ApexEditorRestResource {
* Creates an event with the information in the JSON string passed.
*
* @param jsonString the JSON string to be parsed. See {@linkplain BeanEvent}
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@POST
@Path("Event/Create")
@@ -988,10 +976,10 @@ public class ApexEditorRestResource {
return ret;
}
- final BeanEvent jsonbean = RestUtils.getJSONParameters(jsonString, BeanEvent.class);
+ final BeanEvent jsonbean = RestUtils.getJsonParameters(jsonString, BeanEvent.class);
ret = sessionApexModel.createEvent(jsonbean.getName(), jsonbean.getVersion(), jsonbean.getNameSpace(),
- jsonbean.getSource(), jsonbean.getTarget(), jsonbean.getUuid(), jsonbean.getDescription());
+ jsonbean.getSource(), jsonbean.getTarget(), jsonbean.getUuid(), jsonbean.getDescription());
if (ret.isNok()) {
return ret;
}
@@ -999,19 +987,19 @@ public class ApexEditorRestResource {
for (final Entry<String, BeanField> p : jsonbean.getParameters().entrySet()) {
if (p.getValue() == null) {
ret = new ApexApiResult(Result.FAILED, "Null event parameter information for parameter \""
- + p.getKey() + "\" in event " + jsonbean.getName() + ":" + jsonbean.getVersion()
- + ". The event was created, but there was an error adding the event parameters."
- + " The event has only been partially defined.");
+ + p.getKey() + "\" in event " + jsonbean.getName() + ":" + jsonbean.getVersion()
+ + ". The event was created, but there was an error adding the event parameters."
+ + " The event has only been partially defined.");
return ret;
}
- final ApexApiResult rettmp =
- sessionApexModel.createEventPar(jsonbean.getName(), jsonbean.getVersion(), p.getKey(),
- p.getValue().getName(), p.getValue().getVersion(), p.getValue().getOptional());
+ final ApexApiResult rettmp = sessionApexModel.createEventPar(jsonbean.getName(),
+ jsonbean.getVersion(), p.getKey(), p.getValue().getName(),
+ p.getValue().getVersion(), p.getValue().getOptional());
if (rettmp.isNok()) {
rettmp.addMessage("Failed to add event parameter information for parameter \"" + p.getKey()
- + "\" in event " + jsonbean.getName() + ":" + jsonbean.getVersion()
- + ". The event was created, but there was an error adding the event parameters."
- + " The event has only been partially defined.");
+ + "\" in event " + jsonbean.getName() + ":" + jsonbean.getVersion()
+ + ". The event was created, but there was an error adding the event parameters."
+ + " The event has only been partially defined.");
ret = rettmp;
return ret;
}
@@ -1025,8 +1013,7 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Event/Create" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("Event/Create" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
@@ -1034,8 +1021,8 @@ public class ApexEditorRestResource {
* Update an event with the information in the JSON string passed.
*
* @param jsonString the JSON string to be parsed. See {@linkplain BeanEvent}
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@PUT
@Path("Event/Update")
@@ -1048,12 +1035,12 @@ public class ApexEditorRestResource {
return ret;
}
- final BeanEvent jsonbean = RestUtils.getJSONParameters(jsonString, BeanEvent.class);
+ final BeanEvent jsonbean = RestUtils.getJsonParameters(jsonString, BeanEvent.class);
if (jsonbean.getName() == null || jsonbean.getName().equals("") || jsonbean.getVersion() == null
- || jsonbean.getVersion().equals("")) {
+ || jsonbean.getVersion().equals("")) {
ret = new ApexApiResult(Result.FAILED, "Null/Empty event name/version (\"" + jsonbean.getName() + ":"
- + jsonbean.getVersion() + "\" passed to UpdateEvent");
+ + jsonbean.getVersion() + "\" passed to UpdateEvent");
return ret;
}
@@ -1071,24 +1058,23 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Event/Update" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("Event/Update" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
/**
- * List events with the given key names/versions. If successful the result(s) will be available
- * in the result messages. The returned value(s) will be similar to {@link AxEvent}, with merged
- * {@linkplain AxKeyInfo} for the root object.
+ * List events with the given key names/versions. If successful the result(s) will be available in the result
+ * messages. The returned value(s) will be similar to {@link AxEvent}, with merged {@linkplain AxKeyInfo} for the
+ * root object.
*
* @param name the name to search for. If null or empty, then all names will be queried
* @param version the version to search for. If null then all versions will be searched for.
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@GET
@Path("Event/Get")
- public ApexApiResult listEvent(@QueryParam("name") final String name, @QueryParam("version") final String version) {
+ public ApexApiResult listEvent(@QueryParam("name") final String name, @QueryParam(VERSION) final String version) {
ApexApiResult ret = null;
String name1 = name;
String version1 = version;
@@ -1117,8 +1103,7 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Event/Get" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("Event/Get" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
@@ -1127,13 +1112,13 @@ public class ApexEditorRestResource {
*
* @param name the name to search for. If null or empty, then all names will be queried
* @param version the version to search for. If null then all versions will be searched for.
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@DELETE
@Path("Event/Delete")
public ApexApiResult deleteEvent(@QueryParam("name") final String name,
- @QueryParam("version") final String version) {
+ @QueryParam(VERSION) final String version) {
ApexApiResult ret = null;
String name1 = name;
String version1 = version;
@@ -1160,24 +1145,22 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Event/Delete" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("Event/Delete" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
/**
- * Validate events with the given key names/versions. The result(s) will be available in the
- * result messages.
+ * Validate events with the given key names/versions. The result(s) will be available in the result messages.
*
* @param name the name to search for. If null or empty, then all names will be queried
* @param version the version to search for. If null then all versions will be searched for.
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@GET
@Path("Validate/Event")
public ApexApiResult validateEvent(@QueryParam("name") final String name,
- @QueryParam("version") final String version) {
+ @QueryParam(VERSION) final String version) {
ApexApiResult ret = null;
String name1 = name;
String version1 = version;
@@ -1206,8 +1189,7 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Validate/Event" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("Validate/Event" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
@@ -1215,8 +1197,8 @@ public class ApexEditorRestResource {
* Creates a task with the information in the JSON string passed.
*
* @param jsonString the JSON string to be parsed. See {@linkplain BeanTask}
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@POST
@Path("Task/Create")
@@ -1230,10 +1212,10 @@ public class ApexEditorRestResource {
return ret;
}
- final BeanTask jsonbean = RestUtils.getJSONParameters(jsonString, BeanTask.class);
+ final BeanTask jsonbean = RestUtils.getJsonParameters(jsonString, BeanTask.class);
ret = sessionApexModel.createTask(jsonbean.getName(), jsonbean.getVersion(), jsonbean.getUuid(),
- jsonbean.getDescription());
+ jsonbean.getDescription());
if (ret.isNok()) {
return ret;
}
@@ -1241,28 +1223,28 @@ public class ApexEditorRestResource {
for (final Entry<String, BeanField> fin : jsonbean.getInputFields().entrySet()) {
if (fin.getValue() == null) {
ret = new ApexApiResult(Result.FAILED, "Null task input field information for field \""
- + fin.getKey() + "\" in task " + jsonbean.getName() + ":" + jsonbean.getVersion()
- + ". The task was created, but there was an error adding the input fields."
- + " The task has only been partially defined.");
+ + fin.getKey() + IN_TASK + jsonbean.getName() + ":" + jsonbean.getVersion()
+ + ". The task was created, but there was an error adding the input fields."
+ + TASK_PARTIALLY_DEFINED);
return ret;
}
if (fin.getKey() == null || !fin.getKey().equals(fin.getValue().getLocalName())) {
ret = new ApexApiResult(Result.FAILED, "Invalid task input field information for field \""
- + fin.getKey() + "\" in task " + jsonbean.getName() + ":" + jsonbean.getVersion()
- + ". The localName of the field (\"" + fin.getValue().getLocalName()
- + "\") is not the same as the field name. "
- + "The task was created, but there was an error adding the input fields."
- + " The task has only been partially defined.");
+ + fin.getKey() + IN_TASK + jsonbean.getName() + ":" + jsonbean.getVersion()
+ + ". The localName of the field (\"" + fin.getValue().getLocalName()
+ + "\") is not the same as the field name. "
+ + "The task was created, but there was an error adding the input fields."
+ + TASK_PARTIALLY_DEFINED);
return ret;
}
tempres = sessionApexModel.createTaskInputField(jsonbean.getName(), jsonbean.getVersion(),
- fin.getKey(), fin.getValue().getName(), fin.getValue().getVersion(),
- fin.getValue().getOptional());
+ fin.getKey(), fin.getValue().getName(), fin.getValue().getVersion(),
+ fin.getValue().getOptional());
if (tempres.isNok()) {
tempres.addMessage("Failed to add task input field information for field \"" + fin.getKey()
- + "\" in task " + jsonbean.getName() + ":" + jsonbean.getVersion()
- + ". The task was created, but there was an error adding the input fields."
- + " The task has only been partially defined.");
+ + IN_TASK + jsonbean.getName() + ":" + jsonbean.getVersion()
+ + ". The task was created, but there was an error adding the input fields."
+ + TASK_PARTIALLY_DEFINED);
ret = tempres;
return ret;
}
@@ -1272,28 +1254,28 @@ public class ApexEditorRestResource {
for (final Entry<String, BeanField> fout : jsonbean.getOutputFields().entrySet()) {
if (fout.getValue() == null) {
ret = new ApexApiResult(Result.FAILED, "Null task output field information for field \""
- + fout.getKey() + "\" in task " + jsonbean.getName() + ":" + jsonbean.getVersion()
- + ". The task was created, but there was an error adding the output fields."
- + " The task has only been partially defined.");
+ + fout.getKey() + IN_TASK + jsonbean.getName() + ":" + jsonbean.getVersion()
+ + ". The task was created, but there was an error adding the output fields."
+ + TASK_PARTIALLY_DEFINED);
return ret;
}
if (fout.getKey() == null || !fout.getKey().equals(fout.getValue().getLocalName())) {
ret = new ApexApiResult(Result.FAILED, "Invalid task output field information for field \""
- + fout.getKey() + "\" in task " + jsonbean.getName() + ":" + jsonbean.getVersion()
- + ". The localName of the field (\"" + fout.getValue().getLocalName()
- + "\") is not the same as the field name. "
- + "The task was created, but there was an error adding the output fields."
- + " The task has only been partially defined.");
+ + fout.getKey() + IN_TASK + jsonbean.getName() + ":" + jsonbean.getVersion()
+ + ". The localName of the field (\"" + fout.getValue().getLocalName()
+ + "\") is not the same as the field name. "
+ + "The task was created, but there was an error adding the output fields."
+ + TASK_PARTIALLY_DEFINED);
return ret;
}
tempres = sessionApexModel.createTaskOutputField(jsonbean.getName(), jsonbean.getVersion(),
- fout.getKey(), fout.getValue().getName(), fout.getValue().getVersion(),
- fout.getValue().getOptional());
+ fout.getKey(), fout.getValue().getName(), fout.getValue().getVersion(),
+ fout.getValue().getOptional());
if (tempres.isNok()) {
tempres.addMessage("Failed to add task output field information for field \"" + fout.getKey()
- + "\" in task " + jsonbean.getName() + ":" + jsonbean.getVersion()
- + ". The task was created, but there was an error adding the output fields."
- + " The task has only been partially defined.");
+ + IN_TASK + jsonbean.getName() + ":" + jsonbean.getVersion()
+ + ". The task was created, but there was an error adding the output fields."
+ + TASK_PARTIALLY_DEFINED);
ret = tempres;
return ret;
}
@@ -1302,12 +1284,12 @@ public class ApexEditorRestResource {
if (jsonbean.getTaskLogic() != null) {
final BeanLogic logic = jsonbean.getTaskLogic();
tempres = sessionApexModel.createTaskLogic(jsonbean.getName(), jsonbean.getVersion(),
- logic.getLogicFlavour(), logic.getLogic());
+ logic.getLogicFlavour(), logic.getLogic());
if (tempres.isNok()) {
tempres.addMessage("Failed to add task logic in task " + jsonbean.getName() + ":"
- + jsonbean.getVersion()
- + ". The task was created, but there was an error adding the logic."
- + " The task has only been partially defined.");
+ + jsonbean.getVersion()
+ + ". The task was created, but there was an error adding the logic."
+ + TASK_PARTIALLY_DEFINED);
ret = tempres;
return ret;
}
@@ -1315,21 +1297,22 @@ public class ApexEditorRestResource {
if (jsonbean.getParameters() != null) {
for (final Entry<String, BeanTaskParameter> param : jsonbean.getParameters().entrySet()) {
if (param.getKey() == null || param.getValue() == null
- || !param.getKey().equals(param.getValue().getParameterName())) {
+ || !param.getKey().equals(param.getValue().getParameterName())) {
ret = new ApexApiResult(Result.FAILED,
- "Null or invalid task parameter information for parameter \"" + param.getKey()
- + "\" in task " + jsonbean.getName() + ":" + jsonbean.getVersion()
- + ". The task was created, but there was an error adding the parameters."
- + " The task has only been partially defined.");
+ "Null or invalid task parameter information for parameter \"" + param.getKey()
+ + IN_TASK + jsonbean.getName() + ":" + jsonbean.getVersion()
+ + ". The task was created, "
+ + "but there was an error adding the parameters."
+ + TASK_PARTIALLY_DEFINED);
return ret;
}
tempres = sessionApexModel.createTaskParameter(jsonbean.getName(), jsonbean.getVersion(),
- param.getValue().getParameterName(), param.getValue().getDefaultValue());
+ param.getValue().getParameterName(), param.getValue().getDefaultValue());
if (tempres.isNok()) {
- tempres.addMessage("Failed to add task parameter \"" + param.getKey() + "\" in task "
- + jsonbean.getName() + ":" + jsonbean.getVersion()
- + ". The task was created, but there was an error adding the parameters."
- + " The task has only been partially defined.");
+ tempres.addMessage("Failed to add task parameter \"" + param.getKey() + IN_TASK
+ + jsonbean.getName() + ":" + jsonbean.getVersion()
+ + ". The task was created, but there was an error adding the parameters."
+ + TASK_PARTIALLY_DEFINED);
ret = tempres;
return ret;
}
@@ -1339,20 +1322,22 @@ public class ApexEditorRestResource {
for (final BeanKeyRef contextalbum : jsonbean.getContexts()) {
if (contextalbum.getName() == null || contextalbum.getVersion() == null) {
ret = new ApexApiResult(Result.FAILED,
- "Null or invalid context album reference information in task " + jsonbean.getName()
- + ":" + jsonbean.getVersion()
- + ". The task was created, but there was an error adding the"
- + " context album reference. The task has only been partially defined.");
+ "Null or invalid context album reference information in task "
+ + jsonbean.getName() + ":" + jsonbean.getVersion()
+ + ". The task was created, but there was an error adding the"
+ + " context album reference. "
+ + "The task has only been partially defined.");
return ret;
}
tempres = sessionApexModel.createTaskContextRef(jsonbean.getName(), jsonbean.getVersion(),
- contextalbum.getName(), contextalbum.getVersion());
+ contextalbum.getName(), contextalbum.getVersion());
if (tempres.isNok()) {
ret = new ApexApiResult(Result.FAILED,
- "Failed to add context album reference information in task " + jsonbean.getName() + ":"
- + jsonbean.getVersion()
- + ". The task was created, but there was an error adding the"
- + " context album reference. The task has only been partially defined.");
+ "Failed to add context album reference information in task "
+ + jsonbean.getName() + ":" + jsonbean.getVersion()
+ + ". The task was created, but there was an error adding the"
+ + " context album reference. "
+ + "The task has only been partially defined.");
return ret;
}
}
@@ -1365,8 +1350,7 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Task/Create" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("Task/Create" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
@@ -1374,8 +1358,8 @@ public class ApexEditorRestResource {
* Update a task with the information in the JSON string passed.
*
* @param jsonString the JSON string to be parsed. See {@linkplain BeanTask}
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@PUT
@Path("Task/Update")
@@ -1388,12 +1372,12 @@ public class ApexEditorRestResource {
return ret;
}
- final BeanTask jsonbean = RestUtils.getJSONParameters(jsonString, BeanTask.class);
+ final BeanTask jsonbean = RestUtils.getJsonParameters(jsonString, BeanTask.class);
if (jsonbean.getName() == null || jsonbean.getName().equals("") || jsonbean.getVersion() == null
- || jsonbean.getVersion().equals("")) {
+ || jsonbean.getVersion().equals("")) {
ret = new ApexApiResult(Result.FAILED, "Null/Empty task name/version (\"" + jsonbean.getName() + ":"
- + jsonbean.getVersion() + "\" passed to UpdateTask");
+ + jsonbean.getVersion() + "\" passed to UpdateTask");
return ret;
}
@@ -1411,24 +1395,23 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Task/Update" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("Task/Update" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
/**
- * List tasks with the given key names/versions. If successful the result(s) will be available
- * in the result messages. The returned value(s) will be similar to {@link AxTask}, with merged
- * {@linkplain AxKeyInfo} for the root object.
+ * List tasks with the given key names/versions. If successful the result(s) will be available in the result
+ * messages. The returned value(s) will be similar to {@link AxTask}, with merged {@linkplain AxKeyInfo} for the
+ * root object.
*
* @param name the name to search for. If null or empty, then all names will be queried
* @param version the version to search for. If null then all versions will be searched for.
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@GET
@Path("Task/Get")
- public ApexApiResult listTask(@QueryParam("name") final String name, @QueryParam("version") final String version) {
+ public ApexApiResult listTask(@QueryParam("name") final String name, @QueryParam(VERSION) final String version) {
ApexApiResult ret = null;
String name1 = name;
String version1 = version;
@@ -1457,8 +1440,7 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Task/Get" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("Task/Get" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
@@ -1467,13 +1449,13 @@ public class ApexEditorRestResource {
*
* @param name the name to search for. If null or empty, then all names will be queried
* @param version the version to search for. If null then all versions will be searched for.
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@DELETE
@Path("Task/Delete")
public ApexApiResult deleteTask(@QueryParam("name") final String name,
- @QueryParam("version") final String version) {
+ @QueryParam(VERSION) final String version) {
ApexApiResult ret = null;
String name1 = name;
String version1 = version;
@@ -1503,24 +1485,22 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Task/Delete" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("Task/Delete" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
/**
- * Validate tasks with the given key names/versions. The result(s) will be available in the
- * result messages.
+ * Validate tasks with the given key names/versions. The result(s) will be available in the result messages.
*
* @param name the name to search for. If null or empty, then all names will be queried
* @param version the version to search for. If null then all versions will be searched for.
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@GET
@Path("Validate/Task")
public ApexApiResult validateTask(@QueryParam("name") final String name,
- @QueryParam("version") final String version) {
+ @QueryParam(VERSION) final String version) {
ApexApiResult ret = null;
String name1 = name;
String version1 = version;
@@ -1549,8 +1529,7 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Validate/Task" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("Validate/Task" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
@@ -1559,8 +1538,8 @@ public class ApexEditorRestResource {
* Creates a policy with the information in the JSON string passed.
*
* @param jsonString the JSON string to be parsed See {@linkplain BeanPolicy}
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@POST
@Path("Policy/Create")
@@ -1575,21 +1554,22 @@ public class ApexEditorRestResource {
return ret;
}
- final BeanPolicy jsonbean = RestUtils.getJSONParameters(jsonString, BeanPolicy.class);
+ final BeanPolicy jsonbean = RestUtils.getJsonParameters(jsonString, BeanPolicy.class);
final String policyname = jsonbean.getName();
final String policyversion = jsonbean.getVersion();
ret = sessionApexModel.createPolicy(policyname, policyversion, jsonbean.getTemplate(),
- jsonbean.getFirstState(), jsonbean.getUuid(), jsonbean.getDescription());
+ jsonbean.getFirstState(), jsonbean.getUuid(), jsonbean.getDescription());
if (ret.isNok()) {
return ret;
}
if (jsonbean.getStates() == null || jsonbean.getStates().isEmpty()) {
- ret = new ApexApiResult(Result.FAILED, "Null or empty state map; no states defined for policy \""
- + policyname + ":" + policyversion
- + "\". The policy was created, but there was an error adding states."
- + " The policy has only been partially defined.");
+ ret = new ApexApiResult(Result.FAILED,
+ "Null or empty state map; no states defined for policy \"" + policyname + ":"
+ + policyversion
+ + "\". The policy was created, but there was an error adding states."
+ + POLICY_PARTIALLY_DEFINED);
return ret;
}
@@ -1599,29 +1579,29 @@ public class ApexEditorRestResource {
final String statename = e.getKey();
final BeanState state = e.getValue();
if (state == null) {
- ret = new ApexApiResult(Result.FAILED, "Null or invalid state information for state \"" + statename
- + "\" for policy \"" + policyname + ":" + policyversion
- + "\". The policy was created, but there was an error adding the state."
- + " The policy has only been partially defined.");
+ ret = new ApexApiResult(Result.FAILED,
+ "Null or invalid state information for state \"" + statename + FOR_POLICY
+ + policyname + ":" + policyversion + POLICY_CREATED_STATE_ERROR
+ + POLICY_PARTIALLY_DEFINED);
return ret;
}
if (state.getTrigger() == null) {
- ret = new ApexApiResult(Result.FAILED, "Null or invalid state trigger for state \"" + statename
- + "\" for policy \"" + policyname + ":" + policyversion
- + "\". The policy was created, but there was an error adding the state."
- + " The policy has only been partially defined.");
+ ret = new ApexApiResult(Result.FAILED,
+ "Null or invalid state trigger for state \"" + statename + FOR_POLICY + policyname
+ + ":" + policyversion + POLICY_CREATED_STATE_ERROR
+ + POLICY_PARTIALLY_DEFINED);
return ret;
}
if (state.getDefaultTask() == null) {
- ret = new ApexApiResult(Result.FAILED, "Null or invalid default task for state \"" + statename
- + "\" for policy \"" + policyname + ":" + policyversion
- + "\". The policy was created, but there was an error adding the state."
- + " The policy has only been partially defined.");
+ ret = new ApexApiResult(Result.FAILED,
+ "Null or invalid default task for state \"" + statename + FOR_POLICY + policyname
+ + ":" + policyversion + POLICY_CREATED_STATE_ERROR
+ + POLICY_PARTIALLY_DEFINED);
return ret;
}
tempres = sessionApexModel.createPolicyState(policyname, policyversion, statename,
- state.getTrigger().getName(), state.getTrigger().getVersion(), state.getDefaultTask().getName(),
- state.getDefaultTask().getVersion());
+ state.getTrigger().getName(), state.getTrigger().getVersion(),
+ state.getDefaultTask().getName(), state.getDefaultTask().getVersion());
if (tempres.isNok()) {
ret = tempres;
return ret;
@@ -1635,12 +1615,13 @@ public class ApexEditorRestResource {
final BeanLogic tsl = state.getTaskSelectionLogic();
if (tsl != null) {
tempres = sessionApexModel.createPolicyStateTaskSelectionLogic(policyname, policyversion, statename,
- tsl.getLogicFlavour(), tsl.getLogic());
+ tsl.getLogicFlavour(), tsl.getLogic());
if (tempres.isNok()) {
tempres.addMessage("Failed to add task selection logic for state \"" + statename + "\" for"
- + " policy \"" + policyname + ":" + policyversion
- + "\". The policy was created, but there was an error adding the task selection logic "
- + "for the state. The policy has only been partially defined.");
+ + " policy \"" + policyname + ":" + policyversion
+ + POLICY_WAS_CREATED
+ + "but there was an error adding the task selection logic "
+ + "for the state. The policy has only been partially defined.");
ret = tempres;
return ret;
}
@@ -1650,20 +1631,20 @@ public class ApexEditorRestResource {
if (contexts != null) {
for (final BeanKeyRef c : contexts) {
if (c == null) {
- ret = new ApexApiResult(Result.FAILED,
- "Null or invalid context reference \"" + c + "\" for" + " state \"" + statename
- + "\" for policy \"" + policyname + ":" + policyversion
+ ret = new ApexApiResult(Result.FAILED, "Null or invalid context reference \"" + c + "\" for"
+ + " state \"" + statename + FOR_POLICY + policyname + ":" + policyversion
+ "\". The policy was created, but there was an error adding the context "
+ "reference for the state. The policy has only been partially defined.");
return ret;
}
tempres = sessionApexModel.createPolicyStateContextRef(policyname, policyversion, statename,
- c.getName(), c.getVersion());
+ c.getName(), c.getVersion());
if (tempres.isNok()) {
tempres.addMessage("Failed to add context reference \"" + c + "\" for state \"" + statename
- + "\" for policy \"" + policyname + ":" + policyversion
- + "\". The policy was created, but there was an error adding the context reference "
- + "for the state. The policy has only been partially defined.");
+ + FOR_POLICY + policyname + ":" + policyversion
+ + POLICY_WAS_CREATED
+ + "but there was an error adding the context reference "
+ + "for the state. The policy has only been partially defined.");
ret = tempres;
return ret;
}
@@ -1677,21 +1658,21 @@ public class ApexEditorRestResource {
final BeanLogic finalizer = f.getValue();
if (finalizername == null || finalizer == null) {
ret = new ApexApiResult(Result.FAILED,
- "Null or invalid finalizer information for finalizer " + "named \"" + finalizername
- + "\" in state \"" + statename + "\" for policy \"" + policyname + ":"
- + policyversion
- + "\". The policy and state were created, but there was an error adding the"
- + " finalizer. The policy has only been partially defined.");
+ "Null or invalid finalizer information for finalizer " + "named \""
+ + finalizername + IN_STATE + statename + FOR_POLICY
+ + policyname + ":" + policyversion
+ + POLICY_STATE_CREATED_OTHER_ERROR
+ + " finalizer. The policy has only "
+ + "been partially defined.");
return ret;
}
tempres = sessionApexModel.createPolicyStateFinalizerLogic(policyname, policyversion, statename,
- finalizername, finalizer.getLogicFlavour(), finalizer.getLogic());
+ finalizername, finalizer.getLogicFlavour(), finalizer.getLogic());
if (tempres.isNok()) {
tempres.addMessage("Failed to add finalizer information for finalizer named \""
- + finalizername + "\" in" + " state \"" + statename + "\" for policy \""
- + policyname + ":" + policyversion
- + "\". The policy and state were created, but there was an error adding the"
- + " finalizer. The policy has only been partially defined.");
+ + finalizername + "\" in" + " state \"" + statename + FOR_POLICY
+ + policyname + ":" + policyversion + POLICY_STATE_CREATED_OTHER_ERROR
+ + " finalizer. The policy has only been partially defined.");
ret = tempres;
return ret;
}
@@ -1699,9 +1680,8 @@ public class ApexEditorRestResource {
}
final Map<String, BeanStateOutput> outputs = state.getStateOutputs();
if (outputs == null || outputs.isEmpty()) {
- ret = new ApexApiResult(Result.FAILED,
- "No state outputs have been defined in state \"" + statename + "\" for policy \""
- + policyname + ":" + policyversion
+ ret = new ApexApiResult(Result.FAILED, "No state outputs have been defined in state \"" + statename
+ + FOR_POLICY + policyname + ":" + policyversion
+ "\". The policy and state were created, but there was an error adding state"
+ " outputs. The policy has only been partially defined.");
return ret;
@@ -1711,19 +1691,19 @@ public class ApexEditorRestResource {
final BeanStateOutput output = o.getValue();
if (outputname == null || output == null || output.getEvent() == null) {
ret = new ApexApiResult(Result.FAILED,
- "Null or invalid output information for output named \"" + outputname + "\" in state \""
- + statename + "\" for policy \"" + policyname + ":" + policyversion
- + "\". The policy and state were created, but there was an error adding the"
- + " output. The policy has only been partially defined.");
+ "Null or invalid output information for output named \"" + outputname + IN_STATE
+ + statename + FOR_POLICY + policyname + ":" + policyversion
+ + POLICY_STATE_CREATED_OTHER_ERROR
+ + " output. The policy has only been partially defined.");
return ret;
}
tempres = sessionApexModel.createPolicyStateOutput(policyname, policyversion, statename, outputname,
- output.getEvent().getName(), output.getEvent().getVersion(), output.getNextState());
+ output.getEvent().getName(), output.getEvent().getVersion(), output.getNextState());
if (tempres.isNok()) {
tempres.addMessage("Failed to add output information for output named \"" + outputname
- + "\" in state \"" + statename + "\" for policy \"" + policyname + ":" + policyversion
- + "\". The policy and state were created, but there was an error adding the output."
- + " The policy has only been partially defined.");
+ + IN_STATE + statename + FOR_POLICY + policyname + ":" + policyversion
+ + "\". The policy and state were created, "
+ + "but there was an error adding the output." + POLICY_PARTIALLY_DEFINED);
ret = tempres;
return ret;
}
@@ -1731,32 +1711,31 @@ public class ApexEditorRestResource {
final Map<String, BeanStateTaskRef> taskmap = state.getTasks();
if (taskmap == null || taskmap.isEmpty()) {
- ret = new ApexApiResult(Result.FAILED,
- "No tasks have been defined in state \"" + statename + "\" for policy \"" + policyname + ":"
- + policyversion
+ ret = new ApexApiResult(Result.FAILED, "No tasks have been defined in state \"" + statename
+ + FOR_POLICY + policyname + ":" + policyversion
+ "\". The policy and state were created, but there was an error adding tasks."
- + " The policy has only been partially defined.");
+ + POLICY_PARTIALLY_DEFINED);
return ret;
}
for (final Map.Entry<String, BeanStateTaskRef> t : taskmap.entrySet()) {
final String tasklocalname = t.getKey();
final BeanStateTaskRef taskref = t.getValue();
if (tasklocalname == null || taskref == null || taskref.getTask() == null) {
- ret = new ApexApiResult(Result.FAILED,
- "Null or invalid task information for task named \"" + tasklocalname + "\" in state \""
- + statename + "\" for for policy \"" + policyname + ":" + policyversion
+ ret = new ApexApiResult(Result.FAILED, "Null or invalid task information for task named \""
+ + tasklocalname + IN_STATE + statename + "\" for for policy \"" + policyname
+ + ":" + policyversion
+ "\". The policy and state were created, but there was an error adding the "
+ "task. The policy has only been partially defined.");
return ret;
}
tempres = sessionApexModel.createPolicyStateTaskRef(policyname, policyversion, statename,
- tasklocalname, taskref.getTask().getName(), taskref.getTask().getVersion(),
- taskref.getOutputType(), taskref.getOutputName());
+ tasklocalname, taskref.getTask().getName(), taskref.getTask().getVersion(),
+ taskref.getOutputType(), taskref.getOutputName());
if (tempres.isNok()) {
tempres.addMessage("Failed to add task reference \"" + t + "\" for state \"" + statename
- + "\" for policy \"" + policyname + ":" + policyversion
- + "\". The policy was created, but there was an error adding the task reference for"
- + " the state. The policy has only been partially defined.");
+ + FOR_POLICY + policyname + ":" + policyversion + POLICY_WAS_CREATED
+ + "but there was an error adding the task reference for"
+ + " the state. The policy has only been partially defined.");
ret = tempres;
return ret;
}
@@ -1771,8 +1750,7 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Policy/Create" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("Policy/Create" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
// CHECKSTYLE:ON: MethodLength
@@ -1782,13 +1760,13 @@ public class ApexEditorRestResource {
*
* @param firstStatePeriodic indicates if periodic event should be created and added to model
* @param jsonString the JSON string to be parsed. See {@linkplain BeanPolicy}
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@PUT
@Path("Policy/Update")
public ApexApiResult updatePolicy(@QueryParam("firstStatePeriodic") final boolean firstStatePeriodic,
- final String jsonString) {
+ final String jsonString) {
ApexApiResult ret = null;
LOGGER.entry(jsonString);
try {
@@ -1797,12 +1775,12 @@ public class ApexEditorRestResource {
return ret;
}
- final BeanPolicy jsonbean = RestUtils.getJSONParameters(jsonString, BeanPolicy.class);
+ final BeanPolicy jsonbean = RestUtils.getJsonParameters(jsonString, BeanPolicy.class);
if (jsonbean.getName() == null || jsonbean.getName().equals("") || jsonbean.getVersion() == null
- || jsonbean.getVersion().equals("")) {
+ || jsonbean.getVersion().equals("")) {
ret = new ApexApiResult(Result.FAILED, "Null/Empty Policy name/version (\"" + jsonbean.getName() + ":"
- + jsonbean.getVersion() + "\" passed to UpdatePolicy");
+ + jsonbean.getVersion() + "\" passed to UpdatePolicy");
return ret;
}
@@ -1813,12 +1791,11 @@ public class ApexEditorRestResource {
if (firstStatePeriodic) {
final ApexApiResult existingPeriodicEvent = sessionApexModel.listEvent("PeriodicEvent", null);
if (existingPeriodicEvent.isNok()) {
- final String periodicEventString =
- "{\"name\":\"PeriodicEvent\",\"version\":\"0.0.1\","
- + "\"uuid\":\"44236da1-3d47-4988-8033-b6fee9d6a0f4\","
- + "\"description\":\"Generated description for concept referred to by key "
- + "'PeriodicEvent:0.0.1'\",\"source\":\"System\",\"target\":\"Apex\","
- + "\"nameSpace\":\"org.onap.policy.apex.domains.aadm.events\",\"parameters\":{}}";
+ final String periodicEventString = "{\"name\":\"PeriodicEvent\",\"version\":\"0.0.1\","
+ + "\"uuid\":\"44236da1-3d47-4988-8033-b6fee9d6a0f4\","
+ + "\"description\":\"Generated description for concept referred to by key "
+ + "'PeriodicEvent:0.0.1'\",\"source\":\"System\",\"target\":\"Apex\","
+ + "\"nameSpace\":\"org.onap.policy.apex.domains.aadm.events\",\"parameters\":{}}";
ret = createEvent(periodicEventString);
if (ret.isNok()) {
return ret;
@@ -1834,25 +1811,24 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Policy/Update" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("Policy/Update" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
/**
- * List policies with the given key names/versions. If successful the result(s) will be
- * available in the result messages. The returned value(s) will be similar to {@link AxPolicy},
- * with merged {@linkplain AxKey Info} for the root object.
+ * List policies with the given key names/versions. If successful the result(s) will be available in the result
+ * messages. The returned value(s) will be similar to {@link AxPolicy}, with merged {@linkplain AxKey Info} for the
+ * root object.
*
* @param name the name to search for. If null or empty, then all names will be queried
* @param version the version to search for. If null then all versions will be searched for.
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@GET
@Path("Policy/Get")
public ApexApiResult listPolicy(@QueryParam("name") final String name,
- @QueryParam("version") final String version) {
+ @QueryParam(VERSION) final String version) {
ApexApiResult ret = null;
String name1 = name;
String version1 = version;
@@ -1882,8 +1858,7 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Policy/Get" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ LOGGER.exit("Policy/Get" + (ret != null && ret.isOk() ? ": OK" : NOT_OK));
}
}
@@ -1892,13 +1867,13 @@ public class ApexEditorRestResource {
*
* @param name the name to search for. If null or empty, then all names will be queried
* @param version the version to search for. If null then all versions will be searched for.
- * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return
- * true. Any messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
*/
@DELETE
@Path("Policy/Delete")
public ApexApiResult deletePolicy(@QueryParam("name") final String name,
- @QueryParam("version") final String version) {
+ @QueryParam(VERSION) final String version) {
ApexApiResult ret = null;
String name1 = name;
String version1 = version;
@@ -1928,20 +1903,18 @@ public class ApexEditorRestResource {
LOGGER.catching(e);
throw e;
} finally {
- LOGGER.exit((ret == null ? false : ret.isOk()));
- LOGGER.info("Policy/Delete" + (ret != null && ret.isOk() ? ": OK" : ": Not OK"));
+ String result = "Policy/Delete" + (ret != null && ret.isOk() ? ": OK" : NOT_OK);
+ LOGGER.exit(result);
}
}
/**
- * The json strings representing the objects listed, stored in result.messages[], does not
- * contain the AxKeyInformation for that object. This utility method retrieves the AxKeyInfo for
- * each object and adds it to the json for the object.
+ * The json strings representing the objects listed, stored in result.messages[], does not contain the
+ * AxKeyInformation for that object. This utility method retrieves the AxKeyInfo for each object and adds it to the
+ * json for the object.
*
- * @param result The list result, containing json representations of objects stored in its
- * "messages" array
- * @return The list result, containing json augmented representations of objects stored in its
- * "messages" array
+ * @param result The list result, containing json representations of objects stored in its "messages" array
+ * @return The list result, containing json augmented representations of objects stored in its "messages" array
*/
private ApexApiResult addKeyInfo2Messages(final ApexApiResult result) {
if (result.isNok()) {
@@ -1962,43 +1935,43 @@ public class ApexEditorRestResource {
JsonObject objecttochange = jsonObject;
String name = null;
if (jsonObject != null && jsonObject.get("key") != null && jsonObject.get("key").isJsonObject()
- && jsonObject.getAsJsonObject("key").get("name") != null) {
+ && jsonObject.getAsJsonObject("key").get("name") != null) {
name = jsonObject.getAsJsonObject("key").get("name").getAsString();
- } else if (jsonObject != null && jsonObject.get("policyKey") != null
- && jsonObject.get("policyKey").isJsonObject()
- && jsonObject.getAsJsonObject("policyKey").get("name") != null) {
- name = jsonObject.getAsJsonObject("policyKey").get("name").getAsString();
+ } else if (jsonObject != null && jsonObject.get(POLICY_KEY) != null
+ && jsonObject.get(POLICY_KEY).isJsonObject()
+ && jsonObject.getAsJsonObject(POLICY_KEY).get("name") != null) {
+ name = jsonObject.getAsJsonObject(POLICY_KEY).get("name").getAsString();
}
String version = null;
if (jsonObject != null && jsonObject.get("key") != null && jsonObject.get("key").isJsonObject()
- && jsonObject.getAsJsonObject("key").get("version") != null) {
- version = jsonObject.getAsJsonObject("key").get("version").getAsString();
- } else if (jsonObject != null && jsonObject.get("policyKey") != null
- && jsonObject.get("policyKey").isJsonObject()
- && jsonObject.getAsJsonObject("policyKey").get("version") != null) {
- version = jsonObject.getAsJsonObject("policyKey").get("version").getAsString();
+ && jsonObject.getAsJsonObject("key").get(VERSION) != null) {
+ version = jsonObject.getAsJsonObject("key").get(VERSION).getAsString();
+ } else if (jsonObject != null && jsonObject.get(POLICY_KEY) != null
+ && jsonObject.get(POLICY_KEY).isJsonObject()
+ && jsonObject.getAsJsonObject(POLICY_KEY).get(VERSION) != null) {
+ version = jsonObject.getAsJsonObject(POLICY_KEY).get(VERSION).getAsString();
}
if (name == null && version == null && jsonObject.entrySet() != null
- && jsonObject.entrySet().size() > 0) {
+ && !jsonObject.entrySet().isEmpty()) {
objecttochange = (JsonObject) jsonObject.entrySet().iterator().next().getValue();
if (objecttochange != null && objecttochange.get("key") != null
- && objecttochange.get("key").isJsonObject()
- && objecttochange.getAsJsonObject("key").get("name") != null) {
+ && objecttochange.get("key").isJsonObject()
+ && objecttochange.getAsJsonObject("key").get("name") != null) {
name = objecttochange.getAsJsonObject("key").get("name").getAsString();
- } else if (objecttochange != null && objecttochange.get("policyKey") != null
- && objecttochange.get("policyKey").isJsonObject()
- && objecttochange.getAsJsonObject("policyKey").get("name") != null) {
- name = objecttochange.getAsJsonObject("policyKey").get("name").getAsString();
+ } else if (objecttochange != null && objecttochange.get(POLICY_KEY) != null
+ && objecttochange.get(POLICY_KEY).isJsonObject()
+ && objecttochange.getAsJsonObject(POLICY_KEY).get("name") != null) {
+ name = objecttochange.getAsJsonObject(POLICY_KEY).get("name").getAsString();
}
if (objecttochange != null && objecttochange.get("key") != null
- && objecttochange.get("key").isJsonObject()
- && objecttochange.getAsJsonObject("key").get("version") != null) {
- version = objecttochange.getAsJsonObject("key").get("version").getAsString();
- } else if (objecttochange != null && objecttochange.get("policyKey") != null
- && objecttochange.get("policyKey").isJsonObject()
- && objecttochange.getAsJsonObject("policyKey").get("version") != null) {
- version = objecttochange.getAsJsonObject("policyKey").get("version").getAsString();
+ && objecttochange.get("key").isJsonObject()
+ && objecttochange.getAsJsonObject("key").get(VERSION) != null) {
+ version = objecttochange.getAsJsonObject("key").get(VERSION).getAsString();
+ } else if (objecttochange != null && objecttochange.get(POLICY_KEY) != null
+ && objecttochange.get(POLICY_KEY).isJsonObject()
+ && objecttochange.getAsJsonObject(POLICY_KEY).get(VERSION) != null) {
+ version = objecttochange.getAsJsonObject(POLICY_KEY).get(VERSION).getAsString();
}
}
@@ -2008,22 +1981,23 @@ public class ApexEditorRestResource {
if (name != null && version != null) {
final ApexApiResult keyInfoResult = sessionApexModel.listKeyInformation(name, version);
final List<String> keyInfoMessages = keyInfoResult.getMessages();
- if (keyInfoResult.isOk() && keyInfoMessages != null && keyInfoMessages.size() > 0) {
+ if (keyInfoResult.isOk() && keyInfoMessages != null && !keyInfoMessages.isEmpty()) {
final String keyInfoJson = keyInfoMessages.get(0);
final JsonObject keyInfoJsonObject = gson.fromJson(keyInfoJson, JsonObject.class);
- if (keyInfoJsonObject != null && keyInfoJsonObject.get("apexKeyInfo") != null
- && keyInfoJsonObject.get("apexKeyInfo").getAsJsonObject().get("UUID") != null) {
- uuid = keyInfoJsonObject.get("apexKeyInfo").getAsJsonObject().get("UUID").getAsString();
+ if (keyInfoJsonObject != null && keyInfoJsonObject.get(APEX_KEY_INFO) != null
+ && keyInfoJsonObject.get(APEX_KEY_INFO).getAsJsonObject().get("UUID") != null) {
+ uuid = keyInfoJsonObject.get(APEX_KEY_INFO).getAsJsonObject().get("UUID").getAsString();
}
- if (keyInfoJsonObject != null && keyInfoJsonObject.get("apexKeyInfo") != null
- && keyInfoJsonObject.get("apexKeyInfo").getAsJsonObject().get("description") != null) {
- desc = keyInfoJsonObject.get("apexKeyInfo").getAsJsonObject().get("description")
- .getAsString();
+ if (keyInfoJsonObject != null && keyInfoJsonObject.get(APEX_KEY_INFO) != null
+ && keyInfoJsonObject.get(APEX_KEY_INFO).getAsJsonObject()
+ .get(DESCRIPTION) != null) {
+ desc = keyInfoJsonObject.get(APEX_KEY_INFO).getAsJsonObject().get(DESCRIPTION)
+ .getAsString();
}
}
}
objecttochange.addProperty("uuid", uuid);
- objecttochange.addProperty("description", desc);
+ objecttochange.addProperty(DESCRIPTION, desc);
augmessages.add(gson.toJson(jsonObject));
} catch (final Exception e) {
augmessages.add(message);
@@ -2040,16 +2014,24 @@ public class ApexEditorRestResource {
}
/*
- * This method is used only for testing and is used to cause an exception on calls from unit
- * test to test exception handling.
+ * This method is used only for testing and is used to cause an exception on calls from unit test to test exception
+ * handling.
*/
protected static int createCorruptSession() {
final ApexEditorRestResource apexEditorRestResource = new ApexEditorRestResource();
final ApexApiResult result = apexEditorRestResource.createSession();
- final int corruptSessionId = new Integer(result.getMessages().get(0));
+ final int corruptSessionId = Integer.parseInt(result.getMessages().get(0));
SESSIONMODELMAP.put(corruptSessionId, null);
return corruptSessionId;
}
+
+ /**
+ * Increment the session number.
+ */
+ private static void incrementNextSession() {
+ nextSession++;
+ }
+
}
diff --git a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/RestUtils.java b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/RestUtils.java
index 02779a4d7..2bd47238a 100644
--- a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/RestUtils.java
+++ b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/RestUtils.java
@@ -103,7 +103,7 @@ public abstract class RestUtils {
* @param jsonString the incoming JSON string
* @return a map of the JSON strings
*/
- public static Map<String, String> getJSONParameters(final String jsonString) {
+ public static Map<String, String> getJsonParameters(final String jsonString) {
final GsonBuilder gb = new GsonBuilder();
gb.serializeNulls().enableComplexMapKeySerialization();
final JsonObject jsonObject = gb.create().fromJson(jsonString, JsonObject.class);
@@ -120,12 +120,12 @@ public abstract class RestUtils {
* Apex HTTP PUT requests send simple single level JSON strings, this method reads those strings
* into a map.
*
- * @param <CLZ> the generic type
+ * @param <C> the generic type
* @param jsonString the incoming JSON string
* @param clz the clz
* @return a map of the JSON strings
*/
- public static <CLZ extends BeanBase> CLZ getJSONParameters(final String jsonString, final Class<CLZ> clz) {
+ public static <C extends BeanBase> C getJsonParameters(final String jsonString, final Class<C> clz) {
final GsonBuilder gb = new GsonBuilder();
gb.serializeNulls().enableComplexMapKeySerialization();
final JsonObject jsonObject = gb.create().fromJson(jsonString, JsonObject.class);
@@ -134,8 +134,7 @@ public abstract class RestUtils {
final JsonElement val = jsonEntry.getValue();
jsonEntry.setValue(blank2null(val));
}
- final CLZ ret = gb.create().fromJson(jsonObject, clz);
- return ret;
+ return gb.create().fromJson(jsonObject, clz);
}
// Regular expressions for checking input types
@@ -148,13 +147,13 @@ public abstract class RestUtils {
/**
* Gets the concept from JSON.
*
- * @param <CLZ> the generic type
+ * @param <C> the generic type
* @param jsonString the json string
* @param clz the clz
* @return the concept from JSON
* @throws JAXBException the JAXB exception
*/
- public static <CLZ extends AxConcept> CLZ getConceptFromJSON(final String jsonString, final Class<CLZ> clz)
+ public static <C extends AxConcept> C getConceptFromJson(final String jsonString, final Class<C> clz)
throws JAXBException {
Unmarshaller unmarshaller = null;
final JAXBContext jaxbContext = JAXBContext.newInstance(clz);
@@ -168,10 +167,8 @@ public abstract class RestUtils {
return null;
}
final StreamSource source = new StreamSource(new StringReader(jsonString));
- final JAXBElement<CLZ> rootElement = unmarshaller.unmarshal(source, clz);
- final CLZ apexConcept = rootElement.getValue();
- return apexConcept;
-
+ final JAXBElement<C> rootElement = unmarshaller.unmarshal(source, clz);
+ return rootElement.getValue();
}
/**
@@ -180,11 +177,9 @@ public abstract class RestUtils {
* @param object the object
* @return the JSO nfrom concept
*/
- public static String getJSONfromConcept(final Object object) {
+ public static String getJsonfromConcept(final Object object) {
final GsonBuilder gb = new GsonBuilder();
gb.serializeNulls().enableComplexMapKeySerialization();
- final String jsonObject = gb.create().toJson(object);
- return jsonObject;
+ return gb.create().toJson(object);
}
-
}
diff --git a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/RestInterfaceTest.java b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/RestInterfaceTest.java
index dc1e1137b..7af4b37c3 100644
--- a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/RestInterfaceTest.java
+++ b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/RestInterfaceTest.java
@@ -102,7 +102,7 @@ public class RestInterfaceTest {
// create the client
final Client c = ClientBuilder.newClient();
// Create the web target
- target = c.target(new ApexEditorParameters().getBaseURI());
+ target = c.target(new ApexEditorParameters().getBaseUri());
// load a test model locally
localmodel = new ApexModelReader<>(AxPolicyModel.class, false)
@@ -149,7 +149,7 @@ public class RestInterfaceTest {
*/
private static int createNewSession() {
final ApexApiResult responseMsg = target.path("editor/-1/Session/Create").request().get(ApexApiResult.class);
- assertEquals(responseMsg.getResult(), ApexApiResult.Result.SUCCESS);
+ assertEquals(ApexApiResult.Result.SUCCESS, responseMsg.getResult());
assertTrue(responseMsg.getMessages().size() == 1);
return Integer.parseInt(responseMsg.getMessages().get(0));
}
@@ -157,11 +157,11 @@ public class RestInterfaceTest {
/**
* Upload policy.
*
- * @param sessionID the session ID
+ * @param sessionId the session ID
* @param modelAsJsonString the model as json string
*/
- private void uploadPolicy(final int sessionID, final String modelAsJsonString) {
- final Builder requestbuilder = target.path("editor/" + sessionID + "/Model/Load").request();
+ private void uploadPolicy(final int sessionId, final String modelAsJsonString) {
+ final Builder requestbuilder = target.path("editor/" + sessionId + "/Model/Load").request();
final ApexApiResult responseMsg = requestbuilder.put(Entity.json(modelAsJsonString), ApexApiResult.class);
assertTrue(responseMsg.isOk());
}
@@ -176,11 +176,11 @@ public class RestInterfaceTest {
@Test
public void testUploadThenGet() throws ApexException, JAXBException {
- final int sessionID = createNewSession();
+ final int sessionId = createNewSession();
- uploadPolicy(sessionID, localmodelString);
+ uploadPolicy(sessionId, localmodelString);
- final ApexApiResult responseMsg = target.path("editor/" + sessionID + "/Policy/Get")
+ final ApexApiResult responseMsg = target.path("editor/" + sessionId + "/Policy/Get")
.queryParam("name", "Policy0").queryParam("version", "0.0.1").request().get(ApexApiResult.class);
assertTrue(responseMsg.isOk());
diff --git a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/TestApexEditorStartup.java b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/TestApexEditorStartup.java
index 699505aa8..0fad411a5 100644
--- a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/TestApexEditorStartup.java
+++ b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/TestApexEditorStartup.java
@@ -336,7 +336,7 @@ public class TestApexEditorStartup {
* @throws InterruptedException if the test is interrupted
*/
@Test
- public void testTTLArg0() throws IOException, InterruptedException {
+ public void testTtlArg0() throws IOException, InterruptedException {
final String[] args = new String[] { "-t10" };
final String outString = runEditor(args);
@@ -359,7 +359,7 @@ public class TestApexEditorStartup {
* @throws InterruptedException if the test is interrupted
*/
@Test
- public void testTTLArg1() throws IOException, InterruptedException {
+ public void testTtlArg1() throws IOException, InterruptedException {
final String[] args = new String[] { "-t", "10", "-l", "localhost" };
final String outString = runEditor(args);
@@ -382,7 +382,7 @@ public class TestApexEditorStartup {
* @throws InterruptedException if the test is interrupted
*/
@Test
- public void testPortTTLArg0() throws IOException, InterruptedException {
+ public void testPortTtlArg0() throws IOException, InterruptedException {
final String[] args = new String[] { "-t", "10", "-p", "12321" };
final String outString = runEditor(args);
@@ -406,7 +406,7 @@ public class TestApexEditorStartup {
* @throws InterruptedException if the test is interrupted
*/
@Test
- public void testPortTTLArg1() throws IOException, InterruptedException {
+ public void testPortTtlArg1() throws IOException, InterruptedException {
final String[] args = new String[] { "--time-to-live", "10", "--port", "12321", "--listen", "127.0.0.1" };
final String outString = runEditor(args);
@@ -430,8 +430,8 @@ public class TestApexEditorStartup {
* @throws InterruptedException if the test is interrupted
*/
private String runEditor(final String[] args) throws InterruptedException {
- final ByteArrayOutputStream outBAStream = new ByteArrayOutputStream();
- final PrintStream outStream = new PrintStream(outBAStream);
+ final ByteArrayOutputStream outBaStream = new ByteArrayOutputStream();
+ final PrintStream outStream = new PrintStream(outBaStream);
final ApexEditorMain editorMain = new ApexEditorMain(args, outStream);
@@ -450,7 +450,7 @@ public class TestApexEditorStartup {
}
editorMain.shutdown();
- final String outString = outBAStream.toString();
+ final String outString = outBaStream.toString();
System.out.println(outString);
return outString;
}
diff --git a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRest.java b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRest.java
index c6460d2c9..774cfc632 100644
--- a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRest.java
+++ b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRest.java
@@ -59,14 +59,14 @@ public class ApexServicesRest {
// Create a resource configuration that scans for JAX-RS resources and providers
// in org.onap.policy.apex.client.full.rest package
- final ResourceConfig rc = new ResourceConfig().packages(parameters.getRESTPackages());
+ final ResourceConfig rc = new ResourceConfig().packages(parameters.getRestPackages());
// Add MultiPartFeature class for jersey-media-multipart
rc.register(MultiPartFeature.class);
// create and start a new instance of grizzly http server
// exposing the Jersey application at BASE_URI
- server = GrizzlyHttpServerFactory.createHttpServer(parameters.getBaseURI(), rc);
+ server = GrizzlyHttpServerFactory.createHttpServer(parameters.getBaseUri(), rc);
// Add static content
server.getServerConfiguration().addHttpHandler(new org.glassfish.grizzly.http.server.CLStaticHttpHandler(
diff --git a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestMain.java b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestMain.java
index a2fb0ac73..c89fcf473 100644
--- a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestMain.java
+++ b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestMain.java
@@ -22,11 +22,20 @@ package org.onap.policy.apex.client.full.rest;
import java.io.PrintStream;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
/**
* This class is the main class that is used to launch the Apex editor from the command line.
*
*/
public class ApexServicesRestMain {
+ // Logger for this class
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexServicesRestMain.class);
+
+ // Recurring string constants
+ private static final String REST_ENDPOINT_PREFIX = "Apex Editor REST endpoint (";
+
/**
* The Enum EditorState holds the current state of the editor.
*/
@@ -65,7 +74,7 @@ public class ApexServicesRestMain {
final ApexServicesRestMain editorMain = new ApexServicesRestMain(args, System.out);
editorMain.init();
} catch (final Exception e) {
- System.err.println(e.getMessage());
+ LOGGER.error(e.getMessage());
}
}
@@ -87,7 +96,7 @@ public class ApexServicesRestMain {
parameters = parser.parse(args);
} catch (final ApexServicesRestParameterException e) {
throw new ApexServicesRestParameterException(
- "Apex Editor REST endpoint (" + this.toString() + ") parameter error, " + e.getMessage() + '\n'
+ REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, " + e.getMessage() + '\n'
+ parser.getHelp(ApexServicesRestMain.class.getCanonicalName()));
}
@@ -99,7 +108,7 @@ public class ApexServicesRestMain {
final String validationMessage = parameters.validate();
if (validationMessage.length() > 0) {
throw new ApexServicesRestParameterException(
- "Apex Editor REST endpoint (" + this.toString() + ") parameters invalid, " + validationMessage
+ REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + validationMessage
+ '\n' + parser.getHelp(ApexServicesRestMain.class.getCanonicalName()));
}
@@ -110,8 +119,8 @@ public class ApexServicesRestMain {
* Initialize the Apex editor.
*/
public void init() {
- outStream.println("Apex Editor REST endpoint (" + this.toString() + ") starting at "
- + parameters.getBaseURI().toString() + " . . .");
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at "
+ + parameters.getBaseUri().toString() + " . . .");
try {
state = EditorState.INITIALIZING;
@@ -125,10 +134,10 @@ public class ApexServicesRestMain {
state = EditorState.RUNNING;
if (parameters.getTimeToLive() == ApexServicesRestParameters.INFINITY_TIME_TO_LIVE) {
- outStream.println("Apex Editor REST endpoint (" + this.toString() + ") started at "
- + parameters.getBaseURI().toString());
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started at "
+ + parameters.getBaseUri().toString());
} else {
- outStream.println("Apex Editor REST endpoint (" + this.toString() + ") started");
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started");
}
// Find out how long is left to wait
@@ -144,7 +153,7 @@ public class ApexServicesRestMain {
}
} catch (final Exception e) {
outStream.println(
- "Apex Editor REST endpoint (" + this.toString() + ") failed at with error: " + e.getMessage());
+ REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage());
} finally {
if (apexServices != null) {
apexServices.shutdown();
@@ -181,11 +190,11 @@ public class ApexServicesRestMain {
*/
public void shutdown() {
if (apexServices != null) {
- outStream.println("Apex Editor REST endpoint (" + this.toString() + ") shutting down");
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") shutting down");
apexServices.shutdown();
}
state = EditorState.STOPPED;
- outStream.println("Apex Editor REST endpoint (" + this.toString() + ") shut down");
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") shut down");
}
/**
diff --git a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameterParser.java b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameterParser.java
index 8a90aa633..bb27943d6 100644
--- a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameterParser.java
+++ b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameterParser.java
@@ -81,7 +81,7 @@ public class ApexServicesRestParameterParser {
}
try {
if (commandLine.hasOption('p')) {
- parameters.setRESTPort(((Number) commandLine.getParsedOptionValue("port")).intValue());
+ parameters.setRestPort(((Number) commandLine.getParsedOptionValue("port")).intValue());
}
} catch (final ParseException e) {
throw new ApexServicesRestParameterException("error parsing argument \"port\" :" + e.getMessage(), e);
diff --git a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameters.java b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameters.java
index 52ad885fd..f5f9d4c35 100644
--- a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameters.java
+++ b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameters.java
@@ -37,14 +37,21 @@ public class ApexServicesRestParameters {
private static final String DEFAULT_STATIC_PATH = "/";
// Package that will field REST requests
- private static final String[] DEFAULT_PACKAGES = new String[] { "org.onap.policy.apex.client.deployment.rest",
- "org.onap.policy.apex.client.editor.rest", "org.onap.policy.apex.client.monitoring.rest" };
+ private static final String[] DEFAULT_PACKAGES = new String[] {
+ "org.onap.policy.apex.client.deployment.rest",
+ "org.onap.policy.apex.client.editor.rest",
+ "org.onap.policy.apex.client.monitoring.rest"
+ };
// The services parameters
private boolean helpSet = false;
private int restPort = DEFAULT_REST_PORT;
private long timeToLive = INFINITY_TIME_TO_LIVE;
+ /**
+ * Validate the parameters.
+ * @return the result of the validation
+ */
public String validate() {
String validationMessage = "";
validationMessage += validatePort();
@@ -53,11 +60,11 @@ public class ApexServicesRestParameters {
return validationMessage;
}
- public URI getBaseURI() {
+ public URI getBaseUri() {
return URI.create(DEFAULT_SERVER_URI_ROOT + restPort + DEFAULT_REST_PATH);
}
- public String[] getRESTPackages() {
+ public String[] getRestPackages() {
return DEFAULT_PACKAGES;
}
@@ -89,11 +96,11 @@ public class ApexServicesRestParameters {
this.helpSet = helpSet;
}
- public int getRESTPort() {
+ public int getRestPort() {
return restPort;
}
- public void setRESTPort(final int restPort) {
+ public void setRestPort(final int restPort) {
this.restPort = restPort;
}
@@ -108,7 +115,7 @@ public class ApexServicesRestParameters {
@Override
public String toString() {
final StringBuilder ret = new StringBuilder();
- ret.append(this.getClass().getSimpleName()).append(": URI=").append(this.getBaseURI()).append(", TTL=")
+ ret.append(this.getClass().getSimpleName()).append(": URI=").append(this.getBaseUri()).append(", TTL=")
.append(this.getTimeToLive()).append("sec");
return ret.toString();
}
diff --git a/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRest.java b/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRest.java
index e7802ae3f..d600fb25c 100644
--- a/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRest.java
+++ b/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRest.java
@@ -56,11 +56,11 @@ public class ApexMonitoringRest {
// Create a resource configuration that scans for JAX-RS resources and providers
// in org.onap.policy.apex.services.client.monitoring.rest package
- final ResourceConfig rc = new ResourceConfig().packages(parameters.getRESTPackages());
+ final ResourceConfig rc = new ResourceConfig().packages(parameters.getRestPackages());
// create and start a new instance of grizzly http server
// exposing the Jersey application at BASE_URI
- server = GrizzlyHttpServerFactory.createHttpServer(parameters.getBaseURI(), rc);
+ server = GrizzlyHttpServerFactory.createHttpServer(parameters.getBaseUri(), rc);
// Add static content
server.getServerConfiguration().addHttpHandler(new org.glassfish.grizzly.http.server.CLStaticHttpHandler(
diff --git a/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestMain.java b/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestMain.java
index bf2365f46..297ee97e9 100644
--- a/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestMain.java
+++ b/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestMain.java
@@ -22,12 +22,21 @@ package org.onap.policy.apex.client.monitoring.rest;
import java.io.PrintStream;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
/**
* The main class for Apex Restful Monitoring.
*
* @author Michael Watkins (michael.watkins@ericsson.com)
*/
public class ApexMonitoringRestMain {
+ // Logger for this class
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexMonitoringRestMain.class);
+
+ // Recurring string constants
+ private static final String REST_ENDPOINT_PREFIX = "Apex Services REST endpoint (";
+
// Services state
public enum ServicesState {
STOPPED, READY, INITIALIZING, RUNNING
@@ -54,7 +63,7 @@ public class ApexMonitoringRestMain {
final ApexMonitoringRestMain restMain = new ApexMonitoringRestMain(args, System.out);
restMain.init();
} catch (final Exception e) {
- System.err.println(e.getMessage());
+ LOGGER.error("start failed", e);
}
}
@@ -76,7 +85,7 @@ public class ApexMonitoringRestMain {
parameters = parser.parse(args);
} catch (final ApexMonitoringRestParameterException e) {
throw new ApexMonitoringRestParameterException(
- "Apex Services REST endpoint (" + this.toString() + ") parameter error, " + e.getMessage() + '\n'
+ REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, " + e.getMessage() + '\n'
+ parser.getHelp(ApexMonitoringRestMain.class.getCanonicalName()));
}
@@ -89,7 +98,7 @@ public class ApexMonitoringRestMain {
final String validationMessage = parameters.validate();
if (validationMessage.length() > 0) {
throw new ApexMonitoringRestParameterException(
- "Apex Services REST endpoint (" + this.toString() + ") parameters invalid, " + validationMessage
+ REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + validationMessage
+ '\n' + parser.getHelp(ApexMonitoringRestMain.class.getCanonicalName()));
}
@@ -100,8 +109,8 @@ public class ApexMonitoringRestMain {
* Initialize the rest service.
*/
public void init() {
- outStream.println("Apex Services REST endpoint (" + this.toString() + ") starting at "
- + parameters.getBaseURI().toString() + " . . .");
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at "
+ + parameters.getBaseUri().toString() + " . . .");
try {
state = ServicesState.INITIALIZING;
@@ -115,10 +124,10 @@ public class ApexMonitoringRestMain {
state = ServicesState.RUNNING;
if (parameters.getTimeToLive() == ApexMonitoringRestParameters.INFINITY_TIME_TO_LIVE) {
- outStream.println("Apex Services REST endpoint (" + this.toString() + ") started at "
- + parameters.getBaseURI().toString());
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started at "
+ + parameters.getBaseUri().toString());
} else {
- outStream.println("Apex Services REST endpoint (" + this.toString() + ") started");
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started");
}
// Find out how long is left to wait
@@ -134,7 +143,7 @@ public class ApexMonitoringRestMain {
}
} catch (final Exception e) {
outStream.println(
- "Apex Services REST endpoint (" + this.toString() + ") failed at with error: " + e.getMessage());
+ REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage());
} finally {
if (apexMonitoringRest != null) {
apexMonitoringRest.shutdown();
@@ -167,11 +176,11 @@ public class ApexMonitoringRestMain {
*/
public void shutdown() {
if (apexMonitoringRest != null) {
- outStream.println("Apex Services REST endpoint (" + this.toString() + ") shutting down");
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") shutting down");
apexMonitoringRest.shutdown();
}
state = ServicesState.STOPPED;
- outStream.println("Apex Services REST endpoint (" + this.toString() + ") shut down");
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") shut down");
}
/**
diff --git a/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestParameterParser.java b/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestParameterParser.java
index af2ff6821..f5c8ad8c0 100644
--- a/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestParameterParser.java
+++ b/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestParameterParser.java
@@ -81,7 +81,7 @@ public class ApexMonitoringRestParameterParser {
}
try {
if (commandLine.hasOption('p')) {
- parameters.setRESTPort(((Number) commandLine.getParsedOptionValue("port")).intValue());
+ parameters.setRestPort(((Number) commandLine.getParsedOptionValue("port")).intValue());
}
} catch (final ParseException e) {
throw new ApexMonitoringRestParameterException("error parsing argument \"port\" :" + e.getMessage(), e);
diff --git a/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestParameters.java b/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestParameters.java
index fea7ae4a8..e4148a470 100644
--- a/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestParameters.java
+++ b/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestParameters.java
@@ -44,6 +44,10 @@ public class ApexMonitoringRestParameters {
private int restPort = DEFAULT_REST_PORT;
private long timeToLive = INFINITY_TIME_TO_LIVE;
+ /**
+ * Validate the parameters.
+ * @return the result of the validation
+ */
public String validate() {
String validationMessage = "";
validationMessage += validatePort();
@@ -52,11 +56,11 @@ public class ApexMonitoringRestParameters {
return validationMessage;
}
- public URI getBaseURI() {
+ public URI getBaseUri() {
return URI.create(DEFAULT_SERVER_URI_ROOT + restPort + DEFAULT_REST_PATH);
}
- public String[] getRESTPackages() {
+ public String[] getRestPackages() {
return DEFAULT_PACKAGES;
}
@@ -88,11 +92,11 @@ public class ApexMonitoringRestParameters {
this.helpSet = helpSet;
}
- public int getRESTPort() {
+ public int getRestPort() {
return restPort;
}
- public void setRESTPort(final int restPort) {
+ public void setRestPort(final int restPort) {
this.restPort = restPort;
}
@@ -107,7 +111,7 @@ public class ApexMonitoringRestParameters {
@Override
public String toString() {
final StringBuilder ret = new StringBuilder();
- ret.append(this.getClass().getSimpleName()).append(": URI=").append(this.getBaseURI()).append(", TTL=")
+ ret.append(this.getClass().getSimpleName()).append(": URI=").append(this.getBaseUri()).append(", TTL=")
.append(this.getTimeToLive()).append("sec");
return ret.toString();
}
diff --git a/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestResource.java b/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestResource.java
index 85465a14b..f8cee7741 100644
--- a/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestResource.java
+++ b/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestResource.java
@@ -48,9 +48,8 @@ import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
/**
- * The class represents the root resource exposed at the base URL<br>
- * The url to access this resource would be in the form {@code <baseURL>/rest/....} <br>
- * For example: a GET request to the following URL
+ * The class represents the root resource exposed at the base URL<br> The url to access this resource would be in the
+ * form {@code <baseURL>/rest/....} <br> For example: a GET request to the following URL
* {@code http://localhost:18989/apexservices/rest/?hostName=localhost&port=12345}
*
* <b>Note:</b> An allocated {@code hostName} and {@code port} query parameter must be included in all requests.
@@ -58,27 +57,26 @@ import org.slf4j.ext.XLoggerFactory;
*
*/
@Path("monitoring/")
-@Produces({ MediaType.APPLICATION_JSON })
-@Consumes({ MediaType.APPLICATION_JSON })
+@Produces(
+ { MediaType.APPLICATION_JSON })
+@Consumes(
+ { MediaType.APPLICATION_JSON })
public class ApexMonitoringRestResource {
// Get a reference to the logger
private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexMonitoringRestResource.class);
+ // Recurring string constants
+ private static final String ERROR_CONNECTING_PREFIX = "Error connecting to Apex Engine Service at ";
+
// Set the maximum number of stored data entries to be stored for each engine
- private static final int maxCachedEntries = 50;
+ private static final int MAX_CACHED_ENTITIES = 50;
// Set up a map separated by host and engine for the data
- private static final HashMap<String, HashMap<String, List<Counter>>> cache =
- new HashMap<String, HashMap<String, List<Counter>>>();
+ private static final HashMap<String, HashMap<String, List<Counter>>> cache = new HashMap<>();
// Set up a map separated by host for storing the state of periodic events
- private static final HashMap<String, Boolean> periodicEventsStateCache = new HashMap<String, Boolean>();
-
- /**
- * Constructor, a new resource director is created for each request.
- */
- public ApexMonitoringRestResource() {}
+ private static final HashMap<String, Boolean> periodicEventsStateCache = new HashMap<>();
/**
* Query the engine service for data.
@@ -96,10 +94,10 @@ public class ApexMonitoringRestResource {
try {
engineServiceFacade.init();
} catch (final ApexDeploymentException e) {
- final String errorMessage = "Error connecting to Apex Engine Service at " + host;
+ final String errorMessage = ERROR_CONNECTING_PREFIX + host;
LOGGER.warn(errorMessage + "<br>", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage + "\n" + e.getMessage())
- .build();
+ .build();
}
final JsonObject responseObject = new JsonObject();
@@ -107,8 +105,8 @@ public class ApexMonitoringRestResource {
// Engine Service data
responseObject.addProperty("engine_id", engineServiceFacade.getKey().getId());
responseObject.addProperty("model_id",
- engineServiceFacade.getApexModelKey() != null ? engineServiceFacade.getApexModelKey().getId()
- : "Not Set");
+ engineServiceFacade.getApexModelKey() != null ? engineServiceFacade.getApexModelKey().getId()
+ : "Not Set");
responseObject.addProperty("server", hostName);
responseObject.addProperty("port", Integer.toString(port));
responseObject.addProperty("periodic_events", getPeriodicEventsState(host));
@@ -127,14 +125,16 @@ public class ApexMonitoringRestResource {
engineStatusObject.addProperty("up_time", axEngineModel.getStats().getUpTime() / 1000L);
engineStatusObject.addProperty("policy_executions", axEngineModel.getStats().getEventCount());
engineStatusObject.addProperty("last_policy_duration",
- gson.toJson(
- getValuesFromCache(host, engineKey.getId() + "_last_policy_duration",
- axEngineModel.getTimestamp(), axEngineModel.getStats().getLastExecutionTime()),
- List.class));
- engineStatusObject.addProperty("average_policy_duration",
- gson.toJson(getValuesFromCache(host, engineKey.getId() + "_average_policy_duration",
- axEngineModel.getTimestamp(),
- (long) axEngineModel.getStats().getAverageExecutionTime()), List.class));
+ gson.toJson(getValuesFromCache(host, engineKey.getId() + "_last_policy_duration",
+ axEngineModel.getTimestamp(),
+ axEngineModel.getStats().getLastExecutionTime()), List.class));
+ engineStatusObject
+ .addProperty("average_policy_duration", gson.toJson(
+ getValuesFromCache(host, engineKey.getId() + "_average_policy_duration",
+ axEngineModel.getTimestamp(),
+ (long) axEngineModel.getStats()
+ .getAverageExecutionTime()),
+ List.class));
engineStatusList.add(engineStatusObject);
} catch (final ApexException e) {
LOGGER.warn("Error getting status of engine with ID " + engineKey.getId() + "<br>", e);
@@ -174,23 +174,26 @@ public class ApexMonitoringRestResource {
@GET
@Path("startstop/")
public Response startStop(@QueryParam("hostName") final String hostName, @QueryParam("port") final int port,
- @QueryParam("engineId") final String engineId, @QueryParam("startstop") final String startStop) {
+ @QueryParam("engineId") final String engineId, @QueryParam("startstop") final String startStop) {
final EngineServiceFacade engineServiceFacade = new EngineServiceFacade(hostName, port);
try {
engineServiceFacade.init();
} catch (final ApexDeploymentException e) {
- final String errorMessage = "Error connecting to Apex Engine Service at " + hostName + ":" + port;
+ final String errorMessage = ERROR_CONNECTING_PREFIX + hostName + ":" + port;
LOGGER.warn(errorMessage + "<br>", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage + "\n" + e.getMessage())
- .build();
+ .build();
}
try {
- final Map<String, String[]> parameterMap = new HashMap<String, String[]>();
- parameterMap.put("hostname", new String[] { hostName });
- parameterMap.put("port", new String[] { Integer.toString(port) });
- parameterMap.put("AxArtifactKey#" + engineId, new String[] { startStop });
+ final Map<String, String[]> parameterMap = new HashMap<>();
+ parameterMap.put("hostname", new String[]
+ { hostName });
+ parameterMap.put("port", new String[]
+ { Integer.toString(port) });
+ parameterMap.put("AxArtifactKey#" + engineId, new String[]
+ { startStop });
final AxArtifactKey engineKey = ParameterCheck.getEngineKey(parameterMap);
if (startStop.equals("Start")) {
engineServiceFacade.startEngine(engineKey);
@@ -203,7 +206,7 @@ public class ApexMonitoringRestResource {
final StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage + "\n" + sw.toString())
- .build();
+ .build();
}
return Response.ok("{}").build();
@@ -222,17 +225,21 @@ public class ApexMonitoringRestResource {
@GET
@Path("periodiceventstartstop/")
public Response periodiceventStartStop(@QueryParam("hostName") final String hostName,
- @QueryParam("port") final int port, @QueryParam("engineId") final String engineId,
- @QueryParam("startstop") final String startStop, @QueryParam("period") final long period) {
+ @QueryParam("port") final int port, @QueryParam("engineId") final String engineId,
+ @QueryParam("startstop") final String startStop, @QueryParam("period") final long period) {
final EngineServiceFacade engineServiceFacade = new EngineServiceFacade(hostName, port);
final String host = hostName + ":" + port;
try {
engineServiceFacade.init();
- final Map<String, String[]> parameterMap = new HashMap<String, String[]>();
- parameterMap.put("hostname", new String[] { hostName });
- parameterMap.put("port", new String[] { Integer.toString(port) });
- parameterMap.put("AxArtifactKey#" + engineId, new String[] { startStop });
- parameterMap.put("period", new String[] { Long.toString(period) });
+ final Map<String, String[]> parameterMap = new HashMap<>();
+ parameterMap.put("hostname", new String[]
+ { hostName });
+ parameterMap.put("port", new String[]
+ { Integer.toString(port) });
+ parameterMap.put("AxArtifactKey#" + engineId, new String[]
+ { startStop });
+ parameterMap.put("period", new String[]
+ { Long.toString(period) });
final AxArtifactKey engineKey = ParameterCheck.getEngineKey(parameterMap);
if (startStop.equals("Start")) {
engineServiceFacade.startPerioidicEvents(engineKey, period);
@@ -242,10 +249,10 @@ public class ApexMonitoringRestResource {
setPeriodicEventsState(host, false);
}
} catch (final ApexDeploymentException e) {
- final String errorMessage = "Error connecting to Apex Engine Service at " + host;
+ final String errorMessage = ERROR_CONNECTING_PREFIX + host;
LOGGER.warn(errorMessage + "<br>", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage + "\n" + e.getMessage())
- .build();
+ .build();
}
return Response.ok("{}").build();
@@ -258,7 +265,11 @@ public class ApexMonitoringRestResource {
* @return a boolean stating if periodic events are running for a given host
*/
private Boolean getPeriodicEventsState(final String host) {
- return periodicEventsStateCache.containsKey(host) ? periodicEventsStateCache.get(host) : false;
+ if (periodicEventsStateCache.containsKey(host)) {
+ return periodicEventsStateCache.get(host);
+ } else {
+ return false;
+ }
}
/**
@@ -282,7 +293,7 @@ public class ApexMonitoringRestResource {
* @return a list of {@code Counter} objects for that engine
*/
private List<Counter> getValuesFromCache(final String host, final String id, final long timestamp,
- final long latestValue) {
+ final long latestValue) {
SlidingWindowList<Counter> valueList;
if (!cache.containsKey(host)) {
@@ -292,7 +303,7 @@ public class ApexMonitoringRestResource {
if (cache.get(host).containsKey(id)) {
valueList = (SlidingWindowList<Counter>) cache.get(host).get(id);
} else {
- valueList = new SlidingWindowList<Counter>(maxCachedEntries);
+ valueList = new SlidingWindowList<>(MAX_CACHED_ENTITIES);
}
valueList.add(new Counter(timestamp, latestValue));