2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ============LICENSE_END=========================================================
21 package org.onap.dmaap.dbcapi.resources;
23 import io.swagger.annotations.Api;
24 import io.swagger.annotations.ApiOperation;
25 import io.swagger.annotations.ApiResponse;
26 import io.swagger.annotations.ApiResponses;
28 import java.util.List;
30 import javax.ws.rs.Consumes;
31 import javax.ws.rs.DELETE;
32 import javax.ws.rs.GET;
33 import javax.ws.rs.POST;
34 import javax.ws.rs.PUT;
35 import javax.ws.rs.Path;
36 import javax.ws.rs.PathParam;
37 import javax.ws.rs.Produces;
38 import javax.ws.rs.core.GenericEntity;
39 import javax.ws.rs.core.MediaType;
40 import javax.ws.rs.core.Response;
42 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
43 import org.onap.dmaap.dbcapi.model.ApiError;
44 import org.onap.dmaap.dbcapi.model.DR_Node;
45 import org.onap.dmaap.dbcapi.service.DR_NodeService;
47 import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
48 import static javax.ws.rs.core.Response.Status.NO_CONTENT;
51 @Api( value= "dr_nodes", description = "Endpoint for a Data Router Node server" )
52 @Consumes(MediaType.APPLICATION_JSON)
53 @Produces(MediaType.APPLICATION_JSON)
55 public class DR_NodeResource extends BaseLoggingClass {
57 private DR_NodeService dr_nodeService = new DR_NodeService();
58 private ResponseBuilder responseBuilder = new ResponseBuilder();
59 private RequiredChecker checker = new RequiredChecker();
62 @ApiOperation( value = "return DR_Node details",
63 notes = "Returns array of `DR_Node` object array. Need to add filter by dcaeLocation.",
64 response = DR_Node.class)
65 @ApiResponses( value = {
66 @ApiResponse( code = 200, message = "Success", response = DR_Node.class),
67 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
69 public Response getDr_Nodes() {
70 List<DR_Node> nodes = dr_nodeService.getAllDr_Nodes();
72 GenericEntity<List<DR_Node>> list = new GenericEntity<List<DR_Node>>(nodes) {
74 return responseBuilder.success(list);
78 @ApiOperation( value = "return DR_Node details",
79 notes = "create a `DR_Node` in a *dcaeLocation*. Note that multiple `DR_Node`s may exist in the same `dcaeLocation`.",
80 response = DR_Node.class)
81 @ApiResponses( value = {
82 @ApiResponse( code = 200, message = "Success", response = DR_Node.class),
83 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
85 public Response addDr_Node(DR_Node node) {
87 ApiError apiError = new ApiError();
90 checker.required( "dcaeLocation", node.getDcaeLocationName());
91 checker.required( "fqdn", node.getFqdn());
92 } catch ( RequiredFieldException rfe ) {
93 return responseBuilder.error(new ApiError(BAD_REQUEST.getStatusCode(),
94 "missing required field", "dcaeLocation, fqdn"));
96 DR_Node nNode = dr_nodeService.addDr_Node(node, apiError);
97 if (apiError.is2xx()) {
98 return responseBuilder.success(nNode);
100 return responseBuilder.error(apiError);
104 @ApiOperation( value = "return DR_Node details",
105 notes = "Update a single `DR_Node` object.",
106 response = DR_Node.class)
107 @ApiResponses( value = {
108 @ApiResponse( code = 200, message = "Success", response = DR_Node.class),
109 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
112 public Response updateDr_Node(@PathParam("fqdn") String name, DR_Node node) {
114 ApiError apiError = new ApiError();
117 checker.required( "dcaeLocation", node.getDcaeLocationName());
118 checker.required( "fqdn", node.getFqdn());
119 } catch ( RequiredFieldException rfe ) {
120 return responseBuilder.error(new ApiError(BAD_REQUEST.getStatusCode(),
121 "missing required field", "dcaeLocation, fqdn"));
124 DR_Node nNode = dr_nodeService.updateDr_Node(node, apiError);
125 if (apiError.is2xx()) {
126 return responseBuilder.success(nNode);
128 return responseBuilder.error(apiError);
132 @ApiOperation( value = "No Content",
133 notes = "Delete a single `DR_Node` object.",
134 response = DR_Node.class)
135 @ApiResponses( value = {
136 @ApiResponse( code = 204, message = "Success", response = DR_Node.class),
137 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
140 public Response deleteDr_Node(
141 @PathParam("fqdn") String name){
144 ApiError apiError = new ApiError();
146 dr_nodeService.removeDr_Node(name, apiError);
147 if (apiError.is2xx()) {
148 return responseBuilder.success(NO_CONTENT.getStatusCode(), null);
150 return responseBuilder.error(apiError);
154 @ApiOperation( value = "return DR_Node details",
155 notes = "Retrieve a single `DR_Node` object.",
156 response = DR_Node.class)
157 @ApiResponses( value = {
158 @ApiResponse( code = 200, message = "Success", response = DR_Node.class),
159 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
162 public Response get(@PathParam("fqdn") String name) {
164 ApiError apiError = new ApiError();
166 DR_Node nNode = dr_nodeService.getDr_Node( name, apiError );
167 if (apiError.is2xx()) {
168 return responseBuilder.success(nNode);
170 return responseBuilder.error(apiError);