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();
60 private RequiredChecker checker = new RequiredChecker();
63 @ApiOperation( value = "return DR_Node details",
64 notes = "Returns array of `DR_Node` object array. Need to add filter by dcaeLocation.",
65 response = DR_Node.class)
66 @ApiResponses( value = {
67 @ApiResponse( code = 200, message = "Success", response = DR_Node.class),
68 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
70 public Response getDr_Nodes() {
71 List<DR_Node> nodes = dr_nodeService.getAllDr_Nodes();
73 GenericEntity<List<DR_Node>> list = new GenericEntity<List<DR_Node>>(nodes) {
75 return responseBuilder.success(list);
79 @ApiOperation( value = "return DR_Node details",
80 notes = "create a `DR_Node` in a *dcaeLocation*. Note that multiple `DR_Node`s may exist in the same `dcaeLocation`.",
81 response = DR_Node.class)
82 @ApiResponses( value = {
83 @ApiResponse( code = 200, message = "Success", response = DR_Node.class),
84 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
86 public Response addDr_Node(
89 ApiService resp = new ApiService();
92 checker.required( "dcaeLocation", node.getDcaeLocationName());
93 checker.required( "fqdn", node.getFqdn());
94 } catch ( RequiredFieldException rfe ) {
95 return responseBuilder.error(new ApiError(BAD_REQUEST.getStatusCode(),
96 "missing required field", "dcaeLocation, fqdn"));
98 DR_Node nNode = dr_nodeService.addDr_Node(node, resp.getErr());
99 if ( resp.getErr().is2xx()) {
100 return responseBuilder.success(nNode);
102 return responseBuilder.error(resp.getErr());
106 @ApiOperation( value = "return DR_Node details",
107 notes = "Update a single `DR_Node` object.",
108 response = DR_Node.class)
109 @ApiResponses( value = {
110 @ApiResponse( code = 200, message = "Success", response = DR_Node.class),
111 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
114 public Response updateDr_Node(
115 @PathParam("fqdn") String name,
118 ApiService resp = new ApiService();
121 checker.required( "dcaeLocation", name);
122 checker.required( "fqdn", node.getFqdn());
123 } catch ( RequiredFieldException rfe ) {
124 return responseBuilder.error(rfe.getApiError());
127 DR_Node nNode = dr_nodeService.updateDr_Node(node, resp.getErr());
128 if ( resp.getErr().is2xx()) {
129 return responseBuilder.success(nNode);
131 return responseBuilder.error(resp.getErr());
135 @ApiOperation( value = "No Content",
136 notes = "Delete a single `DR_Node` object.",
137 response = DR_Node.class)
138 @ApiResponses( value = {
139 @ApiResponse( code = 204, message = "Success", response = DR_Node.class),
140 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
143 public Response deleteDr_Node(
144 @PathParam("fqdn") String name
147 ApiService resp = new ApiService();
150 checker.required( "fqdn", name);
151 } catch ( RequiredFieldException rfe ) {
152 logger.debug( rfe.getApiError().toString() );
153 return responseBuilder.error(rfe.getApiError());
155 dr_nodeService.removeDr_Node(name, resp.getErr());
156 if ( resp.getErr().is2xx() ) {
157 return responseBuilder.success(NO_CONTENT.getStatusCode(), null);
159 return responseBuilder.error(resp.getErr());
163 @ApiOperation( value = "return DR_Node details",
164 notes = "Retrieve a single `DR_Node` object.",
165 response = DR_Node.class)
166 @ApiResponses( value = {
167 @ApiResponse( code = 200, message = "Success", response = DR_Node.class),
168 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
172 @PathParam("fqdn") String name
174 ApiService resp = new ApiService();
176 DR_Node nNode = dr_nodeService.getDr_Node( name, resp.getErr() );
177 if ( resp.getErr().is2xx() ) {
178 return responseBuilder.success(nNode);
180 return responseBuilder.error(resp.getErr());