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=========================================================
24 package org.onap.dmaap.dbcapi.resources;
27 import io.swagger.annotations.Api;
28 import io.swagger.annotations.ApiOperation;
29 import io.swagger.annotations.ApiResponse;
30 import io.swagger.annotations.ApiResponses;
31 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
32 import org.onap.dmaap.dbcapi.model.ApiError;
33 import org.onap.dmaap.dbcapi.model.Dmaap;
34 import org.onap.dmaap.dbcapi.service.DmaapService;
36 import javax.ws.rs.Consumes;
37 import javax.ws.rs.GET;
38 import javax.ws.rs.POST;
39 import javax.ws.rs.PUT;
40 import javax.ws.rs.Path;
41 import javax.ws.rs.Produces;
42 import javax.ws.rs.core.Context;
43 import javax.ws.rs.core.MediaType;
44 import javax.ws.rs.core.Response;
45 import javax.ws.rs.core.UriInfo;
49 @Api( value= "dmaap", description = "Endpoint for this instance of DMaaP object containing values for this OpenDCAE deployment" )
50 @Consumes(MediaType.APPLICATION_JSON)
51 @Produces(MediaType.APPLICATION_JSON)
53 public class DmaapResource extends BaseLoggingClass {
56 private DmaapService dmaapService = new DmaapService();
57 private ResponseBuilder responseBuilder = new ResponseBuilder();
58 private RequiredChecker checker = new RequiredChecker();
61 @ApiOperation( value = "return dmaap details", notes = "returns the `dmaap` object, which contains system wide configuration settings", response = Dmaap.class)
62 @ApiResponses( value = {
63 @ApiResponse( code = 200, message = "Success", response = Dmaap.class),
64 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
67 public Response getDmaap(@Context UriInfo uriInfo) {
68 Dmaap d = dmaapService.getDmaap();
69 return responseBuilder.success(d);
73 @ApiOperation( value = "return dmaap details", notes = "Create a new DMaaP set system wide configuration settings for the *dcaeEnvironment*. Deprecated with introduction of persistence in 1610.", response = Dmaap.class)
74 @ApiResponses( value = {
75 @ApiResponse( code = 200, message = "Success", response = Dmaap.class),
76 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
78 public Response addDmaap( Dmaap obj ) {
81 validateRequiredFields(obj);
82 } catch( RequiredFieldException rfe ) {
83 return responseBuilder.error(rfe.getApiError());
86 Dmaap d = dmaapService.addDmaap(obj);
88 return responseBuilder.notFound();
92 return responseBuilder.success(d);
96 @ApiOperation( value = "return dmaap details", notes = "Update system settings for *dcaeEnvironment*.", response = Dmaap.class)
97 @ApiResponses( value = {
98 @ApiResponse( code = 200, message = "Success", response = Dmaap.class),
99 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
101 public Response updateDmaap( Dmaap obj ) {
104 validateRequiredFields(obj);
105 } catch( RequiredFieldException rfe ) {
106 return responseBuilder.error(rfe.getApiError());
109 Dmaap d = dmaapService.updateDmaap(obj);
111 return responseBuilder.success(d);
113 return responseBuilder.notFound();
117 private void validateRequiredFields(Dmaap obj) throws RequiredFieldException {
118 checker.required( "dmaapName", obj.getDmaapName(), "^\\S+$" ); //no white space allowed in dmaapName
119 checker.required( "dmaapProvUrl", obj.getDrProvUrl());
120 checker.required( "topicNsRoot", obj.getTopicNsRoot());
121 checker.required( "bridgeAdminTopic", obj.getBridgeAdminTopic());