summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-rest/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-rest/src/main')
-rwxr-xr-xcps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java85
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/DeprecationHelper.java73
2 files changed, 97 insertions, 61 deletions
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
index 11517bcc9e..ccb1e9bbb8 100755
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
@@ -28,9 +28,6 @@ import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum
import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.PATCH;
import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.UPDATE;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -48,18 +45,12 @@ import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
import org.onap.cps.ncmp.rest.api.NetworkCmProxyApi;
import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor;
import org.onap.cps.ncmp.rest.mapper.RestOutputCmHandleStateMapper;
-import org.onap.cps.ncmp.rest.model.CmHandleProperties;
-import org.onap.cps.ncmp.rest.model.CmHandleProperty;
import org.onap.cps.ncmp.rest.model.CmHandlePublicProperties;
-import org.onap.cps.ncmp.rest.model.CmHandleQueryRestParameters;
-import org.onap.cps.ncmp.rest.model.CmHandles;
-import org.onap.cps.ncmp.rest.model.ConditionProperties;
-import org.onap.cps.ncmp.rest.model.Conditions;
-import org.onap.cps.ncmp.rest.model.ModuleNameAsJsonObject;
-import org.onap.cps.ncmp.rest.model.ModuleNamesAsJsonArray;
+import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters;
import org.onap.cps.ncmp.rest.model.RestModuleReference;
import org.onap.cps.ncmp.rest.model.RestOutputCmHandle;
import org.onap.cps.ncmp.rest.model.RestOutputCmHandlePublicProperties;
+import org.onap.cps.ncmp.rest.util.DeprecationHelper;
import org.onap.cps.utils.CpsValidator;
import org.onap.cps.utils.JsonObjectMapper;
import org.springframework.beans.factory.annotation.Value;
@@ -79,6 +70,8 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
private static final String NO_TOPIC = null;
private final NetworkCmProxyDataService networkCmProxyDataService;
private final JsonObjectMapper jsonObjectMapper;
+
+ private final DeprecationHelper deprecationHelper;
private final NcmpRestInputMapper ncmpRestInputMapper;
private final RestOutputCmHandleStateMapper restOutputCmHandleStateMapper;
private final CpsNcmpTaskExecutor cpsNcmpTaskExecutor;
@@ -212,30 +205,35 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
}
/**
- * Execute cm handle search.
+ * Query and return cm handles that match the given query parameters.
*
- * @param conditions the conditions
- * @return cm handles returned from search.
+ * @param cmHandleQueryParameters the cm handle query parameters
+ * @return collection of cm handles
*/
@Override
- public ResponseEntity<CmHandles> executeCmHandleSearch(final Conditions conditions) {
- final List<ConditionProperties> conditionProperties =
- conditions.getConditions().stream().collect(Collectors.toList());
- final CmHandles cmHandles = new CmHandles();
- cmHandles.setCmHandles(toCmHandleProperties(processConditions(conditionProperties)));
- return ResponseEntity.ok(cmHandles);
+ public ResponseEntity<List<RestOutputCmHandle>> searchCmHandles(
+ final CmHandleQueryParameters cmHandleQueryParameters) {
+ final CmHandleQueryApiParameters cmHandleQueryApiParameters =
+ deprecationHelper.mapOldConditionProperties(cmHandleQueryParameters);
+ final Set<NcmpServiceCmHandle> cmHandles = networkCmProxyDataService
+ .executeCmHandleSearch(cmHandleQueryApiParameters);
+ final List<RestOutputCmHandle> outputCmHandles =
+ cmHandles.stream().map(this::toRestOutputCmHandle).collect(Collectors.toList());
+ return ResponseEntity.ok(outputCmHandles);
}
/**
- * Query and return cm handles that match the given query parameters.
+ * Query and return cm handle ids that match the given query parameters.
*
- * @param cmHandleQueryRestParameters the cm handle query parameters
+ * @param cmHandleQueryParameters the cm handle query parameters
* @return collection of cm handle ids
*/
- public ResponseEntity<List<String>> queryCmHandles(
- final CmHandleQueryRestParameters cmHandleQueryRestParameters) {
- final Set<String> cmHandleIds = networkCmProxyDataService.queryCmHandles(
- jsonObjectMapper.convertToValueType(cmHandleQueryRestParameters, CmHandleQueryApiParameters.class));
+ @Override
+ public ResponseEntity<List<String>> searchCmHandleIds(
+ final CmHandleQueryParameters cmHandleQueryParameters) {
+ final CmHandleQueryApiParameters cmHandleQueryApiParameters =
+ jsonObjectMapper.convertToValueType(cmHandleQueryParameters, CmHandleQueryApiParameters.class);
+ final Set<String> cmHandleIds = networkCmProxyDataService.executeCmHandleIdSearch(cmHandleQueryApiParameters);
return ResponseEntity.ok(List.copyOf(cmHandleIds));
}
@@ -281,41 +279,6 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
return new ResponseEntity<>(restModuleReferences, HttpStatus.OK);
}
- private Collection<String> processConditions(final List<ConditionProperties> conditionProperties) {
- for (final ConditionProperties conditionProperty : conditionProperties) {
- if (conditionProperty.getName().equals("hasAllModules")) {
- return executeCmHandleSearchesForModuleNames(conditionProperty);
- } else {
- log.warn("Unrecognized condition name {}.", conditionProperty.getName());
- }
- }
- log.warn("No valid conditions found {}.", conditionProperties);
- return Collections.emptyList();
- }
-
- private Collection<String> executeCmHandleSearchesForModuleNames(final ConditionProperties conditionProperties) {
- return networkCmProxyDataService
- .executeCmHandleHasAllModulesSearch(getModuleNames(conditionProperties.getConditionParameters()));
- }
-
- private Collection<String> getModuleNames(final ModuleNamesAsJsonArray moduleNamesAsJsonArray) {
- final Collection<String> moduleNames = new ArrayList<>(moduleNamesAsJsonArray.size());
- for (final ModuleNameAsJsonObject moduleNameAsJsonObject : moduleNamesAsJsonArray) {
- moduleNames.add(moduleNameAsJsonObject.getModuleName());
- }
- return moduleNames;
- }
-
- private CmHandleProperties toCmHandleProperties(final Collection<String> cmHandleIdentifiers) {
- final CmHandleProperties cmHandleProperties = new CmHandleProperties();
- for (final String cmHandleIdentifier : cmHandleIdentifiers) {
- final CmHandleProperty cmHandleProperty = new CmHandleProperty();
- cmHandleProperty.setCmHandleId(cmHandleIdentifier);
- cmHandleProperties.add(cmHandleProperty);
- }
- return cmHandleProperties;
- }
-
private RestOutputCmHandle toRestOutputCmHandle(final NcmpServiceCmHandle ncmpServiceCmHandle) {
final RestOutputCmHandle restOutputCmHandle = new RestOutputCmHandle();
final CmHandlePublicProperties cmHandlePublicProperties = new CmHandlePublicProperties();
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/DeprecationHelper.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/DeprecationHelper.java
new file mode 100644
index 0000000000..fc992da41a
--- /dev/null
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/DeprecationHelper.java
@@ -0,0 +1,73 @@
+/*
+ * ============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.ncmp.rest.util;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import lombok.RequiredArgsConstructor;
+import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters;
+import org.onap.cps.ncmp.api.models.ConditionApiProperties;
+import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters;
+import org.onap.cps.utils.JsonObjectMapper;
+import org.springframework.stereotype.Component;
+
+@Component
+@RequiredArgsConstructor
+public class DeprecationHelper {
+
+ private final JsonObjectMapper jsonObjectMapper;
+
+ /**
+ * Convert the old condition properties to the new schema.
+ * !!! remove it after the old condition removed !!!
+ * it only works for module names
+ *
+ * @param cmHandleQueryParameters the original input parameter
+ */
+ @Deprecated //this method wil be removed in Release 12 (No Name know yet)
+ public CmHandleQueryApiParameters mapOldConditionProperties(
+ final CmHandleQueryParameters cmHandleQueryParameters) {
+ final CmHandleQueryApiParameters cmHandleQueryApiParameters =
+ jsonObjectMapper.convertToValueType(cmHandleQueryParameters, CmHandleQueryApiParameters.class);
+ if (cmHandleQueryParameters.getConditions() != null
+ && cmHandleQueryApiParameters.getCmHandleQueryParameters().isEmpty()) {
+ cmHandleQueryApiParameters.setCmHandleQueryParameters(new ArrayList<>());
+ cmHandleQueryParameters.getConditions().parallelStream().forEach(
+ oldConditionProperty -> {
+ if (oldConditionProperty.getConditionParameters() != null
+ && oldConditionProperty.getName() != null) {
+ final ConditionApiProperties conditionApiProperties = new ConditionApiProperties();
+ conditionApiProperties.setConditionName(oldConditionProperty.getName());
+ conditionApiProperties.setConditionParameters(new ArrayList<>());
+ oldConditionProperty.getConditionParameters().parallelStream().forEach(
+ oldConditionParameter ->
+ conditionApiProperties.getConditionParameters().add(Collections
+ .singletonMap("moduleName", oldConditionParameter.getModuleName()))
+ );
+ cmHandleQueryApiParameters.getCmHandleQueryParameters().add(conditionApiProperties);
+ }
+ }
+ );
+ }
+
+ return cmHandleQueryApiParameters;
+ }
+}