From: Driptaroop Das Date: Wed, 23 Jan 2019 08:10:24 +0000 (+0530) Subject: Multiple fixes - Feed.java X-Git-Tag: 1.0.26~53^2 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=dmaap%2Fdbcapi.git;a=commitdiff_plain;h=0b5b03f6dffd505e36748041fedfe65b92365697 Multiple fixes - Feed.java Multiple fixes - Feed.java Issue-ID: DMAAP-995 Change-Id: Id67df8f786fa8376a43d4cf623ef6b3b160f09e4 Signed-off-by: Driptaroop Das --- diff --git a/src/main/java/org/onap/dmaap/dbcapi/model/Feed.java b/src/main/java/org/onap/dmaap/dbcapi/model/Feed.java index b78377b..b3c7332 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/model/Feed.java +++ b/src/main/java/org/onap/dmaap/dbcapi/model/Feed.java @@ -48,52 +48,32 @@ public class Feed extends DmaapObject { private String formatUuid; private ArrayList pubs; - private ArrayList subs; + private ArrayList subs; - - - public boolean isSuspended() { - return suspended; - } - - public void setSuspended(boolean suspended) { - this.suspended = suspended; - } - - public String getSubscribeURL() { - return subscribeURL; - } - public void setSubscribeURL(String subscribeURL) { - this.subscribeURL = subscribeURL; - } - - - public Feed() { - this.pubs = new ArrayList(); - this.subs = new ArrayList(); + this.pubs = new ArrayList<>(); + this.subs = new ArrayList<>(); this.setStatus( DmaapObject_Status.EMPTY ); - + } - + public Feed( String name, - String version, - String description, - String owner, - String aspr - ) { + String version, + String description, + String owner, + String aspr) { this.feedName = name; this.feedVersion = version; this.feedDescription = description; this.owner = owner; this.asprClassification = aspr; - this.pubs = new ArrayList(); - this.subs = new ArrayList(); + this.pubs = new ArrayList<>(); + this.subs = new ArrayList<>(); this.setStatus( DmaapObject_Status.NEW ); - + } - + // expects a String in JSON format, with known fields to populate Feed object public Feed ( String json ) { JSONParser parser = new JSONParser(); @@ -101,10 +81,10 @@ public class Feed extends DmaapObject { try { jsonObj = (JSONObject) parser.parse( json ); } catch ( ParseException pe ) { - logger.error( "Error parsing provisioning data: " + json ); - this.setStatus( DmaapObject_Status.INVALID ); - return; - } + logger.error( "Error parsing provisioning data: " + json ); + this.setStatus( DmaapObject_Status.INVALID ); + return; + } this.setFeedName( (String) jsonObj.get("name")); this.setFeedVersion( (String) jsonObj.get("version")); @@ -117,30 +97,48 @@ public class Feed extends DmaapObject { this.setPublishURL( url ); this.setFeedId( url.substring( url.lastIndexOf('/')+1, url.length() )); logger.info( "feedid="+ this.getFeedId() ); - this.setSubscribeURL( (String) links.get("subscribe") ); + this.setSubscribeURL( (String) links.get("subscribe") ); this.setLogURL( (String) links.get("log") ); JSONObject auth = (JSONObject) jsonObj.get("authorization"); this.setAsprClassification( (String) auth.get("classification")); JSONArray pubs = (JSONArray) auth.get( "endpoint_ids"); int i; - ArrayList dr_pub = new ArrayList(); - this.subs = new ArrayList(); + ArrayList dr_pub = new ArrayList<>(); + this.subs = new ArrayList<>(); for( i = 0; i < pubs.size(); i++ ) { JSONObject entry = (JSONObject) pubs.get(i); - dr_pub.add( new DR_Pub( "someLocation", - (String) entry.get("id"), - (String) entry.get("password"), - this.getFeedId(), - this.getFeedId() + "." + DR_Pub.nextKey() )); - + dr_pub.add( new DR_Pub( "someLocation", + (String) entry.get("id"), + (String) entry.get("password"), + this.getFeedId(), + this.getFeedId() + "." + DR_Pub.nextKey() )); + } this.setPubs( dr_pub ); - + this.setStatus( DmaapObject_Status.VALID ); } + + + public boolean isSuspended() { + return suspended; + } + + public void setSuspended(boolean suspended) { + this.suspended = suspended; + } + + public String getSubscribeURL() { + return subscribeURL; + } + + public void setSubscribeURL(String subscribeURL) { + this.subscribeURL = subscribeURL; + } + public String getFeedId() { return feedId; } @@ -218,8 +216,7 @@ public class Feed extends DmaapObject { // returns the Feed object in JSON that conforms to DR Prov Server expectations public String toProvJSON() { - ArrayList pubs = this.getPubs(); - String postJSON = String.format("{\"name\": \"%s\", \"version\": \"%s\", \"description\": \"%s\", \"suspend\": %s, \"authorization\": { \"classification\": \"%s\", ", + String postJSON = String.format("{\"name\": \"%s\", \"version\": \"%s\", \"description\": \"%s\", \"suspend\": %s, \"authorization\": { \"classification\": \"%s\", ", this.getFeedName(), this.getFeedVersion(), this.getFeedDescription(), @@ -264,8 +261,7 @@ public class Feed extends DmaapObject { } public static String getSubProvURL( String feedId ) { - String ret = new DmaapService().getDmaap().getDrProvUrl() + "/subscribe/" + feedId ; - return ret; + return new DmaapService().getDmaap().getDrProvUrl() + "/subscribe/" + feedId; } @Override