Introducing NCMP Facades 28/138228/5
authorToineSiebelink <toine.siebelink@est.tech>
Thu, 13 Jun 2024 15:52:45 +0000 (16:52 +0100)
committerToineSiebelink <toine.siebelink@est.tech>
Thu, 20 Jun 2024 16:00:54 +0000 (17:00 +0100)
- NetworkCmProxyDataService was polluted with many non-data operations
- it is now split into:
1) NetworkCmProxyFacade, a single thin facade for the (main) controler to redirect calls to the correct services
2) CmHandleRegistrationService(Impl), methods related to registration only
- introduced NetworkCmProxyInventoryFacade for the invenoty controller
- renamed some services for consitency and clarification
- Use facade to acces ncmp data request handlers (instead of direct from controller)
- remove unnecesarry wrappings between request handlers and facade
- split facades according to names: data & inventory
(the REST controllers are not split properly so I think one rest controller will end up needing both facades)

Issue-ID: CPS-2263
Change-Id: I250732aa16ec28b43ff642d2adf10ba36f67290e
Signed-off-by: ToineSiebelink <toine.siebelink@est.tech>
44 files changed:
cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java
cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy
cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java [deleted file]
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/ParameterizedCmHandleQueryService.java [moved from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyCmHandleQueryService.java with 93% similarity]
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/CmHandleRegistrationService.java [moved from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java with 68% similarity, mode: 0644]
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/CmHandleRegistrationServicePropertyHandler.java [moved from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java with 96% similarity]
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpCachedResourceRequestHandler.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpDatastoreRequestHandler.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpPassthroughResourceRequestHandler.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyFacade.java [new file with mode: 0644]
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyInventoryFacade.java [new file with mode: 0644]
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/ParameterizedCmHandleQueryServiceImpl.java [moved from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandleQueryServiceImpl.java with 94% similarity]
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueryService.java [moved from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueries.java with 87% similarity]
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueryServiceImpl.java [moved from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueriesImpl.java with 99% similarity]
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImpl.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleOperationsUtils.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncService.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginWatchDog.java
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/CmHandleRegistrationServicePropertyHandlerSpec.groovy [moved from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandlerSpec.groovy with 93% similarity]
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/CmHandleRegistrationServiceSpec.groovy [moved from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy with 85% similarity]
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NcmpCachedResourceRequestHandlerSpec.groovy [new file with mode: 0644]
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NcmpDatastoreRequestHandlerSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy [deleted file]
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyFacadeSpec.groovy [new file with mode: 0644]
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyInventoryFacadeSpec.groovy [new file with mode: 0644]
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/ParameterizedCmHandleQueryServiceSpec.groovy [moved from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandleQueryServiceSpec.groovy with 96% similarity]
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueryServiceImplSpec.groovy [moved from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueriesImplSpec.groovy with 98% similarity]
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImplSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleOperationsUtilsSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncServiceSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiDataOperationsSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiModelOperationsSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginWatchDogSpec.groovy
integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy
integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpBearerTokenPassthroughSpec.groovy
integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpCmHandleCreateSpec.groovy
integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpCmHandleUpgradeSpec.groovy

index 58d6ce7..726f4e4 100755 (executable)
@@ -38,10 +38,8 @@ import java.util.Map;
 import java.util.stream.Collectors;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
-import org.onap.cps.ncmp.api.impl.NcmpCachedResourceRequestHandler;
-import org.onap.cps.ncmp.api.impl.NcmpDatastoreRequestHandler;
-import org.onap.cps.ncmp.api.impl.NcmpPassthroughResourceRequestHandler;
+import org.onap.cps.ncmp.api.impl.NetworkCmProxyFacade;
+import org.onap.cps.ncmp.api.impl.NetworkCmProxyInventoryFacade;
 import org.onap.cps.ncmp.api.impl.config.embeddedcache.TrustLevelCacheConfig;
 import org.onap.cps.ncmp.api.impl.exception.InvalidDatastoreException;
 import org.onap.cps.ncmp.api.impl.inventory.CompositeState;
@@ -79,14 +77,15 @@ import org.springframework.web.bind.annotation.RestController;
 public class NetworkCmProxyController implements NetworkCmProxyApi {
 
     private static final String NO_BODY = null;
-    private final NetworkCmProxyDataService networkCmProxyDataService;
+    private final NetworkCmProxyFacade networkCmProxyFacade;
+    private final NetworkCmProxyInventoryFacade networkCmProxyInventoryFacade;
     private final JsonObjectMapper jsonObjectMapper;
     private final DeprecationHelper deprecationHelper;
     private final NcmpRestInputMapper ncmpRestInputMapper;
     private final CmHandleStateMapper cmHandleStateMapper;
-    private final NcmpCachedResourceRequestHandler ncmpCachedResourceRequestHandler;
-    private final NcmpPassthroughResourceRequestHandler ncmpPassthroughResourceRequestHandler;
+
     private final DataOperationRequestMapper dataOperationRequestMapper;
+
     @Qualifier(TrustLevelCacheConfig.TRUST_LEVEL_PER_CM_HANDLE)
     private final Map<String, TrustLevel> trustLevelPerCmHandle;
 
@@ -111,10 +110,9 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
                                                              final String topicParamInQuery,
                                                              final Boolean includeDescendants,
                                                              final String authorization) {
-        final NcmpDatastoreRequestHandler ncmpDatastoreRequestHandler = getNcmpDatastoreRequestHandler(datastoreName);
         final CmResourceAddress cmResourceAddress = new CmResourceAddress(datastoreName, cmHandle, resourceIdentifier);
-        final Object result = ncmpDatastoreRequestHandler.executeRequest(cmResourceAddress, optionsParamInQuery,
-            topicParamInQuery, includeDescendants, authorization);
+        final Object result = networkCmProxyFacade.getResourceDataForCmHandle(cmResourceAddress, optionsParamInQuery,
+                                                               topicParamInQuery, includeDescendants, authorization);
         return ResponseEntity.ok(result);
     }
 
@@ -122,7 +120,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
     public ResponseEntity<Object> executeDataOperationForCmHandles(final String topicParamInQuery,
                                                                    final DataOperationRequest dataOperationRequest,
                                                                    final String authorization) {
-        final Object result = ncmpPassthroughResourceRequestHandler.executeRequest(topicParamInQuery,
+        final Object result = networkCmProxyFacade.executeDataOperationForCmHandles(topicParamInQuery,
                 dataOperationRequestMapper.toDataOperationRequest(dataOperationRequest), authorization);
         return ResponseEntity.ok(result);
     }
@@ -147,7 +145,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
                                                                final String topicParamInQuery,
                                                                final Boolean includeDescendants) {
         validateDataStore(OPERATIONAL, datastoreName);
-        final Collection<DataNode> dataNodes = ncmpCachedResourceRequestHandler.executeRequest(cmHandle, cpsPath,
+        final Collection<DataNode> dataNodes = networkCmProxyFacade.queryResourceDataForCmHandle(cmHandle, cpsPath,
             includeDescendants);
         return ResponseEntity.ok(dataNodes);
     }
@@ -174,7 +172,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
 
         validateDataStore(PASSTHROUGH_RUNNING, datastoreName);
 
-        final Object responseObject = networkCmProxyDataService
+        final Object responseObject = networkCmProxyFacade
                 .writeResourceDataPassThroughRunningForCmHandle(
                         cmHandle, resourceIdentifier, PATCH,
                         jsonObjectMapper.asJsonString(requestBody), contentType, authorization);
@@ -201,7 +199,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
                                                                      final String authorization) {
         validateDataStore(PASSTHROUGH_RUNNING, datastoreName);
 
-        networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
+        networkCmProxyFacade.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
                 resourceIdentifier, CREATE, jsonObjectMapper.asJsonString(requestBody), contentType, authorization);
         return new ResponseEntity<>(HttpStatus.CREATED);
     }
@@ -227,7 +225,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
                                                                        final String authorization) {
         validateDataStore(PASSTHROUGH_RUNNING, datastoreName);
 
-        networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
+        networkCmProxyFacade.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
                 resourceIdentifier, UPDATE, jsonObjectMapper.asJsonString(requestBody), contentType, authorization);
         return new ResponseEntity<>(HttpStatus.OK);
     }
@@ -251,7 +249,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
 
         validateDataStore(PASSTHROUGH_RUNNING, datastoreName);
 
-        networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
+        networkCmProxyFacade.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
                 resourceIdentifier, DELETE, NO_BODY, contentType, authorization);
         return new ResponseEntity<>(HttpStatus.NO_CONTENT);
     }
@@ -268,7 +266,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
             final CmHandleQueryParameters cmHandleQueryParameters) {
         final CmHandleQueryApiParameters cmHandleQueryApiParameters =
                 deprecationHelper.mapOldConditionProperties(cmHandleQueryParameters);
-        final Collection<NcmpServiceCmHandle> cmHandles = networkCmProxyDataService
+        final Collection<NcmpServiceCmHandle> cmHandles = networkCmProxyInventoryFacade
                 .executeCmHandleSearch(cmHandleQueryApiParameters);
         final List<RestOutputCmHandle> outputCmHandles =
                 cmHandles.stream().map(this::toRestOutputCmHandle).collect(Collectors.toList());
@@ -287,7 +285,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
         final CmHandleQueryApiParameters cmHandleQueryApiParameters =
                 jsonObjectMapper.convertToValueType(cmHandleQueryParameters, CmHandleQueryApiParameters.class);
         final Collection<String> cmHandleIds
-            = networkCmProxyDataService.executeCmHandleIdSearch(cmHandleQueryApiParameters);
+            = networkCmProxyInventoryFacade.executeCmHandleIdSearch(cmHandleQueryApiParameters);
         return ResponseEntity.ok(List.copyOf(cmHandleIds));
     }
 
@@ -299,7 +297,8 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
      */
     @Override
     public ResponseEntity<RestOutputCmHandle> retrieveCmHandleDetailsById(final String cmHandleId) {
-        final NcmpServiceCmHandle ncmpServiceCmHandle = networkCmProxyDataService.getNcmpServiceCmHandle(cmHandleId);
+        final NcmpServiceCmHandle ncmpServiceCmHandle
+            = networkCmProxyInventoryFacade.getNcmpServiceCmHandle(cmHandleId);
         final RestOutputCmHandle restOutputCmHandle = toRestOutputCmHandle(ncmpServiceCmHandle);
         return ResponseEntity.ok(restOutputCmHandle);
     }
@@ -314,7 +313,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
     public ResponseEntity<RestOutputCmHandlePublicProperties> getCmHandlePublicPropertiesByCmHandleId(
             final String cmHandleId) {
         final CmHandlePublicProperties cmHandlePublicProperties = new CmHandlePublicProperties();
-        cmHandlePublicProperties.add(networkCmProxyDataService.getCmHandlePublicProperties(cmHandleId));
+        cmHandlePublicProperties.add(networkCmProxyInventoryFacade.getCmHandlePublicProperties(cmHandleId));
         final RestOutputCmHandlePublicProperties restOutputCmHandlePublicProperties =
                 new RestOutputCmHandlePublicProperties();
         restOutputCmHandlePublicProperties.setPublicCmHandleProperties(cmHandlePublicProperties);
@@ -330,7 +329,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
     @Override
     public ResponseEntity<RestOutputCmHandleCompositeState> getCmHandleStateByCmHandleId(
             final String cmHandleId) {
-        final CompositeState cmHandleState = networkCmProxyDataService.getCmHandleCompositeState(cmHandleId);
+        final CompositeState cmHandleState = networkCmProxyInventoryFacade.getCmHandleCompositeState(cmHandleId);
         final RestOutputCmHandleCompositeState restOutputCmHandleCompositeState =
                 new RestOutputCmHandleCompositeState();
         restOutputCmHandleCompositeState.setState(
@@ -353,9 +352,9 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
         final Collection<ModuleDefinition> moduleDefinitions;
         if (StringUtils.hasText(moduleName)) {
             moduleDefinitions =
-                networkCmProxyDataService.getModuleDefinitionsByCmHandleAndModule(cmHandleId, moduleName, revision);
+                networkCmProxyInventoryFacade.getModuleDefinitionsByCmHandleAndModule(cmHandleId, moduleName, revision);
         } else {
-            moduleDefinitions = networkCmProxyDataService.getModuleDefinitionsByCmHandleId(cmHandleId);
+            moduleDefinitions = networkCmProxyInventoryFacade.getModuleDefinitionsByCmHandleId(cmHandleId);
             if (StringUtils.hasText(revision)) {
                 log.warn("Ignoring revision filter as no module name is provided");
             }
@@ -375,7 +374,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
      */
     public ResponseEntity<List<RestModuleReference>> getModuleReferencesByCmHandle(final String cmHandle) {
         final List<RestModuleReference> restModuleReferences =
-                networkCmProxyDataService.getYangResourcesModuleReferences(cmHandle).stream()
+            networkCmProxyInventoryFacade.getYangResourcesModuleReferences(cmHandle).stream()
                         .map(ncmpRestInputMapper::toRestModuleReference)
                         .collect(Collectors.toList());
         return new ResponseEntity<>(restModuleReferences, HttpStatus.OK);
@@ -391,7 +390,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
     @Override
     public ResponseEntity<Object> setDataSyncEnabledFlagForCmHandle(final String cmHandleId,
                                                                     final Boolean dataSyncEnabledFlag) {
-        networkCmProxyDataService.setDataSyncEnabled(cmHandleId, dataSyncEnabledFlag);
+        networkCmProxyInventoryFacade.setDataSyncEnabled(cmHandleId, dataSyncEnabledFlag);
         return new ResponseEntity<>(HttpStatus.OK);
     }
 
@@ -422,11 +421,5 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
         }
     }
 
-    private NcmpDatastoreRequestHandler getNcmpDatastoreRequestHandler(final String datastoreName) {
-        if (OPERATIONAL.equals(DatastoreType.fromDatastoreName(datastoreName))) {
-            return ncmpCachedResourceRequestHandler;
-        }
-        return ncmpPassthroughResourceRequestHandler;
-    }
 }
 
index 5467eef..5185b47 100755 (executable)
@@ -27,7 +27,7 @@ import java.util.Collection;
 import java.util.List;
 import java.util.stream.Collectors;
 import lombok.RequiredArgsConstructor;
-import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
+import org.onap.cps.ncmp.api.impl.NetworkCmProxyInventoryFacade;
 import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
 import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse;
 import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.Status;
@@ -47,7 +47,7 @@ import org.springframework.web.bind.annotation.RestController;
 @RequiredArgsConstructor
 public class NetworkCmProxyInventoryController implements NetworkCmProxyInventoryApi {
 
-    private final NetworkCmProxyDataService networkCmProxyDataService;
+    private final NetworkCmProxyInventoryFacade networkCmProxyInventoryFacade;
     private final NcmpRestInputMapper ncmpRestInputMapper;
 
     @Override
@@ -55,8 +55,8 @@ public class NetworkCmProxyInventoryController implements NetworkCmProxyInventor
         final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = ncmpRestInputMapper
                 .toCmHandleQueryServiceParameters(cmHandleQueryParameters);
 
-        final Collection<String> cmHandleIds = networkCmProxyDataService
-                .executeCmHandleIdSearchForInventory(cmHandleQueryServiceParameters);
+        final Collection<String> cmHandleIds = networkCmProxyInventoryFacade
+                .executeParameterizedCmHandleIdSearch(cmHandleQueryServiceParameters);
         return ResponseEntity.ok(List.copyOf(cmHandleIds));
     }
 
@@ -69,7 +69,7 @@ public class NetworkCmProxyInventoryController implements NetworkCmProxyInventor
     @Override
     public ResponseEntity<List<String>> getAllCmHandleIdsForRegisteredDmi(final String dmiPluginIdentifier) {
         final Collection<String> cmHandleIds =
-                networkCmProxyDataService.getAllCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifier);
+            networkCmProxyInventoryFacade.getAllCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifier);
         return ResponseEntity.ok(List.copyOf(cmHandleIds));
     }
 
@@ -84,7 +84,7 @@ public class NetworkCmProxyInventoryController implements NetworkCmProxyInventor
     public ResponseEntity updateDmiPluginRegistration(
         final @Valid RestDmiPluginRegistration restDmiPluginRegistration) {
         final DmiPluginRegistrationResponse dmiPluginRegistrationResponse =
-            networkCmProxyDataService.updateDmiRegistrationAndSyncModule(
+            networkCmProxyInventoryFacade.updateDmiRegistrationAndSyncModule(
                 ncmpRestInputMapper.toDmiPluginRegistration(restDmiPluginRegistration));
         final DmiPluginRegistrationErrorResponse failedRegistrationErrorResponse =
             getFailureRegistrationResponse(dmiPluginRegistrationResponse);
index 34b9dbe..a498e25 100644 (file)
@@ -32,10 +32,8 @@ import groovy.json.JsonSlurper
 import org.mapstruct.factory.Mappers
 import org.onap.cps.TestUtils
 import org.onap.cps.events.EventsPublisher
-import org.onap.cps.ncmp.api.NetworkCmProxyDataService
-import org.onap.cps.ncmp.api.NetworkCmProxyQueryService
-import org.onap.cps.ncmp.api.impl.NcmpCachedResourceRequestHandler
-import org.onap.cps.ncmp.api.impl.NcmpPassthroughResourceRequestHandler
+import org.onap.cps.ncmp.api.impl.NetworkCmProxyFacade
+import org.onap.cps.ncmp.api.impl.NetworkCmProxyInventoryFacade
 import org.onap.cps.ncmp.api.impl.inventory.CmHandleState
 import org.onap.cps.ncmp.api.impl.inventory.CompositeState
 import org.onap.cps.ncmp.api.impl.inventory.DataStoreSyncState
@@ -48,7 +46,6 @@ import org.onap.cps.ncmp.rest.mapper.DataOperationRequestMapper
 import org.onap.cps.ncmp.rest.model.DataOperationDefinition
 import org.onap.cps.ncmp.rest.model.DataOperationRequest
 import org.onap.cps.ncmp.rest.util.DeprecationHelper
-import org.onap.cps.spi.FetchDescendantsOption
 import org.onap.cps.spi.model.ModuleDefinition
 import org.onap.cps.spi.model.ModuleReference
 import org.onap.cps.utils.JsonObjectMapper
@@ -71,15 +68,12 @@ import java.time.format.DateTimeFormatter
 
 import static org.onap.cps.ncmp.api.impl.inventory.CompositeState.DataStores
 import static org.onap.cps.ncmp.api.impl.inventory.CompositeState.Operational
-import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.OPERATIONAL
 import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_OPERATIONAL
 import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_RUNNING
 import static org.onap.cps.ncmp.api.impl.operations.OperationType.CREATE
 import static org.onap.cps.ncmp.api.impl.operations.OperationType.DELETE
 import static org.onap.cps.ncmp.api.impl.operations.OperationType.PATCH
 import static org.onap.cps.ncmp.api.impl.operations.OperationType.UPDATE
-import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
-import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete
 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch
@@ -93,10 +87,10 @@ class NetworkCmProxyControllerSpec extends Specification {
     MockMvc mvc
 
     @SpringBean
-    NetworkCmProxyDataService mockNetworkCmProxyDataService = Mock()
+    NetworkCmProxyFacade mockNetworkCmProxyFacade = Mock()
 
     @SpringBean
-    NetworkCmProxyQueryService mockNetworkCmProxyQueryService = Mock()
+    NetworkCmProxyInventoryFacade mockNetworkCmProxyInventoryFacade = Mock()
 
     @SpringBean
     ObjectMapper objectMapper = new ObjectMapper()
@@ -119,12 +113,6 @@ class NetworkCmProxyControllerSpec extends Specification {
     @SpringBean
     DeprecationHelper stubbedDeprecationHelper = Stub()
 
-    @SpringBean
-    NcmpCachedResourceRequestHandler ncmpCachedResourceRequestHandler = new NcmpCachedResourceRequestHandler(mockNetworkCmProxyDataService, mockNetworkCmProxyQueryService)
-
-    @SpringBean
-    NcmpPassthroughResourceRequestHandler ncmpPassthroughResourceRequestHandler = new NcmpPassthroughResourceRequestHandler(mockNetworkCmProxyDataService)
-
     @Value('${rest.api.ncmp-base-path}/v1')
     def ncmpBasePathV1
 
@@ -134,17 +122,13 @@ class NetworkCmProxyControllerSpec extends Specification {
 
     @Shared
     def NO_TOPIC = null
+    def NO_OPTIONS = null
     def NO_REQUEST_ID = null
     def NO_AUTH_HEADER = null
-    def TIMEOUT_FOR_TEST = 1234
 
     def logger = Spy(ListAppender<ILoggingEvent>)
 
     def setup() {
-        ncmpCachedResourceRequestHandler.notificationFeatureEnabled = true
-        ncmpCachedResourceRequestHandler.timeOutInMilliSeconds = TIMEOUT_FOR_TEST
-        ncmpPassthroughResourceRequestHandler.notificationFeatureEnabled = true
-        ncmpPassthroughResourceRequestHandler.timeOutInMilliSeconds = TIMEOUT_FOR_TEST
         setupLogger()
     }
 
@@ -160,7 +144,7 @@ class NetworkCmProxyControllerSpec extends Specification {
         when: 'get data resource request is performed'
             def response = mvc.perform(get(getUrl).contentType(MediaType.APPLICATION_JSON)).andReturn().response
         then: 'the NCMP data service is called with correct parameters'
-            1 * mockNetworkCmProxyDataService.getResourceDataForCmHandle(expectedCmResourceAddress, '(a=1,b=2)', NO_TOPIC, NO_REQUEST_ID, NO_AUTH_HEADER) >> Mono.just(new ResponseEntity<Object>(HttpStatus.OK))
+            1 * mockNetworkCmProxyFacade.getResourceDataForCmHandle(expectedCmResourceAddress, '(a=1,b=2)', NO_TOPIC, false, NO_AUTH_HEADER) >> Mono.just(new ResponseEntity<Object>(HttpStatus.OK))
         and: 'response status is Ok'
             assert response.status == HttpStatus.OK.value()
     }
@@ -173,17 +157,16 @@ class NetworkCmProxyControllerSpec extends Specification {
         when: 'get data resource request is performed'
             def response = mvc.perform(get(getUrl).contentType(MediaType.APPLICATION_JSON)).andReturn().response
         then: 'the NCMP data service is called with correct parameters'
-            1 * mockNetworkCmProxyDataService.getResourceDataForCmHandle(expectedCmResourceAddress, expectedIncludeDescendants)
+            1 * mockNetworkCmProxyFacade.getResourceDataForCmHandle(expectedCmResourceAddress, NO_OPTIONS, NO_TOPIC, expectedIncludeDescendants, NO_AUTH_HEADER)
         and: 'response status is OK'
             assert response.status == HttpStatus.OK.value()
         where: 'the following parameters are used'
             scenario                    | additionalUrlParam           || expectedIncludeDescendants
-            'no additional param'       | ''                           || OMIT_DESCENDANTS
-            'include descendants true'  | '&include-descendants=true'  || INCLUDE_ALL_DESCENDANTS
-            'include descendants TRUE'  | '&include-descendants=true'  || INCLUDE_ALL_DESCENDANTS
-            'include descendants false' | '&include-descendants=false' || OMIT_DESCENDANTS
-            'include descendants FALSE' | '&include-descendants=FALSE' || OMIT_DESCENDANTS
-            'options (ignored)'         | '&options=(a-=1)'            || OMIT_DESCENDANTS
+            'no additional param'       | ''                           || false
+            'include descendants true'  | '&include-descendants=true'  || true
+            'include descendants TRUE'  | '&include-descendants=true'  || true
+            'include descendants false' | '&include-descendants=false' || false
+            'include descendants FALSE' | '&include-descendants=FALSE' || false
     }
 
     def 'Execute (async) data operation to read data from dmi service.'() {
@@ -194,45 +177,19 @@ class NetworkCmProxyControllerSpec extends Specification {
             def response = mvc.perform(post(getUrl).contentType(MediaType.APPLICATION_JSON).content(dataOperationRequestJsonData)).andReturn().response
         then: 'response status is Ok'
             assert response.status == HttpStatus.OK.value()
-        and: 'async request id is generated'
-            assert response.contentAsString.contains('requestId')
         then: 'the request for (async) data operation invoked once'
-            1 * mockNetworkCmProxyDataService.executeDataOperationForCmHandles('my-topic-name', _, _, null)
+            1 * mockNetworkCmProxyFacade.executeDataOperationForCmHandles('my-topic-name', _, NO_AUTH_HEADER)
         where: 'the following data stores are used'
             datastore << [PASSTHROUGH_RUNNING, PASSTHROUGH_OPERATIONAL]
     }
 
-    def 'Execute (async) data operation with some validation error.'() {
-        given: 'data operation url'
-            def getUrl = "$ncmpBasePathV1/data?topic=my-topic-name"
-            def dataOperationRequestJsonData = jsonObjectMapper.asJsonString(getDataOperationRequest('read', 'invalid datastore'))
-        when: 'post data resource request is performed'
-            def response = mvc.perform(post(getUrl).contentType(MediaType.APPLICATION_JSON).content(dataOperationRequestJsonData)).andReturn().response
-        then: 'response status is BAD_REQUEST'
-            assert response.status == HttpStatus.BAD_REQUEST.value()
-    }
-
-    def 'Get data operation resource data when notification feature is disabled for datastore: #datastore.'() {
-        given: 'data operation url'
-            def getUrl = "$ncmpBasePathV1/data?topic=my-topic-name"
-            def dataOperationRequestJsonData = jsonObjectMapper.asJsonString(getDataOperationRequest("read", PASSTHROUGH_RUNNING.datastoreName))
-            ncmpPassthroughResourceRequestHandler.notificationFeatureEnabled = false
-        when: 'post data resource request is performed'
-            def response = mvc.perform(post(getUrl).contentType(MediaType.APPLICATION_JSON).content(dataOperationRequestJsonData)
-            ).andReturn().response
-        then: 'response status is Ok'
-            assert response.status == HttpStatus.OK.value()
-        and: 'async request id is unavailable'
-            assert response.contentAsString == '{"status":"Asynchronous request is unavailable as notification feature is currently disabled."}'
-    }
-
     def 'Query Resource Data from operational.'() {
         given: 'the query resource data url'
-            def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:operational/query?cps-path=/cps/path"
+            def getUrl = "$ncmpBasePathV1/ch/ch-1/data/ds/ncmp-datastore:operational/query?cps-path=/cps/path"
         when: 'the query data resource request is performed'
             def response = mvc.perform(get(getUrl).contentType(MediaType.APPLICATION_JSON)).andReturn().response
         then: 'the NCMP query service is called with queryResourceDataOperationalForCmHandle'
-            1 * mockNetworkCmProxyQueryService.queryResourceDataOperational('testCmHandle','/cps/path',FetchDescendantsOption.OMIT_DESCENDANTS)
+            1 * mockNetworkCmProxyFacade.queryResourceDataForCmHandle('ch-1','/cps/path', false)
         and: 'response status is Ok'
             assert response.status == HttpStatus.OK.value()
     }
@@ -250,11 +207,11 @@ class NetworkCmProxyControllerSpec extends Specification {
 
     def 'Get Resource Data from pass-through running with #scenario value in resource identifier param.'() {
         given: 'resource data url'
-            def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=$resourceIdentifier&options=(a=1,b=2)"
+            def getUrl = "$ncmpBasePathV1/ch/ch-1/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=$resourceIdentifier&options=(a=1)"
         and: 'ncmp service returns json object'
-            def expectedCmResourceAddress = new CmResourceAddress(PASSTHROUGH_RUNNING.datastoreName, 'testCmHandle', resourceIdentifier)
-            1 * mockNetworkCmProxyDataService.getResourceDataForCmHandle(expectedCmResourceAddress, '(a=1,b=2)', NO_TOPIC, NO_REQUEST_ID, NO_AUTH_HEADER)
-                    >> Mono.just(new ResponseEntity<Object>('{valid-json}', HttpStatus.OK))
+            def expectedCmResourceAddress = new CmResourceAddress(PASSTHROUGH_RUNNING.datastoreName, 'ch-1', resourceIdentifier)
+            1 * mockNetworkCmProxyFacade.getResourceDataForCmHandle(expectedCmResourceAddress, '(a=1)', NO_TOPIC, false, NO_AUTH_HEADER)
+                    >> new ResponseEntity<Object>('{valid-json}', HttpStatus.OK)
         when: 'get data resource request is performed'
             def response = mvc.perform(get(getUrl).contentType(MediaType.APPLICATION_JSON)).andReturn().response
         then: 'response status is Ok'
@@ -278,7 +235,7 @@ class NetworkCmProxyControllerSpec extends Specification {
         when: 'update data resource request is performed'
             def response = mvc.perform(put(updateUrl).contentType(MediaType.APPLICATION_JSON_VALUE).content(requestBody)).andReturn().response
         then: 'ncmp service method to update resource is called'
-            1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle','parent/child', UPDATE, requestBody, 'application/json;charset=UTF-8', NO_AUTH_HEADER)
+            1 * mockNetworkCmProxyFacade.writeResourceDataPassThroughRunningForCmHandle('testCmHandle','parent/child', UPDATE, requestBody, 'application/json;charset=UTF-8', NO_AUTH_HEADER)
         and: 'the response status is OK'
             assert response.status == HttpStatus.OK.value()
     }
@@ -289,7 +246,7 @@ class NetworkCmProxyControllerSpec extends Specification {
         when: 'create resource request is performed'
             def response = mvc.perform(post(url).contentType(MediaType.APPLICATION_JSON_VALUE).content(requestBody)).andReturn().response
         then: 'ncmp service method to create resource called'
-            1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle', 'parent/child', CREATE, requestBody, 'application/json;charset=UTF-8', NO_AUTH_HEADER)
+            1 * mockNetworkCmProxyFacade.writeResourceDataPassThroughRunningForCmHandle('testCmHandle', 'parent/child', CREATE, requestBody, 'application/json;charset=UTF-8', NO_AUTH_HEADER)
         and: 'resource is created'
             assert response.status == HttpStatus.CREATED.value()
     }
@@ -300,7 +257,7 @@ class NetworkCmProxyControllerSpec extends Specification {
         when: 'get module resource request is performed'
             def response = mvc.perform(get(getUrl)).andReturn().response
         then: 'ncmp service method to get yang resource module references is called'
-            mockNetworkCmProxyDataService.getYangResourcesModuleReferences('some-cmhandle') >> [new ModuleReference(moduleName: 'some-name1', revision: '2021-10-03')]
+            mockNetworkCmProxyInventoryFacade.getYangResourcesModuleReferences('some-cmhandle') >> [new ModuleReference(moduleName: 'some-name1', revision: '2021-10-03')]
         and: 'response contains an array with the module name and revision'
             response.getContentAsString() == '[{"moduleName":"some-name1","revision":"2021-10-03"}]'
         and: 'response returns an OK http code'
@@ -321,7 +278,7 @@ class NetworkCmProxyControllerSpec extends Specification {
             cmHandle2.alternateId = 'someAlternateId'
             cmHandle2.moduleSetTag = 'someModuleSetTag'
             cmHandle2.dataProducerIdentifier = 'someDataProducerIdentifier'
-            mockNetworkCmProxyDataService.executeCmHandleSearch(_) >> [cmHandle1, cmHandle2]
+            mockNetworkCmProxyInventoryFacade.executeCmHandleSearch(_) >> [cmHandle1, cmHandle2]
         and: 'map for trust level per cmHandle has value for only one cm handle'
               trustLevelPerCmHandle.put('ch-1', TrustLevel.NONE)
         when: 'the searches api is invoked'
@@ -342,7 +299,7 @@ class NetworkCmProxyControllerSpec extends Specification {
             def compositeState = compositeStateTestObject()
             def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, dmiProperties: dmiProperties, publicProperties: publicProperties, compositeState: compositeState)
         and: 'the service method is invoked with the cm handle id'
-            1 * mockNetworkCmProxyDataService.getNcmpServiceCmHandle('some-cm-handle') >> ncmpServiceCmHandle
+            1 * mockNetworkCmProxyInventoryFacade.getNcmpServiceCmHandle('some-cm-handle') >> ncmpServiceCmHandle
         and: 'map for trust level per cmHandle has values'
             trustLevelPerCmHandle.get('some-cm-handle') >> { TrustLevel.COMPLETE }
         when: 'the cm handle details api is invoked'
@@ -364,7 +321,7 @@ class NetworkCmProxyControllerSpec extends Specification {
         and: 'some cm handle public properties'
             def publicProperties = ['public prop': 'some public property']
         and: 'the service method is invoked with the cm handle id returning the cm handle public properties'
-            1 * mockNetworkCmProxyDataService.getCmHandlePublicProperties('some-cm-handle') >> publicProperties
+            1 * mockNetworkCmProxyInventoryFacade.getCmHandlePublicProperties('some-cm-handle') >> publicProperties
         when: 'the cm handle properties api is invoked'
             def response = mvc.perform(get(cmHandlePropertiesEndpoint)).andReturn().response
         then: 'the correct response is returned'
@@ -379,7 +336,7 @@ class NetworkCmProxyControllerSpec extends Specification {
         and: 'some cm handle composite state'
             def compositeState = compositeStateTestObject()
         and: 'the service method is invoked with the cm handle id returning the cm handle composite state'
-            1 * mockNetworkCmProxyDataService.getCmHandleCompositeState('some-cm-handle') >> compositeState
+            1 * mockNetworkCmProxyInventoryFacade.getCmHandleCompositeState('some-cm-handle') >> compositeState
         when: 'the cm handle state api is invoked'
             def response = mvc.perform(get(cmHandlePropertiesEndpoint)).andReturn().response
         then: 'the correct response is returned'
@@ -399,7 +356,7 @@ class NetworkCmProxyControllerSpec extends Specification {
             def cmHandel2 = new NcmpServiceCmHandle()
             cmHandel2.cmHandleId = 'ch-2'
             cmHandel2.publicProperties = [color: 'green']
-            mockNetworkCmProxyDataService.executeCmHandleSearch(_) >> [cmHandel1, cmHandel2]
+            mockNetworkCmProxyInventoryFacade.executeCmHandleSearch(_) >> [cmHandel1, cmHandel2]
         and: 'map for trust level per cmHandle has values'
             trustLevelPerCmHandle.put('ch-1', TrustLevel.COMPLETE)
             trustLevelPerCmHandle.put('ch-2', TrustLevel.NONE)
@@ -413,7 +370,7 @@ class NetworkCmProxyControllerSpec extends Specification {
         given: 'an endpoint and json data'
             def searchesEndpoint = "$ncmpBasePathV1/ch/id-searches"
         and: 'the service method is invoked with module names and returns cm handle ids'
-            1 * mockNetworkCmProxyDataService.executeCmHandleIdSearch(_) >> ['ch-1', 'ch-2']
+            1 * mockNetworkCmProxyInventoryFacade.executeCmHandleIdSearch(_) >> ['ch-1', 'ch-2']
         when: 'the searches api is invoked'
             def response = mvc.perform(post(searchesEndpoint).contentType(MediaType.APPLICATION_JSON).content('{}')).andReturn().response
         then: 'cm handle ids are returned'
@@ -435,7 +392,7 @@ class NetworkCmProxyControllerSpec extends Specification {
         when: 'patch data resource request is performed'
             def response = mvc.perform(patch(url).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).content(requestBody)).andReturn().response
         then: 'ncmp service method to update resource is called'
-            1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle', 'parent/child', PATCH, requestBody, 'application/json;charset=UTF-8', NO_AUTH_HEADER)
+            1 * mockNetworkCmProxyFacade.writeResourceDataPassThroughRunningForCmHandle('testCmHandle', 'parent/child', PATCH, requestBody, 'application/json;charset=UTF-8', NO_AUTH_HEADER)
         and: 'the response status is OK'
             assert response.status == HttpStatus.OK.value()
     }
@@ -446,31 +403,16 @@ class NetworkCmProxyControllerSpec extends Specification {
         when: 'delete data resource request is performed'
             def response = mvc.perform(delete(url).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)).andReturn().response
         then: 'the ncmp service method to delete resource is called (with null as body)'
-            1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle', 'parent/child', DELETE, null, 'application/json;charset=UTF-8', NO_AUTH_HEADER)
+            1 * mockNetworkCmProxyFacade.writeResourceDataPassThroughRunningForCmHandle('testCmHandle', 'parent/child', DELETE, null, 'application/json;charset=UTF-8', NO_AUTH_HEADER)
         and: 'the response is No Content'
             assert response.status == HttpStatus.NO_CONTENT.value()
     }
 
-    def 'Get resource data from DMI with valid topic i.e. async request for #scenario'() {
-        given: 'resource data url'
-            def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:${datastoreInUrl}?resourceIdentifier=parent/child&options=(a=1,b=2)&topic=my-topic-name"
-        and: 'the NCMP data service is called with correct parameters'
-            1 * mockNetworkCmProxyDataService.getResourceDataForCmHandle(_, '(a=1,b=2)', 'my-topic-name', _, NO_AUTH_HEADER) >> Mono.just(new ResponseEntity<Object>(HttpStatus.OK))
-        when: 'get data resource request is performed'
-            def response = mvc.perform(get(getUrl).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON_VALUE)).andReturn().response
-        then: 'async request id is generated'
-            assert response.contentAsString.contains("requestId")
-        where: 'the following parameters are used'
-            scenario                   | datastoreInUrl
-            ':passthrough-operational' | 'passthrough-operational'
-            ':passthrough-running'     | 'passthrough-running'
-    }
-
     def 'Getting module definitions for a module'() {
         when: 'get module definition request is performed with module name'
             def response = mvc.perform(get("$ncmpBasePathV1/ch/some-cmhandle/modules/definitions?module-name=sampleModuleName")).andReturn().response
         then: 'ncmp service method is invoked with correct parameters'
-            mockNetworkCmProxyDataService.getModuleDefinitionsByCmHandleAndModule('some-cmhandle', 'sampleModuleName', _)
+            mockNetworkCmProxyInventoryFacade.getModuleDefinitionsByCmHandleAndModule('some-cmhandle', 'sampleModuleName', _)
                 >> [new ModuleDefinition('sampleModuleName', '2021-10-03','module sampleModuleName{ sample module content }')]
         and: 'response contains an array with the module name, revision and content'
             response.getContentAsString() == '[{"moduleName":"sampleModuleName","revision":"2021-10-03","content":"module sampleModuleName{ sample module content }"}]'
@@ -484,9 +426,9 @@ class NetworkCmProxyControllerSpec extends Specification {
                 get("$ncmpBasePathV1/ch/some-cmhandle/modules/definitions?module-name=" + moduleName + "&revision=" + revision))
                 .andReturn().response
         then: 'ncmp service method to get definitions by cm handle is invoked when needed'
-            numberOfCallsToByCmHandleId * mockNetworkCmProxyDataService.getModuleDefinitionsByCmHandleId('some-cmhandle') >> []
+            numberOfCallsToByCmHandleId * mockNetworkCmProxyInventoryFacade.getModuleDefinitionsByCmHandleId('some-cmhandle') >> []
         and: 'ncmp service method to get definitions by module is invoked when needed'
-            numberOfCallsToByModule * mockNetworkCmProxyDataService.getModuleDefinitionsByCmHandleAndModule('some-cmhandle', moduleName, revision) >> []
+            numberOfCallsToByModule * mockNetworkCmProxyInventoryFacade.getModuleDefinitionsByCmHandleAndModule('some-cmhandle', moduleName, revision) >> []
         and: 'response returns an OK http code'
             response.status == HttpStatus.OK.value()
         and: 'the correct message is logged when needed'
@@ -509,7 +451,7 @@ class NetworkCmProxyControllerSpec extends Specification {
                     put("$ncmpBasePathV1/ch/some-cm-handle-id/data-sync?dataSyncEnabled=" + dataSyncEnabledFlag))
                     .andReturn().response
         then: 'method to set data sync enabled is called'
-            1 * mockNetworkCmProxyDataService.setDataSyncEnabled('some-cm-handle-id', dataSyncEnabledFlag)
+            1 * mockNetworkCmProxyInventoryFacade.setDataSyncEnabled('some-cm-handle-id', dataSyncEnabledFlag)
         and: 'the response returns an OK http code'
             response.status == HttpStatus.OK.value()
         where: 'the following parameters are used'
@@ -518,23 +460,6 @@ class NetworkCmProxyControllerSpec extends Specification {
             'disabled' | false
     }
 
-    def 'Get Resource Data from operational with or without descendants'() {
-        given: 'resource data url with descendants #enabled'
-            def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:operational?resourceIdentifier=parent/child&include-descendants=${booleanValue}"
-        and: 'the expected target'
-            def expectedCmResourceAddress = new CmResourceAddress(OPERATIONAL.datastoreName, 'testCmHandle', 'parent/child')
-        when: 'get data resource request is performed'
-            def response = mvc.perform(get(getUrl).contentType(MediaType.APPLICATION_JSON)).andReturn().response
-        then: 'the NCMP data service is called with getResourceDataOperational with #descendantsOption'
-            1 * mockNetworkCmProxyDataService.getResourceDataForCmHandle(expectedCmResourceAddress, descendantsOption)
-        and: 'response status is Ok'
-            assert response.status == HttpStatus.OK.value()
-        where: 'the following parameters are used'
-            booleanValue | descendantsOption
-            false        | OMIT_DESCENDANTS
-            true         | INCLUDE_ALL_DESCENDANTS
-    }
-
     def 'Attempt execute #operation rest operation on resource data with #scenario'() {
         given: 'resource data url'
             def url = "$ncmpBasePathV1/ch/testCmHandle/data/ds/${datastoreInUrl}?resourceIdentifier=parent/child"
index 7b850a7..60d2dc5 100644 (file)
@@ -23,7 +23,9 @@ package org.onap.cps.ncmp.rest.controller
 
 import com.fasterxml.jackson.databind.ObjectMapper
 import org.onap.cps.TestUtils
-import org.onap.cps.ncmp.api.NetworkCmProxyDataService
+import org.onap.cps.ncmp.api.impl.NetworkCmProxyFacade
+import org.onap.cps.ncmp.api.impl.NetworkCmProxyInventoryFacade
+import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters
 import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse
 import org.onap.cps.ncmp.api.models.DmiPluginRegistration
 import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse
@@ -31,7 +33,6 @@ import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters
 import org.onap.cps.ncmp.rest.model.CmHandlerRegistrationErrorResponse
 import org.onap.cps.ncmp.rest.model.DmiPluginRegistrationErrorResponse
 import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration
-import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters
 import org.onap.cps.utils.JsonObjectMapper
 import org.spockframework.spring.SpringBean
 import org.springframework.beans.factory.annotation.Autowired
@@ -54,7 +55,7 @@ class NetworkCmProxyInventoryControllerSpec extends Specification {
     MockMvc mvc
 
     @SpringBean
-    NetworkCmProxyDataService mockNetworkCmProxyDataService = Mock()
+    NetworkCmProxyInventoryFacade mockNetworkCmProxyInventoryFacade = Mock()
 
     @SpringBean
     NcmpRestInputMapper ncmpRestInputMapper = Mock()
@@ -83,7 +84,7 @@ class NetworkCmProxyInventoryControllerSpec extends Specification {
                     .content(jsonData)
             ).andReturn().response
         then: 'the converted object is forwarded to the registration service'
-            1 * mockNetworkCmProxyDataService.updateDmiRegistrationAndSyncModule(mockDmiPluginRegistration) >> new DmiPluginRegistrationResponse()
+            1 * mockNetworkCmProxyInventoryFacade.updateDmiRegistrationAndSyncModule(mockDmiPluginRegistration) >> new DmiPluginRegistrationResponse()
         and: 'response status is no content'
             response.status == HttpStatus.OK.value()
         where: 'the following registration json is used'
@@ -112,7 +113,7 @@ class NetworkCmProxyInventoryControllerSpec extends Specification {
         and: 'the mapper service returns a converted object'
             ncmpRestInputMapper.toCmHandleQueryServiceParameters(_) >> cmHandleQueryServiceParameters
         and: 'the service returns the desired results'
-            mockNetworkCmProxyDataService.executeCmHandleIdSearchForInventory(cmHandleQueryServiceParameters) >> serviceMockResponse
+            mockNetworkCmProxyInventoryFacade.executeParameterizedCmHandleIdSearch(cmHandleQueryServiceParameters) >> serviceMockResponse
         when: 'post request is performed & search is called with the given request parameters'
             def response = mvc.perform(
                     post("$ncmpBasePathV1/ch/searches")
@@ -135,7 +136,7 @@ class NetworkCmProxyInventoryControllerSpec extends Specification {
         and: 'the mapper service returns a converted object'
             ncmpRestInputMapper.toCmHandleQueryServiceParameters(_) >> cmHandleQueryServiceParameters
         and: 'the service returns the desired results'
-            mockNetworkCmProxyDataService.executeCmHandleIdSearchForInventory(cmHandleQueryServiceParameters) >> serviceMockResponse
+            mockNetworkCmProxyInventoryFacade.executeParameterizedCmHandleIdSearch(cmHandleQueryServiceParameters) >> serviceMockResponse
         when: 'post request is performed & search is called with the given request parameters'
             def response = mvc.perform(
                     post("$ncmpBasePathV1/ch/searches")
@@ -156,7 +157,7 @@ class NetworkCmProxyInventoryControllerSpec extends Specification {
         given: 'the mapper service returns a converted object'
             ncmpRestInputMapper.toCmHandleQueryServiceParameters(_) >> cmHandleQueryServiceParameters
         and: 'the service returns the desired results'
-            mockNetworkCmProxyDataService.executeCmHandleIdSearchForInventory(cmHandleQueryServiceParameters) >> []
+            mockNetworkCmProxyInventoryFacade.executeParameterizedCmHandleIdSearch(cmHandleQueryServiceParameters) >> []
         when: 'post request is performed & search is called with the given request parameters'
             def response = mvc.perform(
                     post("$ncmpBasePathV1/ch/searches")
@@ -180,7 +181,7 @@ class NetworkCmProxyInventoryControllerSpec extends Specification {
                 updatedCmHandles: [CmHandleRegistrationResponse.createSuccessResponse('cm-handle-2')],
                 removedCmHandles: [CmHandleRegistrationResponse.createSuccessResponse('cm-handle-3')]
             )
-            mockNetworkCmProxyDataService.updateDmiRegistrationAndSyncModule(*_) >> dmiRegistrationResponse
+            mockNetworkCmProxyInventoryFacade.updateDmiRegistrationAndSyncModule(*_) >> dmiRegistrationResponse
         when: 'registration endpoint is invoked'
             def response = mvc.perform(
                 post("$ncmpBasePathV1/ch")
@@ -204,7 +205,7 @@ class NetworkCmProxyInventoryControllerSpec extends Specification {
                 removedCmHandles: [removeCmHandleResponse],
                 upgradedCmHandles: [upgradeCmHandleResponse]
             )
-            mockNetworkCmProxyDataService.updateDmiRegistrationAndSyncModule(*_) >> dmiRegistrationResponse
+            mockNetworkCmProxyInventoryFacade.updateDmiRegistrationAndSyncModule(*_) >> dmiRegistrationResponse
         when: 'registration endpoint is invoked'
             def response = mvc.perform(
                 post("$ncmpBasePathV1/ch")
@@ -237,7 +238,7 @@ class NetworkCmProxyInventoryControllerSpec extends Specification {
         given: 'an endpoint for returning cm handle IDs for a registered dmi plugin'
             def getUrl = "$ncmpBasePathV1/ch/cmHandles?dmi-plugin-identifier=some-dmi-plugin-identifier"
         and: 'a collection of cm handle IDs are returned'
-            1 * mockNetworkCmProxyDataService.getAllCmHandleIdsByDmiPluginIdentifier('some-dmi-plugin-identifier')
+            1 * mockNetworkCmProxyInventoryFacade.getAllCmHandleIdsByDmiPluginIdentifier('some-dmi-plugin-identifier')
                     >> ['cm-handle-id-1','cm-handle-id-2']
         when: 'the endpoint is invoked'
             def response = mvc.perform(
index af8a8ea..20e8abe 100644 (file)
@@ -24,9 +24,10 @@ package org.onap.cps.ncmp.rest.exceptions
 import groovy.json.JsonSlurper
 import org.mapstruct.factory.Mappers
 import org.onap.cps.TestUtils
-import org.onap.cps.ncmp.api.NetworkCmProxyDataService
 import org.onap.cps.ncmp.api.impl.NcmpCachedResourceRequestHandler
 import org.onap.cps.ncmp.api.impl.NcmpPassthroughResourceRequestHandler
+import org.onap.cps.ncmp.api.impl.NetworkCmProxyFacade
+import org.onap.cps.ncmp.api.impl.NetworkCmProxyInventoryFacade
 import org.onap.cps.ncmp.api.impl.exception.DmiClientRequestException
 import org.onap.cps.ncmp.api.impl.exception.DmiRequestException
 import org.onap.cps.ncmp.api.impl.exception.ServerNcmpException
@@ -68,7 +69,10 @@ class NetworkCmProxyRestExceptionHandlerSpec extends Specification {
     MockMvc mvc
 
     @SpringBean
-    NetworkCmProxyDataService mockNetworkCmProxyDataService = Mock()
+    NetworkCmProxyFacade mockNetworkCmProxyFacade = Mock()
+
+    @SpringBean
+    NetworkCmProxyInventoryFacade mockNetworkCmProxyInventoryFacade = Mock()
 
     @SpringBean
     JsonObjectMapper stubbedJsonObjectMapper = Stub()
@@ -153,9 +157,9 @@ class NetworkCmProxyRestExceptionHandlerSpec extends Specification {
 
     def setupTestException(exception, apiType) {
         if (NCMP == apiType) {
-            mockNetworkCmProxyDataService.getYangResourcesModuleReferences(*_) >> { throw exception }
+            mockNetworkCmProxyInventoryFacade.getYangResourcesModuleReferences(*_) >> { throw exception }
         }
-        mockNetworkCmProxyDataService.updateDmiRegistrationAndSyncModule(*_) >> { throw exception }
+        mockNetworkCmProxyInventoryFacade.updateDmiRegistrationAndSyncModule(*_) >> { throw exception }
     }
 
     def performTestRequest(apiType) {
@@ -174,8 +178,5 @@ class NetworkCmProxyRestExceptionHandlerSpec extends Specification {
         assert expectedErrorDetails == null || content['details'].toString().contains(expectedErrorDetails)
     }
 
-    enum ApiType {
-        NCMP,
-        NCMPINVENTORY;
-    }
+    enum ApiType { NCMP,  NCMPINVENTORY  }
 }
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java
deleted file mode 100644 (file)
index 73c8d96..0000000
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- *  ============LICENSE_START=======================================================
- *  Copyright (C) 2021 highstreet technologies GmbH
- *  Modifications Copyright (C) 2021-2024 Nordix Foundation
- *  Modifications Copyright (C) 2021 Pantheon.tech
- *  Modifications Copyright (C) 2022 Bell Canada
- *  ================================================================================
- *  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.api;
-
-import java.util.Collection;
-import java.util.Map;
-import org.onap.cps.ncmp.api.impl.inventory.CompositeState;
-import org.onap.cps.ncmp.api.impl.operations.OperationType;
-import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters;
-import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
-import org.onap.cps.ncmp.api.models.CmResourceAddress;
-import org.onap.cps.ncmp.api.models.DataOperationRequest;
-import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
-import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse;
-import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
-import org.onap.cps.spi.FetchDescendantsOption;
-import org.onap.cps.spi.model.ModuleDefinition;
-import org.onap.cps.spi.model.ModuleReference;
-import reactor.core.publisher.Mono;
-
-/*
- * Datastore interface for handling CPS data.
- */
-public interface NetworkCmProxyDataService {
-
-    /**
-     * Registration of New CM Handles.
-     *
-     * @param dmiPluginRegistration Dmi Plugin Registration
-     * @return dmiPluginRegistrationResponse
-     */
-    DmiPluginRegistrationResponse updateDmiRegistrationAndSyncModule(DmiPluginRegistration dmiPluginRegistration);
-
-    /**
-     * Fetches resource data for a given data store using DMI (Data Management Interface).
-     * This method retrieves data based on the provided CmResourceAddress and additional query parameters.
-     * It supports asynchronous processing and handles authorization if required.
-     *
-     * @param cmResourceAddress   The target data store, including the CM handle and resource identifier.
-     *                            This parameter must not be null.
-     * @param optionsParamInQuery Additional query parameters that may influence the data retrieval process,
-     *                            such as filters or limits. This parameter can be null.
-     * @param topicParamInQuery   The topic name for triggering asynchronous responses. If specified,
-     *                            the response will be sent to this topic. This parameter can be null.
-     * @param requestId           A unique identifier for the request, used for tracking and correlating
-     *                            asynchronous operations. This parameter must not be null.
-     * @param authorization       The contents of the Authorization header. This parameter can be null
-     *                            if authorization is not required.
-     * @return {@code Mono<Object>} A reactive Mono that emits the resource data on successful retrieval
-     *     or an error signal if the operation fails. The Mono represents a single asynchronous
-     *     computation result.
-     */
-    Mono<Object> getResourceDataForCmHandle(CmResourceAddress cmResourceAddress,
-                                            String optionsParamInQuery,
-                                            String topicParamInQuery,
-                                            String requestId,
-                                            String authorization);
-
-    /**
-     * Get resource data for operational.
-     *
-     * @param cmResourceAddress     target datastore, cm handle and resource identifier
-     * @Link FetchDescendantsOption fetch descendants option
-     * @return {@code Object} resource data
-     */
-    Object getResourceDataForCmHandle(CmResourceAddress cmResourceAddress,
-                                      FetchDescendantsOption fetchDescendantsOption);
-
-    /**
-     * Execute (async) data operation for group of cm handles using dmi.
-     *
-     * @param topicParamInQuery        topic name for (triggering) async responses
-     * @param dataOperationRequest     contains a list of operation definitions(multiple operations)
-     * @param requestId                request ID
-     * @param authorization            contents of Authorization header, or null if not present
-     */
-    void executeDataOperationForCmHandles(String topicParamInQuery,
-                                          DataOperationRequest dataOperationRequest,
-                                          String requestId,
-                                          String authorization);
-
-
-    /**
-     * Write resource data for data store pass-through running using dmi for given cm-handle.
-     *
-     * @param cmHandleId         cm handle identifier
-     * @param resourceIdentifier resource identifier
-     * @param operationType      required operation type
-     * @param requestBody        request body to create resource
-     * @param contentType        content type in body
-     * @param authorization       contents of Authorization header, or null if not present
-     * @return {@code Object} return data
-     */
-    Object writeResourceDataPassThroughRunningForCmHandle(String cmHandleId,
-                                                          String resourceIdentifier,
-                                                          OperationType operationType,
-                                                          String requestBody,
-                                                          String contentType,
-                                                          String authorization);
-
-    /**
-     * Retrieve module references for the given cm handle.
-     *
-     * @param cmHandleId cm handle identifier
-     * @return a collection of modules names and revisions
-     */
-    Collection<ModuleReference> getYangResourcesModuleReferences(String cmHandleId);
-
-    /**
-     * Retrieve module definitions for the given cm handle.
-     *
-     * @param cmHandleId cm handle identifier
-     * @return a collection of module definition (moduleName, revision and yang resource content)
-     */
-    Collection<ModuleDefinition> getModuleDefinitionsByCmHandleId(String cmHandleId);
-
-    /**
-     * Get module definitions for the given parameters.
-     *
-     * @param cmHandleId        cm-handle identifier
-     * @param moduleName        module name
-     * @param moduleRevision    the revision of the module
-     * @return list of module definitions (module name, revision, yang resource content)
-     */
-    Collection<ModuleDefinition> getModuleDefinitionsByCmHandleAndModule(String cmHandleId,
-                                                                         String moduleName,
-                                                                         String moduleRevision);
-
-    /**
-     * Query cm handle details by cm handle's name.
-     *
-     * @param cmHandleId cm handle identifier
-     * @return a collection of cm handle details.
-     */
-    NcmpServiceCmHandle getNcmpServiceCmHandle(String cmHandleId);
-
-    /**
-     * Get cm handle public properties by cm handle id.
-     *
-     * @param cmHandleId cm handle identifier
-     * @return a collection of cm handle public properties.
-     */
-    Map<String, String> getCmHandlePublicProperties(String cmHandleId);
-
-    /**
-     * Get cm handle composite state by cm handle id.
-     *
-     * @param cmHandleId cm handle identifier
-     * @return a cm handle composite state
-     */
-    CompositeState getCmHandleCompositeState(String cmHandleId);
-
-    /**
-     * Query and return cm handles that match the given query parameters.
-     *
-     * @param cmHandleQueryApiParameters the cm handle query parameters
-     * @return collection of cm handles
-     */
-    Collection<NcmpServiceCmHandle> executeCmHandleSearch(CmHandleQueryApiParameters cmHandleQueryApiParameters);
-
-    /**
-     * Query and return cm handle ids that match the given query parameters.
-     *
-     * @param cmHandleQueryApiParameters the cm handle query parameters
-     * @return collection of cm handle ids
-     */
-    Collection<String> executeCmHandleIdSearch(CmHandleQueryApiParameters cmHandleQueryApiParameters);
-
-    /**
-     * Set the data sync enabled flag, along with the data sync state to true or false based on the cm handle id.
-     *
-     * @param cmHandleId cm handle id
-     * @param dataSyncEnabled data sync enabled flag
-     */
-    void setDataSyncEnabled(String cmHandleId, Boolean dataSyncEnabled);
-
-    /**
-     * Get all cm handle IDs by DMI plugin identifier.
-     *
-     * @param dmiPluginIdentifier DMI plugin identifier
-     * @return collection of cm handle IDs
-     */
-    Collection<String> getAllCmHandleIdsByDmiPluginIdentifier(String dmiPluginIdentifier);
-
-    /**
-     * Get all cm handle IDs by various search criteria.
-     *
-     * @param cmHandleQueryServiceParameters cm handle query parameters
-     * @return collection of cm handle IDs
-     */
-    Collection<String> executeCmHandleIdSearchForInventory(CmHandleQueryServiceParameters
-                                                               cmHandleQueryServiceParameters);
-}
@@ -24,7 +24,7 @@ import java.util.Collection;
 import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
 
-public interface NetworkCmProxyCmHandleQueryService {
+public interface ParameterizedCmHandleQueryService {
     /**
      * Query and return cm handle ids that match the given query parameters.
      * Supported query types:
@@ -63,7 +63,8 @@ public interface NetworkCmProxyCmHandleQueryService {
     Collection<NcmpServiceCmHandle> queryCmHandles(CmHandleQueryServiceParameters cmHandleQueryServiceParameters);
 
     /**
-     * Query and return all cm handle objects.
+     * Get all cm handle objects.
+     * Note: it is similar to all the queries above but simply no conditions and hence not 'parameterized'
      *
      * @return collection of cm handles
      */
@@ -1,7 +1,6 @@
 /*
  *  ============LICENSE_START=======================================================
- *  Copyright (C) 2021 highstreet technologies GmbH
- *  Modifications Copyright (C) 2021-2024 Nordix Foundation
+ *  Copyright (C) 2021-2024 Nordix Foundation
  *  Modifications Copyright (C) 2021 Pantheon.tech
  *  Modifications Copyright (C) 2021-2022 Bell Canada
  *  Modifications Copyright (C) 2023 TechMahindra Ltd.
@@ -32,7 +31,6 @@ import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_INVALID_ID;
 import static org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory.MODULE_UPGRADE;
 import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT;
 import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME;
-import static org.onap.cps.ncmp.api.impl.utils.RestQueryParametersValidator.validateCmHandleQueryParameters;
 
 import com.google.common.collect.Lists;
 import com.hazelcast.map.IMap;
@@ -49,11 +47,8 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.onap.cps.api.CpsDataService;
-import org.onap.cps.ncmp.api.NetworkCmProxyCmHandleQueryService;
-import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
 import org.onap.cps.ncmp.api.impl.config.embeddedcache.TrustLevelCacheConfig;
 import org.onap.cps.ncmp.api.impl.events.lcm.LcmEventsCmHandleStateHandler;
-import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueries;
 import org.onap.cps.ncmp.api.impl.inventory.CmHandleState;
 import org.onap.cps.ncmp.api.impl.inventory.CompositeState;
 import org.onap.cps.ncmp.api.impl.inventory.CompositeStateBuilder;
@@ -61,58 +56,46 @@ import org.onap.cps.ncmp.api.impl.inventory.CompositeStateUtils;
 import org.onap.cps.ncmp.api.impl.inventory.DataStoreSyncState;
 import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence;
 import org.onap.cps.ncmp.api.impl.inventory.sync.ModuleOperationsUtils;
-import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations;
-import org.onap.cps.ncmp.api.impl.operations.OperationType;
 import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel;
 import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevelManager;
 import org.onap.cps.ncmp.api.impl.utils.AlternateIdChecker;
-import org.onap.cps.ncmp.api.impl.utils.CmHandleQueryConditions;
-import org.onap.cps.ncmp.api.impl.utils.InventoryQueryConditions;
-import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
 import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
-import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters;
-import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
 import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse;
-import org.onap.cps.ncmp.api.models.CmResourceAddress;
-import org.onap.cps.ncmp.api.models.DataOperationRequest;
 import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
 import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse;
 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
-import org.onap.cps.spi.FetchDescendantsOption;
 import org.onap.cps.spi.exceptions.AlreadyDefinedException;
 import org.onap.cps.spi.exceptions.CpsException;
 import org.onap.cps.spi.exceptions.DataNodeNotFoundException;
 import org.onap.cps.spi.exceptions.DataValidationException;
-import org.onap.cps.spi.model.ModuleDefinition;
-import org.onap.cps.spi.model.ModuleReference;
-import org.onap.cps.utils.JsonObjectMapper;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Service;
-import reactor.core.publisher.Mono;
 
 @Slf4j
 @Service
 @RequiredArgsConstructor
-public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService {
+public class CmHandleRegistrationService {
 
     private static final int DELETE_BATCH_SIZE = 100;
-    private final JsonObjectMapper jsonObjectMapper;
-    private final DmiDataOperations dmiDataOperations;
-    private final NetworkCmProxyDataServicePropertyHandler networkCmProxyDataServicePropertyHandler;
+
+    private final CmHandleRegistrationServicePropertyHandler cmHandleRegistrationServicePropertyHandler;
     private final InventoryPersistence inventoryPersistence;
-    private final CmHandleQueries cmHandleQueries;
-    private final NetworkCmProxyCmHandleQueryService networkCmProxyCmHandleQueryService;
-    private final LcmEventsCmHandleStateHandler lcmEventsCmHandleStateHandler;
     private final CpsDataService cpsDataService;
+    private final LcmEventsCmHandleStateHandler lcmEventsCmHandleStateHandler;
     private final IMap<String, Object> moduleSyncStartedOnCmHandles;
 
     @Qualifier(TrustLevelCacheConfig.TRUST_LEVEL_PER_DMI_PLUGIN)
     private final Map<String, TrustLevel> trustLevelPerDmiPlugin;
-
     private final TrustLevelManager trustLevelManager;
+
     private final AlternateIdChecker alternateIdChecker;
 
-    @Override
+    /**
+     * Registration of Created, Removed, Updated or Upgraded CM Handles.
+     *
+     * @param dmiPluginRegistration Dmi Plugin Registration details
+     * @return dmiPluginRegistrationResponse
+     */
     public DmiPluginRegistrationResponse updateDmiRegistrationAndSyncModule(
         final DmiPluginRegistration dmiPluginRegistration) {
 
@@ -132,91 +115,6 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
         return dmiPluginRegistrationResponse;
     }
 
-    @Override
-    public Mono<Object> getResourceDataForCmHandle(final CmResourceAddress cmResourceAddress,
-                                             final String optionsParamInQuery,
-                                             final String topicParamInQuery,
-                                             final String requestId,
-                                             final String authorization) {
-        return dmiDataOperations.getResourceDataFromDmi(cmResourceAddress, optionsParamInQuery, topicParamInQuery,
-                        requestId, authorization)
-                .flatMap(responseEntity -> Mono.justOrEmpty(responseEntity.getBody()));
-    }
-
-    @Override
-    public Object getResourceDataForCmHandle(final CmResourceAddress cmResourceAddress,
-                                             final FetchDescendantsOption fetchDescendantsOption) {
-        return cpsDataService.getDataNodes(cmResourceAddress.datastoreName(),
-                                           cmResourceAddress.cmHandleId(),
-                                           cmResourceAddress.resourceIdentifier(),
-                                           fetchDescendantsOption).iterator().next();
-    }
-
-    @Override
-    public void executeDataOperationForCmHandles(final String topicParamInQuery,
-                                                 final DataOperationRequest dataOperationRequest,
-                                                 final String requestId,
-                                                 final String authorization) {
-        dmiDataOperations.requestResourceDataFromDmi(topicParamInQuery, dataOperationRequest, requestId, authorization);
-    }
-
-    @Override
-    public Object writeResourceDataPassThroughRunningForCmHandle(final String cmHandleId,
-                                                                 final String resourceIdentifier,
-                                                                 final OperationType operationType,
-                                                                 final String requestData,
-                                                                 final String dataType,
-                                                                 final String authorization) {
-        return dmiDataOperations.writeResourceDataPassThroughRunningFromDmi(cmHandleId, resourceIdentifier,
-            operationType, requestData, dataType, authorization);
-    }
-
-    @Override
-    public Collection<ModuleReference> getYangResourcesModuleReferences(final String cmHandleId) {
-        return inventoryPersistence.getYangResourcesModuleReferences(cmHandleId);
-    }
-
-    @Override
-    public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleId(final String cmHandleId) {
-        return inventoryPersistence.getModuleDefinitionsByCmHandleId(cmHandleId);
-    }
-
-    @Override
-    public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleAndModule(final String cmHandleId,
-                                                                                final String moduleName,
-                                                                                final String moduleRevision) {
-        return inventoryPersistence.getModuleDefinitionsByCmHandleAndModule(cmHandleId, moduleName, moduleRevision);
-    }
-
-    /**
-     * Retrieve cm handles with details for the given query parameters.
-     *
-     * @param cmHandleQueryApiParameters cm handle query parameters
-     * @return cm handles with details
-     */
-    @Override
-    public Collection<NcmpServiceCmHandle> executeCmHandleSearch(
-        final CmHandleQueryApiParameters cmHandleQueryApiParameters) {
-        final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType(
-            cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class);
-        validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES);
-        return networkCmProxyCmHandleQueryService.queryCmHandles(cmHandleQueryServiceParameters);
-    }
-
-    /**
-     * Retrieve cm handle ids for the given query parameters.
-     *
-     * @param cmHandleQueryApiParameters cm handle query parameters
-     * @return cm handle ids
-     */
-    @Override
-    public Collection<String> executeCmHandleIdSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters) {
-        final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType(
-            cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class);
-        validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES);
-        return networkCmProxyCmHandleQueryService.queryCmHandleIds(cmHandleQueryServiceParameters);
-    }
-
     /**
      * Set the data sync enabled flag, along with the data sync state
      * based on the data sync enabled boolean for the cm handle id provided.
@@ -224,7 +122,6 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
      * @param cmHandleId                 cm handle id
      * @param dataSyncEnabledTargetValue data sync enabled flag
      */
-    @Override
     public void setDataSyncEnabled(final String cmHandleId, final Boolean dataSyncEnabledTargetValue) {
         final CompositeState compositeState = inventoryPersistence.getCmHandleState(cmHandleId);
         if (dataSyncEnabledTargetValue.equals(compositeState.getDataSyncEnabled())) {
@@ -248,70 +145,8 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
         }
     }
 
-    /**
-     * Get all cm handle IDs by DMI plugin identifier.
-     *
-     * @param dmiPluginIdentifier DMI plugin identifier
-     * @return set of cm handle IDs
-     */
-    @Override
-    public Collection<String> getAllCmHandleIdsByDmiPluginIdentifier(final String dmiPluginIdentifier) {
-        return cmHandleQueries.getCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifier);
-    }
-
-    /**
-     * Get all cm handle IDs by various properties.
-     *
-     * @param cmHandleQueryServiceParameters cm handle query parameters
-     * @return set of cm handle IDs
-     */
-    @Override
-    public Collection<String> executeCmHandleIdSearchForInventory(
-        final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
-        validateCmHandleQueryParameters(cmHandleQueryServiceParameters, InventoryQueryConditions.ALL_CONDITION_NAMES);
-        return networkCmProxyCmHandleQueryService.queryCmHandleIdsForInventory(cmHandleQueryServiceParameters);
-    }
-
-    /**
-     * Retrieve cm handle details for a given cm handle.
-     *
-     * @param cmHandleId cm handle identifier
-     * @return cm handle details
-     */
-    @Override
-    public NcmpServiceCmHandle getNcmpServiceCmHandle(final String cmHandleId) {
-        return YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle(
-            inventoryPersistence.getYangModelCmHandle(cmHandleId));
-    }
-
-    /**
-     * Get cm handle public properties for a given cm handle id.
-     *
-     * @param cmHandleId cm handle identifier
-     * @return cm handle public properties
-     */
-    @Override
-    public Map<String, String> getCmHandlePublicProperties(final String cmHandleId) {
-        final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId);
-        final List<YangModelCmHandle.Property> yangModelPublicProperties = yangModelCmHandle.getPublicProperties();
-        final Map<String, String> cmHandlePublicProperties = new HashMap<>();
-        YangDataConverter.asPropertiesMap(yangModelPublicProperties, cmHandlePublicProperties);
-        return cmHandlePublicProperties;
-    }
-
-    /**
-     * Get cm handle composite state for a given cm handle id.
-     *
-     * @param cmHandleId cm handle identifier
-     * @return cm handle state
-     */
-    @Override
-    public CompositeState getCmHandleCompositeState(final String cmHandleId) {
-        return inventoryPersistence.getYangModelCmHandle(cmHandleId).getCompositeState();
-    }
-
     protected void processRemovedCmHandles(final DmiPluginRegistration dmiPluginRegistration,
-                                         final DmiPluginRegistrationResponse dmiPluginRegistrationResponse) {
+                                           final DmiPluginRegistrationResponse dmiPluginRegistrationResponse) {
         final List<String> tobeRemovedCmHandleIds = dmiPluginRegistration.getRemovedCmHandles();
         final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses =
             new ArrayList<>(tobeRemovedCmHandleIds.size());
@@ -344,7 +179,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
     }
 
     protected void processCreatedCmHandles(final DmiPluginRegistration dmiPluginRegistration,
-                                         final DmiPluginRegistrationResponse dmiPluginRegistrationResponse) {
+                                           final DmiPluginRegistrationResponse dmiPluginRegistrationResponse) {
         final List<NcmpServiceCmHandle> ncmpServiceCmHandles = dmiPluginRegistration.getCreatedCmHandles();
         final List<CmHandleRegistrationResponse> failedCmHandleRegistrationResponses = new ArrayList<>();
 
@@ -374,8 +209,8 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
     }
 
     protected void processUpdatedCmHandles(final DmiPluginRegistration dmiPluginRegistration,
-                                         final DmiPluginRegistrationResponse dmiPluginRegistrationResponse) {
-        dmiPluginRegistrationResponse.setUpdatedCmHandles(networkCmProxyDataServicePropertyHandler
+                                           final DmiPluginRegistrationResponse dmiPluginRegistrationResponse) {
+        dmiPluginRegistrationResponse.setUpdatedCmHandles(cmHandleRegistrationServicePropertyHandler
             .updateCmHandleProperties(dmiPluginRegistration.getUpdatedCmHandles()));
     }
 
@@ -401,67 +236,24 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
                     }
                 } else {
                     cmHandleUpgradeResponses.add(
-                            CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLES_NOT_READY));
+                        CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLES_NOT_READY));
                 }
             } catch (final DataNodeNotFoundException dataNodeNotFoundException) {
                 log.error("Unable to find data node for cm handle id : {} , caused by : {}",
-                        cmHandleId, dataNodeNotFoundException.getMessage());
+                    cmHandleId, dataNodeNotFoundException.getMessage());
                 cmHandleUpgradeResponses.add(
-                        CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLES_NOT_FOUND));
+                    CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLES_NOT_FOUND));
             } catch (final DataValidationException dataValidationException) {
                 log.error("Unable to upgrade cm handle id: {}, caused by : {}",
-                        cmHandleId, dataValidationException.getMessage());
+                    cmHandleId, dataValidationException.getMessage());
                 cmHandleUpgradeResponses.add(
-                        CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLE_INVALID_ID));
+                    CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLE_INVALID_ID));
             }
         }
         cmHandleUpgradeResponses.addAll(upgradeCmHandles(acceptedCmHandleStatePerCmHandle));
         dmiPluginRegistrationResponse.setUpgradedCmHandles(cmHandleUpgradeResponses);
     }
 
-    private Collection<String> checkAlternateIds(
-        final List<NcmpServiceCmHandle> cmHandlesToBeCreated,
-        final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses) {
-        final Collection<String> rejectedCmHandleIds = alternateIdChecker
-            .getIdsOfCmHandlesWithRejectedAlternateId(cmHandlesToBeCreated, AlternateIdChecker.Operation.CREATE);
-        cmHandleRegistrationResponses.addAll(CmHandleRegistrationResponse.createFailureResponses(
-            rejectedCmHandleIds, ALTERNATE_ID_ALREADY_ASSOCIATED));
-        return rejectedCmHandleIds;
-    }
-
-    private List<String> persistCmHandlesWithState(final DmiPluginRegistration dmiPluginRegistration,
-                                                   final DmiPluginRegistrationResponse dmiPluginRegistrationResponse,
-                                                   final List<NcmpServiceCmHandle> cmHandlesToBeCreated,
-                                                   final Collection<String> rejectedCmHandleIds) {
-        final List<String> succeededCmHandleIds = new ArrayList<>(cmHandlesToBeCreated.size());
-        final List<YangModelCmHandle> yangModelCmHandlesToRegister = new ArrayList<>(cmHandlesToBeCreated.size());
-        final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses =
-            new ArrayList<>(cmHandlesToBeCreated.size());
-        for (final NcmpServiceCmHandle ncmpServiceCmHandle: cmHandlesToBeCreated) {
-            if (!rejectedCmHandleIds.contains(ncmpServiceCmHandle.getCmHandleId())) {
-                yangModelCmHandlesToRegister.add(getYangModelCmHandle(dmiPluginRegistration, ncmpServiceCmHandle));
-                cmHandleRegistrationResponses.add(
-                    CmHandleRegistrationResponse.createSuccessResponse(ncmpServiceCmHandle.getCmHandleId()));
-                succeededCmHandleIds.add(ncmpServiceCmHandle.getCmHandleId());
-            }
-        }
-        lcmEventsCmHandleStateHandler.initiateStateAdvised(yangModelCmHandlesToRegister);
-        dmiPluginRegistrationResponse.setCreatedCmHandles(cmHandleRegistrationResponses);
-        return succeededCmHandleIds;
-    }
-
-    private YangModelCmHandle getYangModelCmHandle(final DmiPluginRegistration dmiPluginRegistration,
-                                                   final NcmpServiceCmHandle ncmpServiceCmHandle) {
-        return YangModelCmHandle.toYangModelCmHandle(
-            dmiPluginRegistration.getDmiPlugin(),
-            dmiPluginRegistration.getDmiDataPlugin(),
-            dmiPluginRegistration.getDmiModelPlugin(),
-            ncmpServiceCmHandle,
-            ncmpServiceCmHandle.getModuleSetTag(),
-            ncmpServiceCmHandle.getAlternateId(),
-            ncmpServiceCmHandle.getDataProducerIdentifier());
-    }
-
     private void processTrustLevels(final Collection<NcmpServiceCmHandle> cmHandlesToBeCreated,
                                     final Collection<String> succeededCmHandleIds) {
         final Map<String, TrustLevel> initialTrustLevelPerCmHandleId = new HashMap<>(cmHandlesToBeCreated.size());
@@ -485,9 +277,9 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
     private static void updateYangModelCmHandleForUpgrade(final YangModelCmHandle yangModelCmHandle,
                                                           final String upgradedModuleSetTag) {
         final String lockReasonWithModuleSetTag = String.format(ModuleOperationsUtils.MODULE_SET_TAG_MESSAGE_FORMAT,
-                upgradedModuleSetTag);
+            upgradedModuleSetTag);
         yangModelCmHandle.setCompositeState(new CompositeStateBuilder().withCmHandleState(CmHandleState.READY)
-                .withLockReason(MODULE_UPGRADE, lockReasonWithModuleSetTag).build());
+            .withLockReason(MODULE_UPGRADE, lockReasonWithModuleSetTag).build());
     }
 
     private CmHandleRegistrationResponse deleteCmHandleAndGetCmHandleRegistrationResponse(final String cmHandleId) {
@@ -565,4 +357,48 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
         }
     }
 
+    private Collection<String> checkAlternateIds(
+        final List<NcmpServiceCmHandle> cmHandlesToBeCreated,
+        final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses) {
+        final Collection<String> rejectedCmHandleIds = alternateIdChecker
+            .getIdsOfCmHandlesWithRejectedAlternateId(cmHandlesToBeCreated, AlternateIdChecker.Operation.CREATE);
+        cmHandleRegistrationResponses.addAll(CmHandleRegistrationResponse.createFailureResponses(
+            rejectedCmHandleIds, ALTERNATE_ID_ALREADY_ASSOCIATED));
+        return rejectedCmHandleIds;
+    }
+
+    private List<String> persistCmHandlesWithState(final DmiPluginRegistration dmiPluginRegistration,
+                                                   final DmiPluginRegistrationResponse dmiPluginRegistrationResponse,
+                                                   final List<NcmpServiceCmHandle> cmHandlesToBeCreated,
+                                                   final Collection<String> rejectedCmHandleIds) {
+        final List<String> succeededCmHandleIds = new ArrayList<>(cmHandlesToBeCreated.size());
+        final List<YangModelCmHandle> yangModelCmHandlesToRegister = new ArrayList<>(cmHandlesToBeCreated.size());
+        final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses =
+            new ArrayList<>(cmHandlesToBeCreated.size());
+        for (final NcmpServiceCmHandle ncmpServiceCmHandle: cmHandlesToBeCreated) {
+            if (!rejectedCmHandleIds.contains(ncmpServiceCmHandle.getCmHandleId())) {
+                yangModelCmHandlesToRegister.add(getYangModelCmHandle(dmiPluginRegistration, ncmpServiceCmHandle));
+                cmHandleRegistrationResponses.add(
+                    CmHandleRegistrationResponse.createSuccessResponse(ncmpServiceCmHandle.getCmHandleId()));
+                succeededCmHandleIds.add(ncmpServiceCmHandle.getCmHandleId());
+            }
+        }
+        lcmEventsCmHandleStateHandler.initiateStateAdvised(yangModelCmHandlesToRegister);
+        dmiPluginRegistrationResponse.setCreatedCmHandles(cmHandleRegistrationResponses);
+        return succeededCmHandleIds;
+    }
+
+    private YangModelCmHandle getYangModelCmHandle(final DmiPluginRegistration dmiPluginRegistration,
+                                                   final NcmpServiceCmHandle ncmpServiceCmHandle) {
+        return YangModelCmHandle.toYangModelCmHandle(
+            dmiPluginRegistration.getDmiPlugin(),
+            dmiPluginRegistration.getDmiDataPlugin(),
+            dmiPluginRegistration.getDmiModelPlugin(),
+            ncmpServiceCmHandle,
+            ncmpServiceCmHandle.getModuleSetTag(),
+            ncmpServiceCmHandle.getAlternateId(),
+            ncmpServiceCmHandle.getDataProducerIdentifier());
+    }
+
+
 }
@@ -25,8 +25,8 @@ package org.onap.cps.ncmp.api.impl;
 import static org.onap.cps.ncmp.api.NcmpResponseStatus.ALTERNATE_ID_ALREADY_ASSOCIATED;
 import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLES_NOT_FOUND;
 import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_INVALID_ID;
-import static org.onap.cps.ncmp.api.impl.NetworkCmProxyDataServicePropertyHandler.PropertyType.DMI_PROPERTY;
-import static org.onap.cps.ncmp.api.impl.NetworkCmProxyDataServicePropertyHandler.PropertyType.PUBLIC_PROPERTY;
+import static org.onap.cps.ncmp.api.impl.CmHandleRegistrationServicePropertyHandler.PropertyType.DMI_PROPERTY;
+import static org.onap.cps.ncmp.api.impl.CmHandleRegistrationServicePropertyHandler.PropertyType.PUBLIC_PROPERTY;
 import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME;
 import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR;
 import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT;
@@ -65,7 +65,7 @@ import org.springframework.util.StringUtils;
 @RequiredArgsConstructor
 //Accepting the security hotspot as the string checked is generated from inside code and not user input.
 @SuppressWarnings("squid:S5852")
-public class NetworkCmProxyDataServicePropertyHandler {
+public class CmHandleRegistrationServicePropertyHandler {
 
     private final InventoryPersistence inventoryPersistence;
     private final CpsDataService cpsDataService;
@@ -138,6 +138,9 @@ public class NetworkCmProxyDataServicePropertyHandler {
                     log.warn("Unable to update dataProducerIdentifier for cmHandle {}. "
                             + "Value for dataProducerIdentifier has been set previously.",
                         ncmpServiceCmHandle.getCmHandleId());
+                } else {
+                    log.debug("dataProducerIdentifier for cmHandle {} is already set to {}.",
+                        ncmpServiceCmHandle.getCmHandleId(), newDataProducerIdentifier);
                 }
             } else {
                 setAndUpdateCmHandleField(
index eb43718..da230cf 100644 (file)
@@ -22,7 +22,7 @@ package org.onap.cps.ncmp.api.impl;
 
 import java.util.Collection;
 import lombok.RequiredArgsConstructor;
-import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
+import org.onap.cps.api.CpsDataService;
 import org.onap.cps.ncmp.api.NetworkCmProxyQueryService;
 import org.onap.cps.ncmp.api.models.CmResourceAddress;
 import org.onap.cps.spi.FetchDescendantsOption;
@@ -34,7 +34,7 @@ import reactor.core.publisher.Mono;
 @RequiredArgsConstructor
 public class NcmpCachedResourceRequestHandler extends NcmpDatastoreRequestHandler {
 
-    private final NetworkCmProxyDataService networkCmProxyDataService;
+    private final CpsDataService cpsDataService;
     private final NetworkCmProxyQueryService networkCmProxyQueryService;
 
     /**
@@ -61,8 +61,12 @@ public class NcmpCachedResourceRequestHandler extends NcmpDatastoreRequestHandle
                                                       final boolean includeDescendants,
                                                       final String authorization) {
         final FetchDescendantsOption fetchDescendantsOption = getFetchDescendantsOption(includeDescendants);
-        return Mono.fromSupplier(
-                () -> networkCmProxyDataService.getResourceDataForCmHandle(cmResourceAddress, fetchDescendantsOption));
+
+        final DataNode dataNode = cpsDataService.getDataNodes(cmResourceAddress.datastoreName(),
+            cmResourceAddress.cmHandleId(),
+            cmResourceAddress.resourceIdentifier(),
+            fetchDescendantsOption).iterator().next();
+        return Mono.justOrEmpty(dataNode);
     }
 
     private static FetchDescendantsOption getFetchDescendantsOption(final boolean includeDescendants) {
index dbd2bb4..302ba44 100644 (file)
@@ -45,46 +45,43 @@ public abstract class NcmpDatastoreRequestHandler {
      * Executes synchronous/asynchronous get request for given cm handle.
      *
      * @param cmResourceAddress   the name of the datastore, cm handle and resource identifier
-     * @param optionsParamInQuery the options param in query
-     * @param topicParamInQuery   the topic param in query
+     * @param options             options to pass through to dmi client
+     * @param topic               topic (optional) for asynchronous responses
      * @param includeDescendants  whether include descendants
      * @param authorization       contents of Authorization header, or null if not present
      * @return the result object, depends on use op topic. With topic a map object with request id is returned
      *         otherwise the result of the request.
      */
     public Object executeRequest(final CmResourceAddress cmResourceAddress,
-                                                 final String optionsParamInQuery,
-                                                 final String topicParamInQuery,
-                                                 final boolean includeDescendants,
-                                                 final String authorization) {
+                                 final String options,
+                                 final String topic,
+                                 final boolean includeDescendants,
+                                 final String authorization) {
 
-        final boolean asyncResponseRequested = topicParamInQuery != null;
+        final boolean asyncResponseRequested = topic != null;
         if (asyncResponseRequested && notificationFeatureEnabled) {
-            return fetchResourceDataAsynchronously(cmResourceAddress, optionsParamInQuery, topicParamInQuery,
-                includeDescendants, authorization);
+            return getResourceDataAsynchronously(cmResourceAddress, options, topic, includeDescendants, authorization);
         }
 
         if (asyncResponseRequested) {
             log.warn("Asynchronous request is unavailable as notification feature is currently disabled, "
                     + "will use synchronous operation.");
         }
-        final Mono<Object> resourceDataMono = getResourceDataForCmHandle(cmResourceAddress, optionsParamInQuery,
+        final Mono<Object> resourceDataMono = getResourceDataForCmHandle(cmResourceAddress, options,
                 NO_TOPIC, NO_REQUEST_ID, includeDescendants, authorization);
         return resourceDataMono.block();
     }
 
-    private Map<String, String> fetchResourceDataAsynchronously(final CmResourceAddress cmResourceAddress,
-                                                                   final String optionsParamInQuery,
-                                                                   final String topicParamInQuery,
-                                                                   final boolean includeDescendants,
-                                                                   final String authorization) {
-        TopicValidator.validateTopicName(topicParamInQuery);
+    private Map<String, String> getResourceDataAsynchronously(final CmResourceAddress cmResourceAddress,
+                                                              final String options,
+                                                              final String topic,
+                                                              final boolean includeDescendants,
+                                                              final String authorization) {
+        TopicValidator.validateTopicName(topic);
         final String requestId = UUID.randomUUID().toString();
-        getResourceDataForCmHandle(cmResourceAddress, optionsParamInQuery, topicParamInQuery, requestId,
-                includeDescendants, authorization)
-                .doOnSuccess(result -> log.debug("Async operation succeeded for request id {}: {}", requestId, result))
-                .doOnError(error ->
-                        log.error("Async operation failed for request id {}: {}", requestId, error.getMessage()))
+        getResourceDataForCmHandle(cmResourceAddress, options, topic, requestId, includeDescendants, authorization)
+                .doOnSuccess(result ->
+                    log.debug("Async operation succeeded for request id {}: {}", requestId, result))
                 .subscribe();
         log.debug("Received Async request with id {}", requestId);
         return Map.of("requestId", requestId);
index 90d9a23..0fd3250 100644 (file)
@@ -26,9 +26,9 @@ import static org.onap.cps.ncmp.api.impl.operations.OperationType.READ;
 import java.util.Map;
 import java.util.UUID;
 import lombok.RequiredArgsConstructor;
-import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
 import org.onap.cps.ncmp.api.impl.exception.InvalidDatastoreException;
 import org.onap.cps.ncmp.api.impl.operations.DatastoreType;
+import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations;
 import org.onap.cps.ncmp.api.impl.operations.OperationType;
 import org.onap.cps.ncmp.api.models.CmResourceAddress;
 import org.onap.cps.ncmp.api.models.DataOperationRequest;
@@ -42,60 +42,60 @@ import reactor.core.publisher.Mono;
 @RequiredArgsConstructor
 public class NcmpPassthroughResourceRequestHandler extends NcmpDatastoreRequestHandler {
 
-    private final NetworkCmProxyDataService networkCmProxyDataService;
+    private final DmiDataOperations dmiDataOperations;
+
     private static final int MAXIMUM_CM_HANDLES_PER_OPERATION = 200;
     private static final String PAYLOAD_TOO_LARGE_TEMPLATE = "Operation '%s' affects too many (%d) cm handles";
 
     /**
      * Executes asynchronous request for group of cm handles to resource data.
      *
-     * @param topicParamInQuery        the topic param in query
-     * @param dataOperationRequest     data operation request details for resource data
-     * @param authorization            contents of Authorization header, or null if not present
+     * @param topic                 the topic param in query
+     * @param dataOperationRequest  data operation request details for resource data
+     * @param authorization         contents of Authorization header, or null if not present
      * @return a map with one entry of request Id for success or status and error when async feature is disabled
      */
-    public Map<String, String> executeRequest(final String topicParamInQuery,
-                                              final DataOperationRequest dataOperationRequest,
-                                              final String authorization) {
-        validateDataOperationRequest(topicParamInQuery, dataOperationRequest);
+    public Map<String, String> executeAsynchronousRequest(final String topic,
+                                                          final DataOperationRequest dataOperationRequest,
+                                                          final String authorization) {
+        validateDataOperationRequest(topic, dataOperationRequest);
         if (!notificationFeatureEnabled) {
             return Map.of("status",
                 "Asynchronous request is unavailable as notification feature is currently disabled.");
         }
         final String requestId = UUID.randomUUID().toString();
-        networkCmProxyDataService.executeDataOperationForCmHandles(topicParamInQuery, dataOperationRequest, requestId,
-            authorization);
+        dmiDataOperations.requestResourceDataFromDmi(topic, dataOperationRequest, requestId, authorization);
         return Map.of("requestId", requestId);
-
     }
 
     @Override
     protected Mono<Object> getResourceDataForCmHandle(final CmResourceAddress cmResourceAddress,
-                                                      final String optionsParamInQuery,
-                                                      final String topicParamInQuery,
+                                                      final String options,
+                                                      final String topic,
                                                       final String requestId,
                                                       final boolean includeDescendants,
                                                       final String authorization) {
-        return networkCmProxyDataService.getResourceDataForCmHandle(cmResourceAddress, optionsParamInQuery,
-                topicParamInQuery, requestId, authorization);
+
+        return dmiDataOperations.getResourceDataFromDmi(cmResourceAddress, options, topic, requestId, authorization)
+            .flatMap(responseEntity -> Mono.justOrEmpty(responseEntity.getBody()));
     }
 
     private void validateDataOperationRequest(final String topicParamInQuery,
                                               final DataOperationRequest dataOperationRequest) {
         TopicValidator.validateTopicName(topicParamInQuery);
-        dataOperationRequest.getDataOperationDefinitions().forEach(dataOperationDetail -> {
-            if (OperationType.fromOperationName(dataOperationDetail.getOperation()) != READ) {
+        dataOperationRequest.getDataOperationDefinitions().forEach(dataOperationDefinition -> {
+            if (OperationType.fromOperationName(dataOperationDefinition.getOperation()) != READ) {
                 throw new OperationNotSupportedException(
-                        dataOperationDetail.getOperation() + " operation not yet supported");
+                        dataOperationDefinition.getOperation() + " operation not yet supported");
             }
-            if (DatastoreType.fromDatastoreName(dataOperationDetail.getDatastore()) == OPERATIONAL) {
-                throw new InvalidDatastoreException(dataOperationDetail.getDatastore()
+            if (DatastoreType.fromDatastoreName(dataOperationDefinition.getDatastore()) == OPERATIONAL) {
+                throw new InvalidDatastoreException(dataOperationDefinition.getDatastore()
                         + " datastore is not supported");
             }
-            if (dataOperationDetail.getCmHandleIds().size() > MAXIMUM_CM_HANDLES_PER_OPERATION) {
+            if (dataOperationDefinition.getCmHandleIds().size() > MAXIMUM_CM_HANDLES_PER_OPERATION) {
                 final String errorMessage = String.format(PAYLOAD_TOO_LARGE_TEMPLATE,
-                        dataOperationDetail.getOperationId(),
-                        dataOperationDetail.getCmHandleIds().size());
+                        dataOperationDefinition.getOperationId(),
+                        dataOperationDefinition.getCmHandleIds().size());
                 throw new PayloadTooLargeException(errorMessage);
             }
         });
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyFacade.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyFacade.java
new file mode 100644 (file)
index 0000000..a24b184
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ *  ============LICENSE_START=======================================================
+ *  Copyright (C) 2021 highstreet technologies GmbH
+ *  Modifications Copyright (C) 2021-2024 Nordix Foundation
+ *  Modifications Copyright (C) 2021 Pantheon.tech
+ *  Modifications Copyright (C) 2021-2022 Bell Canada
+ *  Modifications Copyright (C) 2023 TechMahindra Ltd.
+ *  ================================================================================
+ *  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.api.impl;
+
+import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.OPERATIONAL;
+
+import java.util.Collection;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.onap.cps.ncmp.api.impl.operations.DatastoreType;
+import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations;
+import org.onap.cps.ncmp.api.impl.operations.OperationType;
+import org.onap.cps.ncmp.api.models.CmResourceAddress;
+import org.onap.cps.ncmp.api.models.DataOperationRequest;
+import org.onap.cps.spi.model.DataNode;
+import org.springframework.stereotype.Service;
+
+@Slf4j
+@Service
+@RequiredArgsConstructor
+public class NetworkCmProxyFacade {
+
+    private final NcmpCachedResourceRequestHandler ncmpCachedResourceRequestHandler;
+    private final NcmpPassthroughResourceRequestHandler ncmpPassthroughResourceRequestHandler;
+    private final DmiDataOperations dmiDataOperations;
+
+    /**
+     * Fetches resource data for a given data store using DMI (Data Management Interface).
+     * This method retrieves data based on the provided CmResourceAddress and additional query parameters.
+     * It supports asynchronous processing and handles authorization if required.
+     *
+     * @param cmResourceAddress  The target data store, including the CM handle and resource identifier.
+     *                           This parameter must not be null.
+     * @param options            Additional query parameters that may influence the data retrieval process,
+     *                           such as filters or limits. This parameter can be null.
+     * @param topic              The topic name for triggering asynchronous responses. If specified,
+     *                           the response will be sent to this topic. This parameter can be null.
+     * @param includeDescendants include (all) descendants or not
+     * @param authorization      The contents of the Authorization header. This parameter can be null
+     *                           if authorization is not required.
+     * @return the result object, depends on use op topic. With topic a map object with request id is returned
+     *         otherwise the result of the request.
+     */
+    public Object getResourceDataForCmHandle(final CmResourceAddress cmResourceAddress,
+                                             final String options,
+                                             final String topic,
+                                             final Boolean includeDescendants,
+                                             final String authorization) {
+        final NcmpDatastoreRequestHandler ncmpDatastoreRequestHandler
+            = getNcmpDatastoreRequestHandler(cmResourceAddress.datastoreName());
+
+        return ncmpDatastoreRequestHandler.executeRequest(cmResourceAddress, options, topic, includeDescendants,
+                                                          authorization);
+    }
+
+    /**
+     * Executes asynchronous request for group of cm handles to resource data.
+     *
+     * @param topic                    the topic param in query
+     * @param dataOperationRequest     data operation request details for resource data
+     * @param authorization            contents of Authorization header, or null if not present
+     * @return a map with one entry of request Id for success or status and error when async feature is disabled
+     */
+    public Object executeDataOperationForCmHandles(final String topic,
+                                                   final DataOperationRequest dataOperationRequest,
+                                                   final String authorization) {
+        return ncmpPassthroughResourceRequestHandler.executeAsynchronousRequest(topic,
+                                                                                dataOperationRequest,
+                                                                                authorization);
+    }
+
+    public Collection<DataNode> queryResourceDataForCmHandle(final String cmHandle,
+                                                             final String cpsPath,
+                                                             final Boolean includeDescendants) {
+        return ncmpCachedResourceRequestHandler.executeRequest(cmHandle, cpsPath, includeDescendants);
+    }
+
+    /**
+     * Write resource data for data store pass-through running using dmi for given cm-handle.
+     *
+     * @param cmHandleId         cm handle identifier
+     * @param resourceIdentifier resource identifier
+     * @param operationType      required operation type
+     * @param requestData        request body to create resource
+     * @param dataType        content type in body
+     * @param authorization       contents of Authorization header, or null if not present
+     * @return {@code Object} return data
+     */
+    public Object writeResourceDataPassThroughRunningForCmHandle(final String cmHandleId,
+                                                                 final String resourceIdentifier,
+                                                                 final OperationType operationType,
+                                                                 final String requestData,
+                                                                 final String dataType,
+                                                                 final String authorization) {
+        return dmiDataOperations.writeResourceDataPassThroughRunningFromDmi(cmHandleId, resourceIdentifier,
+            operationType, requestData, dataType, authorization);
+    }
+
+
+    private NcmpDatastoreRequestHandler getNcmpDatastoreRequestHandler(final String datastoreName) {
+        if (OPERATIONAL.equals(DatastoreType.fromDatastoreName(datastoreName))) {
+            return ncmpCachedResourceRequestHandler;
+        }
+        return ncmpPassthroughResourceRequestHandler;
+    }
+
+}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyInventoryFacade.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyInventoryFacade.java
new file mode 100644 (file)
index 0000000..5b439eb
--- /dev/null
@@ -0,0 +1,207 @@
+/*
+ *  ============LICENSE_START=======================================================
+ *  Copyright (C) 2021 highstreet technologies GmbH
+ *  Modifications Copyright (C) 2021-2024 Nordix Foundation
+ *  Modifications Copyright (C) 2021 Pantheon.tech
+ *  Modifications Copyright (C) 2021-2022 Bell Canada
+ *  Modifications Copyright (C) 2023 TechMahindra Ltd.
+ *  ================================================================================
+ *  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.api.impl;
+
+import static org.onap.cps.ncmp.api.impl.utils.RestQueryParametersValidator.validateCmHandleQueryParameters;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.onap.cps.ncmp.api.ParameterizedCmHandleQueryService;
+import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueryService;
+import org.onap.cps.ncmp.api.impl.inventory.CompositeState;
+import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence;
+import org.onap.cps.ncmp.api.impl.utils.CmHandleQueryConditions;
+import org.onap.cps.ncmp.api.impl.utils.InventoryQueryConditions;
+import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
+import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
+import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters;
+import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
+import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
+import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse;
+import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
+import org.onap.cps.spi.model.ModuleDefinition;
+import org.onap.cps.spi.model.ModuleReference;
+import org.onap.cps.utils.JsonObjectMapper;
+import org.springframework.stereotype.Service;
+
+@Slf4j
+@Service
+@RequiredArgsConstructor
+public class NetworkCmProxyInventoryFacade {
+
+    private final CmHandleRegistrationService cmHandleRegistrationService;
+    private final CmHandleQueryService cmHandleQueryService;
+    private final ParameterizedCmHandleQueryService parameterizedCmHandleQueryService;
+    private final InventoryPersistence inventoryPersistence;
+    private final JsonObjectMapper jsonObjectMapper;
+
+    /**
+     * Registration of Created, Removed, Updated or Upgraded CM Handles.
+     *
+     * @param dmiPluginRegistration Dmi Plugin Registration details
+     * @return dmiPluginRegistrationResponse
+     */
+
+    public DmiPluginRegistrationResponse updateDmiRegistrationAndSyncModule(
+        final DmiPluginRegistration dmiPluginRegistration) {
+        return cmHandleRegistrationService.updateDmiRegistrationAndSyncModule(dmiPluginRegistration);
+    }
+
+    /**
+     * Get all cm handle IDs by DMI plugin identifier.
+     *
+     * @param dmiPluginIdentifier DMI plugin identifier
+     * @return collection of cm handle IDs
+     */
+    public Collection<String> getAllCmHandleIdsByDmiPluginIdentifier(final String dmiPluginIdentifier) {
+        return cmHandleQueryService.getCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifier);
+    }
+
+    /**
+     * Get all cm handle IDs by various properties.
+     *
+     * @param cmHandleQueryServiceParameters cm handle query parameters
+     * @return collection of cm handle IDs
+     */
+    public Collection<String> executeParameterizedCmHandleIdSearch(
+        final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+        validateCmHandleQueryParameters(cmHandleQueryServiceParameters, InventoryQueryConditions.ALL_CONDITION_NAMES);
+        return parameterizedCmHandleQueryService.queryCmHandleIdsForInventory(cmHandleQueryServiceParameters);
+    }
+
+
+    /**
+     * Retrieve module references for the given cm handle.
+     *
+     * @param cmHandleId cm handle identifier
+     * @return a collection of modules names and revisions
+     */
+    public Collection<ModuleReference> getYangResourcesModuleReferences(final String cmHandleId) {
+        return inventoryPersistence.getYangResourcesModuleReferences(cmHandleId);
+    }
+
+    /**
+     * Retrieve module definitions for the given cm handle.
+     *
+     * @param cmHandleId cm handle identifier
+     * @return a collection of module definition (moduleName, revision and yang resource content)
+     */
+    public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleId(final String cmHandleId) {
+        return inventoryPersistence.getModuleDefinitionsByCmHandleId(cmHandleId);
+    }
+
+    /**
+     * Get module definitions for the given parameters.
+     *
+     * @param cmHandleId        cm-handle identifier
+     * @param moduleName        module name
+     * @param moduleRevision    the revision of the module
+     * @return list of module definitions (module name, revision, yang resource content)
+     */
+    public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleAndModule(final String cmHandleId,
+                                                                                final String moduleName,
+                                                                                final String moduleRevision) {
+        return inventoryPersistence.getModuleDefinitionsByCmHandleAndModule(cmHandleId, moduleName, moduleRevision);
+    }
+
+    /**
+     * Retrieve cm handles with details for the given query parameters.
+     *
+     * @param cmHandleQueryApiParameters cm handle query parameters
+     * @return cm handles with details
+     */
+    public Collection<NcmpServiceCmHandle> executeCmHandleSearch(
+        final CmHandleQueryApiParameters cmHandleQueryApiParameters) {
+        final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType(
+            cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class);
+        validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES);
+        return parameterizedCmHandleQueryService.queryCmHandles(cmHandleQueryServiceParameters);
+    }
+
+    /**
+     * Retrieve cm handle ids for the given query parameters.
+     *
+     * @param cmHandleQueryApiParameters cm handle query parameters
+     * @return cm handle ids
+     */
+    public Collection<String> executeCmHandleIdSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters) {
+        final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType(
+            cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class);
+        validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES);
+        return parameterizedCmHandleQueryService.queryCmHandleIds(cmHandleQueryServiceParameters);
+    }
+
+    /**
+     * Set the data sync enabled flag, along with the data sync state
+     * based on the data sync enabled boolean for the cm handle id provided.
+     *
+     * @param cmHandleId                 cm handle id
+     * @param dataSyncEnabledTargetValue data sync enabled flag
+     */
+    public void setDataSyncEnabled(final String cmHandleId, final Boolean dataSyncEnabledTargetValue) {
+        cmHandleRegistrationService.setDataSyncEnabled(cmHandleId, dataSyncEnabledTargetValue);
+    }
+
+    /**
+     * Retrieve cm handle details for a given cm handle.
+     *
+     * @param cmHandleId cm handle identifier
+     * @return cm handle details
+     */
+    public NcmpServiceCmHandle getNcmpServiceCmHandle(final String cmHandleId) {
+        return YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle(
+            inventoryPersistence.getYangModelCmHandle(cmHandleId));
+    }
+
+    /**
+     * Get cm handle public properties for a given cm handle id.
+     *
+     * @param cmHandleId cm handle identifier
+     * @return cm handle public properties
+     */
+    public Map<String, String> getCmHandlePublicProperties(final String cmHandleId) {
+        final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId);
+        final List<YangModelCmHandle.Property> yangModelPublicProperties = yangModelCmHandle.getPublicProperties();
+        final Map<String, String> cmHandlePublicProperties = new HashMap<>();
+        YangDataConverter.asPropertiesMap(yangModelPublicProperties, cmHandlePublicProperties);
+        return cmHandlePublicProperties;
+    }
+
+    /**
+     * Get cm handle composite state for a given cm handle id.
+     *
+     * @param cmHandleId cm handle identifier
+     * @return cm handle state
+     */
+    public CompositeState getCmHandleCompositeState(final String cmHandleId) {
+        return inventoryPersistence.getYangModelCmHandle(cmHandleId).getCompositeState();
+    }
+
+
+}
@@ -42,8 +42,8 @@ import java.util.stream.Collectors;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.onap.cps.cpspath.parser.PathParsingException;
-import org.onap.cps.ncmp.api.NetworkCmProxyCmHandleQueryService;
-import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueries;
+import org.onap.cps.ncmp.api.ParameterizedCmHandleQueryService;
+import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueryService;
 import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence;
 import org.onap.cps.ncmp.api.impl.inventory.enums.PropertyType;
 import org.onap.cps.ncmp.api.impl.utils.InventoryQueryConditions;
@@ -59,10 +59,10 @@ import org.springframework.stereotype.Service;
 @Service
 @Slf4j
 @RequiredArgsConstructor
-public class NetworkCmProxyCmHandleQueryServiceImpl implements NetworkCmProxyCmHandleQueryService {
+public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHandleQueryService {
 
     private static final Collection<String> NO_QUERY_TO_EXECUTE = null;
-    private final CmHandleQueries cmHandleQueries;
+    private final CmHandleQueryService cmHandleQueryService;
     private final InventoryPersistence inventoryPersistence;
 
     @Override
@@ -115,7 +115,7 @@ public class NetworkCmProxyCmHandleQueryServiceImpl implements NetworkCmProxyCmH
         final String dmiPluginIdentifierValue = dmiPropertyQueryPairs
             .get(PropertyType.DMI_PLUGIN.getYangContainerName());
 
-        return cmHandleQueries.getCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifierValue);
+        return cmHandleQueryService.getCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifierValue);
     }
 
     private Collection<String> queryCmHandlesByPrivateProperties(
@@ -128,7 +128,7 @@ public class NetworkCmProxyCmHandleQueryServiceImpl implements NetworkCmProxyCmH
         if (privatePropertyQueryPairs.isEmpty()) {
             return NO_QUERY_TO_EXECUTE;
         }
-        return cmHandleQueries.queryCmHandleAdditionalProperties(privatePropertyQueryPairs);
+        return cmHandleQueryService.queryCmHandleAdditionalProperties(privatePropertyQueryPairs);
     }
 
     private Collection<String> queryCmHandlesByPublicProperties(
@@ -141,7 +141,7 @@ public class NetworkCmProxyCmHandleQueryServiceImpl implements NetworkCmProxyCmH
         if (publicPropertyQueryPairs.isEmpty()) {
             return NO_QUERY_TO_EXECUTE;
         }
-        return cmHandleQueries.queryCmHandlePublicProperties(publicPropertyQueryPairs);
+        return cmHandleQueryService.queryCmHandlePublicProperties(publicPropertyQueryPairs);
     }
 
     private Collection<String> queryCmHandlesByTrustLevel(final CmHandleQueryServiceParameters
@@ -154,7 +154,7 @@ public class NetworkCmProxyCmHandleQueryServiceImpl implements NetworkCmProxyCmH
         if (trustLevelPropertyQueryPairs.isEmpty()) {
             return NO_QUERY_TO_EXECUTE;
         }
-        return cmHandleQueries.queryCmHandlesByTrustLevel(trustLevelPropertyQueryPairs);
+        return cmHandleQueryService.queryCmHandlesByTrustLevel(trustLevelPropertyQueryPairs);
     }
 
     private Collection<String> executeModuleNameQuery(
@@ -180,7 +180,7 @@ public class NetworkCmProxyCmHandleQueryServiceImpl implements NetworkCmProxyCmH
         }
         try {
             cpsPathQueryResult = collectCmHandleIdsFromDataNodes(
-                cmHandleQueries.queryCmHandleAncestorsByCpsPath(
+                cmHandleQueryService.queryCmHandleAncestorsByCpsPath(
                         cpsPathCondition.get("cpsPath"), OMIT_DESCENDANTS));
         } catch (final PathParsingException pathParsingException) {
             throw new DataValidationException(pathParsingException.getMessage(), pathParsingException.getDetails(),
index 5811cf9..d4c5d16 100644 (file)
@@ -71,7 +71,7 @@ public class DmiRestClient {
     private final WebClient healthChecksWebClient;
 
     /**
-     * Sends a POST operation to the DMI with a JSON body containing module references.
+     * Sends a synchronous (blocking) POST operation to the DMI with a JSON body containing module references.
      *
      * @param requiredDmiService      Determines if the required service is for a data or model operation.
      * @param dmiUrl                  The DMI resource URL.
@@ -81,17 +81,18 @@ public class DmiRestClient {
      * @return ResponseEntity containing the response from the DMI.
      * @throws DmiClientRequestException If there is an error during the DMI request.
      */
-    public ResponseEntity<Object> postOperationWithJsonData(final RequiredDmiService requiredDmiService,
-                                                            final String dmiUrl,
-                                                            final String requestBodyAsJsonString,
-                                                            final OperationType operationType,
-                                                            final String authorization) {
-        try {
-            return postOperationWithJsonDataAsync(requiredDmiService, dmiUrl, requestBodyAsJsonString, operationType,
-                    authorization).block();
-        } catch (final HttpServerErrorException e) {
-            throw handleDmiClientException(e, operationType.getOperationName());
-        }
+    public ResponseEntity<Object> synchronousPostOperationWithJsonData(final RequiredDmiService requiredDmiService,
+                                                                       final String dmiUrl,
+                                                                       final String requestBodyAsJsonString,
+                                                                       final OperationType operationType,
+                                                                       final String authorization) {
+        final Mono<ResponseEntity<Object>> responseEntityMono =
+            asynchronousPostOperationWithJsonData(requiredDmiService,
+                dmiUrl,
+                requestBodyAsJsonString,
+                operationType,
+                authorization);
+        return responseEntityMono.block();
     }
 
     /**
@@ -105,11 +106,12 @@ public class DmiRestClient {
      * @param authorization           The authorization token to be added to the request headers.
      * @return A Mono emitting the response entity containing the server's response.
      */
-    public Mono<ResponseEntity<Object>> postOperationWithJsonDataAsync(final RequiredDmiService requiredDmiService,
-                                                                       final String dmiUrl,
-                                                                       final String requestBodyAsJsonString,
-                                                                       final OperationType operationType,
-                                                                       final String authorization) {
+    public Mono<ResponseEntity<Object>> asynchronousPostOperationWithJsonData(
+                                                            final RequiredDmiService requiredDmiService,
+                                                            final String dmiUrl,
+                                                            final String requestBodyAsJsonString,
+                                                            final OperationType operationType,
+                                                            final String authorization) {
         final WebClient webClient = getWebClient(requiredDmiService);
         return webClient.post()
                 .uri(toUri(dmiUrl))
@@ -26,18 +26,18 @@ import java.util.Map;
 import org.onap.cps.spi.FetchDescendantsOption;
 import org.onap.cps.spi.model.DataNode;
 
-public interface CmHandleQueries {
+public interface CmHandleQueryService {
 
     /**
-     * Query CmHandles based on additional (private) properties.
+     * Query Cm Handles based on additional (private) properties.
      *
      * @param additionalPropertyQueryPairs private properties for query
-     * @return Ids of CmHandles which have these private properties
+     * @return Ids of Cm Handles which have these private properties
      */
     Collection<String> queryCmHandleAdditionalProperties(Map<String, String> additionalPropertyQueryPairs);
 
     /**
-     * Query CmHandles based on public properties.
+     * Query Cm Handles based on public properties.
      *
      * @param publicPropertyQueryPairs public properties for query
      * @return CmHandles which have these public properties
@@ -45,10 +45,10 @@ public interface CmHandleQueries {
     Collection<String> queryCmHandlePublicProperties(Map<String, String> publicPropertyQueryPairs);
 
     /**
-     * Query CmHandles based on Trust Level.
+     * Query Cm Handles based on Trust Level.
      *
      * @param trustLevelPropertyQueryPairs trust level properties for query
-     * @return CmHandles which have desired trust level
+     * @return Ids of Cm Handles which have desired trust level
      */
     Collection<String> queryCmHandlesByTrustLevel(Map<String, String> trustLevelPropertyQueryPairs);
 
@@ -56,7 +56,7 @@ public interface CmHandleQueries {
      * Method which returns cm handles by the cm handles state.
      *
      * @param cmHandleState cm handle state
-     * @return a list of cm handles
+     * @return a list of data nodes representing the cm handles.
      */
     List<DataNode> queryCmHandlesByState(CmHandleState cmHandleState);
 
@@ -90,7 +90,7 @@ public interface CmHandleQueries {
      * Method which returns cm handles by the operational sync state of cm handle.
      *
      * @param dataStoreSyncState sync state
-     * @return a list of cm handles
+     * @return a list of data nodes representing the cm handles.
      */
     List<DataNode> queryCmHandlesByOperationalSyncState(DataStoreSyncState dataStoreSyncState);
 
@@ -98,7 +98,8 @@ public interface CmHandleQueries {
      * Get all cm handles ids by DMI plugin identifier.
      *
      * @param dmiPluginIdentifier DMI plugin identifier
-     * @return collection of cm handles
+     * @return collection of cm handle ids
      */
     Collection<String> getCmHandleIdsByDmiPluginIdentifier(String dmiPluginIdentifier);
+
 }
@@ -46,7 +46,7 @@ import org.springframework.stereotype.Component;
 
 @RequiredArgsConstructor
 @Component
-public class CmHandleQueriesImpl implements CmHandleQueries {
+public class CmHandleQueryServiceImpl implements CmHandleQueryService {
 
     private static final String DESCENDANT_PATH = "//";
     private static final String ANCESTOR_CM_HANDLES = "/ancestor::cm-handles";
index c4cab31..55fe35d 100644 (file)
@@ -57,7 +57,7 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv
     private final CpsModuleService cpsModuleService;
     private final CpsAnchorService cpsAnchorService;
     private final CpsValidator cpsValidator;
-    private final CmHandleQueries cmHandleQueries;
+    private final CmHandleQueryService cmHandleQueryService;
 
     /**
      * initialize an inventory persistence object.
@@ -70,12 +70,13 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv
      */
     public InventoryPersistenceImpl(final JsonObjectMapper jsonObjectMapper, final CpsDataService cpsDataService,
                                     final CpsModuleService cpsModuleService, final CpsValidator cpsValidator,
-                                    final CpsAnchorService cpsAnchorService, final CmHandleQueries cmHandleQueries) {
+                                    final CpsAnchorService cpsAnchorService,
+                                    final CmHandleQueryService cmHandleQueryService) {
         super(jsonObjectMapper, cpsDataService, cpsModuleService, cpsValidator);
         this.cpsModuleService = cpsModuleService;
         this.cpsAnchorService = cpsAnchorService;
         this.cpsValidator = cpsValidator;
-        this.cmHandleQueries = cmHandleQueries;
+        this.cmHandleQueryService = cmHandleQueryService;
     }
 
 
@@ -170,7 +171,7 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv
     @Override
     public DataNode getCmHandleDataNodeByAlternateId(final String alternateId) {
         final String cpsPathForCmHandleByAlternateId = getCpsPathForCmHandleByAlternateId(alternateId);
-        final Collection<DataNode> dataNodes = cmHandleQueries
+        final Collection<DataNode> dataNodes = cmHandleQueryService
             .queryNcmpRegistryByCpsPath(cpsPathForCmHandleByAlternateId, OMIT_DESCENDANTS);
         if (dataNodes.isEmpty()) {
             throw new DataNodeNotFoundException(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
index 794ca5b..e00a49f 100644 (file)
@@ -21,8 +21,6 @@
 
 package org.onap.cps.ncmp.api.impl.inventory.sync;
 
-import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_OPERATIONAL;
-
 import com.fasterxml.jackson.databind.JsonNode;
 import java.time.Duration;
 import java.time.OffsetDateTime;
@@ -38,7 +36,7 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueries;
+import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueryService;
 import org.onap.cps.ncmp.api.impl.inventory.CmHandleState;
 import org.onap.cps.ncmp.api.impl.inventory.CompositeState;
 import org.onap.cps.ncmp.api.impl.inventory.DataStoreSyncState;
@@ -57,7 +55,7 @@ import org.springframework.stereotype.Service;
 @RequiredArgsConstructor
 public class ModuleOperationsUtils {
 
-    private final CmHandleQueries cmHandleQueries;
+    private final CmHandleQueryService cmHandleQueryService;
     private final DmiDataOperations dmiDataOperations;
     private final JsonObjectMapper jsonObjectMapper;
     private static final String RETRY_ATTEMPT_KEY = "attempt";
@@ -78,7 +76,8 @@ public class ModuleOperationsUtils {
      * @return cm handles (data nodes) in ADVISED state (empty list if none found)
      */
     public List<DataNode> getAdvisedCmHandles() {
-        final List<DataNode> advisedCmHandlesAsDataNodes = cmHandleQueries.queryCmHandlesByState(CmHandleState.ADVISED);
+        final List<DataNode> advisedCmHandlesAsDataNodes =
+            cmHandleQueryService.queryCmHandlesByState(CmHandleState.ADVISED);
         log.debug("Total number of fetched advised cm handle(s) is (are) {}", advisedCmHandlesAsDataNodes.size());
         return advisedCmHandlesAsDataNodes;
     }
@@ -91,13 +90,13 @@ public class ModuleOperationsUtils {
      *         return empty list if not found
      */
     public List<YangModelCmHandle> getUnsynchronizedReadyCmHandles() {
-        final List<DataNode> unsynchronizedCmHandles = cmHandleQueries
+        final List<DataNode> unsynchronizedCmHandles = cmHandleQueryService
                 .queryCmHandlesByOperationalSyncState(DataStoreSyncState.UNSYNCHRONIZED);
 
         final List<YangModelCmHandle> yangModelCmHandles = new ArrayList<>();
         for (final DataNode unsynchronizedCmHandle : unsynchronizedCmHandles) {
             final String cmHandleId = unsynchronizedCmHandle.getLeaves().get("id").toString();
-            if (cmHandleQueries.cmHandleHasState(cmHandleId, CmHandleState.READY)) {
+            if (cmHandleQueryService.cmHandleHasState(cmHandleId, CmHandleState.READY)) {
                 yangModelCmHandles.addAll(convertCmHandlesDataNodesToYangModelCmHandles(
                                 Collections.singletonList(unsynchronizedCmHandle)));
             }
@@ -113,7 +112,7 @@ public class ModuleOperationsUtils {
      */
     public List<YangModelCmHandle> getCmHandlesThatFailedModelSyncOrUpgrade() {
         final List<DataNode> lockedCmHandlesAsDataNodeList
-                = cmHandleQueries.queryCmHandleAncestorsByCpsPath(CPS_PATH_CM_HANDLES_MODEL_SYNC_FAILED_OR_UPGRADE,
+                = cmHandleQueryService.queryCmHandleAncestorsByCpsPath(CPS_PATH_CM_HANDLES_MODEL_SYNC_FAILED_OR_UPGRADE,
                 FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
         return convertCmHandlesDataNodesToYangModelCmHandles(lockedCmHandlesAsDataNodeList);
     }
@@ -198,16 +197,14 @@ public class ModuleOperationsUtils {
     }
 
     /**
-     * Get the Resourece Data from Node through DMI Passthrough service.
+     * Get the Resource Data from Node through DMI Passthrough service.
      *
      * @param cmHandleId cm handle id
      * @return optional string containing the resource data
      */
     public String getResourceData(final String cmHandleId) {
-        final ResponseEntity<Object> resourceDataResponseEntity = dmiDataOperations.getResourceDataFromDmi(
-                PASSTHROUGH_OPERATIONAL.getDatastoreName(),
-                cmHandleId,
-                UUID.randomUUID().toString());
+        final ResponseEntity<Object> resourceDataResponseEntity = dmiDataOperations.getAllResourceDataFromDmi(
+                cmHandleId, UUID.randomUUID().toString());
         if (resourceDataResponseEntity.getStatusCode().is2xxSuccessful()) {
             return getFirstResource(resourceDataResponseEntity.getBody());
         }
index 45156ce..a5f0ba0 100644 (file)
@@ -38,7 +38,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.onap.cps.api.CpsAnchorService;
 import org.onap.cps.api.CpsDataService;
 import org.onap.cps.api.CpsModuleService;
-import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueries;
+import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueryService;
 import org.onap.cps.ncmp.api.impl.inventory.CmHandleState;
 import org.onap.cps.ncmp.api.impl.operations.DmiModelOperations;
 import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
@@ -59,7 +59,7 @@ public class ModuleSyncService {
 
     private final DmiModelOperations dmiModelOperations;
     private final CpsModuleService cpsModuleService;
-    private final CmHandleQueries cmHandleQueries;
+    private final CmHandleQueryService cmHandleQueryService;
     private final CpsDataService cpsDataService;
     private final CpsAnchorService cpsAnchorService;
     private final JsonObjectMapper jsonObjectMapper;
@@ -136,7 +136,7 @@ public class ModuleSyncService {
             return null;
         }
         final String escapedModuleSetTag = moduleSetTag.replace("'", "''");
-        final List<DataNode> dataNodes = cmHandleQueries.queryNcmpRegistryByCpsPath(
+        final List<DataNode> dataNodes = cmHandleQueryService.queryNcmpRegistryByCpsPath(
                 NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@module-set-tag='" + escapedModuleSetTag + "']",
                 FetchDescendantsOption.DIRECT_CHILDREN_ONLY);
         return dataNodes.stream().map(YangDataConverter::convertCmHandleToYangModel)
index 3db8455..7359518 100644 (file)
@@ -21,6 +21,7 @@
 
 package org.onap.cps.ncmp.api.impl.operations;
 
+import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_OPERATIONAL;
 import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_RUNNING;
 import static org.onap.cps.ncmp.api.impl.operations.OperationType.READ;
 import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.DATA;
@@ -69,49 +70,48 @@ public class DmiDataOperations {
      * This method fetches the resource data from the operational data store for a given CM handle
      * identifier on the specified resource using the DMI client.
      *
-     * @param cmResourceAddress   Target datastore, CM handle, and resource identifier.
-     * @param optionsParamInQuery Options query string.
-     * @param topicParamInQuery   Topic name for triggering asynchronous responses.
-     * @param requestId           Request ID for asynchronous responses.
-     * @param authorization       Contents of the Authorization header, or null if not present.
+     * @param cmResourceAddress Target datastore, CM handle, and resource identifier.
+     * @param options           Options query string.
+     * @param topic             Topic name for triggering asynchronous responses.
+     * @param requestId         Request ID for asynchronous responses.
+     * @param authorization     Contents of the Authorization header, or null if not present.
      * @return {@code Mono<ResponseEntity<Object>>} A reactive type representing the response entity.
      */
     @Timed(value = "cps.ncmp.dmi.get",
             description = "Time taken to fetch the resource data from operational data store for given cm handle "
                     + "identifier on given resource using dmi client")
     public Mono<ResponseEntity<Object>> getResourceDataFromDmi(final CmResourceAddress cmResourceAddress,
-                                                         final String optionsParamInQuery,
-                                                         final String topicParamInQuery,
-                                                         final String requestId,
-                                                         final String authorization) {
+                                                               final String options,
+                                                               final String topic,
+                                                               final String requestId,
+                                                               final String authorization) {
         final YangModelCmHandle yangModelCmHandle = getYangModelCmHandle(cmResourceAddress.cmHandleId());
         final CmHandleState cmHandleState = yangModelCmHandle.getCompositeState().getCmHandleState();
         validateIfCmHandleStateReady(yangModelCmHandle, cmHandleState);
         final String jsonRequestBody = getDmiRequestBody(READ, requestId, null, null, yangModelCmHandle);
         final String dmiUrl = getDmiResourceDataUrl(cmResourceAddress.datastoreName(), yangModelCmHandle,
-                cmResourceAddress.resourceIdentifier(), optionsParamInQuery, topicParamInQuery);
-        return dmiRestClient.postOperationWithJsonDataAsync(DATA, dmiUrl, jsonRequestBody, READ, authorization);
+                cmResourceAddress.resourceIdentifier(), options, topic);
+        return dmiRestClient.asynchronousPostOperationWithJsonData(DATA, dmiUrl, jsonRequestBody, READ, authorization);
     }
 
     /**
      * This method fetches all the resource data from operational data store for given cm handle
      * identifier using dmi client.
+     * Note: this method is only used for DataSync
      *
-     * @param datastoreName data store name
      * @param cmHandleId    network resource identifier
      * @param requestId     requestId for async responses
      * @return {@code ResponseEntity} response entity
      */
-    public ResponseEntity<Object> getResourceDataFromDmi(final String datastoreName,
-                                                         final String cmHandleId,
-                                                         final String requestId) {
+    public ResponseEntity<Object> getAllResourceDataFromDmi(final String cmHandleId, final String requestId) {
         final YangModelCmHandle yangModelCmHandle = getYangModelCmHandle(cmHandleId);
         final CmHandleState cmHandleState = yangModelCmHandle.getCompositeState().getCmHandleState();
         validateIfCmHandleStateReady(yangModelCmHandle, cmHandleState);
 
         final String jsonRequestBody = getDmiRequestBody(READ, requestId, null, null, yangModelCmHandle);
-        final String dmiUrl = getDmiResourceDataUrl(datastoreName, yangModelCmHandle, "/", null, null);
-        return dmiRestClient.postOperationWithJsonData(DATA, dmiUrl, jsonRequestBody, READ, null);
+        final String dmiUrl =
+            getDmiResourceDataUrl(PASSTHROUGH_OPERATIONAL.getDatastoreName(), yangModelCmHandle, "/", null, null);
+        return dmiRestClient.synchronousPostOperationWithJsonData(DATA, dmiUrl, jsonRequestBody, READ, null);
     }
 
     /**
@@ -168,7 +168,8 @@ public class DmiDataOperations {
                 yangModelCmHandle);
         final String dmiUrl = getDmiResourceDataUrl(PASSTHROUGH_RUNNING.getDatastoreName(),
             yangModelCmHandle, resourceId, null, null);
-        return dmiRestClient.postOperationWithJsonData(DATA, dmiUrl, jsonRequestBody, operationType, authorization);
+        return dmiRestClient.synchronousPostOperationWithJsonData(DATA, dmiUrl, jsonRequestBody,
+                                                                  operationType, authorization);
     }
 
     private YangModelCmHandle getYangModelCmHandle(final String cmHandleId) {
@@ -256,7 +257,7 @@ public class DmiDataOperations {
                                                             final String authorization) {
         final String dmiDataOperationRequestAsJsonString
                 = createDmiDataOperationRequestAsJsonString(dmiDataOperationRequestBodies);
-        return dmiRestClient.postOperationWithJsonDataAsync(DATA, dmiUrl, dmiDataOperationRequestAsJsonString,
+        return dmiRestClient.asynchronousPostOperationWithJsonData(DATA, dmiUrl, dmiDataOperationRequestAsJsonString,
                         READ, authorization)
                 .then()
                 .onErrorResume(DmiClientRequestException.class, dmiClientRequestException -> {
@@ -293,4 +294,4 @@ public class DmiDataOperations {
         ResourceDataOperationRequestUtils.publishErrorMessageToClientTopic(topicName, requestId,
                 cmHandleIdsPerResponseCodesPerOperation);
     }
-}
\ No newline at end of file
+}
index 77dfcb7..82dccc6 100644 (file)
@@ -21,6 +21,7 @@
 
 package org.onap.cps.ncmp.api.impl.operations;
 
+import static org.onap.cps.ncmp.api.impl.operations.OperationType.READ;
 import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.MODEL;
 
 import com.google.gson.JsonArray;
@@ -111,7 +112,7 @@ public class DmiModelOperations {
                 .variablePathSegment("cmHandleId", cmHandle)
                 .variablePathSegment("resourceName", resourceName)
                 .build(dmiServiceName, dmiProperties.getDmiBasePath());
-        return dmiRestClient.postOperationWithJsonData(MODEL, dmiUrl, jsonRequestBody, OperationType.READ, null);
+        return dmiRestClient.synchronousPostOperationWithJsonData(MODEL, dmiUrl, jsonRequestBody, READ, null);
     }
 
     private static String getRequestBodyToFetchYangResources(final Collection<ModuleReference> newModuleReferences,
index d6d6fd6..1022512 100644 (file)
@@ -24,9 +24,9 @@ import java.util.Collection;
 import java.util.Map;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
 import org.onap.cps.ncmp.api.impl.client.DmiRestClient;
 import org.onap.cps.ncmp.api.impl.config.embeddedcache.TrustLevelCacheConfig;
+import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueryService;
 import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel;
 import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevelManager;
 import org.springframework.beans.factory.annotation.Qualifier;
@@ -39,7 +39,7 @@ import org.springframework.stereotype.Service;
 public class DmiPluginWatchDog {
 
     private final DmiRestClient dmiRestClient;
-    private final NetworkCmProxyDataService networkCmProxyDataService;
+    private final CmHandleQueryService cmHandleQueryService;
     private final TrustLevelManager trustLevelManager;
 
     @Qualifier(TrustLevelCacheConfig.TRUST_LEVEL_PER_DMI_PLUGIN)
@@ -68,7 +68,7 @@ public class DmiPluginWatchDog {
                 log.debug("The Dmi Plugin: {} has already the same trust level: {}", dmiServiceName, newDmiTrustLevel);
             } else {
                 final Collection<String> cmHandleIds =
-                    networkCmProxyDataService.getAllCmHandleIdsByDmiPluginIdentifier(dmiServiceName);
+                    cmHandleQueryService.getCmHandleIdsByDmiPluginIdentifier(dmiServiceName);
                 trustLevelManager.handleUpdateOfDmiTrustLevel(dmiServiceName, cmHandleIds, newDmiTrustLevel);
             }
         });
@@ -47,18 +47,18 @@ import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DA
 import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR
 import static org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.Status
 
-class NetworkCmProxyDataServicePropertyHandlerSpec extends Specification {
+class CmHandleRegistrationServicePropertyHandlerSpec extends Specification {
 
     def mockInventoryPersistence = Mock(InventoryPersistence)
     def mockCpsDataService = Mock(CpsDataService)
     def jsonObjectMapper = new JsonObjectMapper(new ObjectMapper())
     def mockAlternateIdChecker = Mock(AlternateIdChecker)
 
-    def objectUnderTest = new NetworkCmProxyDataServicePropertyHandler(mockInventoryPersistence, mockCpsDataService, jsonObjectMapper, mockAlternateIdChecker)
+    def objectUnderTest = new CmHandleRegistrationServicePropertyHandler(mockInventoryPersistence, mockCpsDataService, jsonObjectMapper, mockAlternateIdChecker)
     def logger = Spy(ListAppender<ILoggingEvent>)
 
     void setup() {
-        def setupLogger = ((Logger) LoggerFactory.getLogger(NetworkCmProxyDataServicePropertyHandler.class))
+        def setupLogger = ((Logger) LoggerFactory.getLogger(CmHandleRegistrationServicePropertyHandler.class))
         setupLogger.addAppender(logger)
         setupLogger.setLevel(Level.DEBUG)
         logger.start()
@@ -67,7 +67,7 @@ class NetworkCmProxyDataServicePropertyHandlerSpec extends Specification {
     }
 
     void cleanup() {
-        ((Logger) LoggerFactory.getLogger(NetworkCmProxyDataServicePropertyHandler.class)).detachAndStopAllAppenders()
+        ((Logger) LoggerFactory.getLogger(CmHandleRegistrationServicePropertyHandler.class)).detachAndStopAllAppenders()
     }
 
     def static cmHandleId = 'myHandle1'
@@ -242,12 +242,12 @@ class NetworkCmProxyDataServicePropertyHandlerSpec extends Specification {
         given: 'an existing cm handle with no data producer identifier'
             DataNode existingCmHandleDataNode = new DataNode(xpath: cmHandleXpath, leaves: ['id': 'cmHandleId','data-producer-identifier': oldDataProducerIdentifier])
         and: 'an update request with a new data producer identifier'
-            def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, dataProducerIdentifier: 'someDataProducerIdentifier')
+            def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, dataProducerIdentifier: 'New Data Producer Identifier')
         when: 'data producer identifier updated'
             objectUnderTest.updateDataProducerIdentifier(existingCmHandleDataNode, ncmpServiceCmHandle)
         then: 'the update node leaves method is invoked once'
             1 * mockCpsDataService.updateNodeLeaves('NCMP-Admin', 'ncmp-dmi-registry', '/dmi-registry', _, _, ContentType.JSON) >> { args ->
-                assert args[3].contains('someDataProducerIdentifier')
+                assert args[3].contains('New Data Producer Identifier')
             }
         and: 'correct information is logged'
             def lastLoggingEvent = logger.list[0]
@@ -259,6 +259,17 @@ class NetworkCmProxyDataServicePropertyHandlerSpec extends Specification {
             'blank to something' | ''
     }
 
+    def 'Update CM Handle data producer identifier with same value'() {
+        given: 'an existing cm handle with no data producer identifier'
+            DataNode existingCmHandleDataNode = new DataNode(xpath: cmHandleXpath, leaves: ['id': 'cmHandleId','data-producer-identifier': 'same id'])
+        and: 'an update request with a new data producer identifier'
+            def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, dataProducerIdentifier: 'same id')
+        when: 'data producer identifier updated'
+            objectUnderTest.updateDataProducerIdentifier(existingCmHandleDataNode, ncmpServiceCmHandle)
+        then: 'the update node leaves method is not invoked'
+            0 * mockCpsDataService.updateNodeLeaves(*_)
+    }
+
     def 'Update CM Handle data producer identifier from some data producer identifier to another data producer identifier'() {
         given: 'an existing cm handle with a data producer identifier'
             DataNode existingCmHandleDataNode = new DataNode(xpath: cmHandleXpath, leaves: ['id': 'cmHandleId', 'data-producer-identifier': 'someDataProducerIdentifier'])
 
 package org.onap.cps.ncmp.api.impl
 
-import static org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.Status
-import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLES_NOT_FOUND
-import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_ALREADY_EXIST
-import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_INVALID_ID
-import static org.onap.cps.ncmp.api.NcmpResponseStatus.UNKNOWN_ERROR
-
-import org.onap.cps.ncmp.api.impl.inventory.CompositeState
-import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevelManager
-import org.onap.cps.ncmp.api.impl.utils.AlternateIdChecker
-import org.onap.cps.ncmp.api.models.UpgradedCmHandles
-import com.fasterxml.jackson.databind.ObjectMapper
 import com.hazelcast.map.IMap
 import org.onap.cps.api.CpsDataService
 import org.onap.cps.api.CpsModuleService
-import org.onap.cps.ncmp.api.NetworkCmProxyCmHandleQueryService
 import org.onap.cps.ncmp.api.impl.events.lcm.LcmEventsCmHandleStateHandler
 import org.onap.cps.ncmp.api.impl.exception.DmiRequestException
-import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations
-import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel
-import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
-import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueries
+import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueryService
 import org.onap.cps.ncmp.api.impl.inventory.CmHandleState
+import org.onap.cps.ncmp.api.impl.inventory.CompositeState
+import org.onap.cps.ncmp.api.impl.inventory.DataStoreSyncState
 import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence
+import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel
+import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevelManager
+import org.onap.cps.ncmp.api.impl.utils.AlternateIdChecker
+import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
 import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse
 import org.onap.cps.ncmp.api.models.DmiPluginRegistration
 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
+import org.onap.cps.ncmp.api.models.UpgradedCmHandles
 import org.onap.cps.spi.exceptions.AlreadyDefinedException
+import org.onap.cps.spi.exceptions.CpsException
 import org.onap.cps.spi.exceptions.DataNodeNotFoundException
 import org.onap.cps.spi.exceptions.DataValidationException
 import org.onap.cps.spi.exceptions.SchemaSetNotFoundException
-import org.onap.cps.utils.JsonObjectMapper
 import spock.lang.Specification
 
-class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
+import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLES_NOT_FOUND
+import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_ALREADY_EXIST
+import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_INVALID_ID
+import static org.onap.cps.ncmp.api.NcmpResponseStatus.UNKNOWN_ERROR
+import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME
+import static org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.Status
+
+class CmHandleRegistrationServiceSpec extends Specification {
 
     def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: 'some-cm-handle-id')
     def mockCpsModuleService = Mock(CpsModuleService)
-    def spiedJsonObjectMapper = Spy(new JsonObjectMapper(new ObjectMapper()))
-    def mockDmiDataOperations = Mock(DmiDataOperations)
-    def mockNetworkCmProxyDataServicePropertyHandler = Mock(NetworkCmProxyDataServicePropertyHandler)
+    def mockNetworkCmProxyDataServicePropertyHandler = Mock(CmHandleRegistrationServicePropertyHandler)
     def mockInventoryPersistence = Mock(InventoryPersistence)
-    def mockCmHandleQueries = Mock(CmHandleQueries)
-    def stubbedNetworkCmProxyCmHandlerQueryService = Stub(NetworkCmProxyCmHandleQueryService)
+    def mockCmHandleQueries = Mock(CmHandleQueryService)
     def mockLcmEventsCmHandleStateHandler = Mock(LcmEventsCmHandleStateHandler)
     def mockCpsDataService = Mock(CpsDataService)
     def mockModuleSyncStartedOnCmHandles = Mock(IMap<String, Object>)
@@ -71,10 +67,9 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
     def mockTrustLevelManager = Mock(TrustLevelManager)
     def mockAlternateIdChecker = Mock(AlternateIdChecker)
 
-    def objectUnderTest = Spy(new NetworkCmProxyDataServiceImpl(spiedJsonObjectMapper, mockDmiDataOperations,
-        mockNetworkCmProxyDataServicePropertyHandler, mockInventoryPersistence, mockCmHandleQueries,
-        stubbedNetworkCmProxyCmHandlerQueryService, mockLcmEventsCmHandleStateHandler, mockCpsDataService,
-        mockModuleSyncStartedOnCmHandles, trustLevelPerDmiPlugin, mockTrustLevelManager, mockAlternateIdChecker))
+    def objectUnderTest = Spy(new CmHandleRegistrationService(
+        mockNetworkCmProxyDataServicePropertyHandler, mockInventoryPersistence, mockCpsDataService, mockLcmEventsCmHandleStateHandler,
+        mockModuleSyncStartedOnCmHandles, trustLevelPerDmiPlugin , mockTrustLevelManager, mockAlternateIdChecker))
 
     def setup() {
         // always accept all cm handles
@@ -418,4 +413,46 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
         'an unexpected exception'    | 'cmhandle'             | new RuntimeException('Failed')            || UNKNOWN_ERROR        | 'Failed'
     }
 
+    def 'Set Cm Handle Data Sync Enabled Flag where data sync flag is  #scenario'() {
+        given: 'an existing cm handle composite state'
+            def compositeState = new CompositeState(cmHandleState: CmHandleState.READY, dataSyncEnabled: initialDataSyncEnabledFlag,
+                dataStores: CompositeState.DataStores.builder()
+                    .operationalDataStore(CompositeState.Operational.builder()
+                        .dataStoreSyncState(initialDataSyncState)
+                        .build()).build())
+        and: 'get cm handle state returns the composite state for the given cm handle id'
+            mockInventoryPersistence.getCmHandleState('some-cm-handle-id') >> compositeState
+        when: 'set data sync enabled is called with the data sync enabled flag set to #dataSyncEnabledFlag'
+            objectUnderTest.setDataSyncEnabled('some-cm-handle-id', dataSyncEnabledFlag)
+        then: 'the data sync enabled flag is set to #dataSyncEnabled'
+            compositeState.dataSyncEnabled == dataSyncEnabledFlag
+        and: 'the data store sync state is set to #expectedDataStoreSyncState'
+            compositeState.dataStores.operationalDataStore.dataStoreSyncState == expectedDataStoreSyncState
+        and: 'the cps data service to delete data nodes is invoked the expected number of times'
+            deleteDataNodeExpectedNumberOfInvocation * mockCpsDataService.deleteDataNode(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, 'some-cm-handle-id', '/netconf-state', _)
+        and: 'the inventory persistence service to update node leaves is called with the correct values'
+            saveCmHandleStateExpectedNumberOfInvocations * mockInventoryPersistence.saveCmHandleState('some-cm-handle-id', compositeState)
+        where: 'the following data sync enabled flag is used'
+            scenario                                              | dataSyncEnabledFlag | initialDataSyncEnabledFlag | initialDataSyncState               || expectedDataStoreSyncState         | deleteDataNodeExpectedNumberOfInvocation | saveCmHandleStateExpectedNumberOfInvocations
+            'enabled'                                             | true                | false                      | DataStoreSyncState.NONE_REQUESTED || DataStoreSyncState.UNSYNCHRONIZED | 0 | 1
+            'disabled'                                            | false               | true                       | DataStoreSyncState.UNSYNCHRONIZED  || DataStoreSyncState.NONE_REQUESTED  | 0                                        | 1
+            'disabled where sync-state is currently SYNCHRONIZED' | false               | true                       | DataStoreSyncState.SYNCHRONIZED    || DataStoreSyncState.NONE_REQUESTED  | 1                                        | 1
+            'is set to existing flag state'                       | true                | true                       | DataStoreSyncState.UNSYNCHRONIZED  || DataStoreSyncState.UNSYNCHRONIZED  | 0                                        | 0
+    }
+
+    def 'Set cm Handle Data Sync Enabled flag with following cm handle not in ready state exception' () {
+        given: 'a cm handle composite state'
+            def compositeState = new CompositeState(cmHandleState: CmHandleState.ADVISED, dataSyncEnabled: false)
+        and: 'get cm handle state returns the composite state for the given cm handle id'
+            mockInventoryPersistence.getCmHandleState('some-cm-handle-id') >> compositeState
+        when: 'set data sync enabled is called with the data sync enabled flag set to true'
+            objectUnderTest.setDataSyncEnabled('some-cm-handle-id', true)
+        then: 'the expected exception is thrown'
+            thrown(CpsException)
+        and: 'the inventory persistence service to update node leaves is not invoked'
+            0 * mockInventoryPersistence.saveCmHandleState(_, _)
+    }
+
+
+
 }
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NcmpCachedResourceRequestHandlerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NcmpCachedResourceRequestHandlerSpec.groovy
new file mode 100644 (file)
index 0000000..781b620
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ *  ============LICENSE_START=======================================================
+ *  Copyright (C) 2024 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.api.impl
+
+import org.onap.cps.api.CpsDataService
+import org.onap.cps.ncmp.api.NetworkCmProxyQueryService
+import org.onap.cps.ncmp.api.models.CmResourceAddress
+import org.onap.cps.spi.model.DataNode
+import reactor.core.publisher.Mono
+import spock.lang.Specification
+
+import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
+import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
+
+class NcmpCachedResourceRequestHandlerSpec extends Specification {
+
+    def cpsDataService = Mock(CpsDataService)
+    def networkCmProxyQueryService= Mock(NetworkCmProxyQueryService)
+
+    def objectUnderTest = new NcmpCachedResourceRequestHandler(cpsDataService, networkCmProxyQueryService)
+
+    def 'Execute a request with include descendants = #includeDescendants.'() {
+        when: 'executing a request'
+            objectUnderTest.executeRequest('ch-1', 'resource', includeDescendants)
+        then: 'it is delegated to the ncmp query service with the correct option'
+            1 * networkCmProxyQueryService.queryResourceDataOperational('ch-1','resource', expectedFetchDescendantsOption)
+        where: 'the following options are used'
+            includeDescendants || expectedFetchDescendantsOption
+            true               || INCLUDE_ALL_DESCENDANTS
+            false              || OMIT_DESCENDANTS
+    }
+
+    def 'Get resource data.'() {
+        given: 'the data service returns 2 nodes for the given resource address'
+            def cmResourceAddress = new CmResourceAddress('datastore','ch-1','resource')
+            def dataNode1 = new DataNode(xpath:'p1')
+            def dataNode2 = new DataNode(xpath:'p2')
+            cpsDataService.getDataNodes('datastore','ch-1','resource',OMIT_DESCENDANTS) >> [dataNode1, dataNode2]
+        when: 'getting the resource data'
+            def result = objectUnderTest.getResourceDataForCmHandle(cmResourceAddress, 'options', 'topic', 'request id', false, 'authorization')
+        then: 'the result is a "Mono" holding just the first data node'
+            assert result instanceof Mono
+            assert result.block() == dataNode1
+    }
+
+}
index b73f9a4..9a845c0 100644 (file)
 
 package org.onap.cps.ncmp.api.impl
 
-import org.onap.cps.ncmp.api.NetworkCmProxyDataService
 import org.onap.cps.ncmp.api.impl.exception.InvalidDatastoreException
 import org.onap.cps.ncmp.api.impl.exception.InvalidOperationException
+import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations
 import org.onap.cps.ncmp.api.models.CmResourceAddress
 import org.onap.cps.ncmp.api.models.DataOperationDefinition
 import org.onap.cps.ncmp.api.models.DataOperationRequest
 import org.onap.cps.ncmp.exceptions.OperationNotSupportedException
 import org.onap.cps.ncmp.exceptions.PayloadTooLargeException
-import org.springframework.http.HttpStatus
 import org.springframework.http.ResponseEntity
 import reactor.core.publisher.Mono
 import spock.lang.Specification
 
+import static org.springframework.http.HttpStatus.I_AM_A_TEAPOT
+
 class NcmpDatastoreRequestHandlerSpec extends Specification {
 
-    def mockNetworkCmProxyDataService = Mock(NetworkCmProxyDataService)
+    def dmiDataOperations = Mock(DmiDataOperations)
 
-    def objectUnderTest = new NcmpPassthroughResourceRequestHandler(mockNetworkCmProxyDataService)
+    def objectUnderTest = new NcmpPassthroughResourceRequestHandler(dmiDataOperations)
 
+    def NO_TOPIC = null
     def NO_AUTH_HEADER = null
 
-    def setup() {
-        objectUnderTest.timeOutInMilliSeconds = 100
-    }
-
     def 'Attempt to execute async get request with #scenario.'() {
         given: 'notification feature is turned on/off'
             objectUnderTest.notificationFeatureEnabled = notificationFeatureEnabled
         and: 'a CM resource address'
             def cmResourceAddress = new CmResourceAddress('ds', 'ch1', 'resource1')
-        and: 'the (mocked) service when called with the correct parameters returns a response from dmi'
-            def resultFromDmi = new ResponseEntity('response from dmi',HttpStatus.I_AM_A_TEAPOT)
-            def synchronousResult = Mono.justOrEmpty(resultFromDmi)
-            mockNetworkCmProxyDataService.getResourceDataForCmHandle(cmResourceAddress, 'options', _, _, NO_AUTH_HEADER) >> synchronousResult
+        and: 'the (mocked) service when called with the correct parameters (with or without topic) returns a response from dmi'
+            def dmiResponse = Mono.justOrEmpty(new ResponseEntity('dmi response',I_AM_A_TEAPOT))
+            dmiDataOperations.getResourceDataFromDmi(cmResourceAddress, 'options', NO_TOPIC, _, NO_AUTH_HEADER) >> dmiResponse
+            dmiDataOperations.getResourceDataFromDmi(cmResourceAddress, 'options', topic, _, NO_AUTH_HEADER) >> dmiResponse
         when: 'get request is executed with topic = #topic'
             def response = objectUnderTest.executeRequest(cmResourceAddress, 'options', topic, false, NO_AUTH_HEADER)
         then: 'a successful result with/without request id is returned'
             if (expectSynchronousResponse) {
-                assert response.toString().contains('response from dmi')
-                assert response.toString().contains("I'm a teapot")
-            } else {
-                // expect request id in a map
+                assert response == 'dmi response'
+            } else { // expect request id in a map
                 assert response.keySet()[0] == 'requestId'
             }
         where: 'the following parameters are used'
@@ -74,33 +70,20 @@ class NcmpDatastoreRequestHandlerSpec extends Specification {
 
     def 'Attempt to execute async data operation request with feature #scenario.'() {
         given: 'a extended request handler that supports bulk requests'
-           def objectUnderTest = new NcmpPassthroughResourceRequestHandler(mockNetworkCmProxyDataService)
+           def objectUnderTest = new NcmpPassthroughResourceRequestHandler(dmiDataOperations)
         and: 'notification feature is turned on/off'
             objectUnderTest.notificationFeatureEnabled = notificationFeatureEnabled
         when: 'data operation request is executed'
-            objectUnderTest.executeRequest('someTopic', new DataOperationRequest(), NO_AUTH_HEADER)
+            def dataOperationDefinition = new DataOperationDefinition(operation: 'read', datastore: 'ncmp-datastore:passthrough-running', cmHandleIds: ['ch'])
+            def result = objectUnderTest.executeAsynchronousRequest('someTopic', new DataOperationRequest(dataOperationDefinitions:[dataOperationDefinition]), NO_AUTH_HEADER)
         then: 'the task is executed in an async fashion or not'
-            expectedCalls * mockNetworkCmProxyDataService.executeDataOperationForCmHandles('someTopic', _, _, null)
+            expectedCalls * dmiDataOperations.requestResourceDataFromDmi('someTopic', _, _, NO_AUTH_HEADER)
+        and:
+            result.keySet()[0] == expectedKeyInMap
         where: 'the following parameters are used'
-            scenario | notificationFeatureEnabled || expectedCalls
-            'on'     | true                       || 1
-            'off'    | false                      || 0
-    }
-
-    def 'Execute async data operation request with datastore #datastore.'() {
-        given: 'notification feature is turned on'
-            objectUnderTest.notificationFeatureEnabled = true
-        and: 'a data operation request with datastore: #datastore'
-            def dataOperationDefinition = new DataOperationDefinition(operation: 'read', datastore: datastore)
-            def dataOperationRequest = new DataOperationRequest(dataOperationDefinitions: [dataOperationDefinition])
-        when: 'data operation request is executed'
-            def response = objectUnderTest.executeRequest('myTopic', dataOperationRequest, NO_AUTH_HEADER)
-        and: 'a map with request id is returned'
-            assert response.keySet()[0] == 'requestId'
-        then: 'the network service is invoked'
-            1 * mockNetworkCmProxyDataService.executeDataOperationForCmHandles('myTopic', dataOperationRequest, _, NO_AUTH_HEADER)
-        where: 'the following datastores are used'
-            datastore << ['ncmp-datastore:passthrough-running', 'ncmp-datastore:passthrough-operational']
+            scenario | notificationFeatureEnabled || expectedCalls || expectedKeyInMap
+            'on'     | true                       || 1             || 'requestId'
+            'off'    | false                      || 0             || 'status'
     }
 
     def 'Attempt to execute async data operation request with error #scenario'() {
@@ -108,7 +91,7 @@ class NcmpDatastoreRequestHandlerSpec extends Specification {
             def dataOperationDefinition = new DataOperationDefinition(operation: 'read', datastore: datastore)
         when: 'data operation request is executed'
             def dataOperationRequest = new DataOperationRequest(dataOperationDefinitions: [dataOperationDefinition])
-            objectUnderTest.executeRequest('myTopic', dataOperationRequest, NO_AUTH_HEADER)
+            objectUnderTest.executeAsynchronousRequest('myTopic', dataOperationRequest, NO_AUTH_HEADER)
         then: 'the correct error is thrown'
             def thrown = thrown(InvalidDatastoreException)
             assert thrown.message.contains(expectedErrorMessage)
@@ -122,7 +105,7 @@ class NcmpDatastoreRequestHandlerSpec extends Specification {
         given: 'a data operation definition with operation: #operation'
             def dataOperationDefinition = new DataOperationDefinition(operation: operation, datastore: 'ncmp-datastore:passthrough-running')
         when: 'data operation request is executed'
-            objectUnderTest.executeRequest('someTopic', new DataOperationRequest(dataOperationDefinitions:[dataOperationDefinition]), NO_AUTH_HEADER)
+            objectUnderTest.executeAsynchronousRequest('someTopic', new DataOperationRequest(dataOperationDefinitions:[dataOperationDefinition]), NO_AUTH_HEADER)
         then: 'the expected type of exception is thrown'
             thrown(expectedException)
         where: 'the following operations are used'
@@ -136,11 +119,11 @@ class NcmpDatastoreRequestHandlerSpec extends Specification {
 
     def 'Attempt to execute async data operation request with too many cm handles.'() {
         given: 'a data operation definition with too many cm handles'
-            def tooMany = objectUnderTest.MAXIMUM_CM_HANDLES_PER_OPERATION+1
+            def tooMany = objectUnderTest.MAXIMUM_CM_HANDLES_PER_OPERATION + 1
             def cmHandleIds = new String[tooMany]
             def dataOperationDefinition = new DataOperationDefinition(operationId: 'abc', operation: 'read', datastore: 'ncmp-datastore:passthrough-running', cmHandleIds: cmHandleIds)
         when: 'data operation request is executed'
-            objectUnderTest.executeRequest('someTopic', new DataOperationRequest(dataOperationDefinitions:[dataOperationDefinition]), NO_AUTH_HEADER)
+            objectUnderTest.executeAsynchronousRequest('someTopic', new DataOperationRequest(dataOperationDefinitions:[dataOperationDefinition]), NO_AUTH_HEADER)
         then: 'a payload too large exception is thrown'
             def exceptionThrown = thrown(PayloadTooLargeException)
         and: 'the error message contains the offending number of cm handles'
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
deleted file mode 100644 (file)
index d91c79d..0000000
+++ /dev/null
@@ -1,413 +0,0 @@
-/*
- *  ============LICENSE_START=======================================================
- *  Copyright (C) 2021-2024 Nordix Foundation
- *  Modifications Copyright (C) 2021 Pantheon.tech
- *  Modifications Copyright (C) 2021-2022 Bell Canada
- *  Modifications Copyright (C) 2023 TechMahindra Ltd.
- *  ================================================================================
- *  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.api.impl
-
-import reactor.core.publisher.Mono
-
-import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME
-import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME
-import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR
-import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.OPERATIONAL
-import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_OPERATIONAL
-import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_RUNNING
-import static org.onap.cps.ncmp.api.impl.operations.OperationType.CREATE
-import static org.onap.cps.ncmp.api.impl.operations.OperationType.UPDATE
-
-import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse
-import org.onap.cps.ncmp.api.models.CmResourceAddress
-import org.onap.cps.ncmp.api.impl.utils.AlternateIdChecker
-import com.hazelcast.map.IMap
-import org.onap.cps.ncmp.api.NetworkCmProxyCmHandleQueryService
-import org.onap.cps.ncmp.api.impl.events.lcm.LcmEventsCmHandleStateHandler
-import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel
-import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevelManager
-import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
-import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueries
-import org.onap.cps.ncmp.api.impl.inventory.CmHandleState
-import org.onap.cps.ncmp.api.impl.inventory.CompositeState
-import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence
-import org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory
-import org.onap.cps.ncmp.api.impl.inventory.DataStoreSyncState
-import org.onap.cps.ncmp.api.models.DataOperationDefinition
-import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters
-import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters
-import org.onap.cps.ncmp.api.models.ConditionApiProperties
-import org.onap.cps.ncmp.api.models.DmiPluginRegistration
-import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
-import org.onap.cps.ncmp.api.models.DataOperationRequest
-import org.onap.cps.spi.exceptions.CpsException
-import org.onap.cps.spi.model.ConditionProperties
-import java.util.stream.Collectors
-import org.onap.cps.utils.JsonObjectMapper
-import com.fasterxml.jackson.databind.ObjectMapper
-import org.onap.cps.api.CpsDataService
-import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations
-import org.onap.cps.spi.FetchDescendantsOption
-import org.onap.cps.spi.model.DataNode
-import org.springframework.http.HttpStatus
-import org.springframework.http.ResponseEntity
-import spock.lang.Specification
-
-class NetworkCmProxyDataServiceImplSpec extends Specification {
-
-    def mockCpsDataService = Mock(CpsDataService)
-    def spiedJsonObjectMapper = Spy(new JsonObjectMapper(new ObjectMapper()))
-    def mockDmiDataOperations = Mock(DmiDataOperations)
-    def nullNetworkCmProxyDataServicePropertyHandler = null
-    def mockInventoryPersistence = Mock(InventoryPersistence)
-    def mockCmHandleQueries = Mock(CmHandleQueries)
-    def mockDmiPluginRegistration = Mock(DmiPluginRegistration)
-    def mockCpsCmHandlerQueryService = Mock(NetworkCmProxyCmHandleQueryService)
-    def mockLcmEventsCmHandleStateHandler = Mock(LcmEventsCmHandleStateHandler)
-    def stubModuleSyncStartedOnCmHandles = Stub(IMap<String, Object>)
-    def stubTrustLevelPerDmiPlugin = Stub(Map<String, TrustLevel>)
-    def mockTrustLevelManager = Mock(TrustLevelManager)
-    def mockAlternateIdChecker = Mock(AlternateIdChecker)
-
-    def NO_TOPIC = null
-    def NO_REQUEST_ID = null
-    def NO_AUTH_HEADER = null
-    def OPTIONS_PARAM = '(a=1,b=2)'
-    def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: 'test-cm-handle-id')
-
-    def objectUnderTest = new NetworkCmProxyDataServiceImpl(
-            spiedJsonObjectMapper,
-            mockDmiDataOperations,
-            nullNetworkCmProxyDataServicePropertyHandler,
-            mockInventoryPersistence,
-            mockCmHandleQueries,
-            mockCpsCmHandlerQueryService,
-            mockLcmEventsCmHandleStateHandler,
-            mockCpsDataService,
-            stubModuleSyncStartedOnCmHandles,
-            stubTrustLevelPerDmiPlugin,
-            mockTrustLevelManager,
-            mockAlternateIdChecker)
-
-    def cmHandleXPath = "/dmi-registry/cm-handles[@id='testCmHandle']"
-
-    def dataNode = [new DataNode(leaves: ['id': 'some-cm-handle', 'dmi-service-name': 'testDmiService'])]
-
-    def 'Write resource data for pass-through running from DMI using POST.'() {
-        given: 'cpsDataService returns valid datanode'
-            mockDataNode()
-        when: 'write resource data is called'
-            objectUnderTest.writeResourceDataPassThroughRunningForCmHandle('testCmHandle',
-                'testResourceId', CREATE,
-                '{some-json}', 'application/json', null)
-        then: 'DMI called with correct data'
-            1 * mockDmiDataOperations.writeResourceDataPassThroughRunningFromDmi('testCmHandle', 'testResourceId',
-                    CREATE, '{some-json}', 'application/json', null)
-                >> { new ResponseEntity<>(HttpStatus.CREATED) }
-    }
-
-    def 'Get resource data from DMI.'() {
-        given: 'cpsDataService returns valid data node'
-            mockDataNode()
-        and: 'some cm resource address'
-            def cmResourceAddress = new CmResourceAddress('some datastore', 'some CM Handle', 'some resource Id')
-        and: 'get resource data from DMI is called'
-            mockDmiDataOperations.getResourceDataFromDmi(cmResourceAddress, OPTIONS_PARAM, NO_TOPIC, NO_REQUEST_ID, NO_AUTH_HEADER) >>
-                    Mono.just(new ResponseEntity<>('dmi-response', HttpStatus.OK))
-        when: 'get resource data operational for the given cm resource address is called'
-            def response = objectUnderTest.getResourceDataForCmHandle(cmResourceAddress, OPTIONS_PARAM, NO_TOPIC, NO_REQUEST_ID, NO_AUTH_HEADER).block()
-        then: 'DMI returns a json response'
-            assert response == 'dmi-response'
-    }
-
-    def 'Get resource data for operational (cached) data.'() {
-        given: 'CPS Data service returns some object(s)'
-            mockCpsDataService.getDataNodes(OPERATIONAL.datastoreName, 'testCmHandle', 'testResourceId', FetchDescendantsOption.OMIT_DESCENDANTS) >> ['First Object', 'other Object']
-        and: 'a cm resource address for the same datastore, cm handle and resource id'
-            def cmResourceAddress = new CmResourceAddress(OPERATIONAL.datastoreName, 'testCmHandle', 'testResourceId')
-        when: 'get resource data is called'
-            def response = objectUnderTest.getResourceDataForCmHandle(cmResourceAddress, FetchDescendantsOption.OMIT_DESCENDANTS)
-        then: 'get resource data returns teh first object from the data service'
-            assert response == 'First Object'
-    }
-
-    def 'Execute (async) data operation for #datastoreName from DMI.'() {
-        given: 'cpsDataService returns valid data node'
-            def dataOperationRequest = getDataOperationRequest(datastoreName)
-        when: 'request resource data for data operation is called'
-            objectUnderTest.executeDataOperationForCmHandles('some topic', dataOperationRequest, 'requestId', NO_AUTH_HEADER)
-        then: 'request resource data for data operation returns expected response'
-            1 * mockDmiDataOperations.requestResourceDataFromDmi('some topic', dataOperationRequest, 'requestId', NO_AUTH_HEADER)
-        where: 'the following data stores are used'
-            datastoreName << [PASSTHROUGH_RUNNING.datastoreName, PASSTHROUGH_OPERATIONAL.datastoreName]
-    }
-
-    def 'Getting Yang Resources.'() {
-        when: 'yang resources is called'
-            objectUnderTest.getYangResourcesModuleReferences('some-cm-handle')
-        then: 'CPS module services is invoked for the correct dataspace and cm handle'
-            1 * mockInventoryPersistence.getYangResourcesModuleReferences('some-cm-handle')
-    }
-
-    def 'Get a cm handle.'() {
-        given: 'the system returns a yang modelled cm handle'
-            def dmiServiceName = 'some service name'
-            def compositeState = new CompositeState(cmHandleState: CmHandleState.ADVISED,
-                    lockReason: CompositeState.LockReason.builder().lockReasonCategory(LockReasonCategory.MODULE_SYNC_FAILED).details("lock details").build(),
-                    lastUpdateTime: 'some-timestamp',
-                    dataSyncEnabled: false,
-                    dataStores: dataStores())
-            def dmiProperties = [new YangModelCmHandle.Property('Book', 'Romance Novel')]
-            def publicProperties = [new YangModelCmHandle.Property('Public Book', 'Public Romance Novel')]
-            def moduleSetTag = 'some-module-set-tag'
-            def alternateId = 'some-alternate-id'
-            def yangModelCmHandle = new YangModelCmHandle(id: 'some-cm-handle', dmiServiceName: dmiServiceName,
-                    dmiProperties: dmiProperties, publicProperties: publicProperties, compositeState: compositeState,
-                    moduleSetTag: moduleSetTag, alternateId: alternateId)
-            1 * mockInventoryPersistence.getYangModelCmHandle('some-cm-handle') >> yangModelCmHandle
-        when: 'getting cm handle details for a given cm handle id from ncmp service'
-            def result = objectUnderTest.getNcmpServiceCmHandle('some-cm-handle')
-        then: 'the result is a ncmpServiceCmHandle'
-            result.class == NcmpServiceCmHandle.class
-        and: 'the cm handle contains the cm handle id'
-            result.cmHandleId == 'some-cm-handle'
-        and: 'the cm handle contains the alternate id'
-            result.alternateId == 'some-alternate-id'
-        and: 'the cm handle contains the module-set-tag'
-            result.moduleSetTag == 'some-module-set-tag'
-        and: 'the cm handle contains the DMI Properties'
-            result.dmiProperties ==[ Book:'Romance Novel' ]
-        and: 'the cm handle contains the public Properties'
-            result.publicProperties == [ "Public Book":'Public Romance Novel' ]
-        and: 'the cm handle contains the cm handle composite state'
-            result.compositeState == compositeState
-    }
-
-    def 'Get cm handle public properties'() {
-        given: 'a yang modelled cm handle'
-            def dmiProperties = [new YangModelCmHandle.Property('prop', 'some DMI property')]
-            def publicProperties = [new YangModelCmHandle.Property('public prop', 'some public prop')]
-            def yangModelCmHandle = new YangModelCmHandle(id:'some-cm-handle', dmiServiceName: 'some service name', dmiProperties: dmiProperties, publicProperties: publicProperties)
-        and: 'the system returns this yang modelled cm handle'
-            1 * mockInventoryPersistence.getYangModelCmHandle('some-cm-handle') >> yangModelCmHandle
-        when: 'getting cm handle public properties for a given cm handle id from ncmp service'
-            def result = objectUnderTest.getCmHandlePublicProperties('some-cm-handle')
-        then: 'the result returns the correct data'
-            result == [ 'public prop' : 'some public prop' ]
-    }
-
-    def 'Execute cm handle id search for inventory'() {
-        given: 'a ConditionApiProperties object'
-            def conditionProperties = new ConditionProperties()
-            conditionProperties.conditionName = 'hasAllProperties'
-            conditionProperties.conditionParameters = [ [ 'some-key' : 'some-value' ] ]
-            def conditionServiceProps = new CmHandleQueryServiceParameters()
-            conditionServiceProps.cmHandleQueryParameters = [conditionProperties] as List<ConditionProperties>
-        and: 'the system returns an set of cmHandle ids'
-            mockCpsCmHandlerQueryService.queryCmHandleIdsForInventory(*_) >> [ 'cmHandle1', 'cmHandle2' ]
-        when: 'getting cm handle id set for a given dmi property'
-            def result = objectUnderTest.executeCmHandleIdSearchForInventory(conditionServiceProps)
-        then: 'the result returns the correct 2 elements'
-            assert result.size() == 2
-            assert result.contains('cmHandle1')
-            assert result.contains('cmHandle2')
-    }
-
-    def 'Get cm handle composite state'() {
-        given: 'a yang modelled cm handle'
-            def compositeState = new CompositeState(cmHandleState: CmHandleState.ADVISED,
-                lockReason: CompositeState.LockReason.builder().lockReasonCategory(LockReasonCategory.MODULE_SYNC_FAILED).details("lock details").build(),
-                lastUpdateTime: 'some-timestamp',
-                dataSyncEnabled: false,
-                dataStores: dataStores())
-            def dmiProperties = [new YangModelCmHandle.Property('prop', 'some DMI property')]
-            def publicProperties = [new YangModelCmHandle.Property('public prop', 'some public prop')]
-            def yangModelCmHandle = new YangModelCmHandle(id:'some-cm-handle', dmiServiceName: 'some service name', dmiProperties: dmiProperties, publicProperties: publicProperties, compositeState: compositeState)
-        and: 'the system returns this yang modelled cm handle'
-            1 * mockInventoryPersistence.getYangModelCmHandle('some-cm-handle') >> yangModelCmHandle
-        when: 'getting cm handle composite state for a given cm handle id from ncmp service'
-            def result = objectUnderTest.getCmHandleCompositeState('some-cm-handle')
-        then: 'the result returns the correct data'
-            result == compositeState
-    }
-
-    def 'Update resource data for pass-through running from dmi using POST #scenario DMI properties.'() {
-        given: 'cpsDataService returns valid datanode'
-            mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
-        when: 'get resource data is called'
-            objectUnderTest.writeResourceDataPassThroughRunningForCmHandle('testCmHandle',
-                'testResourceId', UPDATE,
-                '{some-json}', 'application/json', NO_AUTH_HEADER)
-        then: 'DMI called with correct data'
-            1 * mockDmiDataOperations.writeResourceDataPassThroughRunningFromDmi('testCmHandle', 'testResourceId',
-                    UPDATE, '{some-json}', 'application/json', NO_AUTH_HEADER)
-                >> { new ResponseEntity<>(HttpStatus.OK) }
-    }
-
-    def 'Verify modules and create anchor params.'() {
-        given: 'dmi plugin registration return created cm handles'
-            def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'service1', dmiModelPlugin: 'service1',
-                    dmiDataPlugin: 'service2')
-            dmiPluginRegistration.createdCmHandles = [ncmpServiceCmHandle]
-            mockDmiPluginRegistration.getCreatedCmHandles() >> [ncmpServiceCmHandle]
-        and: 'no rejected cm handles because of alternate ids'
-            mockAlternateIdChecker.getIdsOfCmHandlesWithRejectedAlternateId(*_) >> []
-        when: 'parse and create cm handle in dmi registration then sync module'
-            mockDmiPluginRegistration.createdCmHandles = ['test-cm-handle-id']
-            objectUnderTest.processCreatedCmHandles(mockDmiPluginRegistration, new DmiPluginRegistrationResponse())
-        then: 'system persists the cm handle state'
-            1 * mockLcmEventsCmHandleStateHandler.initiateStateAdvised(_) >> {
-                args -> {
-                          def cmHandleStatePerCmHandle = (args[0] as Collection)
-                          cmHandleStatePerCmHandle.each {
-                            assert it.id == 'test-cm-handle-id'
-                          }
-                    }
-            }
-    }
-
-    def 'Execute cm handle id search'() {
-        given: 'valid CmHandleQueryApiParameters input'
-            def cmHandleQueryApiParameters = new CmHandleQueryApiParameters()
-            def conditionApiProperties = new ConditionApiProperties()
-            conditionApiProperties.conditionName = 'hasAllModules'
-            conditionApiProperties.conditionParameters = [[moduleName: 'module-name-1']]
-            cmHandleQueryApiParameters.cmHandleQueryParameters = [conditionApiProperties]
-        and: 'query cm handle method return with a data node list'
-            mockCpsCmHandlerQueryService.queryCmHandleIds(
-                    spiedJsonObjectMapper.convertToValueType(cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class))
-                    >> ['cm-handle-id-1']
-        when: 'execute cm handle search is called'
-            def result = objectUnderTest.executeCmHandleIdSearch(cmHandleQueryApiParameters)
-        then: 'result is the same collection as returned by the CPS Data Service'
-            assert result == ['cm-handle-id-1']
-    }
-
-    def 'Getting module definitions by module'() {
-        when: 'get module definitions is performed with module name'
-            objectUnderTest.getModuleDefinitionsByCmHandleAndModule('some-cm-handle', 'some-module', '2021-08-04')
-        then: 'ncmp inventory persistence service is invoked once with correct parameters'
-            1 * mockInventoryPersistence.getModuleDefinitionsByCmHandleAndModule('some-cm-handle', 'some-module', '2021-08-04')
-    }
-
-    def 'Getting module definitions by cm handle id'() {
-        when: 'get module definitions is performed with cm handle id'
-            objectUnderTest.getModuleDefinitionsByCmHandleId('some-cm-handle')
-        then: 'ncmp inventory persistence service is invoked once with correct parameter'
-            1 * mockInventoryPersistence.getModuleDefinitionsByCmHandleId('some-cm-handle')
-    }
-
-    def 'Execute cm handle search'() {
-        given: 'valid CmHandleQueryApiParameters input'
-            def cmHandleQueryApiParameters = new CmHandleQueryApiParameters()
-            def conditionApiProperties = new ConditionApiProperties()
-            conditionApiProperties.conditionName = 'hasAllModules'
-            conditionApiProperties.conditionParameters = [[moduleName: 'module-name-1']]
-            cmHandleQueryApiParameters.cmHandleQueryParameters = [conditionApiProperties]
-        and: 'query cm handle method return with a data node list'
-            mockCpsCmHandlerQueryService.queryCmHandles(
-                    spiedJsonObjectMapper.convertToValueType(cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class))
-                    >> [new NcmpServiceCmHandle(cmHandleId: 'cm-handle-id-1')]
-        when: 'execute cm handle search is called'
-            def result = objectUnderTest.executeCmHandleSearch(cmHandleQueryApiParameters)
-        then: 'result is the same collection as returned by the CPS Data Service'
-            assert result.stream().map(d -> d.cmHandleId).collect(Collectors.toSet()) == ['cm-handle-id-1'] as Set
-    }
-
-    def 'Set Cm Handle Data Sync Enabled Flag where data sync flag is  #scenario'() {
-        given: 'an existing cm handle composite state'
-            def compositeState = new CompositeState(cmHandleState: CmHandleState.READY, dataSyncEnabled: initialDataSyncEnabledFlag,
-                dataStores: CompositeState.DataStores.builder()
-                    .operationalDataStore(CompositeState.Operational.builder()
-                        .dataStoreSyncState(initialDataSyncState)
-                        .build()).build())
-        and: 'get cm handle state returns the composite state for the given cm handle id'
-            mockInventoryPersistence.getCmHandleState('some-cm-handle-id') >> compositeState
-        when: 'set data sync enabled is called with the data sync enabled flag set to #dataSyncEnabledFlag'
-            objectUnderTest.setDataSyncEnabled('some-cm-handle-id', dataSyncEnabledFlag)
-        then: 'the data sync enabled flag is set to #dataSyncEnabled'
-            compositeState.dataSyncEnabled == dataSyncEnabledFlag
-        and: 'the data store sync state is set to #expectedDataStoreSyncState'
-            compositeState.dataStores.operationalDataStore.dataStoreSyncState == expectedDataStoreSyncState
-        and: 'the cps data service to delete data nodes is invoked the expected number of times'
-            deleteDataNodeExpectedNumberOfInvocation * mockCpsDataService.deleteDataNode(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, 'some-cm-handle-id', '/netconf-state', _)
-        and: 'the inventory persistence service to update node leaves is called with the correct values'
-            saveCmHandleStateExpectedNumberOfInvocations * mockInventoryPersistence.saveCmHandleState('some-cm-handle-id', compositeState)
-        where: 'the following data sync enabled flag is used'
-            scenario                                              | dataSyncEnabledFlag | initialDataSyncEnabledFlag | initialDataSyncState               || expectedDataStoreSyncState         | deleteDataNodeExpectedNumberOfInvocation | saveCmHandleStateExpectedNumberOfInvocations
-            'enabled'                                             | true                | false                      | DataStoreSyncState.NONE_REQUESTED  || DataStoreSyncState.UNSYNCHRONIZED  | 0                                        | 1
-            'disabled'                                            | false               | true                       | DataStoreSyncState.UNSYNCHRONIZED  || DataStoreSyncState.NONE_REQUESTED  | 0                                        | 1
-            'disabled where sync-state is currently SYNCHRONIZED' | false               | true                       | DataStoreSyncState.SYNCHRONIZED    || DataStoreSyncState.NONE_REQUESTED  | 1                                        | 1
-            'is set to existing flag state'                       | true                | true                       | DataStoreSyncState.UNSYNCHRONIZED  || DataStoreSyncState.UNSYNCHRONIZED  | 0                                        | 0
-    }
-
-    def 'Set cm Handle Data Sync Enabled flag with following cm handle not in ready state exception' () {
-        given: 'a cm handle composite state'
-            def compositeState = new CompositeState(cmHandleState: CmHandleState.ADVISED, dataSyncEnabled: false)
-        and: 'get cm handle state returns the composite state for the given cm handle id'
-            mockInventoryPersistence.getCmHandleState('some-cm-handle-id') >> compositeState
-        when: 'set data sync enabled is called with the data sync enabled flag set to true'
-            objectUnderTest.setDataSyncEnabled('some-cm-handle-id', true)
-        then: 'the expected exception is thrown'
-            thrown(CpsException)
-        and: 'the inventory persistence service to update node leaves is not invoked'
-            0 * mockInventoryPersistence.saveCmHandleState(_, _)
-    }
-
-    def 'Get all cm handle IDs by DMI plugin identifier.' () {
-        given: 'cm handle queries service returns cm handles'
-            1 * mockCmHandleQueries.getCmHandleIdsByDmiPluginIdentifier('some-dmi-plugin-identifier') >> ['cm-handle-1','cm-handle-2']
-        when: 'cm handle Ids are requested with dmi plugin identifier'
-            def result = objectUnderTest.getAllCmHandleIdsByDmiPluginIdentifier('some-dmi-plugin-identifier')
-        then: 'the result size is correct'
-            assert result.size() == 2
-        and: 'the result returns the correct details'
-            assert result.containsAll('cm-handle-1','cm-handle-2')
-    }
-
-    def dataStores() {
-        CompositeState.DataStores.builder()
-            .operationalDataStore(CompositeState.Operational.builder()
-                .dataStoreSyncState(DataStoreSyncState.NONE_REQUESTED)
-                .lastSyncTime('some-timestamp').build()).build()
-    }
-
-    def mockDataNode() {
-        mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
-    }
-
-    def getDataOperationRequest(datastore) {
-        def dataOperationRequest = new DataOperationRequest()
-        def dataOperationDefinitions = new ArrayList()
-        dataOperationDefinitions.add(getDataOperationDefinition(datastore))
-        dataOperationRequest.setDataOperationDefinitions(dataOperationDefinitions)
-        return dataOperationRequest
-    }
-
-    def getDataOperationDefinition(datastore) {
-        def dataOperationDefinition = new DataOperationDefinition()
-        dataOperationDefinition.setOperation("read")
-        dataOperationDefinition.setOperationId("operational-12")
-        dataOperationDefinition.setDatastore(datastore)
-        def targetIds = new ArrayList()
-        targetIds.add("some-cm-handle")
-        dataOperationDefinition.setCmHandleIds(targetIds)
-        return dataOperationDefinition
-    }
-}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyFacadeSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyFacadeSpec.groovy
new file mode 100644 (file)
index 0000000..f79e0ee
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ *  ============LICENSE_START=======================================================
+ *  Copyright (C) 2021-2024 Nordix Foundation
+ *  Modifications Copyright (C) 2021 Pantheon.tech
+ *  Modifications Copyright (C) 2021-2022 Bell Canada
+ *  Modifications Copyright (C) 2023 TechMahindra Ltd.
+ *  ================================================================================
+ *  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.api.impl
+
+import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations
+import org.onap.cps.ncmp.api.models.CmResourceAddress
+import org.onap.cps.ncmp.api.models.DataOperationRequest
+import org.onap.cps.spi.model.DataNode
+import reactor.core.publisher.Mono
+import spock.lang.Specification
+
+import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.OPERATIONAL
+import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_OPERATIONAL
+import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_RUNNING
+import static org.onap.cps.ncmp.api.impl.operations.OperationType.CREATE
+import static org.onap.cps.ncmp.api.impl.operations.OperationType.UPDATE
+
+class NetworkCmProxyFacadeSpec extends Specification {
+
+    def mockDmiDataOperations = Mock(DmiDataOperations)
+    def mockNcmpCachedResourceRequestHandler = Mock(NcmpCachedResourceRequestHandler)
+    def mockNcmpPassthroughResourceRequestHandler = Mock(NcmpPassthroughResourceRequestHandler)
+
+    def objectUnderTest = new NetworkCmProxyFacade(mockNcmpCachedResourceRequestHandler, mockNcmpPassthroughResourceRequestHandler, mockDmiDataOperations)
+
+    def NO_TOPIC = null
+
+    def 'Execute Data Operation for CM Handles (delegation).'() {
+        given: 'a data operation request'
+            def dataOperationRequest = Mock(DataOperationRequest)
+        and: ' a response from the (mocked) pass-through request handler for the given parameters'
+            def responseFromHandler = [attr:'value']
+            mockNcmpPassthroughResourceRequestHandler.executeAsynchronousRequest('topic', dataOperationRequest, 'authorization') >> responseFromHandler
+        expect: 'the response form the handler'
+            assert objectUnderTest.executeDataOperationForCmHandles('topic', dataOperationRequest, 'authorization') == responseFromHandler
+    }
+
+    def 'Query Resource Data for cm handle (delegation).'() {
+        given: 'a response from the (mocked) cached data handler for the given parameters'
+            def responseFromHandler = [Mock(DataNode)]
+            mockNcmpCachedResourceRequestHandler.executeRequest('ch-1', 'some cps path', true) >> responseFromHandler
+        expect: 'the response form the handler'
+            assert objectUnderTest.queryResourceDataForCmHandle('ch-1','some cps path',true) == responseFromHandler
+    }
+
+    def 'Choosing Data Request Handler.'() {
+        expect: '(a mock of) #expectedHandler'
+            assert objectUnderTest.getNcmpDatastoreRequestHandler(datastore.datastoreName).class.name.startsWith(expectedHandler.name)
+        where:
+            datastore               || expectedHandler
+            OPERATIONAL             || NcmpCachedResourceRequestHandler.class
+            PASSTHROUGH_RUNNING     || NcmpPassthroughResourceRequestHandler.class
+            PASSTHROUGH_OPERATIONAL || NcmpPassthroughResourceRequestHandler.class
+    }
+
+    def 'Write resource data for pass-through running from DMI using POST (delegation).'() {
+        when: 'write resource data is called'
+            objectUnderTest.writeResourceDataPassThroughRunningForCmHandle('testCmHandle',
+                'testResourceId', CREATE,
+                '{some-json}', 'application/json', null)
+        then: 'DMI called with correct data'
+            1 * mockDmiDataOperations.writeResourceDataPassThroughRunningFromDmi('testCmHandle', 'testResourceId', CREATE, '{some-json}', 'application/json', null)
+    }
+
+    def 'Get resource data from DMI (delegation).'() {
+        given: 'a cm resource address for datastore operational'
+            def cmResourceAddress = new CmResourceAddress('ncmp-datastore:operational', 'some CM Handle', 'some resource Id')
+        and: 'get resource data from DMI is called'
+            mockNcmpCachedResourceRequestHandler.executeRequest(cmResourceAddress, 'options', NO_TOPIC, false, 'authorization') >>
+                    Mono.just('dmi response')
+        when: 'get resource data operational for the given cm resource address is called'
+            def response = objectUnderTest.getResourceDataForCmHandle(cmResourceAddress, 'options', NO_TOPIC, false, 'authorization').block()
+        then: 'DMI returns a json response'
+            assert response == 'dmi response'
+    }
+
+    def 'Update resource data for pass-through running from dmi (delegation).'() {
+        when: 'get resource data is called'
+            objectUnderTest.writeResourceDataPassThroughRunningForCmHandle('testCmHandle',
+                'testResourceId', UPDATE,
+                '{some-json}', 'application/json', 'authorization')
+        then: 'DMI called with correct data'
+            1 * mockDmiDataOperations.writeResourceDataPassThroughRunningFromDmi('testCmHandle', 'testResourceId', UPDATE, '{some-json}', 'application/json', 'authorization')
+    }
+
+
+}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyInventoryFacadeSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyInventoryFacadeSpec.groovy
new file mode 100644 (file)
index 0000000..f704dbb
--- /dev/null
@@ -0,0 +1,226 @@
+/*
+ *  ============LICENSE_START=======================================================
+ *  Copyright (C) 2021-2024 Nordix Foundation
+ *  Modifications Copyright (C) 2021 Pantheon.tech
+ *  Modifications Copyright (C) 2021-2022 Bell Canada
+ *  Modifications Copyright (C) 2023 TechMahindra Ltd.
+ *  ================================================================================
+ *  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.api.impl
+
+import com.fasterxml.jackson.databind.ObjectMapper
+import org.onap.cps.ncmp.api.ParameterizedCmHandleQueryService
+import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueryService
+import org.onap.cps.ncmp.api.impl.inventory.CmHandleState
+import org.onap.cps.ncmp.api.impl.inventory.CompositeState
+import org.onap.cps.ncmp.api.impl.inventory.DataStoreSyncState
+import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence
+import org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory
+import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
+import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters
+import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters
+import org.onap.cps.ncmp.api.models.ConditionApiProperties
+import org.onap.cps.ncmp.api.models.DmiPluginRegistration
+import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
+import org.onap.cps.spi.model.ConditionProperties
+import org.onap.cps.utils.JsonObjectMapper
+import spock.lang.Specification
+
+import java.util.stream.Collectors
+
+class NetworkCmProxyInventoryFacadeSpec extends Specification {
+
+    def mockCmHandleRegistrationService = Mock(CmHandleRegistrationService)
+    def mockCmHandleQueryService = Mock(CmHandleQueryService)
+    def mockParameterizedCmHandleQueryService = Mock(ParameterizedCmHandleQueryService)
+    def spiedJsonObjectMapper = Spy(new JsonObjectMapper(new ObjectMapper()))
+    def mockInventoryPersistence = Mock(InventoryPersistence)
+
+    def objectUnderTest = new NetworkCmProxyInventoryFacade(mockCmHandleRegistrationService, mockCmHandleQueryService, mockParameterizedCmHandleQueryService, mockInventoryPersistence, spiedJsonObjectMapper)
+
+    def 'Update DMI Registration'() {
+        given: 'an (updated) dmi plugin registration'
+            def dmiPluginRegistration = Mock(DmiPluginRegistration)
+        when: 'the registration is submitted '
+           objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
+        then: 'the call is delegated to the cm handle registration service'
+            1 * mockCmHandleRegistrationService.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
+    }
+
+    def 'Execute cm handle id search for inventory'() {
+        given: 'a ConditionApiProperties object'
+            def conditionProperties = new ConditionProperties()
+            conditionProperties.conditionName = 'hasAllProperties'
+            conditionProperties.conditionParameters = [ [ 'some-key' : 'some-value' ] ]
+            def cmHandleQueryServiceParameters = new CmHandleQueryServiceParameters()
+            cmHandleQueryServiceParameters.cmHandleQueryParameters = [conditionProperties] as List<ConditionProperties>
+        and: 'the system returns an set of cmHandle ids'
+            mockParameterizedCmHandleQueryService.queryCmHandleIdsForInventory(*_) >> [ 'cmHandle1', 'cmHandle2' ]
+        when: 'executing the search'
+            def result = objectUnderTest.executeParameterizedCmHandleIdSearch(cmHandleQueryServiceParameters)
+        then: 'the result returns the correct 2 elements'
+            assert result.size() == 2
+            assert result.contains('cmHandle1')
+            assert result.contains('cmHandle2')
+    }
+
+    def 'Get all cm handle IDs by DMI plugin identifier.' () {
+        given: 'cm handle queries service returns cm handles'
+            1 * mockCmHandleQueryService.getCmHandleIdsByDmiPluginIdentifier('some-dmi-plugin-identifier') >> ['cm-handle-1','cm-handle-2']
+        when: 'cm handle Ids are requested with dmi plugin identifier'
+            def result = objectUnderTest.getAllCmHandleIdsByDmiPluginIdentifier('some-dmi-plugin-identifier')
+        then: 'the result size is correct'
+            assert result.size() == 2
+        and: 'the result returns the correct details'
+            assert result.containsAll('cm-handle-1','cm-handle-2')
+    }
+
+    def 'Getting Yang Resources.'() {
+        when: 'yang resources is called'
+            objectUnderTest.getYangResourcesModuleReferences('some-cm-handle')
+        then: 'CPS module services is invoked for the correct dataspace and cm handle'
+            1 * mockInventoryPersistence.getYangResourcesModuleReferences('some-cm-handle')
+    }
+
+    def 'Get a cm handle.'() {
+        given: 'the system returns a yang modelled cm handle'
+            def dmiServiceName = 'some service name'
+            def compositeState = new CompositeState(cmHandleState: CmHandleState.ADVISED,
+                lockReason: CompositeState.LockReason.builder().lockReasonCategory(LockReasonCategory.MODULE_SYNC_FAILED).details("lock details").build(),
+                lastUpdateTime: 'some-timestamp',
+                dataSyncEnabled: false,
+                dataStores: dataStores())
+            def dmiProperties = [new YangModelCmHandle.Property('Book', 'Romance Novel')]
+            def publicProperties = [new YangModelCmHandle.Property('Public Book', 'Public Romance Novel')]
+            def moduleSetTag = 'some-module-set-tag'
+            def alternateId = 'some-alternate-id'
+            def yangModelCmHandle = new YangModelCmHandle(id: 'some-cm-handle', dmiServiceName: dmiServiceName,
+                dmiProperties: dmiProperties, publicProperties: publicProperties, compositeState: compositeState,
+                moduleSetTag: moduleSetTag, alternateId: alternateId)
+            1 * mockInventoryPersistence.getYangModelCmHandle('some-cm-handle') >> yangModelCmHandle
+        when: 'getting cm handle details for a given cm handle id from ncmp service'
+            def result = objectUnderTest.getNcmpServiceCmHandle('some-cm-handle')
+        then: 'the result is a ncmpServiceCmHandle'
+            result.class == NcmpServiceCmHandle.class
+        and: 'the cm handle contains the cm handle id'
+            result.cmHandleId == 'some-cm-handle'
+        and: 'the cm handle contains the alternate id'
+            result.alternateId == 'some-alternate-id'
+        and: 'the cm handle contains the module-set-tag'
+            result.moduleSetTag == 'some-module-set-tag'
+        and: 'the cm handle contains the DMI Properties'
+            result.dmiProperties ==[ Book:'Romance Novel' ]
+        and: 'the cm handle contains the public Properties'
+            result.publicProperties == [ "Public Book":'Public Romance Novel' ]
+        and: 'the cm handle contains the cm handle composite state'
+            result.compositeState == compositeState
+    }
+
+    def 'Get cm handle public properties'() {
+        given: 'a yang modelled cm handle'
+            def dmiProperties = [new YangModelCmHandle.Property('prop', 'some DMI property')]
+            def publicProperties = [new YangModelCmHandle.Property('public prop', 'some public prop')]
+            def yangModelCmHandle = new YangModelCmHandle(id:'some-cm-handle', dmiServiceName: 'some service name', dmiProperties: dmiProperties, publicProperties: publicProperties)
+        and: 'the system returns this yang modelled cm handle'
+            1 * mockInventoryPersistence.getYangModelCmHandle('some-cm-handle') >> yangModelCmHandle
+        when: 'getting cm handle public properties for a given cm handle id from ncmp service'
+            def result = objectUnderTest.getCmHandlePublicProperties('some-cm-handle')
+        then: 'the result returns the correct data'
+            result == [ 'public prop' : 'some public prop' ]
+    }
+
+    def 'Get cm handle composite state'() {
+        given: 'a yang modelled cm handle'
+            def compositeState = new CompositeState(cmHandleState: CmHandleState.ADVISED,
+                lockReason: CompositeState.LockReason.builder().lockReasonCategory(LockReasonCategory.MODULE_SYNC_FAILED).details("lock details").build(),
+                lastUpdateTime: 'some-timestamp',
+                dataSyncEnabled: false,
+                dataStores: dataStores())
+            def dmiProperties = [new YangModelCmHandle.Property('prop', 'some DMI property')]
+            def publicProperties = [new YangModelCmHandle.Property('public prop', 'some public prop')]
+            def yangModelCmHandle = new YangModelCmHandle(id:'some-cm-handle', dmiServiceName: 'some service name', dmiProperties: dmiProperties, publicProperties: publicProperties, compositeState: compositeState)
+        and: 'the system returns this yang modelled cm handle'
+            1 * mockInventoryPersistence.getYangModelCmHandle('some-cm-handle') >> yangModelCmHandle
+        when: 'getting cm handle composite state for a given cm handle id from ncmp service'
+            def result = objectUnderTest.getCmHandleCompositeState('some-cm-handle')
+        then: 'the result returns the correct data'
+            result == compositeState
+    }
+
+    def 'Execute cm handle id search'() {
+        given: 'valid CmHandleQueryApiParameters input'
+            def cmHandleQueryApiParameters = new CmHandleQueryApiParameters()
+            def conditionApiProperties = new ConditionApiProperties()
+            conditionApiProperties.conditionName = 'hasAllModules'
+            conditionApiProperties.conditionParameters = [[moduleName: 'module-name-1']]
+            cmHandleQueryApiParameters.cmHandleQueryParameters = [conditionApiProperties]
+        and: 'query cm handle method return with a data node list'
+            mockParameterizedCmHandleQueryService.queryCmHandleIds(
+                spiedJsonObjectMapper.convertToValueType(cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class))
+                >> ['cm-handle-id-1']
+        when: 'execute cm handle search is called'
+            def result = objectUnderTest.executeCmHandleIdSearch(cmHandleQueryApiParameters)
+        then: 'result is the same collection as returned by the CPS Data Service'
+            assert result == ['cm-handle-id-1']
+    }
+
+    def 'Getting module definitions by module'() {
+        when: 'get module definitions is performed with module name'
+            objectUnderTest.getModuleDefinitionsByCmHandleAndModule('some-cm-handle', 'some-module', '2021-08-04')
+        then: 'ncmp inventory persistence service is invoked once with correct parameters'
+            1 * mockInventoryPersistence.getModuleDefinitionsByCmHandleAndModule('some-cm-handle', 'some-module', '2021-08-04')
+    }
+
+    def 'Getting module definitions by cm handle id'() {
+        when: 'get module definitions is performed with cm handle id'
+            objectUnderTest.getModuleDefinitionsByCmHandleId('some-cm-handle')
+        then: 'ncmp inventory persistence service is invoked once with correct parameter'
+            1 * mockInventoryPersistence.getModuleDefinitionsByCmHandleId('some-cm-handle')
+    }
+
+    def 'Execute cm handle search'() {
+        given: 'valid CmHandleQueryApiParameters input'
+            def cmHandleQueryApiParameters = new CmHandleQueryApiParameters()
+            def conditionApiProperties = new ConditionApiProperties()
+            conditionApiProperties.conditionName = 'hasAllModules'
+            conditionApiProperties.conditionParameters = [[moduleName: 'module-name-1']]
+            cmHandleQueryApiParameters.cmHandleQueryParameters = [conditionApiProperties]
+        and: 'query cm handle method return with a data node list'
+            mockParameterizedCmHandleQueryService.queryCmHandles(
+                spiedJsonObjectMapper.convertToValueType(cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class))
+                >> [new NcmpServiceCmHandle(cmHandleId: 'cm-handle-id-1')]
+        when: 'execute cm handle search is called'
+            def result = objectUnderTest.executeCmHandleSearch(cmHandleQueryApiParameters)
+        then: 'result is the same collection as returned by the CPS Data Service'
+            assert result.stream().map(cmHandle -> cmHandle.cmHandleId).collect(Collectors.toSet()) == ['cm-handle-id-1'] as Set
+    }
+
+    def 'Set Cm Handle Data Sync flag.'() {
+        when: 'setting data sync enabled flag'
+            objectUnderTest.setDataSyncEnabled('ch-1',true)
+        then: 'call is delegated to the cm handle registration service'
+            mockCmHandleRegistrationService.setDataSyncEnabled('ch-1', true)
+    }
+
+    def dataStores() {
+        CompositeState.DataStores.builder()
+            .operationalDataStore(CompositeState.Operational.builder()
+                .dataStoreSyncState(DataStoreSyncState.NONE_REQUESTED)
+                .lastSyncTime('some-timestamp').build()).build()
+    }
+}
@@ -24,8 +24,7 @@ import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DM
 
 import org.onap.cps.cpspath.parser.PathParsingException
 import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
-import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueries
-import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueriesImpl
+import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueryService
 import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence
 import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters
 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
@@ -36,16 +35,16 @@ import org.onap.cps.spi.model.ConditionProperties
 import org.onap.cps.spi.model.DataNode
 import spock.lang.Specification
 
-class NetworkCmProxyCmHandleQueryServiceSpec extends Specification {
+class ParameterizedCmHandleQueryServiceSpec extends Specification {
 
-    def cmHandleQueries = Mock(CmHandleQueries)
-    def partiallyMockedCmHandleQueries = Spy(CmHandleQueries)
+    def cmHandleQueries = Mock(CmHandleQueryService)
+    def partiallyMockedCmHandleQueries = Spy(CmHandleQueryService)
     def mockInventoryPersistence = Mock(InventoryPersistence)
 
     def dmiRegistry = new DataNode(xpath: NCMP_DMI_REGISTRY_PARENT, childDataNodes: createDataNodeList(['PNFDemo1', 'PNFDemo2', 'PNFDemo3', 'PNFDemo4']))
 
-    def objectUnderTest = new NetworkCmProxyCmHandleQueryServiceImpl(cmHandleQueries, mockInventoryPersistence)
-    def objectUnderTestWithPartiallyMockedQueries = new NetworkCmProxyCmHandleQueryServiceImpl(partiallyMockedCmHandleQueries, mockInventoryPersistence)
+    def objectUnderTest = new ParameterizedCmHandleQueryServiceImpl(cmHandleQueries, mockInventoryPersistence)
+    def objectUnderTestWithPartiallyMockedQueries = new ParameterizedCmHandleQueryServiceImpl(partiallyMockedCmHandleQueries, mockInventoryPersistence)
 
     def 'Query cm handle ids with cpsPath.'() {
         given: 'a cmHandleWithCpsPath condition property'
index 2c22127..bb73c68 100644 (file)
 
 package org.onap.cps.ncmp.api.impl.client
 
-import static org.onap.cps.ncmp.api.NcmpResponseStatus.UNKNOWN_ERROR
-import static org.onap.cps.ncmp.api.impl.operations.OperationType.CREATE
-import static org.onap.cps.ncmp.api.impl.operations.OperationType.PATCH
-import static org.onap.cps.ncmp.api.impl.operations.OperationType.READ
-import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.DATA
-import static org.springframework.http.HttpStatus.SERVICE_UNAVAILABLE
-import static org.onap.cps.ncmp.api.NcmpResponseStatus.DMI_SERVICE_NOT_RESPONDING
-import static org.onap.cps.ncmp.api.NcmpResponseStatus.UNABLE_TO_READ_RESOURCE_DATA
-
 import com.fasterxml.jackson.databind.JsonNode
 import com.fasterxml.jackson.databind.ObjectMapper
 import com.fasterxml.jackson.databind.node.ObjectNode
+import org.onap.cps.ncmp.api.impl.config.DmiProperties
 import org.onap.cps.ncmp.api.impl.exception.DmiClientRequestException
 import org.onap.cps.ncmp.api.impl.exception.InvalidDmiResourceUrlException
-import org.onap.cps.ncmp.api.impl.config.DmiProperties
 import org.onap.cps.ncmp.utils.TestUtils
 import org.onap.cps.utils.JsonObjectMapper
 import org.springframework.http.HttpHeaders
 import org.springframework.http.HttpStatus
 import org.springframework.http.ResponseEntity
-import org.springframework.web.client.HttpServerErrorException
 import org.springframework.web.reactive.function.client.WebClient
-import org.springframework.web.reactive.function.client.WebClientResponseException
 import org.springframework.web.reactive.function.client.WebClientRequestException
+import org.springframework.web.reactive.function.client.WebClientResponseException
 import reactor.core.publisher.Mono
 import spock.lang.Specification
 
+import static org.onap.cps.ncmp.api.NcmpResponseStatus.DMI_SERVICE_NOT_RESPONDING
+import static org.onap.cps.ncmp.api.NcmpResponseStatus.UNABLE_TO_READ_RESOURCE_DATA
+import static org.onap.cps.ncmp.api.NcmpResponseStatus.UNKNOWN_ERROR
+import static org.onap.cps.ncmp.api.impl.operations.OperationType.CREATE
+import static org.onap.cps.ncmp.api.impl.operations.OperationType.PATCH
+import static org.onap.cps.ncmp.api.impl.operations.OperationType.READ
+import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.DATA
+import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.MODEL
+
 class DmiRestClientSpec extends Specification {
 
     static final NO_AUTH_HEADER = null
@@ -61,7 +60,6 @@ class DmiRestClientSpec extends Specification {
     def mockRequestBody = Mock(WebClient.RequestBodyUriSpec)
     def mockResponse = Mock(WebClient.ResponseSpec)
 
-    def responseBody = [message: 'Success']
     def mockDmiProperties = Mock(DmiProperties)
 
     JsonObjectMapper jsonObjectMapper = new JsonObjectMapper(new ObjectMapper())
@@ -75,34 +73,31 @@ class DmiRestClientSpec extends Specification {
         mockRequestBody.retrieve() >> mockResponse
     }
 
-    def 'DMI POST Operation with JSON for status #httpStatusCode'() {
-        given: 'the web client returns a valid response entity for the expected parameters'
+    def 'DMI POST Operation with JSON for DMI Data Service '() {
+        given: 'the Data web client returns a valid response entity for the expected parameters'
             mockDataServicesWebClient.post() >> mockRequestBody
-            mockResponse.toEntity(Object.class) >> Mono.just(new ResponseEntity<>(responseBody, httpStatusCode))
-        when: 'POST operation is invoked'
-            def response = objectUnderTest.postOperationWithJsonData(DATA, '/my/url', 'some json', READ, NO_AUTH_HEADER)
+            mockResponse.toEntity(Object.class) >> Mono.just(new ResponseEntity<>('from Data service', HttpStatus.I_AM_A_TEAPOT))
+        when: 'POST operation is invoked fro Data Service'
+            def response = objectUnderTest.synchronousPostOperationWithJsonData(DATA, '/my/url', 'some json', READ, NO_AUTH_HEADER)
         then: 'the output of the method is equal to the output from the test template'
-            assert response.statusCode == httpStatusCode
-            assert response.body == responseBody
-        where: 'the following status codes are used'
-            httpStatusCode << [HttpStatus.OK, HttpStatus.CREATED, HttpStatus.ACCEPTED]
+            assert response.statusCode == HttpStatus.I_AM_A_TEAPOT
+            assert response.body == 'from Data service'
     }
 
-    def 'Failing DMI POST operation for server error'() {
-        given: 'the web client throws an exception'
-            mockDataServicesWebClient.post() >> { throw new HttpServerErrorException(SERVICE_UNAVAILABLE, null, null, null) }
-        when: 'POST operation is invoked'
-            objectUnderTest.postOperationWithJsonData(DATA, '/some', 'some json', READ, NO_AUTH_HEADER)
-        then: 'a http client exception is thrown'
-            def thrown = thrown(DmiClientRequestException)
-        and: 'the exception has the relevant details from the error response'
-            thrown.ncmpResponseStatus.code == '102'
-            thrown.httpStatusCode == 503
+    def 'DMI POST Operation with JSON for DMI Model Service '() {
+        given: 'the Model web client returns a valid response entity for the expected parameters'
+            mockModelServicesWebClient.post() >> mockRequestBody
+            mockResponse.toEntity(Object.class) >> Mono.just(new ResponseEntity<>('from Model service', HttpStatus.I_AM_A_TEAPOT))
+        when: 'POST operation is invoked for Model Service'
+            def response = objectUnderTest.synchronousPostOperationWithJsonData(MODEL, '/my/url', 'some json', READ, NO_AUTH_HEADER)
+        then: 'the output of the method is equal to the output from the test template'
+            assert response.statusCode == HttpStatus.I_AM_A_TEAPOT
+            assert response.body == 'from Model service'
     }
 
     def 'Failing DMI POST operation due to invalid dmi resource url.'() {
         when: 'POST operation is invoked with invalid dmi resource url'
-            objectUnderTest.postOperationWithJsonData(DATA, '/invalid dmi url', null, null, NO_AUTH_HEADER)
+            objectUnderTest.synchronousPostOperationWithJsonData(DATA, '/invalid dmi url', null, null, NO_AUTH_HEADER)
         then: 'invalid dmi resource url exception is thrown'
             def thrown = thrown(InvalidDmiResourceUrlException)
         and: 'the exception has the relevant details from the error response'
@@ -117,7 +112,7 @@ class DmiRestClientSpec extends Specification {
             mockDataServicesWebClient.post() >> mockRequestBody
             mockResponse.toEntity(Object.class) >> Mono.error(exceptionType)
         when: 'POST operation is invoked'
-            objectUnderTest.postOperationWithJsonData(DATA, '/my/url', 'some json', READ, NO_AUTH_HEADER)
+            objectUnderTest.synchronousPostOperationWithJsonData(DATA, '/my/url', 'some json', READ, NO_AUTH_HEADER)
         then: 'a http client exception is thrown'
             def thrown = thrown(DmiClientRequestException)
         and: 'the exception has the relevant details from the error response'
@@ -176,4 +171,4 @@ class DmiRestClientSpec extends Specification {
             'DMI basic auth disabled, with NCMP bearer token' | false       | BEARER_AUTH_HEADER || BEARER_AUTH_HEADER
             'DMI basic auth disabled, with NCMP basic auth'   | false       | BASIC_AUTH_HEADER  || NO_AUTH_HEADER
     }
-}
\ No newline at end of file
+}
@@ -33,7 +33,7 @@ import org.onap.cps.spi.model.DataNode
 import spock.lang.Shared
 import spock.lang.Specification
 
-class CmHandleQueriesImplSpec extends Specification {
+class CmHandleQueryServiceImplSpec extends Specification {
 
     def mockCpsDataPersistenceService = Mock(CpsDataPersistenceService)
 
@@ -43,7 +43,7 @@ class CmHandleQueriesImplSpec extends Specification {
 
     def mockCpsValidator = Mock(CpsValidator)
 
-    def objectUnderTest = new CmHandleQueriesImpl(mockCpsDataPersistenceService, trustLevelPerDmiPlugin, trustLevelPerCmHandle, mockCpsValidator)
+    def objectUnderTest = new CmHandleQueryServiceImpl(mockCpsDataPersistenceService, trustLevelPerDmiPlugin, trustLevelPerCmHandle, mockCpsValidator)
 
     @Shared
     def static sampleDataNodes = [new DataNode()]
index 66fd7d8..775824b 100644 (file)
@@ -61,7 +61,7 @@ class InventoryPersistenceImplSpec extends Specification {
 
     def mockCpsValidator = Mock(CpsValidator)
 
-    def mockCmHandleQueries = Mock(CmHandleQueries)
+    def mockCmHandleQueries = Mock(CmHandleQueryService)
 
     def objectUnderTest = new InventoryPersistenceImpl(spiedJsonObjectMapper, mockCpsDataService, mockCpsModuleService,
             mockCpsValidator, mockCpsAnchorService, mockCmHandleQueries)
index 44bc182..e9038ec 100644 (file)
@@ -35,7 +35,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
 import com.fasterxml.jackson.databind.JsonNode
 import com.fasterxml.jackson.databind.ObjectMapper
 import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations
-import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueries
+import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueryService
 import org.onap.cps.ncmp.api.impl.inventory.CmHandleState
 import org.onap.cps.ncmp.api.impl.inventory.CompositeState
 import org.onap.cps.ncmp.api.impl.inventory.CompositeStateBuilder
@@ -52,7 +52,7 @@ import java.util.stream.Collectors
 
 class ModuleOperationsUtilsSpec extends Specification{
 
-    def mockCmHandleQueries = Mock(CmHandleQueries)
+    def mockCmHandleQueries = Mock(CmHandleQueryService)
 
     def mockDmiDataOperations = Mock(DmiDataOperations)
 
@@ -202,7 +202,7 @@ class ModuleOperationsUtilsSpec extends Specification{
             def jsonString = '{"stores:bookstore":{"categories":[{"code":"01"}]}}'
             JsonNode jsonNode = jsonObjectMapper.convertToJsonNode(jsonString);
             def responseEntity = new ResponseEntity<>(jsonNode, HttpStatus.OK)
-            mockDmiDataOperations.getResourceDataFromDmi(PASSTHROUGH_OPERATIONAL.datastoreName, 'cm-handle-123', _) >> responseEntity
+            mockDmiDataOperations.getAllResourceDataFromDmi('cm-handle-123', _) >> responseEntity
         when: 'get resource data is called'
             def result = objectUnderTest.getResourceData('cm-handle-123')
         then: 'the returned data is correct'
index cb933fa..9f7b953 100644 (file)
@@ -32,7 +32,7 @@ import org.onap.cps.api.CpsModuleService
 import org.onap.cps.spi.model.DataNodeBuilder
 import org.onap.cps.ncmp.api.impl.operations.DmiModelOperations
 import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
-import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueries
+import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueryService
 import org.onap.cps.ncmp.api.impl.inventory.CompositeStateBuilder
 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
 import org.onap.cps.spi.CascadeDeleteAllowed
@@ -46,7 +46,7 @@ class ModuleSyncServiceSpec extends Specification {
     def mockCpsModuleService = Mock(CpsModuleService)
     def mockDmiModelOperations = Mock(DmiModelOperations)
     def mockCpsAnchorService = Mock(CpsAnchorService)
-    def mockCmHandleQueries = Mock(CmHandleQueries)
+    def mockCmHandleQueries = Mock(CmHandleQueryService)
     def mockCpsDataService = Mock(CpsDataService)
     def mockJsonObjectMapper = Mock(JsonObjectMapper)
 
index b286e9f..a0c6d00 100644 (file)
@@ -78,7 +78,7 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec {
             def responseFromDmi = Mono.just(new ResponseEntity<Object>('{some-key:some-value}', HttpStatus.OK))
             def expectedUrl = "${dmiServiceBaseUrl}${expectedDatastoreInUrl}?resourceIdentifier=${resourceIdentifier}${expectedOptionsInUrl}"
             def expectedJson = '{"operation":"read","cmHandleProperties":' + expectedProperties + ',"moduleSetTag":""}'
-            mockDmiRestClient.postOperationWithJsonDataAsync(DATA, expectedUrl, expectedJson, READ, NO_AUTH_HEADER) >> responseFromDmi
+            mockDmiRestClient.asynchronousPostOperationWithJsonData(DATA, expectedUrl, expectedJson, READ, NO_AUTH_HEADER) >> responseFromDmi
         when: 'get resource data is invoked'
             def cmResourceAddress = new CmResourceAddress(dataStore.datastoreName, cmHandleId, resourceIdentifier)
             def result = objectUnderTest.getResourceDataFromDmi(cmResourceAddress, options, NO_TOPIC, NO_REQUEST_ID, NO_AUTH_HEADER).block()
@@ -105,11 +105,11 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec {
             def responseFromDmi = Mono.just(new ResponseEntity<Object>(HttpStatus.ACCEPTED))
             def expectedDmiBatchResourceDataUrl = "someServiceName/dmi/v1/data?requestId=requestId&topic=my-topic-name"
             def expectedBatchRequestAsJson = '{"operations":[{"operation":"read","operationId":"operational-14","datastore":"ncmp-datastore:passthrough-operational","options":"some option","resourceIdentifier":"some resource identifier","cmHandles":[{"id":"some-cm-handle","moduleSetTag":"","cmHandleProperties":{"prop1":"val1"}}]}]}'
-            mockDmiRestClient.postOperationWithJsonDataAsync(DATA, expectedDmiBatchResourceDataUrl, _, READ, NO_AUTH_HEADER) >> responseFromDmi
+            mockDmiRestClient.asynchronousPostOperationWithJsonData(DATA, expectedDmiBatchResourceDataUrl, _, READ, NO_AUTH_HEADER) >> responseFromDmi
         when: 'get resource data for group of cm handles is invoked'
             objectUnderTest.requestResourceDataFromDmi('my-topic-name', dataOperationRequest, 'requestId', NO_AUTH_HEADER)
         then: 'the post operation was called with the expected URL and JSON request body'
-            1 * mockDmiRestClient.postOperationWithJsonDataAsync(DATA, expectedDmiBatchResourceDataUrl, expectedBatchRequestAsJson, READ, NO_AUTH_HEADER)
+            1 * mockDmiRestClient.asynchronousPostOperationWithJsonData(DATA, expectedDmiBatchResourceDataUrl, expectedBatchRequestAsJson, READ, NO_AUTH_HEADER)
     }
 
     def 'Execute (async) data operation from DMI service with Exception.'() {
@@ -122,7 +122,7 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec {
             def actualDataOperationCloudEvent = null
             eventsPublisher.publishCloudEvent('my-topic-name', 'my-request-id', _) >> { args -> actualDataOperationCloudEvent = args[2] }
         and: 'a DMI client request exception is thrown when DMI service is called'
-            mockDmiRestClient.postOperationWithJsonDataAsync(*_) >> { Mono.error(new DmiClientRequestException(123, '', '', UNKNOWN_ERROR)) }
+            mockDmiRestClient.asynchronousPostOperationWithJsonData(*_) >> { Mono.error(new DmiClientRequestException(123, '', '', UNKNOWN_ERROR)) }
         when: 'attempt to get resource data for group of cm handles is invoked'
             objectUnderTest.requestResourceDataFromDmi('my-topic-name', dataOperationRequest, 'my-request-id', NO_AUTH_HEADER)
         then: 'the event contains the expected error details'
@@ -141,9 +141,9 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec {
             def responseFromDmi = new ResponseEntity<Object>(HttpStatus.OK)
             def expectedUrl = dmiServiceBaseUrl + "passthrough-operational?resourceIdentifier=/"
             def expectedJson = '{"operation":"read","cmHandleProperties":{"prop1":"val1"},"moduleSetTag":"my-module-set-tag"}'
-            mockDmiRestClient.postOperationWithJsonData(DATA, expectedUrl, expectedJson, READ, null) >> responseFromDmi
+            mockDmiRestClient.synchronousPostOperationWithJsonData(DATA, expectedUrl, expectedJson, READ, null) >> responseFromDmi
         when: 'get resource data is invoked'
-            def result = objectUnderTest.getResourceDataFromDmi( PASSTHROUGH_OPERATIONAL.datastoreName, cmHandleId, NO_REQUEST_ID)
+            def result = objectUnderTest.getAllResourceDataFromDmi(cmHandleId, NO_REQUEST_ID)
         then: 'the result is the response from the DMI service'
             assert result == responseFromDmi
     }
@@ -155,7 +155,7 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec {
             def expectedUrl = "${dmiServiceBaseUrl}passthrough-running?resourceIdentifier=${resourceIdentifier}"
             def expectedJson = '{"operation":"' + expectedOperationInUrl + '","dataType":"some data type","data":"requestData","cmHandleProperties":{"prop1":"val1"},"moduleSetTag":""}'
             def responseFromDmi = new ResponseEntity<Object>(HttpStatus.OK)
-            mockDmiRestClient.postOperationWithJsonData(DATA, expectedUrl, expectedJson, operation, NO_AUTH_HEADER) >> responseFromDmi
+            mockDmiRestClient.synchronousPostOperationWithJsonData(DATA, expectedUrl, expectedJson, operation, NO_AUTH_HEADER) >> responseFromDmi
         when: 'write resource method is invoked'
             def result = objectUnderTest.writeResourceDataPassThroughRunningFromDmi(cmHandleId, 'parent/child', operation, 'requestData', 'some data type', NO_AUTH_HEADER)
         then: 'the result is the response from the DMI service'
index db7f26f..9ab52b9 100644 (file)
@@ -59,7 +59,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
             def moduleReferencesAsLisOfMaps = [[moduleName: 'mod1', revision: 'A'], [moduleName: 'mod2', revision: 'X']]
             def expectedUrl = "${dmiServiceName}/dmi/v1/ch/${cmHandleId}/modules"
             def responseFromDmi = new ResponseEntity([schemas: moduleReferencesAsLisOfMaps], HttpStatus.OK)
-            mockDmiRestClient.postOperationWithJsonData(MODEL, expectedUrl, '{"cmHandleProperties":{},"moduleSetTag":""}', READ, NO_AUTH_HEADER) >> responseFromDmi
+            mockDmiRestClient.synchronousPostOperationWithJsonData(MODEL, expectedUrl, '{"cmHandleProperties":{},"moduleSetTag":""}', READ, NO_AUTH_HEADER) >> responseFromDmi
         when: 'get module references is called'
             def result = objectUnderTest.getModuleReferences(yangModelCmHandle)
         then: 'the result consists of expected module references'
@@ -72,7 +72,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
         and: 'any response from DMI service when it is called with the expected parameters'
             // TODO (toine): production code ignores any error code from DMI, this should be improved in future
             def responseFromDmi = new ResponseEntity(bodyAsMap, HttpStatus.NO_CONTENT)
-            mockDmiRestClient.postOperationWithJsonData(*_) >> responseFromDmi
+            mockDmiRestClient.synchronousPostOperationWithJsonData(*_) >> responseFromDmi
         when: 'get module references is called'
             def result = objectUnderTest.getModuleReferences(yangModelCmHandle)
         then: 'the result is empty'
@@ -90,7 +90,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
             mockYangModelCmHandleRetrieval(dmiProperties)
         and: 'a positive response from DMI service when it is called with tha expected parameters'
             def responseFromDmi = new ResponseEntity<String>(HttpStatus.OK)
-            mockDmiRestClient.postOperationWithJsonData(MODEL, "${dmiServiceName}/dmi/v1/ch/${cmHandleId}/modules",
+            mockDmiRestClient.synchronousPostOperationWithJsonData(MODEL, "${dmiServiceName}/dmi/v1/ch/${cmHandleId}/modules",
                     '{"cmHandleProperties":' + expectedAdditionalPropertiesInRequest + ',"moduleSetTag":""}', READ, NO_AUTH_HEADER) >> responseFromDmi
         when: 'a get module references is called'
             def result = objectUnderTest.getModuleReferences(yangModelCmHandle)
@@ -109,7 +109,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
             def responseFromDmi = new ResponseEntity([[moduleName: 'mod1', revision: 'A', yangSource: 'some yang source'],
                                                       [moduleName: 'mod2', revision: 'C', yangSource: 'other yang source']], HttpStatus.OK)
             def expectedModuleReferencesInRequest = '{"name":"mod1","revision":"A"},{"name":"mod2","revision":"X"}'
-            mockDmiRestClient.postOperationWithJsonData(MODEL, "${dmiServiceName}/dmi/v1/ch/${cmHandleId}/moduleResources",
+            mockDmiRestClient.synchronousPostOperationWithJsonData(MODEL, "${dmiServiceName}/dmi/v1/ch/${cmHandleId}/moduleResources",
                     '{"data":{"modules":[' + expectedModuleReferencesInRequest + ']},"cmHandleProperties":{}}', READ, NO_AUTH_HEADER) >> responseFromDmi
         when: 'get new yang resources from DMI service'
             def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, newModuleReferences)
@@ -125,7 +125,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
         and: 'a positive response from DMI service when it is called with tha expected parameters'
             // TODO (toine): production code ignores any error code from DMI, this should be improved in future
             def responseFromDmi = new ResponseEntity(responseFromDmiBody, HttpStatus.NO_CONTENT)
-            mockDmiRestClient.postOperationWithJsonData(*_) >> responseFromDmi
+            mockDmiRestClient.synchronousPostOperationWithJsonData(*_) >> responseFromDmi
         when: 'get new yang resources from DMI service'
             def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, newModuleReferences)
         then: 'the result is empty'
@@ -141,7 +141,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
             mockYangModelCmHandleRetrieval(dmiProperties)
         and: 'a positive response from DMI service when it is called with the expected moduleSetTag, modules and properties'
             def responseFromDmi = new ResponseEntity<>([[moduleName: 'mod1', revision: 'A', yangSource: 'some yang source']], HttpStatus.OK)
-            mockDmiRestClient.postOperationWithJsonData(MODEL, "${dmiServiceName}/dmi/v1/ch/${cmHandleId}/moduleResources",
+            mockDmiRestClient.synchronousPostOperationWithJsonData(MODEL, "${dmiServiceName}/dmi/v1/ch/${cmHandleId}/moduleResources",
                     '{"data":{"modules":[{"name":"mod1","revision":"A"},{"name":"mod2","revision":"X"}]},"cmHandleProperties":' + expectedAdditionalPropertiesInRequest + '}',
                     READ, NO_AUTH_HEADER) >> responseFromDmi
         when: 'get new yang resources from DMI service'
@@ -159,7 +159,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
             mockYangModelCmHandleRetrieval([], moduleSetTag)
         and: 'a positive response from DMI service when it is called with the expected moduleSetTag'
             def responseFromDmi = new ResponseEntity<>([[moduleName: 'mod1', revision: 'A', yangSource: 'some yang source']], HttpStatus.OK)
-            mockDmiRestClient.postOperationWithJsonData(MODEL, "${dmiServiceName}/dmi/v1/ch/${cmHandleId}/moduleResources",
+            mockDmiRestClient.synchronousPostOperationWithJsonData(MODEL, "${dmiServiceName}/dmi/v1/ch/${cmHandleId}/moduleResources",
                     '{' + expectedModuleSetTagInRequest + '"data":{"modules":[{"name":"mod1","revision":"A"},{"name":"mod2","revision":"X"}]},"cmHandleProperties":{}}',
                     READ, NO_AUTH_HEADER) >> responseFromDmi
         when: 'get new yang resources from DMI service'
@@ -180,7 +180,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
         then: 'no resources are returned'
             assert result == [:]
         and: 'no request is sent to DMI'
-            0 * mockDmiRestClient.postOperationWithJsonData(*_)
+            0 * mockDmiRestClient.synchronousPostOperationWithJsonData(*_)
     }
 
     def 'Retrieving yang resources from DMI with null DMI properties.'() {
index 446126b..5305757 100644 (file)
@@ -20,8 +20,8 @@
 
 package org.onap.cps.ncmp.api.impl.trustlevel.dmiavailability
 
-import org.onap.cps.ncmp.api.NetworkCmProxyDataService
 import org.onap.cps.ncmp.api.impl.client.DmiRestClient
+import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueryService
 import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel
 import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevelManager
 import spock.lang.Specification
@@ -29,15 +29,12 @@ import spock.lang.Specification
 class DmiPluginWatchDogSpec extends Specification {
 
     def mockDmiRestClient = Mock(DmiRestClient)
-    def mockNetworkCmProxyDataService = Mock(NetworkCmProxyDataService)
+    def mockCmHandleQueryService = Mock(CmHandleQueryService)
     def mockTrustLevelManager = Mock(TrustLevelManager)
     def trustLevelPerDmiPlugin = [:]
 
 
-    def objectUnderTest = new DmiPluginWatchDog(mockDmiRestClient,
-        mockNetworkCmProxyDataService,
-        mockTrustLevelManager,
-        trustLevelPerDmiPlugin)
+    def objectUnderTest = new DmiPluginWatchDog(mockDmiRestClient, mockCmHandleQueryService, mockTrustLevelManager, trustLevelPerDmiPlugin)
 
     def 'watch dmi plugin health status for #dmiHealhStatus'() {
         given: 'the cache has been initialised and "knows" about dmi-1'
index 85f479f..0c5c816 100644 (file)
 
 package org.onap.cps.integration.base
 
-import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME
-import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR
-import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT
-
-import java.time.OffsetDateTime
-import java.time.format.DateTimeFormatter
 import okhttp3.mockwebserver.MockWebServer
-import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence
 import org.onap.cps.api.CpsAnchorService
 import org.onap.cps.api.CpsDataService
 import org.onap.cps.api.CpsDataspaceService
@@ -36,20 +29,22 @@ import org.onap.cps.api.CpsModuleService
 import org.onap.cps.api.CpsQueryService
 import org.onap.cps.integration.DatabaseTestContainer
 import org.onap.cps.integration.KafkaTestContainer
-import org.onap.cps.ncmp.api.NetworkCmProxyCmHandleQueryService
-import org.onap.cps.ncmp.api.NetworkCmProxyDataService
 import org.onap.cps.ncmp.api.NetworkCmProxyQueryService
+import org.onap.cps.ncmp.api.ParameterizedCmHandleQueryService
+import org.onap.cps.ncmp.api.impl.NetworkCmProxyFacade
+import org.onap.cps.ncmp.api.impl.NetworkCmProxyInventoryFacade
 import org.onap.cps.ncmp.api.impl.inventory.CmHandleState
+import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence
 import org.onap.cps.ncmp.api.impl.inventory.sync.ModuleSyncWatchdog
 import org.onap.cps.ncmp.api.models.DmiPluginRegistration
 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
+import org.onap.cps.ncmp.utils.AlternateIdMatcher
 import org.onap.cps.spi.exceptions.DataspaceNotFoundException
 import org.onap.cps.spi.model.DataNode
 import org.onap.cps.spi.repository.DataspaceRepository
 import org.onap.cps.spi.utils.SessionManager
-import org.onap.cps.ncmp.utils.AlternateIdMatcher
-import org.onap.cps.utils.JsonObjectMapper
 import org.onap.cps.utils.ContentType
+import org.onap.cps.utils.JsonObjectMapper
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
 import org.springframework.boot.autoconfigure.domain.EntityScan
@@ -63,6 +58,13 @@ import spock.lang.Shared
 import spock.lang.Specification
 import spock.util.concurrent.PollingConditions
 
+import java.time.OffsetDateTime
+import java.time.format.DateTimeFormatter
+
+import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME
+import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR
+import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT
+
 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK, classes = [CpsDataspaceService])
 @Testcontainers
 @EnableAutoConfiguration
@@ -100,10 +102,13 @@ abstract class CpsIntegrationSpecBase extends Specification {
     SessionManager sessionManager
 
     @Autowired
-    NetworkCmProxyCmHandleQueryService networkCmProxyCmHandleQueryService
+    ParameterizedCmHandleQueryService networkCmProxyCmHandleQueryService
+
+    @Autowired
+    NetworkCmProxyFacade networkCmProxyFacade
 
     @Autowired
-    NetworkCmProxyDataService networkCmProxyDataService
+    NetworkCmProxyInventoryFacade NetworkCmProxyInventoryFacade
 
     @Autowired
     NetworkCmProxyQueryService networkCmProxyQueryService
@@ -212,10 +217,10 @@ abstract class CpsIntegrationSpecBase extends Specification {
 
     def registerCmHandle(dmiPlugin, cmHandleId, moduleSetTag) {
         def cmHandleToCreate = new NcmpServiceCmHandle(cmHandleId: cmHandleId, moduleSetTag: moduleSetTag)
-        networkCmProxyDataService.updateDmiRegistrationAndSyncModule(new DmiPluginRegistration(dmiPlugin: dmiPlugin, createdCmHandles: [cmHandleToCreate]))
+        networkCmProxyInventoryFacade.updateDmiRegistrationAndSyncModule(new DmiPluginRegistration(dmiPlugin: dmiPlugin, createdCmHandles: [cmHandleToCreate]))
         moduleSyncWatchdog.moduleSyncAdvisedCmHandles()
         new PollingConditions().within(3, () -> {
-            CmHandleState.READY == networkCmProxyDataService.getCmHandleCompositeState(cmHandleId).cmHandleState
+            CmHandleState.READY == networkCmProxyInventoryFacade.getCmHandleCompositeState(cmHandleId).cmHandleState
         })
     }
 
@@ -224,7 +229,7 @@ abstract class CpsIntegrationSpecBase extends Specification {
     }
 
     def deregisterCmHandles(dmiPlugin, cmHandleIds) {
-        networkCmProxyDataService.updateDmiRegistrationAndSyncModule(new DmiPluginRegistration(dmiPlugin: dmiPlugin, removedCmHandles: cmHandleIds))
+        networkCmProxyInventoryFacade.updateDmiRegistrationAndSyncModule(new DmiPluginRegistration(dmiPlugin: dmiPlugin, removedCmHandles: cmHandleIds))
     }
 
     def overrideCmHandleLastUpdateTime(cmHandleId, newUpdateTime) {
index 4ffe586..2a35313 100644 (file)
 
 package org.onap.cps.integration.functional
 
-import static org.springframework.http.HttpMethod.GET
-import static org.springframework.http.HttpMethod.DELETE
-import static org.springframework.http.HttpMethod.PATCH
-import static org.springframework.http.HttpMethod.POST
-import static org.springframework.http.HttpMethod.PUT
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.request
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
-
 import okhttp3.mockwebserver.Dispatcher
 import okhttp3.mockwebserver.MockResponse
 import okhttp3.mockwebserver.RecordedRequest
@@ -38,6 +30,14 @@ import org.springframework.http.HttpStatus
 import org.springframework.http.MediaType
 import spock.util.concurrent.PollingConditions
 
+import static org.springframework.http.HttpMethod.DELETE
+import static org.springframework.http.HttpMethod.GET
+import static org.springframework.http.HttpMethod.PATCH
+import static org.springframework.http.HttpMethod.POST
+import static org.springframework.http.HttpMethod.PUT
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.request
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
+
 class NcmpBearerTokenPassthroughSpec extends CpsIntegrationSpecBase {
 
     def lastAuthHeaderReceived = null
index 5c337f1..8186c41 100644 (file)
 
 package org.onap.cps.integration.functional
 
-import java.time.Duration
-import java.time.OffsetDateTime
 import org.apache.kafka.common.TopicPartition
 import org.apache.kafka.common.serialization.StringDeserializer
 import org.onap.cps.integration.KafkaTestContainer
 import org.onap.cps.integration.base.CpsIntegrationSpecBase
-import org.onap.cps.ncmp.api.NetworkCmProxyDataService
+import org.onap.cps.ncmp.api.impl.NetworkCmProxyInventoryFacade
 import org.onap.cps.ncmp.api.impl.inventory.CmHandleState
 import org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory
 import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse
@@ -35,14 +33,17 @@ import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
 import org.onap.cps.ncmp.events.lcm.v1.LcmEvent
 import spock.util.concurrent.PollingConditions
 
+import java.time.Duration
+import java.time.OffsetDateTime
+
 class NcmpCmHandleCreateSpec extends CpsIntegrationSpecBase {
 
-    NetworkCmProxyDataService objectUnderTest
+    NetworkCmProxyInventoryFacade objectUnderTest
 
     def kafkaConsumer = KafkaTestContainer.getConsumer('ncmp-group', StringDeserializer.class)
 
     def setup() {
-        objectUnderTest = networkCmProxyDataService
+        objectUnderTest = networkCmProxyInventoryFacade
     }
 
     def 'CM Handle registration is successful.'() {
@@ -55,7 +56,7 @@ class NcmpCmHandleCreateSpec extends CpsIntegrationSpecBase {
         when: 'a CM-handle is registered for creation'
             def cmHandleToCreate = new NcmpServiceCmHandle(cmHandleId: 'ch-1')
             def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: DMI_URL, createdCmHandles: [cmHandleToCreate])
-            def dmiPluginRegistrationResponse = networkCmProxyDataService.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
+            def dmiPluginRegistrationResponse = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
 
         then: 'registration gives successful response'
             assert dmiPluginRegistrationResponse.createdCmHandles == [CmHandleRegistrationResponse.createSuccessResponse('ch-1')]
@@ -93,7 +94,7 @@ class NcmpCmHandleCreateSpec extends CpsIntegrationSpecBase {
         when: 'a CM-handle is registered for creation'
             def cmHandleToCreate = new NcmpServiceCmHandle(cmHandleId: 'ch-1')
             def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: DMI_URL, createdCmHandles: [cmHandleToCreate])
-            networkCmProxyDataService.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
+            objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
 
         and: 'module sync runs'
             moduleSyncWatchdog.moduleSyncAdvisedCmHandles()
@@ -121,7 +122,7 @@ class NcmpCmHandleCreateSpec extends CpsIntegrationSpecBase {
 
         when: 'a CM-handle is registered for creation with moduleSetTag "B"'
             def cmHandleToCreate = new NcmpServiceCmHandle(cmHandleId: 'ch-3', moduleSetTag: 'B')
-            networkCmProxyDataService.updateDmiRegistrationAndSyncModule(new DmiPluginRegistration(dmiPlugin: DMI_URL, createdCmHandles: [cmHandleToCreate]))
+            objectUnderTest.updateDmiRegistrationAndSyncModule(new DmiPluginRegistration(dmiPlugin: DMI_URL, createdCmHandles: [cmHandleToCreate]))
 
         then: 'the CM-handle goes to READY state after module sync'
             moduleSyncWatchdog.moduleSyncAdvisedCmHandles()
@@ -146,7 +147,7 @@ class NcmpCmHandleCreateSpec extends CpsIntegrationSpecBase {
         when: 'CM-handles are registered for creation'
             def cmHandlesToCreate = [new NcmpServiceCmHandle(cmHandleId: 'ch-1'), new NcmpServiceCmHandle(cmHandleId: 'ch-2')]
             def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: DMI_URL, createdCmHandles: cmHandlesToCreate)
-            networkCmProxyDataService.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
+            objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
         and: 'module sync runs'
             moduleSyncWatchdog.moduleSyncAdvisedCmHandles()
         then: 'CM-handles go to LOCKED state'
index 4d1d77e..f5c0b7b 100644 (file)
@@ -21,7 +21,7 @@
 package org.onap.cps.integration.functional
 
 import org.onap.cps.integration.base.CpsIntegrationSpecBase
-import org.onap.cps.ncmp.api.NetworkCmProxyDataService
+import org.onap.cps.ncmp.api.impl.NetworkCmProxyInventoryFacade
 import org.onap.cps.ncmp.api.impl.inventory.CmHandleState
 import org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory
 import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse
@@ -31,13 +31,13 @@ import spock.util.concurrent.PollingConditions
 
 class NcmpCmHandleUpgradeSpec extends CpsIntegrationSpecBase {
 
-    NetworkCmProxyDataService objectUnderTest
+    NetworkCmProxyInventoryFacade objectUnderTest
 
     static final CM_HANDLE_ID = 'ch-1'
     static final CM_HANDLE_ID_WITH_EXISTING_MODULE_SET_TAG = 'ch-2'
 
     def setup() {
-        objectUnderTest = networkCmProxyDataService
+        objectUnderTest = networkCmProxyInventoryFacade
     }
 
     def 'Upgrade CM-handle with new moduleSetTag or no moduleSetTag.'() {
@@ -48,7 +48,7 @@ class NcmpCmHandleUpgradeSpec extends CpsIntegrationSpecBase {
 
         when: "the CM-handle is upgraded with given moduleSetTag '${updatedModuleSetTag}'"
             def cmHandlesToUpgrade = new UpgradedCmHandles(cmHandles: [CM_HANDLE_ID], moduleSetTag: updatedModuleSetTag)
-            def dmiPluginRegistrationResponse = networkCmProxyDataService.updateDmiRegistrationAndSyncModule(
+            def dmiPluginRegistrationResponse = objectUnderTest.updateDmiRegistrationAndSyncModule(
                     new DmiPluginRegistration(dmiPlugin: DMI_URL, upgradedCmHandles: cmHandlesToUpgrade))
 
         then: 'registration gives successful response'
@@ -101,7 +101,7 @@ class NcmpCmHandleUpgradeSpec extends CpsIntegrationSpecBase {
 
         when: "CM-handle is upgraded to moduleSetTag '${updatedModuleSetTag}'"
             def cmHandlesToUpgrade = new UpgradedCmHandles(cmHandles: [CM_HANDLE_ID], moduleSetTag: updatedModuleSetTag)
-            def dmiPluginRegistrationResponse = networkCmProxyDataService.updateDmiRegistrationAndSyncModule(
+            def dmiPluginRegistrationResponse = objectUnderTest.updateDmiRegistrationAndSyncModule(
                     new DmiPluginRegistration(dmiPlugin: DMI_URL, upgradedCmHandles: cmHandlesToUpgrade))
 
         then: 'registration gives successful response'
@@ -139,7 +139,7 @@ class NcmpCmHandleUpgradeSpec extends CpsIntegrationSpecBase {
 
         when: 'CM-handle is upgraded with the same moduleSetTag'
             def cmHandlesToUpgrade = new UpgradedCmHandles(cmHandles: [CM_HANDLE_ID], moduleSetTag: 'same')
-            networkCmProxyDataService.updateDmiRegistrationAndSyncModule(
+            objectUnderTest.updateDmiRegistrationAndSyncModule(
                     new DmiPluginRegistration(dmiPlugin: DMI_URL, upgradedCmHandles: cmHandlesToUpgrade))
 
         then: 'CM-handle remains in READY state'
@@ -164,7 +164,7 @@ class NcmpCmHandleUpgradeSpec extends CpsIntegrationSpecBase {
 
         when: 'the CM-handle is upgraded'
             def cmHandlesToUpgrade = new UpgradedCmHandles(cmHandles: [CM_HANDLE_ID], moduleSetTag: 'newTag')
-            networkCmProxyDataService.updateDmiRegistrationAndSyncModule(
+            objectUnderTest.updateDmiRegistrationAndSyncModule(
                     new DmiPluginRegistration(dmiPlugin: DMI_URL, upgradedCmHandles: cmHandlesToUpgrade))
 
         and: 'module sync runs'