From f696068ae5cced10c0fdf6a1686c4eadbdfdfff0 Mon Sep 17 00:00:00 2001 From: kissand Date: Mon, 13 Jun 2022 10:55:49 +0200 Subject: Fix sonar code smells - https://sonarcloud.io/project/issues?resolved=false&types=CODE_SMELL&id=onap_cps&open=AYFC3OguDZ5Vb3SQMOU1 Issue-ID: CPS-1016 Change-Id: Ic8fdae78337da1ff2c239ae2dfae67e23e88a4bb Signed-off-by: kissand --- .../cps/spi/model/CmHandleQueryParameters.java | 41 --------------------- .../spi/model/CmHandleQueryServiceParameters.java | 41 +++++++++++++++++++++ .../CmHandleQueryRestParametersValidator.java | 43 ++++++++++++---------- .../cps/api/impl/CpsAdminServiceImplSpec.groovy | 1 - ...CmHandleQueryRestParametersValidatorSpec.groovy | 8 ++-- 5 files changed, 68 insertions(+), 66 deletions(-) delete mode 100644 cps-service/src/main/java/org/onap/cps/spi/model/CmHandleQueryParameters.java create mode 100644 cps-service/src/main/java/org/onap/cps/spi/model/CmHandleQueryServiceParameters.java (limited to 'cps-service') diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/CmHandleQueryParameters.java b/cps-service/src/main/java/org/onap/cps/spi/model/CmHandleQueryParameters.java deleted file mode 100644 index cf364db3a..000000000 --- a/cps-service/src/main/java/org/onap/cps/spi/model/CmHandleQueryParameters.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation - * ================================================================================ - * 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.cps.spi.model; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Collections; -import java.util.List; -import javax.validation.Valid; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -@Setter -@Getter -@EqualsAndHashCode -@JsonInclude(Include.NON_EMPTY) -public class CmHandleQueryParameters { - @JsonProperty("cmHandleQueryParameters") - @Valid - private List cmHandleQueryParameters = Collections.emptyList(); -} diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/CmHandleQueryServiceParameters.java b/cps-service/src/main/java/org/onap/cps/spi/model/CmHandleQueryServiceParameters.java new file mode 100644 index 000000000..8dcf88b0e --- /dev/null +++ b/cps-service/src/main/java/org/onap/cps/spi/model/CmHandleQueryServiceParameters.java @@ -0,0 +1,41 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022 Nordix Foundation + * ================================================================================ + * 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.cps.spi.model; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Collections; +import java.util.List; +import javax.validation.Valid; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +@EqualsAndHashCode +@JsonInclude(Include.NON_EMPTY) +public class CmHandleQueryServiceParameters { + @JsonProperty("cmHandleQueryParameters") + @Valid + private List cmHandleQueryParameters = Collections.emptyList(); +} diff --git a/cps-service/src/main/java/org/onap/cps/utils/CmHandleQueryRestParametersValidator.java b/cps-service/src/main/java/org/onap/cps/utils/CmHandleQueryRestParametersValidator.java index c510a73af..c3811eb48 100644 --- a/cps-service/src/main/java/org/onap/cps/utils/CmHandleQueryRestParametersValidator.java +++ b/cps-service/src/main/java/org/onap/cps/utils/CmHandleQueryRestParametersValidator.java @@ -27,7 +27,7 @@ import java.util.Map; import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.onap.cps.spi.exceptions.DataValidationException; -import org.onap.cps.spi.model.CmHandleQueryParameters; +import org.onap.cps.spi.model.CmHandleQueryServiceParameters; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class CmHandleQueryRestParametersValidator { @@ -36,10 +36,11 @@ public class CmHandleQueryRestParametersValidator { /** * Validate cm handle query parameters. - * @param cmHandleQueryParameters name of data to be validated + * @param cmHandleQueryServiceParameters name of data to be validated */ - public static void validateCmHandleQueryParameters(final CmHandleQueryParameters cmHandleQueryParameters) { - cmHandleQueryParameters.getCmHandleQueryParameters().forEach( + public static void validateCmHandleQueryParameters( + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { + cmHandleQueryServiceParameters.getCmHandleQueryParameters().forEach( conditionApiProperty -> { if (Strings.isNullOrEmpty(conditionApiProperty.getConditionName())) { throwDataValidationException("Missing 'conditionName' - please supply a valid name."); @@ -54,27 +55,29 @@ public class CmHandleQueryRestParametersValidator { "Empty 'conditionsParameters' - please supply a valid condition parameter."); } conditionApiProperty.getConditionParameters().forEach( - conditionParameter -> { - if (conditionParameter.isEmpty()) { - throwDataValidationException( - "Empty 'conditionsParameter' - please supply a valid condition parameter."); - } - if (conditionParameter.size() > 1) { - throwDataValidationException("Too many name in one 'conditionsParameter' -" - + " please supply one name in one condition parameter."); - } - conditionParameter.forEach((key, value) -> { - if (Strings.isNullOrEmpty(key)) { - throwDataValidationException( - "Missing 'conditionsParameterName' - please supply a valid name."); - } - }); - } + CmHandleQueryRestParametersValidator::validateConditionParameter ); } ); } + private static void validateConditionParameter(final Map conditionParameter) { + if (conditionParameter.isEmpty()) { + throwDataValidationException( + "Empty 'conditionsParameter' - please supply a valid condition parameter."); + } + if (conditionParameter.size() > 1) { + throwDataValidationException("Too many name in one 'conditionsParameter' -" + + " please supply one name in one condition parameter."); + } + conditionParameter.forEach((key, value) -> { + if (Strings.isNullOrEmpty(key)) { + throwDataValidationException( + "Missing 'conditionsParameterName' - please supply a valid name."); + } + }); + } + /** * Validate module name condition properties. * @param conditionProperty name of data to be validated diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy index def99e21f..41fcb29ed 100755 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy @@ -26,7 +26,6 @@ import org.onap.cps.api.CpsDataService import org.onap.cps.spi.CpsAdminPersistenceService import org.onap.cps.spi.exceptions.DataValidationException import org.onap.cps.spi.model.Anchor -import org.onap.cps.spi.model.CmHandleQueryParameters import spock.lang.Specification import java.time.OffsetDateTime diff --git a/cps-service/src/test/groovy/org/onap/cps/utils/CmHandleQueryRestParametersValidatorSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/utils/CmHandleQueryRestParametersValidatorSpec.groovy index 645829b2a..a9b04c1ce 100644 --- a/cps-service/src/test/groovy/org/onap/cps/utils/CmHandleQueryRestParametersValidatorSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/utils/CmHandleQueryRestParametersValidatorSpec.groovy @@ -21,14 +21,14 @@ package org.onap.cps.utils import org.onap.cps.spi.exceptions.DataValidationException -import org.onap.cps.spi.model.CmHandleQueryParameters +import org.onap.cps.spi.model.CmHandleQueryServiceParameters import org.onap.cps.spi.model.ConditionProperties import spock.lang.Specification class CmHandleQueryRestParametersValidatorSpec extends Specification { def 'CM Handle Query validation: empty query.'() { given: 'a cm handle query' - def cmHandleQueryParameters = new CmHandleQueryParameters() + def cmHandleQueryParameters = new CmHandleQueryServiceParameters() when: 'validator is invoked' CmHandleQueryRestParametersValidator.validateCmHandleQueryParameters(cmHandleQueryParameters) then: 'data validation exception is not thrown' @@ -37,7 +37,7 @@ class CmHandleQueryRestParametersValidatorSpec extends Specification { def 'CM Handle Query validation: normal query.'() { given: 'a cm handle query' - def cmHandleQueryParameters = new CmHandleQueryParameters() + def cmHandleQueryParameters = new CmHandleQueryServiceParameters() def condition = new ConditionProperties() condition.conditionName = 'hasAllProperties' condition.conditionParameters = [[key1:'value1'],[key2:'value2']] @@ -50,7 +50,7 @@ class CmHandleQueryRestParametersValidatorSpec extends Specification { def 'CM Handle Query validation: #scenario.'() { given: 'a cm handle query' - def cmHandleQueryParameters = new CmHandleQueryParameters() + def cmHandleQueryParameters = new CmHandleQueryServiceParameters() def condition = new ConditionProperties() condition.conditionName = conditionName condition.conditionParameters = conditionParameters -- cgit 1.2.3-korg