Near-RT-RIC Simualator & README files
[nonrtric.git] / near-rt-ric-simulator / nearric-simulator / nearric-service / src / main / java / org / onap / nearric / simulator / controller / A1PApiController.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.nearric.simulator.controller;
22
23 import java.lang.reflect.InvocationTargetException;
24 import java.util.ArrayList;
25 import java.util.List;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.validation.Valid;
28
29 import org.apache.commons.beanutils.BeanUtils;
30 import org.onap.nearric.simulator.model.PolicyType;
31 import org.onap.nearric.simulator.service.A1PApiServiceImpl;
32 import org.oransc.ric.a1med.api.model.InlineResponse200;
33 import org.oransc.ric.a1med.api.model.PolicyTypeSchema;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.http.HttpStatus;
38 import org.springframework.http.ResponseEntity;
39 import org.springframework.web.bind.annotation.PathVariable;
40 import org.springframework.web.bind.annotation.RequestBody;
41 import org.springframework.web.bind.annotation.RestController;
42 import com.fasterxml.jackson.databind.ObjectMapper;
43
44 import io.swagger.annotations.ApiParam;
45
46 /**
47  * This class provides all the operation performed by A1 API.
48  * 
49  * @author lathishbabu.ganesan@est.tech
50  *
51  */
52 @RestController
53 public class A1PApiController implements A1PApi {
54
55   private static final Logger log = LoggerFactory.getLogger(A1PApiController.class);
56
57   private final ObjectMapper objectMapper;
58
59   private final HttpServletRequest request;
60
61   //@Autowired
62   private A1PApiServiceImpl a1pApiService;
63   //private A1PApiService a1pApiService;
64
65   @Autowired
66   public A1PApiController(ObjectMapper objectMapper, HttpServletRequest request) {
67       this.objectMapper = objectMapper;
68       this.request = request;
69       a1pApiService = new A1PApiServiceImpl();
70       a1pApiService.set(objectMapper, request);
71   }
72   
73   public ResponseEntity<Void> a1ControllerCreateOrReplacePolicyInstance(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "",required=true) @PathVariable("policy_instance_id") String policyInstanceId,@ApiParam(value = ""  )  @Valid @RequestBody Object body) {
74       return a1pApiService.createReplaceInstance(policyTypeId, policyInstanceId, body);
75   }
76
77   public ResponseEntity<Void> a1ControllerCreatePolicyType(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = ""  )  @Valid @RequestBody PolicyTypeSchema body) {
78         return a1pApiService.createReplaceType(policyTypeId, body);
79   }
80
81   public ResponseEntity<Void> a1ControllerDeletePolicyInstance(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "",required=true) @PathVariable("policy_instance_id") String policyInstanceId) {
82         return a1pApiService.deleteInstance(policyTypeId, policyInstanceId);
83   }
84
85   public ResponseEntity<Void> a1ControllerDeletePolicyType(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId) {
86         return a1pApiService.deleteType(policyTypeId);
87   }
88
89   public ResponseEntity<List<String>> a1ControllerGetAllInstancesForType(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId) {
90       return a1pApiService.getAllInstanceForType(policyTypeId);
91   }
92
93   public ResponseEntity<List<Integer>> a1ControllerGetAllPolicyTypes() {
94         return a1pApiService.getAllTypes();
95   }
96
97   public ResponseEntity<Void> a1ControllerGetHealthcheck() {
98       String accept = request.getHeader("Accept");
99       return new ResponseEntity<Void>(HttpStatus.ACCEPTED);
100   }
101
102   public ResponseEntity<Object> a1ControllerGetPolicyInstance(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "",required=true) @PathVariable("policy_instance_id") String policyInstanceId) {
103       return a1pApiService.getPolicyInstance(policyTypeId, policyInstanceId);
104   }
105
106   public ResponseEntity<List<InlineResponse200>> a1ControllerGetPolicyInstanceStatus(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "",required=true) @PathVariable("policy_instance_id") String policyInstanceId) {
107         return a1pApiService.getStatus(policyTypeId, policyInstanceId);
108   }
109
110   public ResponseEntity<PolicyTypeSchema> a1ControllerGetPolicyType(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId) {
111       return a1pApiService.getPolicyTypeSchema(policyTypeId);
112   }
113
114 }