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