Fix the sonar issue of esr-server.
[aai/esr-server.git] / esr-mgr / src / main / java / org / onap / aai / esr / resource / EmsManager.java
1 /**
2  * Copyright 2016-2017 ZTE Corporation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.aai.esr.resource;
17
18 import com.codahale.metrics.annotation.Timed;
19 import io.swagger.annotations.Api;
20 import io.swagger.annotations.ApiOperation;
21 import io.swagger.annotations.ApiParam;
22 import io.swagger.annotations.ApiResponse;
23 import io.swagger.annotations.ApiResponses;
24
25 import org.eclipse.jetty.http.HttpStatus;
26 import org.onap.aai.esr.entity.rest.EmsRestData;
27 import org.onap.aai.esr.util.ExtsysUtil;
28 import org.onap.aai.esr.util.RestResponseUtil;
29 import org.onap.aai.esr.wrapper.EmsManagerWrapper;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;  
32
33 import javax.ws.rs.Consumes;
34 import javax.ws.rs.DELETE;
35 import javax.ws.rs.GET;
36 import javax.ws.rs.POST;
37 import javax.ws.rs.PUT;
38 import javax.ws.rs.Path;
39 import javax.ws.rs.PathParam;
40 import javax.ws.rs.Produces;
41 import javax.ws.rs.core.MediaType;
42 import javax.ws.rs.core.Response;
43
44 @Path("/emses")
45 @Api(tags = {" ems Management "})
46 public class EmsManager {
47
48   private static final Logger LOGGER = LoggerFactory.getLogger(EmsManager.class);
49
50   /**
51    * query all ems.
52    */
53   @Path("")
54   @GET
55   @ApiOperation(value = "get  all ems ")
56   @Produces(MediaType.APPLICATION_JSON)
57   @ApiResponses(value = {
58       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
59           response = String.class),
60       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
61           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
62       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
63           response = String.class)})
64   @Timed
65   public Response queryEmsList() {
66     LOGGER.info("start query all ems!");
67     return EmsManagerWrapper.getInstance().queryEmsList();
68   }
69   
70   /**
71    * query  ems info by id.
72    */
73   @Path("/{emsId}")
74   @GET
75   @ApiOperation(value = "get ems by id")
76   @Produces(MediaType.APPLICATION_JSON)
77   @ApiResponses(value = {
78       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
79           response = String.class),
80       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
81           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
82       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
83           response = String.class)})
84   @Timed
85   public Response queryemsById(@ApiParam(value = "ems id") @PathParam("emsId") String emsId) {
86     LOGGER.info("start query  ems by id." + emsId);
87     return EmsManagerWrapper.getInstance().queryEmsById(emsId);
88   }
89   
90   /**
91    * delete ems by id.
92    */
93   @Path("/{emsId}")
94   @DELETE
95   @ApiOperation(value = "delete a ems")
96   @ApiResponses(value = {
97       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
98           response = String.class),
99       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
100           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
101       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
102           response = String.class)})
103   @Timed
104   public Response delems(@ApiParam(value = "ems id") @PathParam("emsId") String emsId) {
105     LOGGER.info("start delete ems .id:" + emsId);
106     return EmsManagerWrapper.getInstance().delEms(emsId);
107   }
108   
109   /**
110    * update ems by id.
111    */
112   @PUT
113   @Path("/{emsId}")
114   @Consumes(MediaType.APPLICATION_JSON)
115   @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
116   @ApiOperation(value = "update a ems")
117   @ApiResponses(value = {
118       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
119           response = String.class),
120       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
121           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
122       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
123           response = String.class)})
124   @Timed
125   public Response updateEms(@ApiParam(value = "ems", required = true) EmsRestData ems,
126       @ApiParam(value = "ems id", required = true) @PathParam("emsId") String emsId) {
127     LOGGER.info("start update ems .id:" + emsId + " info:" + ExtsysUtil.objectToString(ems));
128     return RestResponseUtil.getSuccessResponse(new EmsRestData());
129   }
130   
131   /**
132    * register ems.
133    */
134   @POST
135   @Path("")
136   @Consumes(MediaType.APPLICATION_JSON)
137   @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
138   @ApiOperation(value = "create a ems")
139   @ApiResponses(value = {
140       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
141           response = String.class),
142       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
143           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
144       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
145           response = String.class)})
146   @Timed
147   public Response registerEms(@ApiParam(value = "ems", required = true) EmsRestData ems) {
148     LOGGER.info("start add ems" + " info:" + ExtsysUtil.objectToString(ems));
149     return EmsManagerWrapper.getInstance().registerEms(ems);
150   }
151 }