summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormichal.banka <michal.banka@nokia.com>2019-03-12 13:01:26 +0100
committermichal.banka <michal.banka@nokia.com>2019-03-12 13:02:20 +0100
commit89695a32a794bd1a12464878a7ce834b2e2e07d3 (patch)
tree14541dcf194de8ecc1358e40035d9969e04ca20e
parent43f0b01f68e145b74993e31adf7ef41379c72be1 (diff)
Add updateGlobalPropertiesJson controller
Change-Id: I83d474a3616462cdb0cc31eadae3a189dd275683 Issue-ID: CLAMP-301 Signed-off-by: michal.banka <michal.banka@nokia.com>
-rw-r--r--src/main/java/org/onap/clamp/loop/LoopController.java10
-rw-r--r--src/main/java/org/onap/clamp/loop/LoopService.java38
-rw-r--r--src/main/resources/clds/camel/rest/clamp-api-v2.xml13
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java40
4 files changed, 75 insertions, 26 deletions
diff --git a/src/main/java/org/onap/clamp/loop/LoopController.java b/src/main/java/org/onap/clamp/loop/LoopController.java
index 7e4517492..2bcce1e37 100644
--- a/src/main/java/org/onap/clamp/loop/LoopController.java
+++ b/src/main/java/org/onap/clamp/loop/LoopController.java
@@ -24,6 +24,8 @@
package org.onap.clamp.loop;
import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
@@ -60,13 +62,17 @@ public class LoopController {
public Loop updateOperationalPolicies(String loopName, JsonArray operationalPoliciesJson) {
List<OperationalPolicy> operationalPolicies = JsonUtils.GSON
.fromJson(operationalPoliciesJson, OPERATIONAL_POLICY_TYPE);
- return loopService.updateOperationalPolicies(loopName, operationalPolicies);
+ return loopService.updateAndSaveOperationalPolicies(loopName, operationalPolicies);
}
public Loop updateMicroservicePolicies(String loopName, JsonArray microServicePoliciesJson) {
List<MicroServicePolicy> microservicePolicies = JsonUtils.GSON
.fromJson(microServicePoliciesJson, MICROSERVICE_POLICY_TYPE);
- return loopService.updateMicroservicePolicies(loopName, microservicePolicies);
+ return loopService.updateAndSaveMicroservicePolicies(loopName, microservicePolicies);
+ }
+
+ public Loop updateGlobalPropertiesJson(String loopName, JsonObject globalProperties){
+ return loopService.updateAndSaveGlobalPropertiesJson(loopName, globalProperties);
}
public String getSVGRepresentation(String loopName) {
diff --git a/src/main/java/org/onap/clamp/loop/LoopService.java b/src/main/java/org/onap/clamp/loop/LoopService.java
index 91b4bdf89..cf2f4c669 100644
--- a/src/main/java/org/onap/clamp/loop/LoopService.java
+++ b/src/main/java/org/onap/clamp/loop/LoopService.java
@@ -26,6 +26,8 @@ package org.onap.clamp.loop;
import java.util.List;
import java.util.Set;
import javax.persistence.EntityNotFoundException;
+
+import com.google.gson.JsonObject;
import org.onap.clamp.policy.microservice.MicroservicePolicyService;
import org.onap.clamp.policy.operational.OperationalPolicyService;
import org.onap.clamp.policy.microservice.MicroServicePolicy;
@@ -66,22 +68,42 @@ public class LoopService {
return closedLoopByName.getSvgRepresentation();
}
- Loop updateOperationalPolicies(String loopName, List<OperationalPolicy> newOperationalPolicies) {
+ Loop updateAndSaveOperationalPolicies(String loopName, List<OperationalPolicy> newOperationalPolicies) {
Loop loop = findClosedLoopByName(loopName);
- Set<OperationalPolicy> newPolicies = operationalPolicyService
- .updatePolicies(loop, newOperationalPolicies);
+ updateOperationalPolicies(loop, newOperationalPolicies);
+ return loopsRepository.save(loop);
+ }
- loop.setOperationalPolicies(newPolicies);
+ Loop updateAndSaveMicroservicePolicies(String loopName, List<MicroServicePolicy> newMicroservicePolicies) {
+ Loop loop = findClosedLoopByName(loopName);
+ updateMicroservicePolicies(loop, newMicroservicePolicies);
return loopsRepository.save(loop);
}
- Loop updateMicroservicePolicies(String loopName, List<MicroServicePolicy> newMicroservicePolicies) {
+ Loop updateAndSaveGlobalPropertiesJson(String loopName, JsonObject newGlobalPropertiesJson) {
Loop loop = findClosedLoopByName(loopName);
- Set<MicroServicePolicy> newPolicies = microservicePolicyService
- .updatePolicies(loop, newMicroservicePolicies);
+ updateGlobalPropertiesJson(loop, newGlobalPropertiesJson);
+ return loopsRepository.save(loop);
+ }
+ private Loop updateOperationalPolicies(Loop loop, List<OperationalPolicy> newOperationalPolicies) {
+ Set<OperationalPolicy> newPolicies = operationalPolicyService
+ .updatePolicies(loop, newOperationalPolicies);
+
+ loop.setOperationalPolicies(newPolicies);
+ return loop;
+ }
+
+ private Loop updateMicroservicePolicies(Loop loop, List<MicroServicePolicy> newMicroservicePolicies) {
+ Set<MicroServicePolicy> newPolicies = microservicePolicyService
+ .updatePolicies(loop, newMicroservicePolicies);
loop.setMicroServicePolicies(newPolicies);
- return loopsRepository.save(loop);
+ return loop;
+ }
+
+ private Loop updateGlobalPropertiesJson(Loop loop, JsonObject newGlobalPropertiesJson) {
+ loop.setGlobalPropertiesJson(newGlobalPropertiesJson);
+ return loop;
}
private Loop findClosedLoopByName(String loopName) {
diff --git a/src/main/resources/clds/camel/rest/clamp-api-v2.xml b/src/main/resources/clds/camel/rest/clamp-api-v2.xml
index 442375278..abc7dc091 100644
--- a/src/main/resources/clds/camel/rest/clamp-api-v2.xml
+++ b/src/main/resources/clds/camel/rest/clamp-api-v2.xml
@@ -20,13 +20,14 @@
<to
uri="bean:org.onap.clamp.loop.LoopController?method=getSVGRepresentation(${header.loopName})" />
</get>
- <post uri="/v2/loop/globalProperties/{loopName}"
- type="com.google.gson.JsonArray"
- consumes="application/json"
- outType="org.onap.clamp.loop.Loop"
- produces="application/json">
+
+ <post uri="/v2/loop/updateGlobalProperties/{loopName}"
+ type="com.google.gson.JsonObject"
+ consumes="application/json"
+ outType="org.onap.clamp.loop.Loop"
+ produces="application/json">
<to
- uri="bean:org.onap.clamp.loop.LoopController?method=updateOperationalPolicies(${header.loopName},${body})" />
+ uri="bean:org.onap.clamp.loop.LoopController?method=updateGlobalPropertiesJson(${header.loopName},${body})" />
</post>
<post uri="/v2/loop/updateOperationalPolicies/{loopName}"
type="com.google.gson.JsonArray"
diff --git a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
index b7781bf2c..d247344a6 100644
--- a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
+++ b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
@@ -92,7 +92,7 @@ public class LoopServiceTestItCase {
//when
Loop actualLoop = loopService
- .updateOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(operationalPolicy));
+ .updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(operationalPolicy));
//then
assertThat(actualLoop).isNotNull();
@@ -118,7 +118,7 @@ public class LoopServiceTestItCase {
//when
Loop actualLoop = loopService
- .updateMicroservicePolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(microServicePolicy));
+ .updateAndSaveMicroservicePolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(microServicePolicy));
//then
assertThat(actualLoop).isNotNull();
@@ -143,14 +143,14 @@ public class LoopServiceTestItCase {
String secondPolicyTosca = "secondPolicyTosca";
MicroServicePolicy firstMicroServicePolicy = new MicroServicePolicy(firstPolicyName, "policyTosca",
false, JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
- loopService.updateMicroservicePolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstMicroServicePolicy));
+ loopService.updateAndSaveMicroservicePolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstMicroServicePolicy));
MicroServicePolicy secondMicroServicePolicy = new MicroServicePolicy(secondPolicyName, secondPolicyTosca, true,
newJsonRepresentation, null);
//when
firstMicroServicePolicy.setJsonRepresentation(newJsonRepresentation);
- Loop actualLoop = loopService.updateMicroservicePolicies(EXAMPLE_LOOP_NAME,
+ Loop actualLoop = loopService.updateAndSaveMicroservicePolicies(EXAMPLE_LOOP_NAME,
Lists.newArrayList(firstMicroServicePolicy, secondMicroServicePolicy));
//then
@@ -180,14 +180,14 @@ public class LoopServiceTestItCase {
String secondPolicyTosca = "secondPolicyTosca";
MicroServicePolicy firstMicroServicePolicy = new MicroServicePolicy(firstPolicyName, "policyTosca",
false, JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
- loopService.updateMicroservicePolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstMicroServicePolicy));
+ loopService.updateAndSaveMicroservicePolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstMicroServicePolicy));
MicroServicePolicy secondMicroServicePolicy = new MicroServicePolicy(secondPolicyName, secondPolicyTosca, true,
jsonRepresentation, null);
//when
Loop actualLoop = loopService
- .updateMicroservicePolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(secondMicroServicePolicy));
+ .updateAndSaveMicroservicePolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(secondMicroServicePolicy));
//then
assertThat(actualLoop).isNotNull();
@@ -210,13 +210,13 @@ public class LoopServiceTestItCase {
String secondPolicyName = "secondPolicyName";
OperationalPolicy firstOperationalPolicy = new OperationalPolicy(firstPolicyName, null,
JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class));
- loopService.updateOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstOperationalPolicy));
+ loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstOperationalPolicy));
OperationalPolicy secondOperationalPolicy = new OperationalPolicy(secondPolicyName, null, newJsonConfiguration);
//when
firstOperationalPolicy.setConfigurationsJson(newJsonConfiguration);
- Loop actualLoop = loopService.updateOperationalPolicies(EXAMPLE_LOOP_NAME,
+ Loop actualLoop = loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME,
Lists.newArrayList(firstOperationalPolicy, secondOperationalPolicy));
//then
@@ -244,13 +244,13 @@ public class LoopServiceTestItCase {
String secondPolicyName = "policyName";
OperationalPolicy firstOperationalPolicy = new OperationalPolicy(firstPolicyName, null,
JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class));
- loopService.updateOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstOperationalPolicy));
+ loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstOperationalPolicy));
OperationalPolicy secondOperationalPolicy = new OperationalPolicy(secondPolicyName, null, jsonRepresentation);
//when
Loop actualLoop = loopService
- .updateOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(secondOperationalPolicy));
+ .updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(secondOperationalPolicy));
//then
assertThat(actualLoop).isNotNull();
@@ -264,6 +264,26 @@ public class LoopServiceTestItCase {
}
+ @Test
+ public void shouldCreateModelPropertiesAndUpdateJsonRepresentationOfOldOne() {
+ //given
+ saveTestLoopToDb();
+ String expectedJson = "{\"test\":\"test\"}";
+ JsonObject baseGlobalProperites = JsonUtils.GSON.fromJson("{}", JsonObject.class);
+ JsonObject updatedGlobalProperites = JsonUtils.GSON.fromJson(expectedJson, JsonObject.class);
+ loopService.updateAndSaveGlobalPropertiesJson(EXAMPLE_LOOP_NAME, baseGlobalProperites);
+
+ //when
+ Loop actualLoop = loopService
+ .updateAndSaveGlobalPropertiesJson(EXAMPLE_LOOP_NAME, updatedGlobalProperites);
+
+ //then
+ assertThat(actualLoop).isNotNull();
+ assertThat(actualLoop.getName()).isEqualTo(EXAMPLE_LOOP_NAME);
+ JsonObject returnedGlobalProperties = actualLoop.getGlobalPropertiesJson();
+ assertThat(returnedGlobalProperties.getAsJsonObject()).isEqualTo(updatedGlobalProperites);
+ }
+
private Loop createTestLoop(String loopName, String loopBlueprint, String loopSvg) {
return new Loop(loopName, loopBlueprint, loopSvg);
}