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.ApiService;
46 import org.onap.dmaap.dbcapi.service.DR_NodeService;
48 import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
49 import static javax.ws.rs.core.Response.Status.NO_CONTENT;
52 @Api( value= "dr_nodes", description = "Endpoint for a Data Router Node server" )
53 @Consumes(MediaType.APPLICATION_JSON)
54 @Produces(MediaType.APPLICATION_JSON)
56 public class DR_NodeResource extends BaseLoggingClass {
58 private DR_NodeService dr_nodeService = new DR_NodeService();
59 private ResponseBuilder responseBuilder = new ResponseBuilder();
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(
88 ApiService resp = new ApiService();
91 resp.required( "dcaeLocation", node.getDcaeLocationName(), "");
92 resp.required( "fqdn", node.getFqdn(), "");
93 } catch ( RequiredFieldException rfe ) {
94 return responseBuilder.error(new ApiError(BAD_REQUEST.getStatusCode(),
95 "missing required field", "dcaeLocation, fqdn"));
97 DR_Node nNode = dr_nodeService.addDr_Node(node, resp.getErr());
98 if ( resp.getErr().is2xx()) {
99 return responseBuilder.success(nNode);
101 return responseBuilder.error(resp.getErr());
105 @ApiOperation( value = "return DR_Node details",
106 notes = "Update a single `DR_Node` object.",
107 response = DR_Node.class)
108 @ApiResponses( value = {
109 @ApiResponse( code = 200, message = "Success", response = DR_Node.class),
110 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
113 public Response updateDr_Node(
114 @PathParam("fqdn") String name,
117 ApiService resp = new ApiService();
120 resp.required( "dcaeLocation", name, "");
121 resp.required( "fqdn", node.getFqdn(), "");
122 } catch ( RequiredFieldException rfe ) {
123 return responseBuilder.error(resp.getErr());
126 DR_Node nNode = dr_nodeService.updateDr_Node(node, resp.getErr());
127 if ( resp.getErr().is2xx()) {
128 return responseBuilder.success(nNode);
130 return responseBuilder.error(resp.getErr());
134 @ApiOperation( value = "No Content",
135 notes = "Delete a single `DR_Node` object.",
136 response = DR_Node.class)
137 @ApiResponses( value = {
138 @ApiResponse( code = 204, message = "Success", response = DR_Node.class),
139 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
142 public Response deleteDr_Node(
143 @PathParam("fqdn") String name
146 ApiService resp = new ApiService();
149 resp.required( "fqdn", name, "");
150 } catch ( RequiredFieldException rfe ) {
151 logger.debug( resp.toString() );
152 return responseBuilder.error(resp.getErr());
154 dr_nodeService.removeDr_Node(name, resp.getErr());
155 if ( resp.getErr().is2xx() ) {
156 return responseBuilder.success(NO_CONTENT.getStatusCode(), null);
158 return responseBuilder.error(resp.getErr());
162 @ApiOperation( value = "return DR_Node details",
163 notes = "Retrieve a single `DR_Node` object.",
164 response = DR_Node.class)
165 @ApiResponses( value = {
166 @ApiResponse( code = 200, message = "Success", response = DR_Node.class),
167 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
171 @PathParam("fqdn") String name
173 ApiService resp = new ApiService();
175 DR_Node nNode = dr_nodeService.getDr_Node( name, resp.getErr() );
176 if ( resp.getErr().is2xx() ) {
177 return responseBuilder.success(nNode);
179 return responseBuilder.error(resp.getErr());