2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Bell Canada
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 package org.onap.cps.ncmp.rest.controller;
23 import com.fasterxml.jackson.databind.ObjectMapper;
24 import javax.validation.Valid;
25 import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
26 import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
27 import org.onap.cps.ncmp.rest.api.NetworkCmProxyInventoryApi;
28 import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration;
29 import org.springframework.http.HttpStatus;
30 import org.springframework.http.ResponseEntity;
31 import org.springframework.web.bind.annotation.RequestMapping;
32 import org.springframework.web.bind.annotation.RestController;
35 @RequestMapping("${rest.api.ncmp-inventory-base-path}")
36 public class NetworkCmProxyInventoryController implements NetworkCmProxyInventoryApi {
38 private final NetworkCmProxyDataService networkCmProxyDataService;
39 private final ObjectMapper objectMapper;
42 * Constructor Injection for Dependencies.
43 * @param networkCmProxyDataService Data Service Interface
44 * @param objectMapper Object Mapper
46 public NetworkCmProxyInventoryController(final NetworkCmProxyDataService networkCmProxyDataService,
47 final ObjectMapper objectMapper) {
48 this.networkCmProxyDataService = networkCmProxyDataService;
49 this.objectMapper = objectMapper;
53 * Update DMI Plugin Registration (used for first registration also).
54 * @param restDmiPluginRegistration the registration data
57 public ResponseEntity<Void> updateDmiPluginRegistration(
58 final @Valid RestDmiPluginRegistration restDmiPluginRegistration) {
59 final DmiPluginRegistration dmiPluginRegistration =
60 convertRestObjectToJavaApiObject(restDmiPluginRegistration);
61 networkCmProxyDataService.updateDmiRegistrationAndSyncModule(dmiPluginRegistration);
62 return new ResponseEntity<>(HttpStatus.CREATED);
65 private DmiPluginRegistration convertRestObjectToJavaApiObject(
66 final RestDmiPluginRegistration restDmiPluginRegistration) {
67 return objectMapper.convertValue(restDmiPluginRegistration, DmiPluginRegistration.class);