Fix sonar code smell 36/78636/3
authorArindam Mondal <arind.mondal@samsung.com>
Mon, 18 Feb 2019 09:27:51 +0000 (18:27 +0900)
committerarindamm <arind.mondal@samsung.com>
Wed, 20 Feb 2019 01:59:42 +0000 (10:59 +0900)
Issue-ID: POLICY-1523
Change-Id: I24f9fe5811bb93597efe79c98572c5249e74026c
Signed-off-by: arindamm <arind.mondal@samsung.com>
auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditor.java
auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/TaskDeclarationBuilder.java [new file with mode: 0644]
auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java
tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2cli/Model2Cli.java

index acfc087..0636bbe 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ *  Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -278,19 +279,17 @@ public class CodeGeneratorCliEditor {
      * @param parameters any task parameter
      * @param contextRefs any context reference
      */
-    public void addTaskDeclaration(final String name, final String version, final String uuid, final String description,
-            final List<ST> infields, final List<ST> outfields, final ST logic, final List<ST> parameters,
-            final List<ST> contextRefs) {
+    public void addTaskDeclaration(TaskDeclarationBuilder taskDeclarationBuilder) {
         final ST st = stg.getInstanceOf("taskDecl");
-        st.add(NAME, name);
-        st.add(VERSION, version);
-        st.add(UUID, uuid);
-        st.add(DESCRIPTION, description);
-        st.add(INFIELDS, infields);
-        st.add(OUTFIELDS, outfields);
-        st.add(LOGIC, logic);
-        st.add(PARAMS, parameters);
-        st.add(CONTEXT_REFS, contextRefs);
+        st.add(NAME, taskDeclarationBuilder.getName());
+        st.add(VERSION, taskDeclarationBuilder.getVersion());
+        st.add(UUID, taskDeclarationBuilder.getUuid());
+        st.add(DESCRIPTION, taskDeclarationBuilder.getDescription());
+        st.add(INFIELDS, taskDeclarationBuilder.getInfields());
+        st.add(OUTFIELDS, taskDeclarationBuilder.getOutfields());
+        st.add(LOGIC, taskDeclarationBuilder.getLogic());
+        st.add(PARAMS, taskDeclarationBuilder.getParameters());
+        st.add(CONTEXT_REFS, taskDeclarationBuilder.getContextRefs());
         model.add(DECLARATION, st);
     }
 
diff --git a/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/TaskDeclarationBuilder.java b/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/TaskDeclarationBuilder.java
new file mode 100644 (file)
index 0000000..566fa03
--- /dev/null
@@ -0,0 +1,118 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.auth.clicodegen;
+
+import java.util.List;
+import org.stringtemplate.v4.ST;
+
+public class TaskDeclarationBuilder {
+
+    private String name;
+    private String version;
+    private String uuid;
+    private String description;
+    private List<ST> infields;
+    private List<ST> outfields;
+    private ST logic;
+    private List<ST> parameters;
+    private List<ST> contextRefs;
+
+    public String getName() {
+        return name;
+    }
+
+    public String getVersion() {
+        return version;
+    }
+
+    public String getUuid() {
+        return uuid;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public List<ST> getInfields() {
+        return infields;
+    }
+
+    public List<ST> getOutfields() {
+        return outfields;
+    }
+
+    public ST getLogic() {
+        return logic;
+    }
+
+    public List<ST> getParameters() {
+        return parameters;
+    }
+
+    public List<ST> getContextRefs() {
+        return contextRefs;
+    }
+
+    public TaskDeclarationBuilder setName(String name) {
+        this.name = name;
+        return this;
+    }
+
+    public TaskDeclarationBuilder setVersion(String version) {
+        this.version = version;
+        return this;
+    }
+
+    public TaskDeclarationBuilder setUuid(String uuid) {
+        this.uuid = uuid;
+        return this;
+    }
+
+    public TaskDeclarationBuilder setDescription(String description) {
+        this.description = description;
+        return this;
+    }
+
+    public TaskDeclarationBuilder setInfields(List<ST> infields) {
+        this.infields = infields;
+        return this;
+    }
+
+    public TaskDeclarationBuilder setOutfields(List<ST> outfields) {
+        this.outfields = outfields;
+        return this;
+    }
+
+    public TaskDeclarationBuilder setLogic(ST logic) {
+        this.logic = logic;
+        return this;
+    }
+
+    public TaskDeclarationBuilder setParameters(List<ST> parameters) {
+        this.parameters = parameters;
+        return this;
+    }
+
+    public TaskDeclarationBuilder setContextRefs(List<ST> contextRefs) {
+        this.contextRefs = contextRefs;
+        return this;
+    }
+}
index e1bf3b2..615f2e9 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2018 Ericsson. All rights reserved.
+ *  Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -120,8 +121,11 @@ public class CodeGeneratorCliEditorTest {
             final List<ST> parameters = getParametersForTask(codeGen, t);
             final List<ST> contextRefs = getCtxtRefsForTask(codeGen, t);
 
-            codeGen.addTaskDeclaration(kig.getName(key), kig.getVersion(key), kig.getUuid(key), kig.getDesc(key),
-                            infields, outfields, logic, parameters, contextRefs);
+            codeGen.addTaskDeclaration(
+                    new TaskDeclarationBuilder().setName(kig.getName(key)).setVersion(kig.getVersion(key))
+                            .setUuid(kig.getUuid(key)).setDescription(kig.getDesc(key)).setInfields(infields)
+                            .setOutfields(outfields).setLogic(logic).setParameters(parameters)
+                            .setContextRefs(contextRefs));
         }
 
         // 3: events
index 4d2e99b..f5f0d66 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ *  Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -34,6 +35,7 @@ import org.apache.commons.lang3.Validate;
 import org.onap.policy.apex.auth.clicodegen.CodeGenCliEditorBuilder;
 import org.onap.policy.apex.auth.clicodegen.CodeGeneratorCliEditor;
 import org.onap.policy.apex.auth.clicodegen.EventDeclarationBuilder;
+import org.onap.policy.apex.auth.clicodegen.TaskDeclarationBuilder;
 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
@@ -168,8 +170,10 @@ public class Model2Cli {
             final List<ST> parameters = getParametersForTask(codeGen, t);
             final List<ST> contextRefs = getCtxtRefsForTask(codeGen, t);
 
-            codeGen.addTaskDeclaration(kig.getName(key), kig.getVersion(key), kig.getUuid(key), kig.getDesc(key),
-                    infields, outfields, logic, parameters, contextRefs);
+            codeGen.addTaskDeclaration(new TaskDeclarationBuilder().setName(kig.getName(key))
+                    .setVersion(kig.getVersion(key)).setUuid(kig.getUuid(key))
+                    .setDescription(kig.getDesc(key)).setInfields(infields).setOutfields(outfields)
+                    .setLogic(logic).setParameters(parameters).setContextRefs(contextRefs));
         }
 
         // 3: events