Sonar fix- RestMusicVersionAPI.java
[music.git] / src / main / java / org / onap / music / rest / RestMusicVersionAPI.java
1 /*
2  * ============LICENSE_START==========================================
3  * org.onap.music
4  * ===================================================================
5  *  Copyright (c) 2017 AT&T Intellectual Property
6  *
7  *  Modifications Copyright (C) 2019 IBM.
8  * ===================================================================
9  *  Licensed under the Apache License, Version 2.0 (the "License");
10  *  you may not use this file except in compliance with the License.
11  *  You may obtain a copy of the License at
12  * 
13  *     http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  *  Unless required by applicable law or agreed to in writing, software
16  *  distributed under the License is distributed on an "AS IS" BASIS,
17  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  *  See the License for the specific language governing permissions and
19  *  limitations under the License.
20  * 
21  * ============LICENSE_END=============================================
22  * ====================================================================
23  */
24
25 package org.onap.music.rest;
26
27 import java.util.Map;
28
29 import javax.servlet.http.HttpServletResponse;
30 import javax.ws.rs.GET;
31 import javax.ws.rs.Path;
32 import javax.ws.rs.Produces;
33 import javax.ws.rs.core.Context;
34 import javax.ws.rs.core.MediaType;
35
36 import org.onap.music.response.jsonobjects.JsonResponse;
37 import org.onap.music.eelf.logging.EELFLoggerDelegate;
38 import org.onap.music.main.MusicUtil;
39 import org.onap.music.main.ResultType;
40
41 import io.swagger.annotations.Api;
42 import io.swagger.annotations.ApiOperation;
43
44
45 @Path("/v{version: [0-9]+}/version")
46 @Api(value="Version Api")
47 public class RestMusicVersionAPI {
48
49     private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestMusicVersionAPI.class);
50     private static final String MUSIC_KEY = "MUSIC:";
51     /**
52      * Get the version of MUSIC.
53      * @return
54      */
55     @GET
56     @ApiOperation(value = "Get Version", response = Map.class)
57     @Produces(MediaType.APPLICATION_JSON)
58     public Map<String,Object> version(@Context HttpServletResponse response) {
59         logger.info("Replying to request for MUSIC version with MUSIC:" + MusicUtil.getVersion());
60         response.addHeader("X-latestVersion",MusicUtil.getVersion());
61         return new JsonResponse(ResultType.SUCCESS).
62             setMusicVersion(MUSIC_KEY + MusicUtil.getVersion()).toMap();
63     }
64
65     /**
66      * Get the version of MUSIC.
67      * @return
68      */
69     @GET
70     @Path("/build")
71     @ApiOperation(value = "Get Version", response = Map.class)
72     @Produces(MediaType.APPLICATION_JSON)
73     public Map<String,Object> build(@Context HttpServletResponse response) {
74         logger.info("Replying to request for MUSIC build with MUSIC:" + MusicUtil.getBuild());
75         response.addHeader("X-latestVersion",MusicUtil.getVersion());
76         return new JsonResponse(ResultType.SUCCESS)
77             .setMusicBuild(MUSIC_KEY + MusicUtil.getBuild())
78             .setMusicVersion(MUSIC_KEY + MusicUtil.getVersion()).toMap();
79     }
80
81
82 }