More sonar fixes in models
[policy/models.git] / models-interactions / model-simulators / src / main / java / org / onap / policy / simulators / SoSimulatorJaxRs.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * simulators
4  * ================================================================================
5  * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2019 Nordix Foundation.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.simulators;
23
24 import com.google.gson.Gson;
25
26 import java.util.UUID;
27 import javax.ws.rs.Consumes;
28 import javax.ws.rs.DELETE;
29 import javax.ws.rs.POST;
30 import javax.ws.rs.Path;
31 import javax.ws.rs.PathParam;
32 import javax.ws.rs.Produces;
33 import javax.ws.rs.core.MediaType;
34 import org.onap.policy.so.SoRequest;
35 import org.onap.policy.so.SoRequestReferences;
36 import org.onap.policy.so.SoRequestStatus;
37 import org.onap.policy.so.SoResponse;
38
39
40 @Path("/")
41 public class SoSimulatorJaxRs {
42
43     /**
44      * SO post query.
45      *
46      * @param serviceInstanceId the service instance Id
47      * @param vnfInstanceId the VNF Id
48      * @return the response
49      */
50     @POST
51     @Path("/serviceInstantiation/v7/serviceInstances/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/scaleOut")
52     @Consumes(MediaType.APPLICATION_JSON)
53     @Produces("application/json")
54     public String soPostQuery(@PathParam("serviceInstanceId") final String serviceInstanceId,
55                     @PathParam("vnfInstanceId") final String vnfInstanceId) {
56         return makeCompleteSuccess();
57     }
58
59     /**
60      * SO Delete.
61      *
62      * @param serviceInstanceId the service instance Id
63      * @param vnfInstanceId the VNF Id
64      * @return the response
65      */
66     @DELETE
67     @Path("/serviceInstances/v7/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/{vfModuleInstanceId}")
68     @Consumes(MediaType.APPLICATION_JSON)
69     @Produces("application/json")
70     public String soDelete(@PathParam("serviceInstanceId") final String serviceInstanceId,
71                     @PathParam("vnfInstanceId") final String vnfInstanceId,
72                     @PathParam("vfModuleInstanceId") final String vfModuleInstanceId) {
73         return makeCompleteSuccess();
74     }
75
76     private String makeCompleteSuccess() {
77         final SoRequest request = new SoRequest();
78         final SoRequestStatus requestStatus = new SoRequestStatus();
79         requestStatus.setRequestState("COMPLETE");
80         request.setRequestStatus(requestStatus);
81         request.setRequestId(UUID.randomUUID());
82
83         final SoResponse response = new SoResponse();
84
85         final SoRequestReferences requestReferences = new SoRequestReferences();
86         final String requestId = UUID.randomUUID().toString();
87         requestReferences.setRequestId(requestId);
88         response.setRequestReferences(requestReferences);
89
90         response.setRequest(request);
91
92         return new Gson().toJson(response);
93     }
94 }