From 517610a8a99a416ba4e81b333dea7deca10caed2 Mon Sep 17 00:00:00 2001 From: Arindam Mondal Date: Mon, 18 Feb 2019 18:27:51 +0900 Subject: Fix sonar code smell Issue-ID: POLICY-1523 Change-Id: I24f9fe5811bb93597efe79c98572c5249e74026c Signed-off-by: arindamm --- .../auth/clicodegen/CodeGeneratorCliEditor.java | 23 ++-- .../auth/clicodegen/TaskDeclarationBuilder.java | 118 +++++++++++++++++++++ .../clicodegen/CodeGeneratorCliEditorTest.java | 8 +- 3 files changed, 135 insertions(+), 14 deletions(-) create mode 100644 auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/TaskDeclarationBuilder.java (limited to 'auth/cli-codegen/src') diff --git a/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditor.java b/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditor.java index acfc087ac..0636bbef6 100644 --- a/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditor.java +++ b/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditor.java @@ -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 infields, final List outfields, final ST logic, final List parameters, - final List 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 index 000000000..566fa03d8 --- /dev/null +++ b/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/TaskDeclarationBuilder.java @@ -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 infields; + private List outfields; + private ST logic; + private List parameters; + private List contextRefs; + + public String getName() { + return name; + } + + public String getVersion() { + return version; + } + + public String getUuid() { + return uuid; + } + + public String getDescription() { + return description; + } + + public List getInfields() { + return infields; + } + + public List getOutfields() { + return outfields; + } + + public ST getLogic() { + return logic; + } + + public List getParameters() { + return parameters; + } + + public List 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 infields) { + this.infields = infields; + return this; + } + + public TaskDeclarationBuilder setOutfields(List outfields) { + this.outfields = outfields; + return this; + } + + public TaskDeclarationBuilder setLogic(ST logic) { + this.logic = logic; + return this; + } + + public TaskDeclarationBuilder setParameters(List parameters) { + this.parameters = parameters; + return this; + } + + public TaskDeclarationBuilder setContextRefs(List contextRefs) { + this.contextRefs = contextRefs; + return this; + } +} diff --git a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java index e1bf3b298..615f2e903 100644 --- a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java +++ b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java @@ -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 parameters = getParametersForTask(codeGen, t); final List 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 -- cgit 1.2.3-korg