summaryrefslogtreecommitdiffstats
path: root/controlloop/common/policy-yaml
diff options
context:
space:
mode:
authorKrishnajinka <kris.jinka@samsung.com>2018-11-07 19:16:43 +0900
committerKrishnajinka <kris.jinka@samsung.com>2018-11-07 19:42:59 +0900
commit91fe0bcd2d0212f949587ec82d93109946491d63 (patch)
treed3e9be0246e5afb234e27749b7102ecd6dc8bf47 /controlloop/common/policy-yaml
parent72d4564ec8089f6217e7a3773a2aa0dde6306241 (diff)
Apply builder pattern for policy
Fix an issue reported by sonar for using more than 7 parameters in the method. Fix imports order in files. Fix line lengths to less than 120 chars Issue-ID: POLICY-1251 Change-Id: I42defc9d6acf970bb555c4a6c5d172241231e483 Signed-off-by: Krishnajinka <kris.jinka@samsung.com>
Diffstat (limited to 'controlloop/common/policy-yaml')
-rw-r--r--controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Policy.java27
-rw-r--r--controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/PolicyParam.java132
-rw-r--r--controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/impl/ControlLoopPolicyBuilderImpl.java37
-rw-r--r--controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/PolicyTest.java12
4 files changed, 180 insertions, 28 deletions
diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Policy.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Policy.java
index 06dc36e69..b7cb78711 100644
--- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Policy.java
+++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Policy.java
@@ -84,8 +84,8 @@ public class Policy implements Serializable {
* @param retries retries
* @param timeout timeout
*/
- public Policy(String name, String actor, String recipe, Map<String, String> payload, Target target,
- Integer retries, Integer timeout) {
+ public Policy(String name, String actor, String recipe, Map<String, String> payload, Target target,
+ Integer retries, Integer timeout) {
this(name, actor, recipe, payload, target);
this.retry = retries;
this.timeout = timeout;
@@ -93,22 +93,14 @@ public class Policy implements Serializable {
/**
* Constructor.
- *
- * @param id id
- * @param name name
- * @param description description
- * @param actor actor
- * @param payload payload
- * @param target target
- * @param recipe recipe
- * @param retries retries
- * @param timeout timeout
+ *
+ * @param policyParam provide parameter object
*/
- public Policy(String id, String name, String description, String actor, Map<String, String> payload,
- Target target, String recipe, Integer retries, Integer timeout) {
- this(name, actor, recipe, payload, target, retries, timeout);
- this.id = id;
- this.description = description;
+ public Policy(PolicyParam policyParam) {
+ this(policyParam.getName(), policyParam.getActor(), policyParam.getRecipe(), policyParam.getPayload(),
+ policyParam.getTarget(), policyParam.getRetries(), policyParam.getTimeout());
+ this.id = policyParam.getId();
+ this.description = policyParam.getDescription();
}
/**
@@ -341,5 +333,4 @@ public class Policy implements Serializable {
}
return obj1.equals(obj2);
}
-
}
diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/PolicyParam.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/PolicyParam.java
new file mode 100644
index 000000000..8891a3f5b
--- /dev/null
+++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/PolicyParam.java
@@ -0,0 +1,132 @@
+/*
+ * ============LICENSE_START=======================================================
+ * policy-endpoints
+ * ================================================================================
+ * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.controlloop.policy;
+
+import java.util.Map;
+
+public class PolicyParam {
+ private String id;
+ private String name;
+ private String description;
+ private String actor;
+ private Map<String, String> payload;
+ private Target target;
+ private String recipe;
+ private Integer retries;
+ private Integer timeout;
+
+ public static PolicyParamBuilder builder() {
+ return new PolicyParamBuilder();
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getActor() {
+ return actor;
+ }
+
+ public Map<String, String> getPayload() {
+ return payload;
+ }
+
+ public Target getTarget() {
+ return target;
+ }
+
+ public String getRecipe() {
+ return recipe;
+ }
+
+ public Integer getRetries() {
+ return retries;
+ }
+
+ public Integer getTimeout() {
+ return timeout;
+ }
+
+ public static class PolicyParamBuilder {
+
+ PolicyParam policyParm = new PolicyParam();
+
+ private PolicyParamBuilder() {
+ }
+
+ public PolicyParam build() {
+ return policyParm;
+ }
+
+ public PolicyParamBuilder id(String id) {
+ policyParm.id = id;
+ return this;
+ }
+
+ public PolicyParamBuilder name(String name) {
+ policyParm.name = name;
+ return this;
+ }
+
+ public PolicyParamBuilder description(String description) {
+ policyParm.description = description;
+ return this;
+ }
+
+ public PolicyParamBuilder actor(String actor) {
+ policyParm.actor = actor;
+ return this;
+ }
+
+ public PolicyParamBuilder payload(Map<String, String> payload) {
+ policyParm.payload = payload;
+ return this;
+ }
+
+ public PolicyParamBuilder target(Target target) {
+ policyParm.target = target;
+ return this;
+ }
+
+ public PolicyParamBuilder recipe(String recipe) {
+ policyParm.recipe = recipe;
+ return this;
+ }
+
+ public PolicyParamBuilder retries(Integer retries) {
+ policyParm.retries = retries;
+ return this;
+ }
+
+ public PolicyParamBuilder timeout(Integer timeout) {
+ policyParm.timeout = timeout;
+ return this;
+ }
+ }
+} \ No newline at end of file
diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/impl/ControlLoopPolicyBuilderImpl.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/impl/ControlLoopPolicyBuilderImpl.java
index ba434356a..48f929149 100644
--- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/impl/ControlLoopPolicyBuilderImpl.java
+++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/impl/ControlLoopPolicyBuilderImpl.java
@@ -21,11 +21,9 @@
package org.onap.policy.controlloop.policy.builder.impl;
import com.google.common.base.Strings;
-
import java.util.LinkedList;
import java.util.Map;
import java.util.UUID;
-
import org.onap.policy.aai.Pnf;
import org.onap.policy.controlloop.compiler.CompilerException;
import org.onap.policy.controlloop.compiler.ControlLoopCompiler;
@@ -35,6 +33,7 @@ import org.onap.policy.controlloop.policy.ControlLoopPolicy;
import org.onap.policy.controlloop.policy.FinalResult;
import org.onap.policy.controlloop.policy.OperationsAccumulateParams;
import org.onap.policy.controlloop.policy.Policy;
+import org.onap.policy.controlloop.policy.PolicyParam;
import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.controlloop.policy.Target;
import org.onap.policy.controlloop.policy.builder.BuilderException;
@@ -200,11 +199,21 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder {
}
@Override
- public Policy setTriggerPolicy(String name, String description, String actor, Target target, String recipe,
- Map<String, String> payload, Integer retries, Integer timeout) throws BuilderException {
+ public Policy setTriggerPolicy(String name, String description, String actor, Target target,
+ String recipe, Map<String, String> payload, Integer retries, Integer timeout)
+ throws BuilderException {
- Policy trigger = new Policy(UUID.randomUUID().toString(), name, description, actor, payload, target, recipe,
- retries, timeout);
+ Policy trigger = new Policy(PolicyParam.builder()
+ .id(UUID.randomUUID().toString())
+ .name(name)
+ .description(description)
+ .actor(actor)
+ .payload(payload)
+ .target(target)
+ .recipe(recipe)
+ .retries(retries)
+ .timeout(timeout)
+ .build());
controlLoopPolicy.getControlLoop().setTrigger_policy(trigger.getId());
@@ -231,7 +240,8 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder {
@Override
public Policy setPolicyForPolicyResult(String name, String description, String actor, Target target, String recipe,
- Map<String, String> payload, Integer retries, Integer timeout, String policyId, PolicyResult... results)
+ Map<String, String> payload, Integer retries, Integer timeout,
+ String policyId, PolicyResult... results)
throws BuilderException {
//
// Find the existing policy
@@ -243,8 +253,17 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder {
//
// Create the new Policy
//
- Policy newPolicy = new Policy(UUID.randomUUID().toString(), name, description, actor, payload, target, recipe,
- retries, timeout);
+ Policy newPolicy = new Policy(
+ PolicyParam.builder().id(UUID.randomUUID().toString())
+ .name(name)
+ .description(description)
+ .actor(actor)
+ .payload(payload)
+ .target(target)
+ .recipe(recipe)
+ .retries(retries)
+ .timeout(timeout)
+ .build());
//
// Connect the results
//
diff --git a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/PolicyTest.java b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/PolicyTest.java
index 6e13b326b..d903b1534 100644
--- a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/PolicyTest.java
+++ b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/PolicyTest.java
@@ -161,7 +161,17 @@ public class PolicyTest {
Target target = new Target();
target.setResourceID("myresourceD");
- policy = new Policy("idD", "nameD", "descD", "actorD", payload, target, "recipeD", 301, 302);
+ policy = new Policy(
+ PolicyParam.builder().id("idD")
+ .name("nameD")
+ .description("descD")
+ .actor("actorD")
+ .payload(payload)
+ .target(target)
+ .recipe("recipeD")
+ .retries(301)
+ .timeout(302)
+ .build());
assertEquals("idD", policy.getId());
assertEquals("nameD", policy.getName());
assertEquals("descD", policy.getDescription());