Merge "Fix: Update OpenSSF Scorecard to RelEng reusable"
[cps.git] / cps-ncmp-rest / src / main / java / org / onap / cps / ncmp / rest / controller / NetworkCmProxyController.java
old mode 100755 (executable)
new mode 100644 (file)
index 2f6668a..fd4ced3
@@ -1,7 +1,7 @@
 /*
  *  ============LICENSE_START=======================================================
  *  Copyright (C) 2021 Pantheon.tech
- *  Modifications Copyright (C) 2021-2022 Nordix Foundation
+ *  Modifications Copyright (C) 2021-2025 OpenInfra Foundation Europe
  *  Modifications Copyright (C) 2021 highstreet technologies GmbH
  *  Modifications Copyright (C) 2021-2022 Bell Canada
  *  ================================================================================
 
 package org.onap.cps.ncmp.rest.controller;
 
-import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.CREATE;
-import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.DELETE;
-import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.PATCH;
-import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.UPDATE;
+import static org.onap.cps.ncmp.api.data.models.DatastoreType.OPERATIONAL;
+import static org.onap.cps.ncmp.api.data.models.DatastoreType.PASSTHROUGH_RUNNING;
+import static org.onap.cps.ncmp.api.data.models.OperationType.CREATE;
+import static org.onap.cps.ncmp.api.data.models.OperationType.DELETE;
+import static org.onap.cps.ncmp.api.data.models.OperationType.PATCH;
+import static org.onap.cps.ncmp.api.data.models.OperationType.UPDATE;
 
+import io.micrometer.core.annotation.Timed;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
-import java.util.Set;
+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.inventory.CompositeState;
-import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters;
-import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
+import org.onap.cps.api.model.DataNode;
+import org.onap.cps.api.model.ModuleDefinition;
+import org.onap.cps.ncmp.api.data.exceptions.InvalidDatastoreException;
+import org.onap.cps.ncmp.api.data.models.CmResourceAddress;
+import org.onap.cps.ncmp.api.data.models.DatastoreType;
+import org.onap.cps.ncmp.api.inventory.NetworkCmProxyInventoryFacade;
+import org.onap.cps.ncmp.api.inventory.models.CmHandleQueryApiParameters;
+import org.onap.cps.ncmp.api.inventory.models.CompositeState;
+import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle;
+import org.onap.cps.ncmp.impl.data.NetworkCmProxyFacade;
 import org.onap.cps.ncmp.rest.api.NetworkCmProxyApi;
-import org.onap.cps.ncmp.rest.controller.handlers.DatastoreType;
-import org.onap.cps.ncmp.rest.controller.handlers.NcmpDatastoreResourceRequestHandler;
-import org.onap.cps.ncmp.rest.controller.handlers.NcmpDatastoreResourceRequestHandlerFactory;
-import org.onap.cps.ncmp.rest.exceptions.InvalidDatastoreException;
-import org.onap.cps.ncmp.rest.mapper.CmHandleStateMapper;
-import org.onap.cps.ncmp.rest.model.CmHandlePublicProperties;
 import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters;
+import org.onap.cps.ncmp.rest.model.DataOperationRequest;
 import org.onap.cps.ncmp.rest.model.RestModuleDefinition;
 import org.onap.cps.ncmp.rest.model.RestModuleReference;
 import org.onap.cps.ncmp.rest.model.RestOutputCmHandle;
 import org.onap.cps.ncmp.rest.model.RestOutputCmHandleCompositeState;
-import org.onap.cps.ncmp.rest.model.RestOutputCmHandlePublicProperties;
+import org.onap.cps.ncmp.rest.model.RestOutputPublicCmHandleProperties;
+import org.onap.cps.ncmp.rest.util.CmHandleStateMapper;
+import org.onap.cps.ncmp.rest.util.CountCmHandleSearchExecution;
+import org.onap.cps.ncmp.rest.util.DataOperationRequestMapper;
 import org.onap.cps.ncmp.rest.util.DeprecationHelper;
+import org.onap.cps.ncmp.rest.util.NcmpRestInputMapper;
+import org.onap.cps.ncmp.rest.util.RestOutputCmHandleMapper;
 import org.onap.cps.utils.JsonObjectMapper;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
+import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -64,135 +76,178 @@ 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 NcmpDatastoreResourceRequestHandlerFactory ncmpDatastoreResourceRequestHandlerFactory;
+    private final DataOperationRequestMapper dataOperationRequestMapper;
+    private final RestOutputCmHandleMapper restOutputCmHandleMapper;
 
     /**
      * Get resource data from datastore.
      *
-     * @param datastoreName       name of the datastore
-     * @param cmHandle            cm handle identifier
-     * @param resourceIdentifier  resource identifier
-     * @param optionsParamInQuery options query parameter
-     * @param topicParamInQuery   topic query parameter
-     * @param includeDescendants  whether include descendants
+     * @param datastoreName        name of the datastore
+     * @param cmHandleReference    cm handle or alternate id identifier
+     * @param resourceIdentifier   resource identifier
+     * @param optionsParamInQuery  options query parameter
+     * @param topicParamInQuery    topic query parameter
+     * @param includeDescendants   whether to include descendants or not
+     * @param authorization        contents of Authorization header, or null if not present
      * @return {@code ResponseEntity} response from dmi plugin
      */
-
     @Override
+    @Timed(value = "cps.ncmp.controller.get", description = "Time taken to get resource data from datastore")
     public ResponseEntity<Object> getResourceDataForCmHandle(final String datastoreName,
-                                                             final String cmHandle,
+                                                             final String cmHandleReference,
                                                              final String resourceIdentifier,
                                                              final String optionsParamInQuery,
                                                              final String topicParamInQuery,
-                                                             final Boolean includeDescendants) {
+                                                             final Boolean includeDescendants,
+                                                             final String authorization) {
+        final CmResourceAddress cmResourceAddress = new CmResourceAddress(datastoreName, cmHandleReference,
+            resourceIdentifier);
+        final Object result = networkCmProxyFacade.getResourceDataForCmHandle(cmResourceAddress, optionsParamInQuery,
+            topicParamInQuery, includeDescendants, authorization);
+        return ResponseEntity.ok(result);
+    }
+
+    @Override
+    public ResponseEntity<Object> executeDataOperationForCmHandles(final String topicParamInQuery,
+                                                                   final DataOperationRequest dataOperationRequest,
+                                                                   final String authorization) {
+        final Object result = networkCmProxyFacade.executeDataOperationForCmHandles(topicParamInQuery,
+                dataOperationRequestMapper.toDataOperationRequest(dataOperationRequest), authorization);
+        return ResponseEntity.ok(result);
+    }
 
-        final NcmpDatastoreResourceRequestHandler ncmpDatastoreResourceRequestHandler =
-                ncmpDatastoreResourceRequestHandlerFactory.getNcmpDatastoreResourceRequestHandler(
-                        DatastoreType.fromDatastoreName(datastoreName));
+    /**
+     * Query resource data from datastore.
+     *
+     * @param datastoreName        name of the datastore (currently only supports "ncmp-datastore:operational")
+     * @param cmHandle             cm handle identifier
+     * @param cpsPath              CPS Path
+     * @param optionsParamInQuery  options query parameter
+     * @param topicParamInQuery    topic query parameter
+     * @param includeDescendants   whether to include descendants or not
+     * @return {@code ResponseEntity} response. Body contains a collection of DataNodes
+     */
 
-        return ncmpDatastoreResourceRequestHandler.getResourceData(cmHandle, resourceIdentifier,
-                optionsParamInQuery, topicParamInQuery, includeDescendants);
+    @Override
+    public ResponseEntity<Object> queryResourceDataForCmHandle(final String datastoreName,
+                                                               final String cmHandle,
+                                                               final String cpsPath,
+                                                               final String optionsParamInQuery,
+                                                               final String topicParamInQuery,
+                                                               final Boolean includeDescendants) {
+        validateDataStore(OPERATIONAL, datastoreName);
+        final Collection<DataNode> dataNodes = networkCmProxyFacade.queryResourceDataForCmHandle(cmHandle, cpsPath,
+            includeDescendants);
+        return ResponseEntity.ok(dataNodes);
     }
 
     /**
-     * Patch resource data from passthrough-running.
+     * Patch resource data.
      *
+     * @param datastoreName      name of the datastore (currently only supports "ncmp-datastore:passthrough-running")
+     * @param cmHandleReference  cm handle or alternate identifier
      * @param resourceIdentifier resource identifier
-     * @param datastoreName      name of the datastore
-     * @param cmHandle           cm handle identifier
      * @param requestBody        the request body
      * @param contentType        content type of body
+     * @param authorization      contents of Authorization header, or null if not present
      * @return {@code ResponseEntity} response from dmi plugin
      */
 
     @Override
-    public ResponseEntity<Object> patchResourceDataRunningForCmHandle(final String resourceIdentifier,
-                                                                      final String datastoreName,
-                                                                      final String cmHandle,
+    public ResponseEntity<Object> patchResourceDataRunningForCmHandle(final String datastoreName,
+                                                                      final String cmHandleReference,
+                                                                      final String resourceIdentifier,
                                                                       final Object requestBody,
-                                                                      final String contentType) {
+                                                                      final String contentType,
+                                                                      final String authorization) {
 
-        acceptPassthroughRunningOnly(datastoreName);
+        validateDataStore(PASSTHROUGH_RUNNING, datastoreName);
 
-        final Object responseObject = networkCmProxyDataService
+        final Object responseObject = networkCmProxyFacade
                 .writeResourceDataPassThroughRunningForCmHandle(
-                        cmHandle, resourceIdentifier, PATCH,
-                        jsonObjectMapper.asJsonString(requestBody), contentType);
+                        cmHandleReference, resourceIdentifier, PATCH,
+                        jsonObjectMapper.asJsonString(requestBody), contentType, authorization);
         return ResponseEntity.ok(responseObject);
     }
 
     /**
-     * Create resource data in datastore pass-through running for given cm-handle.
+     * Create resource data for given cm-handle.
      *
+     * @param datastoreName      name of the datastore (currently only supports "ncmp-datastore:passthrough-running")
+     * @param cmHandleReference  cm handle or alternate identifier
      * @param resourceIdentifier resource identifier
-     * @param datastoreName      name of the datastore
-     * @param cmHandle           cm handle identifier
      * @param requestBody        the request body
      * @param contentType        content type of body
+     * @param authorization      contents of Authorization header, or null if not present
      * @return {@code ResponseEntity} response from dmi plugin
      */
     @Override
-    public ResponseEntity<Void> createResourceDataRunningForCmHandle(final String resourceIdentifier,
-                                                                     final String datastoreName,
-                                                                     final String cmHandle,
+    public ResponseEntity<Void> createResourceDataRunningForCmHandle(final String datastoreName,
+                                                                     final String cmHandleReference,
+                                                                     final String resourceIdentifier,
                                                                      final Object requestBody,
-                                                                     final String contentType) {
+                                                                     final String contentType,
+                                                                     final String authorization) {
+        validateDataStore(PASSTHROUGH_RUNNING, datastoreName);
 
-        acceptPassthroughRunningOnly(datastoreName);
-
-        networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
-                resourceIdentifier, CREATE, jsonObjectMapper.asJsonString(requestBody), contentType);
+        networkCmProxyFacade.writeResourceDataPassThroughRunningForCmHandle(cmHandleReference,
+                resourceIdentifier, CREATE, jsonObjectMapper.asJsonString(requestBody), contentType, authorization);
         return new ResponseEntity<>(HttpStatus.CREATED);
     }
 
     /**
-     * Update resource data in datastore pass-through running for given cm-handle.
+     * Update resource data for given cm-handle.
      *
+     * @param datastoreName      name of the datastore (currently only supports "ncmp-datastore:passthrough-running")
+     * @param cmHandleReference  cm handle or alternate identifier
      * @param resourceIdentifier resource identifier
-     * @param datastoreName      name of the datastore
-     * @param cmHandle           cm handle identifier
      * @param requestBody        the request body
      * @param contentType        content type of the body
+     * @param authorization      contents of Authorization header, or null if not present
      * @return response entity
      */
 
     @Override
-    public ResponseEntity<Object> updateResourceDataRunningForCmHandle(final String resourceIdentifier,
-                                                                       final String datastoreName,
-                                                                       final String cmHandle,
+    public ResponseEntity<Object> updateResourceDataRunningForCmHandle(final String datastoreName,
+                                                                       final String cmHandleReference,
+                                                                       final String resourceIdentifier,
                                                                        final Object requestBody,
-                                                                       final String contentType) {
-        acceptPassthroughRunningOnly(datastoreName);
+                                                                       final String contentType,
+                                                                       final String authorization) {
+        validateDataStore(PASSTHROUGH_RUNNING, datastoreName);
 
-        networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
-                resourceIdentifier, UPDATE, jsonObjectMapper.asJsonString(requestBody), contentType);
+        networkCmProxyFacade.writeResourceDataPassThroughRunningForCmHandle(cmHandleReference,
+                resourceIdentifier, UPDATE, jsonObjectMapper.asJsonString(requestBody), contentType, authorization);
         return new ResponseEntity<>(HttpStatus.OK);
     }
 
     /**
-     * Delete resource data in datastore pass-through running for a given cm-handle.
+     * Delete resource data for a given cm-handle.
      *
-     * @param datastoreName      name of the datastore
-     * @param cmHandle           cm handle identifier
+     * @param datastoreName      name of the datastore (currently only supports "ncmp-datastore:passthrough-running")
+     * @param cmHandleReference  cm handle or alternate identifier
      * @param resourceIdentifier resource identifier
      * @param contentType        content type of the body
+     * @param authorization      contents of Authorization header, or null if not present
      * @return response entity no content if request is successful
      */
     @Override
     public ResponseEntity<Void> deleteResourceDataRunningForCmHandle(final String datastoreName,
-                                                                     final String cmHandle,
+                                                                     final String cmHandleReference,
                                                                      final String resourceIdentifier,
-                                                                     final String contentType) {
+                                                                     final String contentType,
+                                                                     final String authorization) {
 
-        acceptPassthroughRunningOnly(datastoreName);
+        validateDataStore(PASSTHROUGH_RUNNING, datastoreName);
 
-        networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
-                resourceIdentifier, DELETE, NO_BODY, contentType);
+        networkCmProxyFacade.writeResourceDataPassThroughRunningForCmHandle(cmHandleReference,
+                resourceIdentifier, DELETE, NO_BODY, contentType, authorization);
         return new ResponseEntity<>(HttpStatus.NO_CONTENT);
     }
 
@@ -204,72 +259,81 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
      */
     @Override
     @SuppressWarnings("deprecation") // mapOldConditionProperties method will be removed in Release 12
+    @CountCmHandleSearchExecution(methodName = "searchCmHandles", interfaceName = "CPS-E-05",
+        description = "Search for cm handles within CPS-E-05 interface")
     public ResponseEntity<List<RestOutputCmHandle>> searchCmHandles(
             final CmHandleQueryParameters cmHandleQueryParameters) {
         final CmHandleQueryApiParameters cmHandleQueryApiParameters =
                 deprecationHelper.mapOldConditionProperties(cmHandleQueryParameters);
-        final Set<NcmpServiceCmHandle> cmHandles = networkCmProxyDataService
-                .executeCmHandleSearch(cmHandleQueryApiParameters);
-        final List<RestOutputCmHandle> outputCmHandles =
-                cmHandles.stream().map(this::toRestOutputCmHandle).collect(Collectors.toList());
-        return ResponseEntity.ok(outputCmHandles);
+        final List<RestOutputCmHandle> restOutputCmHandles =
+                networkCmProxyInventoryFacade.northboundCmHandleSearch(cmHandleQueryApiParameters)
+                        .map(ncmpServiceCmHandle -> restOutputCmHandleMapper
+                                .toRestOutputCmHandle(ncmpServiceCmHandle, false)).collectList().block();
+        return ResponseEntity.ok(restOutputCmHandles);
     }
 
     /**
-     * Query and return cm handle ids that match the given query parameters.
+     * Query and return cm handle ids or alternate ids that match the given query parameters.
      *
-     * @param cmHandleQueryParameters the cm handle query parameters
-     * @return collection of cm handle ids
+     * @param cmHandleQueryParameters   the cm handle query parameters
+     * @param outputAlternateId         Boolean for cm handle reference type either
+     *                                  cm handle id (false or null) or alternate id (true)
+     * @return                          collection of cm handle ids
      */
     @Override
-    public ResponseEntity<List<String>> searchCmHandleIds(
-            final CmHandleQueryParameters cmHandleQueryParameters) {
+    @CountCmHandleSearchExecution(methodName = "searchCmHandleIds", interfaceName = "CPS-E-05",
+            description = "Search for cm handles within CPS-E-05 interface")
+    public ResponseEntity<List<String>> searchCmHandleIds(final CmHandleQueryParameters cmHandleQueryParameters,
+                                                          final Boolean outputAlternateId) {
         final CmHandleQueryApiParameters cmHandleQueryApiParameters =
                 jsonObjectMapper.convertToValueType(cmHandleQueryParameters, CmHandleQueryApiParameters.class);
-        final Set<String> cmHandleIds = networkCmProxyDataService.executeCmHandleIdSearch(cmHandleQueryApiParameters);
+        final Collection<String> cmHandleIds
+            = networkCmProxyInventoryFacade.northboundCmHandleIdSearch(cmHandleQueryApiParameters, outputAlternateId);
         return ResponseEntity.ok(List.copyOf(cmHandleIds));
     }
 
     /**
      * Search for Cm Handle and Properties by Name.
      *
-     * @param cmHandleId cm-handle identifier
+     * @param cmHandleReference cm-handle or alternate identifier
      * @return cm handle and its properties
      */
     @Override
-    public ResponseEntity<RestOutputCmHandle> retrieveCmHandleDetailsById(final String cmHandleId) {
-        final NcmpServiceCmHandle ncmpServiceCmHandle = networkCmProxyDataService.getNcmpServiceCmHandle(cmHandleId);
-        final RestOutputCmHandle restOutputCmHandle = toRestOutputCmHandle(ncmpServiceCmHandle);
+    public ResponseEntity<RestOutputCmHandle> retrieveCmHandleDetailsById(final String cmHandleReference) {
+        final NcmpServiceCmHandle ncmpServiceCmHandle
+            = networkCmProxyInventoryFacade.getNcmpServiceCmHandle(cmHandleReference);
+        final RestOutputCmHandle restOutputCmHandle = restOutputCmHandleMapper
+                .toRestOutputCmHandle(ncmpServiceCmHandle, false);
         return ResponseEntity.ok(restOutputCmHandle);
     }
 
     /**
-     * Get Cm Handle Properties by Cm Handle Id.
+     * Get Cm Handle Properties by Cm Handle or alternate Identifier.
      *
-     * @param cmHandleId cm-handle identifier
+     * @param cmHandleReference cm-handle or alternate identifier
      * @return cm handle properties
      */
     @Override
-    public ResponseEntity<RestOutputCmHandlePublicProperties> getCmHandlePublicPropertiesByCmHandleId(
-            final String cmHandleId) {
-        final CmHandlePublicProperties cmHandlePublicProperties = new CmHandlePublicProperties();
-        cmHandlePublicProperties.add(networkCmProxyDataService.getCmHandlePublicProperties(cmHandleId));
-        final RestOutputCmHandlePublicProperties restOutputCmHandlePublicProperties =
-                new RestOutputCmHandlePublicProperties();
-        restOutputCmHandlePublicProperties.setPublicCmHandleProperties(cmHandlePublicProperties);
-        return ResponseEntity.ok(restOutputCmHandlePublicProperties);
+    public ResponseEntity<RestOutputPublicCmHandleProperties> getPublicCmHandlePropertiesByCmHandleId(
+            final String cmHandleReference) {
+        final List<Map<String, String>> publicCmHandleProperties = new ArrayList<>(1);
+        publicCmHandleProperties.add(networkCmProxyInventoryFacade.getPublicCmHandleProperties(cmHandleReference));
+        final RestOutputPublicCmHandleProperties restOutputPublicCmHandleProperties =
+                new RestOutputPublicCmHandleProperties();
+        restOutputPublicCmHandleProperties.setPublicCmHandleProperties(publicCmHandleProperties);
+        return ResponseEntity.ok(restOutputPublicCmHandleProperties);
     }
 
     /**
      * Get Cm Handle State by Cm Handle Id.
      *
-     * @param cmHandleId cm-handle identifier
+     * @param cmHandleReference cm-handle or alternate identifier
      * @return cm handle state
      */
     @Override
     public ResponseEntity<RestOutputCmHandleCompositeState> getCmHandleStateByCmHandleId(
-            final String cmHandleId) {
-        final CompositeState cmHandleState = networkCmProxyDataService.getCmHandleCompositeState(cmHandleId);
+            final String cmHandleReference) {
+        final CompositeState cmHandleState = networkCmProxyInventoryFacade.getCmHandleCompositeState(cmHandleReference);
         final RestOutputCmHandleCompositeState restOutputCmHandleCompositeState =
                 new RestOutputCmHandleCompositeState();
         restOutputCmHandleCompositeState.setState(
@@ -278,29 +342,45 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
     }
 
     /**
-     * Return module definitions for a cm handle.
+     * Return module definitions.
      *
-     * @param cmHandleId cm-handle identifier
+     * @param cmHandleReference   cm handle or alternate id identifier
+     * @param moduleName          module name
+     * @param revision            the revision of the module
      * @return list of module definitions (module name, revision, yang resource content)
      */
     @Override
-    public ResponseEntity<List<RestModuleDefinition>> getModuleDefinitionsByCmHandleId(final String cmHandleId) {
-        final List<RestModuleDefinition> restModuleDefinitions =
-                networkCmProxyDataService.getModuleDefinitionsByCmHandleId(cmHandleId).stream()
-                        .map(ncmpRestInputMapper::toRestModuleDefinition)
-                        .collect(Collectors.toList());
-        return new ResponseEntity<>(restModuleDefinitions, HttpStatus.OK);
+    public ResponseEntity<List<RestModuleDefinition>> getModuleDefinitions(final String cmHandleReference,
+                                                                           final String moduleName,
+                                                                           final String revision) {
+        final Collection<ModuleDefinition> moduleDefinitions;
+        if (StringUtils.hasText(moduleName)) {
+            moduleDefinitions =
+                networkCmProxyInventoryFacade.getModuleDefinitionsByCmHandleAndModule(cmHandleReference,
+                    moduleName, revision);
+        } else {
+            moduleDefinitions =
+                networkCmProxyInventoryFacade.getModuleDefinitionsByCmHandleReference(cmHandleReference);
+            if (StringUtils.hasText(revision)) {
+                log.warn("Ignoring revision filter as no module name is provided");
+            }
+        }
+        final List<RestModuleDefinition> response = new ArrayList<>();
+        for (final ModuleDefinition moduleDefinition: moduleDefinitions) {
+            response.add(ncmpRestInputMapper.toRestModuleDefinition(moduleDefinition));
+        }
+        return new ResponseEntity<>(response, HttpStatus.OK);
     }
 
     /**
      * Return module references for a cm handle.
      *
-     * @param cmHandle the cm handle
+     * @param cmHandleReference cm handle or alternate id identifier
      * @return module references for cm handle. Namespace will be always blank because restConf does not include this.
      */
-    public ResponseEntity<List<RestModuleReference>> getModuleReferencesByCmHandle(final String cmHandle) {
+    public ResponseEntity<List<RestModuleReference>> getModuleReferencesByCmHandle(final String cmHandleReference) {
         final List<RestModuleReference> restModuleReferences =
-                networkCmProxyDataService.getYangResourcesModuleReferences(cmHandle).stream()
+            networkCmProxyInventoryFacade.getYangResourcesModuleReferences(cmHandleReference).stream()
                         .map(ncmpRestInputMapper::toRestModuleReference)
                         .collect(Collectors.toList());
         return new ResponseEntity<>(restModuleReferences, HttpStatus.OK);
@@ -316,28 +396,17 @@ 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);
     }
 
+    private void validateDataStore(final DatastoreType acceptableDataStoreType, final String requestedDatastoreName) {
+        final DatastoreType datastoreType = DatastoreType.fromDatastoreName(requestedDatastoreName);
 
-    private RestOutputCmHandle toRestOutputCmHandle(final NcmpServiceCmHandle ncmpServiceCmHandle) {
-        final RestOutputCmHandle restOutputCmHandle = new RestOutputCmHandle();
-        final CmHandlePublicProperties cmHandlePublicProperties = new CmHandlePublicProperties();
-        restOutputCmHandle.setCmHandle(ncmpServiceCmHandle.getCmHandleId());
-        cmHandlePublicProperties.add(ncmpServiceCmHandle.getPublicProperties());
-        restOutputCmHandle.setPublicCmHandleProperties(cmHandlePublicProperties);
-        restOutputCmHandle.setState(cmHandleStateMapper.toCmHandleCompositeStateExternalLockReason(
-                ncmpServiceCmHandle.getCompositeState()));
-        return restOutputCmHandle;
-    }
-
-    private void acceptPassthroughRunningOnly(final String datastoreName) {
-        final DatastoreType datastoreType = DatastoreType.fromDatastoreName(datastoreName);
-
-        if (DatastoreType.PASSTHROUGH_RUNNING != datastoreType) {
-            throw new InvalidDatastoreException(datastoreName + " is not supported");
+        if (acceptableDataStoreType != datastoreType) {
+            throw new InvalidDatastoreException(requestedDatastoreName + " is not supported");
         }
     }
+
 }