diff options
author | dglFromAtt <dgl@research.att.com> | 2018-10-25 08:06:45 -0400 |
---|---|---|
committer | dglFromAtt <dgl@research.att.com> | 2018-10-25 08:29:01 -0400 |
commit | 87bf9245434ad317ea39a84a0099233197f3d7c2 (patch) | |
tree | 69be5c0a6f623ebe23a0f30c739a8bf420bafd65 /src/main | |
parent | ebdb8b74c1d10e4bdc477c0f5e61311a9bfd9ead (diff) |
Introduce useExisting query param for feeds/topics
Change-Id: I0eb7000cff801a7fb622c70d4621458fe3574fed
Signed-off-by: dglFromAtt <dgl@research.att.com>
Issue-ID: DMAAP-878
Diffstat (limited to 'src/main')
4 files changed, 23 insertions, 8 deletions
diff --git a/src/main/java/org/onap/dmaap/dbcapi/resources/FeedResource.java b/src/main/java/org/onap/dmaap/dbcapi/resources/FeedResource.java index c0fdd0d..97336c1 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/resources/FeedResource.java +++ b/src/main/java/org/onap/dmaap/dbcapi/resources/FeedResource.java @@ -100,7 +100,8 @@ public class FeedResource extends BaseLoggingClass { @ApiResponse( code = 400, message = "Error", response = ApiError.class ) }) public Response addFeed( - @WebParam(name = "feed") Feed feed + @WebParam(name = "feed") Feed feed, + @QueryParam("useExisting") String useExisting ) { ApiService resp = new ApiService(); @@ -115,6 +116,7 @@ public class FeedResource extends BaseLoggingClass { return resp.error(); } + FeedService feedService = new FeedService(); Feed nfeed = feedService.getFeedByName( feed.getFeedName(), feed.getFeedVersion(), resp.getErr() ); if ( nfeed == null ) { @@ -136,6 +138,8 @@ public class FeedResource extends BaseLoggingClass { return resp.error(); } + } else if ( (useExisting != null) && ("true".compareToIgnoreCase( useExisting ) == 0)) { + return resp.success(nfeed); } resp.setCode(Status.CONFLICT.getStatusCode()); diff --git a/src/main/java/org/onap/dmaap/dbcapi/resources/TopicResource.java b/src/main/java/org/onap/dmaap/dbcapi/resources/TopicResource.java index cab48ca..8ed2558 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/resources/TopicResource.java +++ b/src/main/java/org/onap/dmaap/dbcapi/resources/TopicResource.java @@ -35,6 +35,7 @@ import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.GenericEntity; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -94,9 +95,10 @@ public class TopicResource extends BaseLoggingClass { @ApiResponse( code = 400, message = "Error", response = ApiError.class ) }) public Response addTopic( - Topic topic + Topic topic, + @QueryParam("useExisting") String useExisting ) { - logger.info( "addTopic request: " + topic ); + logger.info( "addTopic request: " + topic + " useExisting=" + useExisting ); ApiService check = new ApiService(); try { @@ -118,8 +120,12 @@ public class TopicResource extends BaseLoggingClass { topic.setFqtnStyle( defaultTopicStyle ); } topic.setLastMod(); + Boolean flag = false; + if (useExisting != null) { + flag = "true".compareToIgnoreCase( useExisting ) == 0; + } - Topic mrc = mr_topicService.addTopic(topic, check.getErr()); + Topic mrc = mr_topicService.addTopic(topic, check.getErr(), flag); if ( mrc != null && check.getErr().is2xx() ) { return check.success(Status.CREATED.getStatusCode(), mrc); } diff --git a/src/main/java/org/onap/dmaap/dbcapi/service/DmaapService.java b/src/main/java/org/onap/dmaap/dbcapi/service/DmaapService.java index e2bc379..5aae1d4 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/service/DmaapService.java +++ b/src/main/java/org/onap/dmaap/dbcapi/service/DmaapService.java @@ -290,7 +290,7 @@ public class DmaapService extends BaseLoggingClass { TopicService svc = new TopicService(); try { @SuppressWarnings("unused") - Topic nTopic = svc.addTopic(mmaTopic, err); + Topic nTopic = svc.addTopic(mmaTopic, err, true); if ( err.is2xx() || err.getCode() == 409 ) { return false; } diff --git a/src/main/java/org/onap/dmaap/dbcapi/service/TopicService.java b/src/main/java/org/onap/dmaap/dbcapi/service/TopicService.java index 6e7b744..6a93a21 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/service/TopicService.java +++ b/src/main/java/org/onap/dmaap/dbcapi/service/TopicService.java @@ -102,14 +102,19 @@ public class TopicService extends BaseLoggingClass { return t; } - public Topic addTopic( Topic topic, ApiError err ) { + public Topic addTopic( Topic topic, ApiError err, Boolean useExisting ) { logger.info( "Entry: addTopic"); logger.info( "Topic name=" + topic.getTopicName() + " fqtnStyle=" + topic.getFqtnStyle() ); String nFqtn = topic.genFqtn(); logger.info( "FQTN=" + nFqtn ); - if ( getTopic( nFqtn, err ) != null ) { + Topic pTopic = getTopic( nFqtn, err ); + if ( pTopic != null ) { String t = "topic already exists: " + nFqtn; logger.info( t ); + if ( useExisting ) { + err.setCode(Status.OK.getStatusCode()); + return pTopic; + } err.setMessage( t ); err.setFields( "fqtn"); err.setCode(Status.CONFLICT.getStatusCode()); @@ -251,7 +256,7 @@ public class TopicService extends BaseLoggingClass { TopicService ts = new TopicService(); ApiError err = new ApiError(); - ts.addTopic(bridgeAdminTopic, err); + ts.addTopic(bridgeAdminTopic, err, true); if ( err.is2xx() || err.getCode() == 409 ){ err.setCode(200); |