aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openecomp/dmaapbc/resources/TopicResource.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openecomp/dmaapbc/resources/TopicResource.java')
-rw-r--r--src/main/java/org/openecomp/dmaapbc/resources/TopicResource.java183
1 files changed, 95 insertions, 88 deletions
diff --git a/src/main/java/org/openecomp/dmaapbc/resources/TopicResource.java b/src/main/java/org/openecomp/dmaapbc/resources/TopicResource.java
index 5d4b9a7..47983c8 100644
--- a/src/main/java/org/openecomp/dmaapbc/resources/TopicResource.java
+++ b/src/main/java/org/openecomp/dmaapbc/resources/TopicResource.java
@@ -20,165 +20,172 @@
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.ws.rs.Consumes;
import javax.ws.rs.DELETE;
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;
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.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.DR_Pub;
+import org.openecomp.dmaapbc.model.ReplicationType;
import org.openecomp.dmaapbc.model.Topic;
import org.openecomp.dmaapbc.service.ApiService;
import org.openecomp.dmaapbc.service.TopicService;
@Path("/topics")
+@Api( value= "topics", description = "Endpoint for retreiving MR Topics" )
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
-public class TopicResource {
-
- static final Logger logger = Logger.getLogger(TopicResource.class);
+@Authorization
+public class TopicResource extends BaseLoggingClass {
TopicService mr_topicService = new TopicService();
@GET
- public List<Topic> getTopics(@Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
- logger.info("Entry: /GET" );
+ @ApiOperation( value = "return Topic details",
+ notes = "Returns array of `Topic` objects.",
+ response = Topic.class)
+ @ApiResponses( value = {
+ @ApiResponse( code = 200, message = "Success", response = DR_Pub.class),
+ @ApiResponse( code = 400, message = "Error", response = ApiError.class )
+ })
+ public Response getTopics() {
+
ApiService check = new ApiService();
- try {
- check.checkAuthorization( basicAuth, uriInfo.getPath(), "GET");
- } catch ( AuthenticationErrorException ae ) {
- return null; // check.unauthorized();
- } catch ( Exception e ) {
- logger.error( "Unexpected exception " + e );
- return null; //check.unavailable();
- }
- return mr_topicService.getAllTopics();
+
+ List<Topic> allTopics = mr_topicService.getAllTopics();
+
+ GenericEntity<List<Topic>> list = new GenericEntity<List<Topic>>(allTopics) {
+ };
+ return check.success(list);
+
}
@POST
- public Response addTopic( Topic topic, @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth ) {
- logger.info("Entry: /POST" );
+ @ApiOperation( value = "return Topic details",
+ notes = "Create `Topic` object.",
+ response = Topic.class)
+ @ApiResponses( value = {
+ @ApiResponse( code = 200, message = "Success", response = DR_Pub.class),
+ @ApiResponse( code = 400, message = "Error", response = ApiError.class )
+ })
+ public Response addTopic(
+ Topic topic
+ ) {
+ logger.info( "addTopic request: " + String.valueOf(topic) );
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();
- }
+
try {
check.required( "topicName", topic.getTopicName(), "^\\S+$" ); //no white space allowed in topicName
check.required( "topicDescription", topic.getTopicDescription(), "" );
check.required( "owner", topic.getOwner(), "" );
} catch( RequiredFieldException rfe ) {
- return Response.status(check.getErr().getCode())
- .entity( check.getErr() )
- .build();
+ return check.error();
}
- //String fqtn = Topic.genFqtn(topic.getTopicName());
- ApiError err = check.getErr();
-
+
+ //String repReq = topic.getReplicationRequest();
+ ReplicationType t = topic.getReplicationCase();
+ if ( t == null || t == ReplicationType.REPLICATION_NOT_SPECIFIED ) {
+ topic.setReplicationCase( mr_topicService.reviewTopic(topic));
+ }
+
topic.setLastMod();
- Topic mrc = mr_topicService.addTopic(topic, err);
+ Topic mrc = mr_topicService.addTopic(topic, check.getErr());
if ( mrc != null && mrc.isStatusValid() ) {
- return Response.status(Status.CREATED)
- .entity(mrc)
- .build();
+ return check.success(Status.CREATED.getStatusCode(), mrc);
}
- return Response.status(err.getCode())
- .entity(err)
- .build();
-
+ return check.error();
}
@PUT
+ @ApiOperation( value = "return Topic details",
+ notes = "Update a `Topic` object, identified by topicId",
+ response = Topic.class)
+ @ApiResponses( value = {
+ @ApiResponse( code = 200, message = "Success", response = DR_Pub.class),
+ @ApiResponse( code = 400, message = "Error", response = ApiError.class )
+ })
@Path("/{topicId}")
- public Response updateTopic( @PathParam("topicId") String topicId, Topic topic, @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth ) {
- logger.info("Entry: /PUT " + topic );
- ApiError err = new ApiError();
- err.setCode(Status.BAD_REQUEST.getStatusCode());
- err.setMessage( "Method /PUT not supported for /topics");
+ public Response updateTopic(
+ @PathParam("topicId") String topicId
+ ) {
+ ApiService check = new ApiService();
+
+ check.setCode(Status.BAD_REQUEST.getStatusCode());
+ check.setMessage( "Method /PUT not supported for /topics");
- return Response.status(err.getCode())
- .entity( err )
- .build();
- //return mr_topicService.updateTopic(topic);
+ return check.error();
}
@DELETE
+ @ApiOperation( value = "return Topic details",
+ notes = "Delete a `Topic` object, identified by topicId",
+ response = Topic.class)
+ @ApiResponses( value = {
+ @ApiResponse( code = 204, message = "Success", response = DR_Pub.class),
+ @ApiResponse( code = 400, message = "Error", response = ApiError.class )
+ })
@Path("/{topicId}")
- public Response deleteTopic( @PathParam("topicId") String id, @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth ){
- logger.info("Entry: /DELETE " + id );
+ public Response deleteTopic(
+ @PathParam("topicId") String id
+ ){
ApiService check = new ApiService();
- try {
- check.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "DELETE");
- } catch ( AuthenticationErrorException ae ) {
- return check.unauthorized();
- } catch ( Exception e ) {
- logger.error( "Unexpected exception " + e );
- return check.unavailable();
- }
+
try {
check.required( "fqtn", id, "" );
} catch( RequiredFieldException rfe ) {
- return Response.status(check.getErr().getCode())
- .entity( check.getErr() )
- .build();
+ return check.error();
}
- Topic topic = mr_topicService.removeTopic(id, check.getErr());
+ mr_topicService.removeTopic(id, check.getErr());
if ( check.getErr().is2xx()) {
- return Response.status(Status.NO_CONTENT.getStatusCode())
- .build();
+ return check.success(Status.NO_CONTENT.getStatusCode(), null);
}
- return Response.status(check.getErr().getCode())
- .entity( check.getErr() )
- .build();
+ return check.error();
}
@GET
+ @ApiOperation( value = "return Topic details",
+ notes = "Retrieve a `Topic` object, identified by topicId",
+ response = Topic.class)
+ @ApiResponses( value = {
+ @ApiResponse( code = 200, message = "Success", response = DR_Pub.class),
+ @ApiResponse( code = 400, message = "Error", response = ApiError.class )
+ })
@Path("/{topicId}")
- public Response getTopic( @PathParam("topicId") String id , @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ public Response getTopic(
+ @PathParam("topicId") String id
+ ) {
logger.info("Entry: /GET " + id);
ApiService check = new ApiService();
- try {
- check.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "GET");
- } catch ( AuthenticationErrorException ae ) {
- return check.unauthorized();
- } catch ( Exception e ) {
- logger.error( "Unexpected exception " + e );
- return check.unavailable();
- }
+
try {
check.required( "topicName", id, "^\\S+$" ); //no white space allowed in topicName
} catch( RequiredFieldException rfe ) {
- return Response.status(check.getErr().getCode())
- .entity( check.getErr() )
- .build();
+ return check.error();
}
Topic mrc = mr_topicService.getTopic( id, check.getErr() );
if ( mrc == null ) {
- return Response.status(check.getErr().getCode())
- .entity(check.getErr())
- .build();
+ return check.error();
}
- return Response.ok(mrc)
- .build();
+ return check.success(mrc);
}
}