9e888fb1c5cb5ff93a01329befd677469320c495
[cps.git] / cps-ncmp-rest / src / main / java / org / onap / cps / ncmp / rest / controller / NetworkCmProxyInventoryController.java
1 /*
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
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21
22 package org.onap.cps.ncmp.rest.controller;
23
24
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;
36
37 @RestController
38 @RequestMapping("${rest.api.ncmp-inventory-base-path}")
39 @RequiredArgsConstructor
40 public class NetworkCmProxyInventoryController implements NetworkCmProxyInventoryApi {
41
42     private final NetworkCmProxyDataService networkCmProxyDataService;
43     private final ObjectMapper objectMapper;
44
45     /**
46      * Update DMI Plugin Registration (used for first registration also).
47      * @param restDmiPluginRegistration the registration data
48      */
49     @Override
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);
56     }
57
58     private DmiPluginRegistration convertRestObjectToJavaApiObject(
59         final RestDmiPluginRegistration restDmiPluginRegistration) {
60         return objectMapper.convertValue(restDmiPluginRegistration, DmiPluginRegistration.class);
61     }
62 }