aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openecomp/dmaapbc/resources/FeedResource.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openecomp/dmaapbc/resources/FeedResource.java')
-rw-r--r--src/main/java/org/openecomp/dmaapbc/resources/FeedResource.java168
1 files changed, 85 insertions, 83 deletions
diff --git a/src/main/java/org/openecomp/dmaapbc/resources/FeedResource.java b/src/main/java/org/openecomp/dmaapbc/resources/FeedResource.java
index b1dcd57..61130ec 100644
--- a/src/main/java/org/openecomp/dmaapbc/resources/FeedResource.java
+++ b/src/main/java/org/openecomp/dmaapbc/resources/FeedResource.java
@@ -20,6 +20,11 @@
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 java.util.List;
import javax.jws.WebParam;
@@ -33,6 +38,7 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
+import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
@@ -59,56 +65,59 @@ import org.apache.log4j.Logger;
import org.openecomp.dmaapbc.authentication.AuthenticationErrorException;
+import org.openecomp.dmaapbc.logging.BaseLoggingClass;
+import org.openecomp.dmaapbc.logging.DmaapbcLogMessageEnum;
+import org.openecomp.dmaapbc.model.ApiError;
+import org.openecomp.dmaapbc.model.DR_Pub;
+import org.openecomp.dmaapbc.model.DR_Sub;
import org.openecomp.dmaapbc.model.Feed;
+import org.openecomp.dmaapbc.model.Topic;
import org.openecomp.dmaapbc.service.ApiService;
import org.openecomp.dmaapbc.service.FeedService;
@Path("/feeds")
+@Api( value= "Feeds", description = "Endpoint for a Data Router Feed" )
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
-public class FeedResource extends ApiResource {
- static final Logger logger = Logger.getLogger(FeedResource.class);
-
+@Authorization
+public class FeedResource extends BaseLoggingClass {
@GET
- public List<Feed> getFeeds(@Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
- logger.debug( "Entry: GET " + uriInfo.getPath() );
+ @ApiOperation( value = "return Feed details",
+ notes = "Returns array of `Feed` objects.",
+ response = Feed.class)
+ @ApiResponses( value = {
+ @ApiResponse( code = 200, message = "Success", response = DR_Pub.class),
+ @ApiResponse( code = 400, message = "Error", response = ApiError.class )
+ })
+ public Response getFeeds() {
+
ApiService resp = new ApiService();
- try {
- resp.checkAuthorization( basicAuth, uriInfo.getPath(), "GET");
- } catch ( AuthenticationErrorException ae ) {
- return null; //resp.unauthorized();
- } catch ( Exception e ) {
- logger.error( "Unexpected exception " + e );
- return null; //resp.unavailable();
- }
+
FeedService feedService = new FeedService();
List<Feed> nfeeds = feedService.getAllFeeds();
-// tried this: http://www.adam-bien.com/roller/abien/entry/jax_rs_returning_a_list
-// but still didn't seem to work...
-// GenericEntity<List<Feed>> list = new GenericEntity<List<Feed>>(nfeeds){};
-// return Response.status(Status.OK)
-// .entity( list )
-// .build();
- return nfeeds;
+ GenericEntity<List<Feed>> list = new GenericEntity<List<Feed>>(nfeeds) {
+ };
+ return resp.success(list);
}
@POST
- public Response addFeed( @WebParam(name = "feed") Feed feed , @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth ) {
- logger.debug( "Entry: POST " + uriInfo.getPath());
+ @ApiOperation( value = "return Feed details",
+ notes = "Create a of `Feed` object.",
+ response = Feed.class)
+ @ApiResponses( value = {
+ @ApiResponse( code = 200, message = "Success", response = DR_Pub.class),
+ @ApiResponse( code = 400, message = "Error", response = ApiError.class )
+ })
+ public Response addFeed(
+ @WebParam(name = "feed") Feed feed
+ ) {
ApiService resp = new ApiService();
- try {
- resp.checkAuthorization( basicAuth, uriInfo.getPath(), "POST");
- } catch ( AuthenticationErrorException ae ) {
- return resp.unauthorized();
- } catch ( Exception e ) {
- logger.error( "Unexpected exception " + e );
- return resp.unavailable();
- }
+
try {
resp.required( "feedName", feed.getFeedName(), "");
resp.required( "feedVersion", feed.getFeedVersion(), "");
@@ -116,51 +125,47 @@ public class FeedResource extends ApiResource {
resp.required( "asprClassification", feed.getAsprClassification(), "" );
} catch ( RequiredFieldException rfe ) {
logger.debug( resp.toString() );
- return Response.status(Status.BAD_REQUEST).entity( resp ).build();
+ return resp.error();
}
FeedService feedService = new FeedService();
Feed nfeed = feedService.addFeed( feed, resp.getErr() );
if ( nfeed != null ) {
- return Response.status(Status.OK)
- .entity(nfeed)
- .build();
+ return resp.success(nfeed);
} else {
logger.error( "Unable to create: " + feed.getFeedName() + ":" + feed.getFeedVersion());
- return Response.status(resp.getErr().getCode())
- .entity( resp )
- .build();
+ return resp.error();
}
}
@PUT
+ @ApiOperation( value = "return Feed details",
+ notes = "Update a `Feed` object, specified by id.",
+ response = Feed.class)
+ @ApiResponses( value = {
+ @ApiResponse( code = 200, message = "Success", response = DR_Pub.class),
+ @ApiResponse( code = 400, message = "Error", response = ApiError.class )
+ })
@Path("/{id}")
- public Response updateFeed( @PathParam("id") String id, Feed feed, @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
- logger.debug( "Entry: PUT " + uriInfo.getPath());
+ public Response updateFeed(
+ @PathParam("id") String id,
+ @WebParam(name = "feed") Feed feed
+ ) {
FeedService feedService = new FeedService();
ApiService resp = new ApiService();
- try {
- resp.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "PUT");
- } catch ( AuthenticationErrorException ae ) {
- return resp.unauthorized();
- } catch ( Exception e ) {
- logger.error( "Unexpected exception " + e );
- return resp.unavailable();
- }
+
try {
resp.required( "feedId", id, "");
} catch ( RequiredFieldException rfe ) {
logger.debug( resp.toString() );
- return Response.status(Status.BAD_REQUEST.getStatusCode()).entity( resp ).build();
+ return resp.error();
}
Feed nfeed = feedService.getFeed( id, resp.getErr() );
if ( nfeed == null ) {
- return Response.status(resp.getErr().getCode())
- .entity( resp.getErr() )
- .build();
+ return resp.notFound();
}
// we assume there is no updates allowed for pubs and subs objects via this api...
@@ -171,57 +176,54 @@ public class FeedResource extends ApiResource {
nfeed = feedService.updateFeed(nfeed, resp.getErr());
if ( nfeed != null ) {
- return Response.status(Status.OK)
- .entity(nfeed)
- .build();
+ return resp.success(nfeed);
} else {
logger.info( "Unable to update: " + feed.getFeedName() + ":" + feed.getFeedVersion());
- return Response.status(resp.getErr().getCode())
- .entity( resp.getErr() )
- .build();
+ return resp.error();
}
}
@DELETE
+ @ApiOperation( value = "return Feed details",
+ notes = "Delete a `Feed` object, specified by id.",
+ response = Feed.class)
+ @ApiResponses( value = {
+ @ApiResponse( code = 204, message = "Success", response = DR_Pub.class),
+ @ApiResponse( code = 400, message = "Error", response = ApiError.class )
+ })
@Path("/{id}")
- public Response deleteFeed( @PathParam("id") String id, @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth ){
+ public Response deleteFeed(
+ @PathParam("id") String id
+ ){
ApiService resp = new ApiService();
- try {
- resp.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "DELETE");
- } catch ( AuthenticationErrorException ae ) {
- return resp.unauthorized();
- } catch ( Exception e ) {
- logger.error( "Unexpected exception " + e );
- return resp.unavailable();
- }
- logger.debug( "Entry: DELETE " + uriInfo.getPath());
+
+ logger.debug( "Entry: DELETE " + id);
FeedService feedService = new FeedService();
feedService.removeFeed(id);
- return Response.status(Status.NO_CONTENT)
- .build();
+ return resp.success(Status.NO_CONTENT.getStatusCode(), null);
}
@GET
+ @ApiOperation( value = "return Feed details",
+ notes = "Retrieve a `Feed` object, specified by id.",
+ response = Feed.class)
+ @ApiResponses( value = {
+ @ApiResponse( code = 200, message = "Success", response = DR_Pub.class),
+ @ApiResponse( code = 400, message = "Error", response = ApiError.class )
+ })
@Path("/{id}")
- public Response getFeed( @PathParam("id") String id, @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth ) {
- logger.debug( "Entry: GET " + uriInfo.getPath());
+ public Response getFeed(
+ @PathParam("id") String id
+ ) {
ApiService resp = new ApiService();
- try {
- resp.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "GET");
- } catch ( AuthenticationErrorException ae ) {
- return resp.unauthorized();
- } catch ( Exception e ) {
- logger.error( "Unexpected exception " + e );
- return resp.unavailable();
- }
+
FeedService feedService = new FeedService();
Feed nfeed = feedService.getFeed( id, resp.getErr() );
if ( nfeed == null ) {
- return Response.status(Status.NOT_FOUND).entity( resp.getErr() ).build();
+ resp.setCode(Status.NOT_FOUND.getStatusCode());
+ return resp.error();
}
- return Response.status(Status.OK)
- .entity(nfeed)
- .build();
+ return resp.success(nfeed);
}
}