X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdbcapi%2Fmodel%2FFeed.java;h=b3c7332626cbfbe996b2aa390317980c276a8a85;hb=HEAD;hp=b327f3a4ea806855d240375a225bf67ca756e1be;hpb=503da874ce876dbe463bcc1a03f63ea0f48fe650;p=dmaap%2Fdbcapi.git 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 b327f3a..b3c7332 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/model/Feed.java +++ b/src/main/java/org/onap/dmaap/dbcapi/model/Feed.java @@ -3,6 +3,8 @@ * org.onap.dmaap * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * + * Modifications Copyright (C) 2019 IBM. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,124 +48,97 @@ 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(); JSONObject jsonObj; - logger.info( "templog:Feed at 10" ); try { jsonObj = (JSONObject) parser.parse( json ); } catch ( ParseException pe ) { - logger.error( "Error parsing provisioning data: " + json ); - this.setStatus( DmaapObject_Status.INVALID ); - return; - } - logger.info( "templog:Feed at 11" ); + logger.error( "Error parsing provisioning data: " + json ); + this.setStatus( DmaapObject_Status.INVALID ); + return; + } this.setFeedName( (String) jsonObj.get("name")); - logger.info( "templog:Feed at 12" ); - this.setFeedVersion( (String) jsonObj.get("version")); - logger.info( "templog:Feed at 13" ); this.setFeedDescription( (String) jsonObj.get("description")); - logger.info( "templog:Feed at 14" ); this.setOwner( (String) jsonObj.get("publisher")); - logger.info( "templog:Feed at 15" ); this.setSuspended( (boolean) jsonObj.get("suspend")); - logger.info( "templog:Feed at 16" ); JSONObject links = (JSONObject) jsonObj.get("links"); - logger.info( "templog:Feed at 17" ); String url = (String) links.get("publish"); - logger.info( "templog:Feed at 18" ); this.setPublishURL( url ); - logger.info( "templog:Feed at 19" ); this.setFeedId( url.substring( url.lastIndexOf('/')+1, url.length() )); - logger.info( "templog:Feed at 20" ); logger.info( "feedid="+ this.getFeedId() ); - logger.info( "templog:Feed at 21" ); - this.setSubscribeURL( (String) links.get("subscribe") ); - logger.info( "templog:Feed at 22" ); + this.setSubscribeURL( (String) links.get("subscribe") ); this.setLogURL( (String) links.get("log") ); - logger.info( "templog:Feed at 23" ); JSONObject auth = (JSONObject) jsonObj.get("authorization"); - logger.info( "templog:Feed at 24" ); this.setAsprClassification( (String) auth.get("classification")); - logger.info( "templog:Feed at 25" ); JSONArray pubs = (JSONArray) auth.get( "endpoint_ids"); - logger.info( "templog:Feed at 26" ); int i; - logger.info( "templog:Feed at 27" ); - ArrayList dr_pub = new ArrayList(); - logger.info( "templog:Feed at 28" ); - this.subs = new ArrayList(); + ArrayList dr_pub = new ArrayList<>(); + this.subs = new ArrayList<>(); for( i = 0; i < pubs.size(); i++ ) { - logger.info( "templog:Feed at 29 " + i ); JSONObject entry = (JSONObject) pubs.get(i); - logger.info( "templog:Feed at 30" ); - 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() )); + } - logger.info( "templog:Feed at 31" ); this.setPubs( dr_pub ); - - logger.info( "templog:Feed at 32" ); + this.setStatus( DmaapObject_Status.VALID ); - logger.info( "templog:Feed at 33" ); } + + + 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; } @@ -241,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(), @@ -287,9 +261,7 @@ public class Feed extends DmaapObject { } public static String getSubProvURL( String feedId ) { - String ret = new String(); - ret = new DmaapService().getDmaap().getDrProvUrl() + "/subscribe/" + feedId ; - return ret; + return new DmaapService().getDmaap().getDrProvUrl() + "/subscribe/" + feedId; } @Override