/*
* ============LICENSE_START=======================================================
* Copyright (C) 2021 Pantheon.tech
- * Modifications (C) 2021-2022 Nordix Foundation
+ * Modifications Copyright (C) 2021-2022 Nordix Foundation
* Modification Copyright (C) 2021 highstreet technologies GmbH
* Modifications (C) 2021 Bell Canada
* ================================================================================
* 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.
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 com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.stream.Collectors;
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;
import org.onap.cps.ncmp.rest.model.CmHandleProperties;
import org.onap.cps.ncmp.rest.model.CmHandleProperty;
+import org.onap.cps.ncmp.rest.model.CmHandlePublicProperties;
import org.onap.cps.ncmp.rest.model.CmHandles;
import org.onap.cps.ncmp.rest.model.ConditionProperties;
import org.onap.cps.ncmp.rest.model.Conditions;
import org.onap.cps.ncmp.rest.model.ModuleNameAsJsonObject;
import org.onap.cps.ncmp.rest.model.ModuleNamesAsJsonArray;
-import org.onap.cps.ncmp.rest.model.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;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
@Slf4j
@RestController
@RequestMapping("${rest.api.ncmp-base-path}")
+@RequiredArgsConstructor
public class NetworkCmProxyController implements NetworkCmProxyApi {
- private static final Gson GSON = new GsonBuilder().create();
private static final String NO_BODY = null;
- private final ModelMapper modelMapper = new ModelMapper();
private final NetworkCmProxyDataService networkCmProxyDataService;
-
- /**
- * Constructor Injection for Dependencies.
- * @param networkCmProxyDataService Data Service Interface
- */
- public NetworkCmProxyController(final NetworkCmProxyDataService networkCmProxyDataService) {
- this.networkCmProxyDataService = networkCmProxyDataService;
- }
+ private final JsonObjectMapper jsonObjectMapper;
+ private final NcmpRestInputMapper ncmpRestInputMapper;
/**
* Get resource data from operational datastore.
* @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);
}
* @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);
}
public ResponseEntity<Object> patchResourceDataRunningForCmHandle(final String resourceIdentifier,
final String cmHandle,
final Object requestBody, final String contentType) {
- networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
- resourceIdentifier, PATCH, GSON.toJson(requestBody), contentType);
- return new ResponseEntity<>(HttpStatus.OK);
+ final Object responseObject = networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
+ resourceIdentifier, PATCH, jsonObjectMapper.asJsonString(requestBody), contentType);
+ return ResponseEntity.ok(responseObject);
}
/**
public ResponseEntity<Void> createResourceDataRunningForCmHandle(final String resourceIdentifier,
final String cmHandle, final Object requestBody, final String contentType) {
networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
- resourceIdentifier, CREATE, GSON.toJson(requestBody), contentType);
+ resourceIdentifier, CREATE, jsonObjectMapper.asJsonString(requestBody), contentType);
return new ResponseEntity<>(HttpStatus.CREATED);
}
final Object requestBody,
final String contentType) {
networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
- resourceIdentifier, UPDATE, GSON.toJson(requestBody), contentType);
+ resourceIdentifier, UPDATE, jsonObjectMapper.asJsonString(requestBody), contentType);
return new ResponseEntity<>(HttpStatus.OK);
}
return ResponseEntity.ok(cmHandles);
}
+ /**
+ * Search for Cm Handle and Properties by Name.
+ * @param cmHandleId cm-handle 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);
+ return ResponseEntity.ok(restOutputCmHandle);
+ }
+
/**
* 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) {
}
return cmHandleProperties;
}
+
+ 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);
+ return restOutputCmHandle;
+ }
}