aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openecomp/dmaapbc/resources/DmaapResource.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openecomp/dmaapbc/resources/DmaapResource.java')
-rw-r--r--src/main/java/org/openecomp/dmaapbc/resources/DmaapResource.java93
1 files changed, 41 insertions, 52 deletions
diff --git a/src/main/java/org/openecomp/dmaapbc/resources/DmaapResource.java b/src/main/java/org/openecomp/dmaapbc/resources/DmaapResource.java
index 03c731f..07c178d 100644
--- a/src/main/java/org/openecomp/dmaapbc/resources/DmaapResource.java
+++ b/src/main/java/org/openecomp/dmaapbc/resources/DmaapResource.java
@@ -25,9 +25,13 @@ package org.openecomp.dmaapbc.resources;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
@@ -36,10 +40,9 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
-import javax.ws.rs.core.Response.Status;
-import org.apache.log4j.Logger;
-import org.openecomp.dmaapbc.authentication.AuthenticationErrorException;
+import org.openecomp.dmaapbc.logging.BaseLoggingClass;
+import org.openecomp.dmaapbc.model.ApiError;
import org.openecomp.dmaapbc.model.Dmaap;
import org.openecomp.dmaapbc.service.ApiService;
import org.openecomp.dmaapbc.service.DmaapService;
@@ -47,92 +50,78 @@ import org.openecomp.dmaapbc.service.DmaapService;
@Path("/dmaap")
+@Api( value= "dmaap", description = "Endpoint for this instance of DMaaP object containing values for this OpenDCAE deployment" )
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
-public class DmaapResource {
- static final Logger logger = Logger.getLogger(DmaapResource.class);
+@Authorization
+public class DmaapResource extends BaseLoggingClass {
+
DmaapService dmaapService = new DmaapService();
@GET
- public Response getDmaap(@Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth ) {
- logger.debug( "Entry: GET " + uriInfo.getPath() );
+ @ApiOperation( value = "return dmaap details", notes = "returns the `dmaap` object, which contains system wide configuration settings", response = Dmaap.class)
+ @ApiResponses( value = {
+ @ApiResponse( code = 200, message = "Success", response = Dmaap.class),
+ @ApiResponse( code = 400, message = "Error", response = ApiError.class )
+ })
+
+ public Response getDmaap(@Context UriInfo uriInfo) {
ApiService check = new ApiService();
- try {
- check.checkAuthorization( basicAuth, uriInfo.getPath(), "GET");
- } catch ( AuthenticationErrorException ae ) {
- return check.unauthorized();
- } catch ( Exception e ) {
- logger.error( "Unexpected exception " + e );
- return check.unavailable();
- }
+
Dmaap d = dmaapService.getDmaap();
- return Response.ok(d)
- .build();
+ return check.success(d);
}
@POST
- public Response addDmaap( Dmaap obj,@Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth ) {
-
- ApiService check = new ApiService();
- try {
- check.checkAuthorization( basicAuth, uriInfo.getPath(), "POST");
- } catch ( AuthenticationErrorException ae ) {
- return check.unauthorized();
- } catch ( Exception e ) {
- logger.error( "Unexpected exception " + e );
- return check.unavailable();
- }
+ @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)
+ @ApiResponses( value = {
+ @ApiResponse( code = 200, message = "Success", response = Dmaap.class),
+ @ApiResponse( code = 400, message = "Error", response = ApiError.class )
+ })
+ public Response addDmaap( Dmaap obj ) {
+ ApiService check = new ApiService();
+
try { //check for required fields
check.required( "dmaapName", obj.getDmaapName(), "^\\S+$" ); //no white space allowed in dmaapName
check.required( "dmaapProvUrl", obj.getDrProvUrl(), "" );
check.required( "topicNsRoot", obj.getTopicNsRoot(), "" );
check.required( "bridgeAdminTopic", obj.getBridgeAdminTopic(), "" );
} catch( RequiredFieldException rfe ) {
- return Response.status(check.getErr().getCode())
- .entity( check.getErr() )
- .build();
+ return check.error();
}
Dmaap d = dmaapService.addDmaap(obj);
if ( d == null ) {
- return Response.status(Status.NOT_FOUND)
- .build();
+ return check.notFound();
}
- return Response.ok(d)
- .build();
+ return check.success(d);
}
@PUT
- public Response updateDmaap( Dmaap obj, @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth ) {
+ @ApiOperation( value = "return dmaap details", notes = "Update system settings for *dcaeEnvironment*.", response = Dmaap.class)
+ @ApiResponses( value = {
+ @ApiResponse( code = 200, message = "Success", response = Dmaap.class),
+ @ApiResponse( code = 400, message = "Error", response = ApiError.class )
+ })
+ public Response updateDmaap( Dmaap obj ) {
ApiService check = new ApiService();
- try {
- check.checkAuthorization( basicAuth, uriInfo.getPath(), "PUT");
- } catch ( AuthenticationErrorException ae ) {
- return check.unauthorized();
- } catch ( Exception e ) {
- logger.error( "Unexpected exception " + e );
- return check.unavailable();
- }
+
try { //check for required fields
check.required( "dmaapName", obj.getDmaapName(), "^\\S+$" ); //no white space allowed in dmaapName
check.required( "dmaapProvUrl", obj.getDrProvUrl(), "" );
check.required( "topicNsRoot", obj.getTopicNsRoot(), "" );
check.required( "bridgeAdminTopic", obj.getBridgeAdminTopic(), "" );
} catch( RequiredFieldException rfe ) {
- return Response.status(check.getErr().getCode())
- .entity( check.getErr() )
- .build();
+ return check.error();
}
Dmaap d = dmaapService.updateDmaap(obj);
if ( d != null ) {
- return Response.ok(d)
- .build();
+ return check.success(d);
} else {
- return Response.status(Status.NOT_FOUND)
- .build();
+ return check.notFound();
}
}