Java 17 Upgrade
[policy/models.git] / models-sim / models-sim-dmaap / src / main / java / org / onap / policy / models / sim / dmaap / rest / DmaapSimRestControllerV1.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019, 2021, 2023 Nordix Foundation.
4  *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
5  *  Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.models.sim.dmaap.rest;
24
25 import jakarta.ws.rs.Consumes;
26 import jakarta.ws.rs.DefaultValue;
27 import jakarta.ws.rs.GET;
28 import jakarta.ws.rs.POST;
29 import jakarta.ws.rs.Path;
30 import jakarta.ws.rs.PathParam;
31 import jakarta.ws.rs.Produces;
32 import jakarta.ws.rs.QueryParam;
33 import jakarta.ws.rs.core.Response;
34 import org.onap.policy.models.sim.dmaap.provider.DmaapSimProvider;
35
36 /**
37  * Class to provide REST endpoints for DMaaP simulator component statistics.
38  */
39 @Path("/")
40 @Produces(DmaapSimRestControllerV1.MEDIA_TYPE_APPLICATION_JSON)
41 public class DmaapSimRestControllerV1 extends BaseRestControllerV1 {
42     public static final String MEDIA_TYPE_APPLICATION_JSON = "application/json";
43
44     /**
45      * Get a DMaaP message.
46      *
47      * @param topicName topic to get message from
48      * @param consumerGroup consumer group that is getting the message
49      * @param consumerId consumer ID that is getting the message
50      * @param timeoutMs timeout for the message
51      * @return the message
52      */
53     @GET
54     @Path("events/{topicName}/{consumerGroup}/{consumerId}")
55     public Response getDmaapMessage(@PathParam("topicName") final String topicName,
56                     @PathParam("consumerGroup") final String consumerGroup,
57                     @PathParam("consumerId") final String consumerId,
58                     @QueryParam("limit") @DefaultValue("1") final int limit,
59                     @QueryParam("timeout") @DefaultValue("15000") final long timeoutMs) {
60
61         return DmaapSimProvider.getInstance().processDmaapMessageGet(topicName, consumerGroup, consumerId, limit,
62                         timeoutMs);
63     }
64
65     /**
66      * Post a DMaaP message.
67      *
68      * @param topicName topic to get message from
69      * @return the response to the post
70      */
71     @POST
72     @Path("events/{topicName}")
73     @Consumes(value = {CambriaMessageBodyHandler.MEDIA_TYPE_APPLICATION_CAMBRIA,
74         TextMessageBodyHandler.MEDIA_TYPE_TEXT_PLAIN, MEDIA_TYPE_APPLICATION_JSON})
75     public Response postDmaapMessage(@PathParam("topicName") final String topicName, final Object dmaapMessage) {
76
77         return DmaapSimProvider.getInstance().processDmaapMessagePut(topicName, dmaapMessage);
78     }
79
80     /**
81      * Get the list of topics configured.
82      *
83      * @return the message
84      */
85     @GET
86     @Path("topics")
87     public Response getDmaapTopics() {
88
89         return DmaapSimProvider.getInstance().processDmaapTopicsGet();
90     }
91 }