diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2019-02-25 20:03:28 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-02-25 20:03:28 +0000 |
commit | 44e82485ceb9845280a6a2115dd1c0c59a6037c1 (patch) | |
tree | 58c967e55acd5910084b5e175fe3d3c800c88330 | |
parent | 085fed0cc5b2aca4bd4af81c7ccd5ad4d3aa5a10 (diff) | |
parent | 9a80ab9464a0ccdb8ae7829ed4a30042d35ae876 (diff) |
Merge "sonar:reduce number of method param"
3 files changed, 217 insertions, 93 deletions
diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ApexModelImpl.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ApexModelImpl.java index c15eadc7d..fae1d5951 100644 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ApexModelImpl.java +++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ApexModelImpl.java @@ -931,22 +931,36 @@ public final class ApexModelImpl implements ApexModel { return policyFacade.deletePolicyStateFinalizerLogic(name, version, stateName, finalizerLogicName); } - /* - * (non-Javadoc) - * - * @see - * org.onap.policy.apex.core.modelapi.ApexEditorAPI#createPolicyStateTaskRef(java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.lang.String) - */ - @Override - // CHECKSTYLE:OFF: checkstyle:parameterNumber - public ApexApiResult createPolicyStateTaskRef(final String name, final String version, final String stateName, - final String taskLocalName, final String taskName, final String taskVersion, final String outputType, - final String outputName) { - return policyFacade.createPolicyStateTaskRef(name, version, stateName, taskLocalName, taskName, taskVersion, - outputType, outputName); - } + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.core.modelapi.ApexEditorAPI#createPolicyStateTaskRef(java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.lang.String) + */ + @Override + // CHECKSTYLE:OFF: checkstyle:parameterNumber + public ApexApiResult createPolicyStateTaskRef( + final String name, + final String version, + final String stateName, + final String taskLocalName, + final String taskName, + final String taskVersion, + final String outputType, + final String outputName) { + return policyFacade.createPolicyStateTaskRef( + new CreatePolicyStateTaskRefBuilder() + .setName(name) + .setVersion(version) + .setStateName(stateName) + .setTaskLocalName(taskLocalName) + .setTaskName(taskName) + .setTaskVersion(taskVersion) + .setOutputType(outputType) + .setOutputName(outputName)); + } // CHECKSTYLE:ON: checkstyle:parameterNumber /* diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/CreatePolicyStateTaskRefBuilder.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/CreatePolicyStateTaskRefBuilder.java new file mode 100644 index 000000000..d313c9d24 --- /dev/null +++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/CreatePolicyStateTaskRefBuilder.java @@ -0,0 +1,104 @@ +/*- + * ============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.model.modelapi.impl; + +public class CreatePolicyStateTaskRefBuilder { + private String name; + private String version; + private String stateName; + private String taskLocalName; + private String taskName; + private String taskVersion; + private String outputType; + private String outputName; + + public String getName() { + return name; + } + + public String getVersion() { + return version; + } + + public String getStateName() { + return stateName; + } + + public String getTaskLocalName() { + return taskLocalName; + } + + public String getTaskName() { + return taskName; + } + + public String getTaskVersion() { + return taskVersion; + } + + public String getOutputType() { + return outputType; + } + + public String getOutputName() { + return outputName; + } + + public CreatePolicyStateTaskRefBuilder setName(String name) { + this.name = name; + return this; + } + + public CreatePolicyStateTaskRefBuilder setVersion(String version) { + this.version = version; + return this; + } + + public CreatePolicyStateTaskRefBuilder setStateName(String stateName) { + this.stateName = stateName; + return this; + } + + public CreatePolicyStateTaskRefBuilder setTaskLocalName(String taskLocalName) { + this.taskLocalName = taskLocalName; + return this; + } + + public CreatePolicyStateTaskRefBuilder setTaskName(String taskName) { + this.taskName = taskName; + return this; + } + + public CreatePolicyStateTaskRefBuilder setTaskVersion(String taskVersion) { + this.taskVersion = taskVersion; + return this; + } + + public CreatePolicyStateTaskRefBuilder setOutputType(String outputType) { + this.outputType = outputType; + return this; + } + + public CreatePolicyStateTaskRefBuilder setOutputName(String outputName) { + this.outputName = outputName; + return this; + } +} diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/PolicyFacade.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/PolicyFacade.java index 1d07b2e8c..d43ef3bd0 100644 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/PolicyFacade.java +++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/PolicyFacade.java @@ -1010,85 +1010,91 @@ public class PolicyFacade { } } - /** - * Create a policy state task reference. - * - * @param name name of the policy - * @param version version of the policy, set to null to use the latest version - * @param stateName of the state - * @param taskLocalName the task local name - * @param taskName name of the task - * @param taskVersion version of the task, set to null to use the latest version - * @param outputType Type of output for the task, must be DIRECT for direct output to a state - * output or LOGIC for output to state finalizer logic - * @param outputName the name of the state output or state state finalizer logic to handle the - * task output - * @return result of the operation - */ - // CHECKSTYLE:OFF: checkstyle:parameterNumber - public ApexApiResult createPolicyStateTaskRef(final String name, final String version, final String stateName, - final String taskLocalName, final String taskName, final String taskVersion, final String outputType, - final String outputName) { - try { - Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL); - Assertions.argumentNotNull(outputName, "outputName may not be null"); - - final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version); - if (policy == null) { - return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); - } - - final AxState state = policy.getStateMap().get(stateName); - if (state == null) { - return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); - } - - final AxTask task = apexModel.getPolicyModel().getTasks().get(taskName, taskVersion); - if (task == null) { - return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + taskName + ':' + taskVersion + DOES_NOT_EXIST); - } - - if (state.getTaskReferences().containsKey(task.getKey())) { - return new ApexApiResult(ApexApiResult.Result.CONCEPT_EXISTS, "task " + task.getKey().getId() - + " already has reference with output " + state.getTaskReferences().get(task.getKey())); - } - - AxReferenceKey refKey; - if (taskLocalName == null) { - refKey = new AxReferenceKey(state.getKey(), state.getKey().getParentKeyName()); - } else { - refKey = new AxReferenceKey(state.getKey(), taskLocalName); - } - - // The reference to the output we're using here - final AxReferenceKey outputRefKey = new AxReferenceKey(state.getKey(), outputName); - - final AxStateTaskOutputType stateTaskOutputType = AxStateTaskOutputType.valueOf(outputType); - if (stateTaskOutputType.equals(AxStateTaskOutputType.DIRECT)) { - if (!state.getStateOutputs().containsKey(outputRefKey.getLocalName())) { - return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - "state output concept " + outputRefKey.getId() + DOES_NOT_EXIST); - } - } else if (stateTaskOutputType.equals(AxStateTaskOutputType.LOGIC)) { - if (!state.getStateFinalizerLogicMap().containsKey(outputRefKey.getLocalName())) { - return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - "state finalizer logic concept " + outputRefKey.getId() + DOES_NOT_EXIST); - } - } else { - return new ApexApiResult(ApexApiResult.Result.FAILED, "output type " + outputType + " invalid"); - } - - state.getTaskReferences().put(task.getKey(), - new AxStateTaskReference(refKey, stateTaskOutputType, outputRefKey)); - return new ApexApiResult(); - } catch (final Exception e) { - return new ApexApiResult(ApexApiResult.Result.FAILED, e); + /** + * Create a policy state task reference. + * + * @param CreatePolicyStateTaskRefBuilder + + * @return result of the operation + */ + public ApexApiResult createPolicyStateTaskRef(CreatePolicyStateTaskRefBuilder builder) { + try { + Assertions.argumentNotNull(builder.getStateName(), STATE_NAME_MAY_NOT_BE_NULL); + Assertions.argumentNotNull(builder.getOutputName(), "outputName may not be null"); + + final AxPolicy policy = + apexModel.getPolicyModel().getPolicies().get(builder.getName(), builder.getVersion()); + if (policy == null) { + return new ApexApiResult( + ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, + CONCEPT + builder.getName() + ':' + builder.getVersion() + DOES_NOT_EXIST); + } + + final AxState state = policy.getStateMap().get(builder.getStateName()); + if (state == null) { + return new ApexApiResult( + ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, + CONCEPT + policy.getKey().getId() + ':' + builder.getStateName() + DOES_NOT_EXIST); + } + + final AxTask task = + apexModel + .getPolicyModel() + .getTasks() + .get(builder.getTaskName(), builder.getTaskVersion()); + if (task == null) { + return new ApexApiResult( + ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, + CONCEPT + builder.getTaskName() + ':' + builder.getTaskVersion() + DOES_NOT_EXIST); + } + + if (state.getTaskReferences().containsKey(task.getKey())) { + return new ApexApiResult( + ApexApiResult.Result.CONCEPT_EXISTS, + "task " + + task.getKey().getId() + + " already has reference with output " + + state.getTaskReferences().get(task.getKey())); + } + + AxReferenceKey refKey; + if (builder.getTaskLocalName() == null) { + refKey = new AxReferenceKey(state.getKey(), state.getKey().getParentKeyName()); + } else { + refKey = new AxReferenceKey(state.getKey(), builder.getTaskLocalName()); + } + + // The reference to the output we're using here + final AxReferenceKey outputRefKey = + new AxReferenceKey(state.getKey(), builder.getOutputName()); + + final AxStateTaskOutputType stateTaskOutputType = + AxStateTaskOutputType.valueOf(builder.getOutputType()); + if (stateTaskOutputType.equals(AxStateTaskOutputType.DIRECT)) { + if (!state.getStateOutputs().containsKey(outputRefKey.getLocalName())) { + return new ApexApiResult( + ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, + "state output concept " + outputRefKey.getId() + DOES_NOT_EXIST); } + } else if (stateTaskOutputType.equals(AxStateTaskOutputType.LOGIC)) { + if (!state.getStateFinalizerLogicMap().containsKey(outputRefKey.getLocalName())) { + return new ApexApiResult( + ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, + "state finalizer logic concept " + outputRefKey.getId() + DOES_NOT_EXIST); + } + } else { + return new ApexApiResult( + ApexApiResult.Result.FAILED, "output type " + builder.getOutputType() + " invalid"); + } + + state + .getTaskReferences() + .put(task.getKey(), new AxStateTaskReference(refKey, stateTaskOutputType, outputRefKey)); + return new ApexApiResult(); + } catch (final Exception e) { + return new ApexApiResult(ApexApiResult.Result.FAILED, e); + } } - // CHECKSTYLE:ON: checkstyle:parameterNumber /** * List policy state task references. |