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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.nearric.simulator.controller;
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;
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 import org.springframework.web.bind.annotation.RequestMapping;
44 import org.springframework.web.bind.annotation.RequestMethod;
46 import io.swagger.annotations.ApiParam;
49 * This class provides all the operation performed by A1 API.
51 * @author lathishbabu.ganesan@est.tech
55 public class A1PApiController implements A1PApi {
57 private static final Logger log = LoggerFactory.getLogger(A1PApiController.class);
59 private final ObjectMapper objectMapper;
61 private final HttpServletRequest request;
64 private A1PApiServiceImpl a1pApiService;
65 //private A1PApiService a1pApiService;
68 public A1PApiController(ObjectMapper objectMapper, HttpServletRequest request) {
69 this.objectMapper = objectMapper;
70 this.request = request;
71 a1pApiService = new A1PApiServiceImpl();
72 a1pApiService.set(objectMapper, request);
76 @RequestMapping(value = "reset",
77 method = RequestMethod.GET)
79 a1pApiService.reset();
82 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) {
83 return a1pApiService.createReplaceInstance(policyTypeId, policyInstanceId, body);
86 public ResponseEntity<Void> a1ControllerCreatePolicyType(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "" ) @Valid @RequestBody PolicyTypeSchema body) {
87 return a1pApiService.createReplaceType(policyTypeId, body);
90 public ResponseEntity<Void> a1ControllerDeletePolicyInstance(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "",required=true) @PathVariable("policy_instance_id") String policyInstanceId) {
91 return a1pApiService.deleteInstance(policyTypeId, policyInstanceId);
94 public ResponseEntity<Void> a1ControllerDeletePolicyType(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId) {
95 return a1pApiService.deleteType(policyTypeId);
98 public ResponseEntity<List<String>> a1ControllerGetAllInstancesForType(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId) {
99 return a1pApiService.getAllInstanceForType(policyTypeId);
102 public ResponseEntity<List<Integer>> a1ControllerGetAllPolicyTypes() {
103 return a1pApiService.getAllTypes();
106 public ResponseEntity<Void> a1ControllerGetHealthcheck() {
107 return new ResponseEntity<Void>(HttpStatus.OK);
110 public ResponseEntity<Object> a1ControllerGetPolicyInstance(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "",required=true) @PathVariable("policy_instance_id") String policyInstanceId) {
111 return a1pApiService.getPolicyInstance(policyTypeId, policyInstanceId);
114 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) {
115 return a1pApiService.getStatus(policyTypeId, policyInstanceId);
118 public ResponseEntity<PolicyTypeSchema> a1ControllerGetPolicyType(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId) {
119 return a1pApiService.getPolicyTypeSchema(policyTypeId);