diff options
author | dglFromAtt <dgl@research.att.com> | 2019-03-04 16:04:11 -0500 |
---|---|---|
committer | dglFromAtt <dgl@research.att.com> | 2019-03-04 16:04:18 -0500 |
commit | d6ac6f8b10e90411dd650d6f7a9ee51179e39bfc (patch) | |
tree | 0d26b34a07f3add44d1c03543ea1d32cf8b0912e /src/main/java | |
parent | ecd4be66f501c6cbbcd53b302f477bd0c8d17a6a (diff) |
Allow POST dr_sub using FeedName
Change-Id: I7237755d265fc14205d3c04173d170c250be4817
Signed-off-by: dglFromAtt <dgl@research.att.com>
Issue-ID: DMAAP-1045
Diffstat (limited to 'src/main/java')
7 files changed, 95 insertions, 14 deletions
diff --git a/src/main/java/org/onap/dmaap/dbcapi/client/DrProvConnection.java b/src/main/java/org/onap/dmaap/dbcapi/client/DrProvConnection.java index 441596a..3cb3d67 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/client/DrProvConnection.java +++ b/src/main/java/org/onap/dmaap/dbcapi/client/DrProvConnection.java @@ -411,7 +411,7 @@ public class DrProvConnection extends BaseLoggingClass { if (rc >= 200 && rc < 300 ) { responseBody = bodyToString( uc.getInputStream() ); logger.info( "responseBody=" + responseBody ); - + err.setCode( rc ); } else if ( rc == 404 ) { err.setCode( rc ); err.setFields( "feedid"); diff --git a/src/main/java/org/onap/dmaap/dbcapi/model/DR_Pub.java b/src/main/java/org/onap/dmaap/dbcapi/model/DR_Pub.java index 06598f7..0d146b7 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/model/DR_Pub.java +++ b/src/main/java/org/onap/dmaap/dbcapi/model/DR_Pub.java @@ -32,6 +32,10 @@ public class DR_Pub extends DmaapObject { private String userpwd; private String feedId; private String pubId; + + // NOTE: the following fields are optional in the API but not stored in the DB + private String feedName; + private String feedVersion; public DR_Pub() { @@ -114,6 +118,22 @@ public class DR_Pub extends DmaapObject { public void setNextPubId() { this.pubId = this.feedId + "." + DR_Pub.nextKey(); } + + public String getFeedName() { + return feedName; + } + + public void setFeedName(String feedName) { + this.feedName = feedName; + } + + public String getFeedVersion() { + return feedVersion; + } + + public void setFeedVersion(String feedVersion) { + this.feedVersion = feedVersion; + } public DR_Pub setRandomUserName() { RandomString r = new RandomString(15); diff --git a/src/main/java/org/onap/dmaap/dbcapi/model/DR_Sub.java b/src/main/java/org/onap/dmaap/dbcapi/model/DR_Sub.java index dd0b85d..9b6e2d7 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/model/DR_Sub.java +++ b/src/main/java/org/onap/dmaap/dbcapi/model/DR_Sub.java @@ -45,6 +45,10 @@ public class DR_Sub extends DmaapObject { private boolean guaranteedDelivery; private boolean guaranteedSequence; private boolean privilegedSubscriber; + + // NOTE: the following fields are optional in the API but not stored in the DB + private String feedName; + private String feedVersion; public DR_Sub() { @@ -230,6 +234,24 @@ public class DR_Sub extends DmaapObject { public void setPrivilegedSubscriber(boolean privilegedSubscriber) { this.privilegedSubscriber = privilegedSubscriber; } + + + + public String getFeedName() { + return feedName; + } + + public void setFeedName(String feedName) { + this.feedName = feedName; + } + + public String getFeedVersion() { + return feedVersion; + } + + public void setFeedVersion(String feedVersion) { + this.feedVersion = feedVersion; + } public byte[] getBytes(String provApi) { if ( "AT&T".equals(provApi)) { diff --git a/src/main/java/org/onap/dmaap/dbcapi/resources/DR_PubResource.java b/src/main/java/org/onap/dmaap/dbcapi/resources/DR_PubResource.java index bcdb4b3..1673857 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/resources/DR_PubResource.java +++ b/src/main/java/org/onap/dmaap/dbcapi/resources/DR_PubResource.java @@ -91,21 +91,42 @@ public class DR_PubResource extends BaseLoggingClass { DR_Pub pub ) { ApiService resp = new ApiService(); + FeedService feeds = new FeedService(); + Feed fnew = null; logger.info( "Entry: POST /dr_pubs"); try { resp.required( "feedId", pub.getFeedId(), ""); + } catch ( RequiredFieldException rfe ) { + try { + resp.required( "feedName", pub.getFeedName(), ""); + }catch ( RequiredFieldException rfe2 ) { + logger.debug( resp.toString() ); + return resp.error(); + } + // if we found a FeedName instead of a FeedId then try to look it up. + List<Feed> nfeeds = feeds.getAllFeeds( pub.getFeedName(), pub.getFeedVersion(), "equals"); + if ( nfeeds.size() != 1 ) { + logger.debug( "Attempt to match "+ pub.getFeedName() + " ver="+pub.getFeedVersion() + " matched " + nfeeds.size() ); + return resp.error(); + } + fnew = nfeeds.get(0); + } + try { resp.required( "dcaeLocationName", pub.getDcaeLocationName(), ""); } catch ( RequiredFieldException rfe ) { logger.debug( resp.getErr().toString() ); return resp.error(); } - FeedService feeds = new FeedService(); - Feed fnew = feeds.getFeed( pub.getFeedId(), resp.getErr() ); + + // we may have fnew already if located by FeedName if ( fnew == null ) { - logger.info( "Specified feed " + pub.getFeedId() + " not known to Bus Controller"); + fnew = feeds.getFeed( pub.getFeedId(), resp.getErr() ); + } + if ( fnew == null ) { + logger.info( "Specified feed " + pub.getFeedId() + " or " + pub.getFeedName() + " not known to Bus Controller"); return resp.error(); } diff --git a/src/main/java/org/onap/dmaap/dbcapi/resources/DR_SubResource.java b/src/main/java/org/onap/dmaap/dbcapi/resources/DR_SubResource.java index 28bfdc5..498454e 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/resources/DR_SubResource.java +++ b/src/main/java/org/onap/dmaap/dbcapi/resources/DR_SubResource.java @@ -92,24 +92,41 @@ public class DR_SubResource extends BaseLoggingClass { ) { ApiService resp = new ApiService(); - + FeedService feeds = new FeedService(); + Feed fnew = null; try { resp.required( "feedId", sub.getFeedId(), ""); + } catch ( RequiredFieldException rfe ) { + try { + resp.required( "feedName", sub.getFeedName(), ""); + }catch ( RequiredFieldException rfe2 ) { + logger.debug( resp.toString() ); + return resp.error(); + } + // if we found a FeedName instead of a FeedId then try to look it up. + List<Feed> nfeeds = feeds.getAllFeeds( sub.getFeedName(), sub.getFeedVersion(), "equals"); + if ( nfeeds.size() != 1 ) { + logger.debug( "Attempt to match "+ sub.getFeedName() + " ver="+sub.getFeedVersion() + " matched " + nfeeds.size() ); + return resp.error(); + } + fnew = nfeeds.get(0); + } + + try { resp.required( "dcaeLocationName", sub.getDcaeLocationName(), ""); - } catch ( RequiredFieldException rfe ) { logger.debug( resp.toString() ); return resp.error(); } - - FeedService feeds = new FeedService(); - Feed fnew = feeds.getFeed( sub.getFeedId(), resp.getErr() ); + // we may have fnew already if located by FeedName if ( fnew == null ) { - logger.warn( "Specified feed " + sub.getFeedId() + " not known to Bus Controller"); + fnew = feeds.getFeed( sub.getFeedId(), resp.getErr() ); + } + if ( fnew == null ) { + logger.warn( "Specified feed " + sub.getFeedId() + " or " + sub.getFeedName() + " not known to Bus Controller"); resp.setCode(Status.NOT_FOUND.getStatusCode()); return resp.error(); } - DR_SubService dr_subService = new DR_SubService( fnew.getSubscribeURL()); ArrayList<DR_Sub> subs = fnew.getSubs(); logger.info( "num existing subs before = " + subs.size() ); @@ -157,7 +174,7 @@ public class DR_SubResource extends BaseLoggingClass { logger.warn( "Specified feed " + sub.getFeedId() + " not known to Bus Controller"); return resp.error(); } - + DR_SubService dr_subService = new DR_SubService(); sub.setSubId(name); DR_Sub nsub = dr_subService.updateDr_Sub(sub, resp.getErr() ); diff --git a/src/main/java/org/onap/dmaap/dbcapi/service/ApiService.java b/src/main/java/org/onap/dmaap/dbcapi/service/ApiService.java index 6ae639d..48f81db 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/service/ApiService.java +++ b/src/main/java/org/onap/dmaap/dbcapi/service/ApiService.java @@ -165,6 +165,7 @@ public class ApiService extends BaseLoggingClass { // test for presence of a required field public void required( String name, Object val, String expr ) throws RequiredFieldException { + err.setCode(0); if ( val == null ) { err.setCode(Status.BAD_REQUEST.getStatusCode()); err.setMessage("missing required field"); diff --git a/src/main/java/org/onap/dmaap/dbcapi/service/DR_SubService.java b/src/main/java/org/onap/dmaap/dbcapi/service/DR_SubService.java index 99c8f31..9d233a5 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/service/DR_SubService.java +++ b/src/main/java/org/onap/dmaap/dbcapi/service/DR_SubService.java @@ -98,7 +98,7 @@ public class DR_SubService extends BaseLoggingClass { String resp = prov.doPostDr_Sub( sub, apiError ); if ( "Yes".equals(unit_test) ) { resp = simulateResp( sub, "POST" ); - apiError.setCode(200); + apiError.setCode(201); } logger.debug( "addDr_Sub resp=" + resp ); @@ -110,7 +110,7 @@ public class DR_SubService extends BaseLoggingClass { snew.setLastMod(); addEgressRoute( snew, apiError ); dr_subs.put( snew.getSubId(), snew ); - apiError.setCode(200); + apiError.setCode(201); } else { apiError.setCode(400); } |