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;
41 import javax.ws.rs.core.Response.Status;
43 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
44 import org.onap.dmaap.dbcapi.model.ApiError;
45 import org.onap.dmaap.dbcapi.model.DR_Node;
46 import org.onap.dmaap.dbcapi.service.ApiService;
47 import org.onap.dmaap.dbcapi.service.DR_NodeService;
50 @Api( value= "dr_nodes", description = "Endpoint for a Data Router Node server" )
51 @Consumes(MediaType.APPLICATION_JSON)
52 @Produces(MediaType.APPLICATION_JSON)
54 public class DR_NodeResource extends BaseLoggingClass {
56 DR_NodeService dr_nodeService = new DR_NodeService();
59 @ApiOperation( value = "return DR_Node details",
60 notes = "Returns array of `DR_Node` object array. Need to add filter by dcaeLocation.",
61 response = DR_Node.class)
62 @ApiResponses( value = {
63 @ApiResponse( code = 200, message = "Success", response = DR_Node.class),
64 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
66 public Response getDr_Nodes() {
67 ApiService resp = new ApiService();
69 List<DR_Node> nodes = dr_nodeService.getAllDr_Nodes();
71 GenericEntity<List<DR_Node>> list = new GenericEntity<List<DR_Node>>(nodes) {
73 return resp.success(list);
77 @ApiOperation( value = "return DR_Node details",
78 notes = "create a `DR_Node` in a *dcaeLocation*. Note that multiple `DR_Node`s may exist in the same `dcaeLocation`.",
79 response = DR_Node.class)
80 @ApiResponses( value = {
81 @ApiResponse( code = 200, message = "Success", response = DR_Node.class),
82 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
84 public Response addDr_Node(
87 ApiService resp = new ApiService();
90 resp.required( "dcaeLocation", node.getDcaeLocationName(), "");
91 resp.required( "fqdn", node.getFqdn(), "");
92 } catch ( RequiredFieldException rfe ) {
93 resp.setCode(Status.BAD_REQUEST.getStatusCode());
94 resp.setMessage("missing required field");
95 resp.setFields("dcaeLocation, fqdn");
99 DR_Node nNode = dr_nodeService.addDr_Node(node, resp.getErr());
100 if ( resp.getErr().is2xx()) {
101 return resp.success(nNode);
107 @ApiOperation( value = "return DR_Node details",
108 notes = "Update a single `DR_Node` object.",
109 response = DR_Node.class)
110 @ApiResponses( value = {
111 @ApiResponse( code = 200, message = "Success", response = DR_Node.class),
112 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
115 public Response updateDr_Node(
116 @PathParam("fqdn") String name,
119 ApiService resp = new ApiService();
122 resp.required( "dcaeLocation", name, "");
123 resp.required( "fqdn", node.getFqdn(), "");
124 } catch ( RequiredFieldException rfe ) {
128 DR_Node nNode = dr_nodeService.updateDr_Node(node, resp.getErr());
129 if ( resp.getErr().is2xx()) {
130 return resp.success(nNode);
136 @ApiOperation( value = "No Content",
137 notes = "Delete a single `DR_Node` object.",
138 response = DR_Node.class)
139 @ApiResponses( value = {
140 @ApiResponse( code = 204, message = "Success", response = DR_Node.class),
141 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
144 public Response deleteDr_Node(
145 @PathParam("fqdn") String name
148 ApiService resp = new ApiService();
151 resp.required( "fqdn", name, "");
152 } catch ( RequiredFieldException rfe ) {
153 logger.debug( resp.toString() );
156 dr_nodeService.removeDr_Node(name, resp.getErr());
157 if ( resp.getErr().is2xx() ) {
158 return resp.success(Status.NO_CONTENT.getStatusCode(), null);
164 @ApiOperation( value = "return DR_Node details",
165 notes = "Retrieve a single `DR_Node` object.",
166 response = DR_Node.class)
167 @ApiResponses( value = {
168 @ApiResponse( code = 200, message = "Success", response = DR_Node.class),
169 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
173 @PathParam("fqdn") String name
175 ApiService resp = new ApiService();
177 DR_Node nNode = dr_nodeService.getDr_Node( name, resp.getErr() );
178 if ( resp.getErr().is2xx() ) {
179 return resp.success(nNode);