summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-impl/rest/src/main
diff options
context:
space:
mode:
authorStraubs, Ralph (rs8887) <rs8887@att.com>2019-10-22 10:43:09 -0500
committerStraubs, Ralph (rs8887) <rs8887@att.com>2019-10-24 11:09:45 -0500
commitffc78b2ad00d35e49e8ca3f8524483f6df171d50 (patch)
tree44613578158b205e82e339e82f92d486d804501d /models-interactions/model-impl/rest/src/main
parent5f69582dfaf325a8552ebeaa7cd69f81bc7d478f (diff)
Changes in preparation for the m2 model
1) Replace enum 'ControlLoopTargetType' with 'String' -- symbols such as 'ControlLoopTargetType.VM' still work, but now expand into a String. This gives the ability to add new application-specific types. 2) Move 'ControlLoopEvent.payload' to 'VirtualControlLoopEvent'. This symbol isn't common to all 'ControlLoopEvent' types, and this definition collides with a 'payload' defined in our application. 3) Add 'RestManager.patch(...)', which performs a REST patch. 4) Add lombok getters and setters 5) Remove trailing spaces 6) Fix order of arguments in 'assertEquals' in 'ControlLoopTargetTypeTest' 7) Update Junit tests in 'RestTest' to include 'RestManager.patch(...)' Issue-ID: POLICY-1948 Signed-off-by: Straubs, Ralph (rs8887) <rs8887@att.com> Change-Id: I08e04ea3cbcf368c760b630bcfe23a4370cf94dc
Diffstat (limited to 'models-interactions/model-impl/rest/src/main')
-rw-r--r--models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java28
1 files changed, 28 insertions, 0 deletions
diff --git a/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java b/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java
index 643c629b3..dde3aa2e2 100644
--- a/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java
+++ b/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java
@@ -29,6 +29,7 @@ import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPatch;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpRequestBase;
@@ -172,6 +173,33 @@ public class RestManager {
}
/**
+ * Perform REST Patch.
+ *
+ * @param url the url
+ * @param username the user name
+ * @param password the password
+ * @param headers any headers
+ * @param body body to send
+ * @return the response status code and the body
+ */
+ public Pair<Integer, String> patch(String url, String username, String password,
+ Map<String, String> headers, String body) {
+ String contentType = "application/merge-patch+json";
+ HttpPatch patch = new HttpPatch(url);
+ addHeaders(patch, username, password, headers);
+ patch.addHeader(CONTENT_TYPE, contentType);
+ try {
+ StringEntity input = new StringEntity(body);
+ input.setContentType(contentType);
+ patch.setEntity(input);
+ } catch (Exception e) {
+ logger.error("patch threw: ", e);
+ return null;
+ }
+ return sendRequest(patch);
+ }
+
+ /**
* Send REST request.
*
* @param request http request to send