[cps] Fix getResourceDataForPassthroughOperational endpoint
[cps.git] / cps-ncmp-rest / src / main / java / org / onap / cps / ncmp / rest / controller / NetworkCmProxyController.java
index 86f4460..de6c3c4 100755 (executable)
@@ -3,7 +3,7 @@
  *  Copyright (C) 2021 Pantheon.tech
  *  Modifications Copyright (C) 2021-2022 Nordix Foundation
  *  Modification Copyright (C) 2021 highstreet technologies GmbH
- *  Modifications (C) 2021 Bell Canada
+ *  Modifications (C) 2021-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.
@@ -37,7 +37,6 @@ import javax.validation.Valid;
 import javax.validation.constraints.NotNull;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.modelmapper.ModelMapper;
 import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
 import org.onap.cps.ncmp.rest.api.NetworkCmProxyApi;
@@ -49,7 +48,7 @@ import org.onap.cps.ncmp.rest.model.ConditionProperties;
 import org.onap.cps.ncmp.rest.model.Conditions;
 import org.onap.cps.ncmp.rest.model.ModuleNameAsJsonObject;
 import org.onap.cps.ncmp.rest.model.ModuleNamesAsJsonArray;
-import org.onap.cps.ncmp.rest.model.ModuleReference;
+import org.onap.cps.ncmp.rest.model.RestModuleReference;
 import org.onap.cps.ncmp.rest.model.RestOutputCmHandle;
 import org.onap.cps.utils.JsonObjectMapper;
 import org.springframework.http.HttpStatus;
@@ -65,28 +64,28 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
 
     private static final String NO_BODY = null;
 
-    private final ModelMapper modelMapper;
     private final NetworkCmProxyDataService networkCmProxyDataService;
     private final JsonObjectMapper jsonObjectMapper;
+    private final NcmpRestInputMapper ncmpRestInputMapper;
 
     /**
      * Get resource data from operational datastore.
      *
      * @param cmHandle cm handle identifier
      * @param resourceIdentifier resource identifier
-     * @param acceptParamInHeader accept header parameter
      * @param optionsParamInQuery options query parameter
+     * @param topicParamInQuery topic query parameter
      * @return {@code ResponseEntity} response from dmi plugin
      */
     @Override
     public ResponseEntity<Object> getResourceDataOperationalForCmHandle(final String cmHandle,
                                                                         final @NotNull @Valid String resourceIdentifier,
-                                                                        final String acceptParamInHeader,
-                                                                        final @Valid String optionsParamInQuery) {
+                                                                        final @Valid String optionsParamInQuery,
+                                                                        final @Valid String topicParamInQuery) {
         final Object responseObject = networkCmProxyDataService.getResourceDataOperationalForCmHandle(cmHandle,
                 resourceIdentifier,
-                acceptParamInHeader,
-                optionsParamInQuery);
+                optionsParamInQuery,
+                topicParamInQuery);
         return ResponseEntity.ok(responseObject);
     }
 
@@ -95,19 +94,19 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
      *
      * @param cmHandle cm handle identifier
      * @param resourceIdentifier resource identifier
-     * @param acceptParamInHeader accept header parameter
      * @param optionsParamInQuery options query parameter
+     * @param topicParamInQuery topic query parameter
      * @return {@code ResponseEntity} response from dmi plugin
      */
     @Override
     public ResponseEntity<Object> getResourceDataRunningForCmHandle(final String cmHandle,
                                                                     final @NotNull @Valid String resourceIdentifier,
-                                                                    final String acceptParamInHeader,
-                                                                    final @Valid String optionsParamInQuery) {
+                                                                    final @Valid String optionsParamInQuery,
+                                                                    final @Valid String topicParamInQuery) {
         final Object responseObject = networkCmProxyDataService.getResourceDataPassThroughRunningForCmHandle(cmHandle,
                 resourceIdentifier,
-                acceptParamInHeader,
-                optionsParamInQuery);
+                optionsParamInQuery,
+                topicParamInQuery);
         return ResponseEntity.ok(responseObject);
     }
 
@@ -205,14 +204,14 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
      * Return module references for a cm handle.
      *
      * @param cmHandle the cm handle
-     * @return module references for cm handle
+     * @return module references for cm handle. Namespace will be always blank because restConf does not include this.
      */
-    public ResponseEntity<List<ModuleReference>> getModuleReferencesByCmHandle(final String cmHandle) {
-        final List<ModuleReference> moduleReferences =
+    public ResponseEntity<List<RestModuleReference>> getModuleReferencesByCmHandle(final String cmHandle) {
+        final List<RestModuleReference> restModuleReferences =
             networkCmProxyDataService.getYangResourcesModuleReferences(cmHandle).stream()
-            .map(moduleReference -> modelMapper.map(moduleReference, ModuleReference.class))
+            .map(ncmpRestInputMapper::toRestModuleReference)
                 .collect(Collectors.toList());
-        return new ResponseEntity<>(moduleReferences, HttpStatus.OK);
+        return new ResponseEntity<>(restModuleReferences, HttpStatus.OK);
     }
 
     private Collection<String> processConditions(final List<ConditionProperties> conditionProperties) {