Fix Resources Jersey tests
[dmaap/dbcapi.git] / src / main / java / org / onap / dmaap / dbcapi / model / DR_Sub.java
index a5d9999..8ac0880 100644 (file)
@@ -42,11 +42,19 @@ public class DR_Sub extends DmaapObject {
        private boolean use100;
        private boolean suspended;
        private String owner;
+       private boolean guaranteedDelivery;
+       private boolean guaranteedSequence;
+       private boolean privilegedSubscriber;
+       private boolean decompressData;
 
+       // NOTE: the following fields are optional in the API but not stored in the DB
+
+       private String  feedName;
+       private String  feedVersion;
        public DR_Sub() {
 
        }
-       
+
        public DR_Sub( String dLN,
                                        String uN,
                                        String uP,
@@ -64,12 +72,12 @@ public class DR_Sub extends DmaapObject {
                this.setStatus( DmaapObject_Status.NEW );
                this.subId = "0";
        }
-       
+
        public DR_Sub ( String json ) {
                logger.info( "DR_Sub:" + json );
                JSONParser parser = new JSONParser();
                JSONObject jsonObj;
-               
+
                try {
                        jsonObj = (JSONObject) parser.parse( json );
                } catch ( ParseException pe ) {
@@ -80,17 +88,41 @@ public class DR_Sub extends DmaapObject {
 
                this.setOwner( (String) jsonObj.get("subscriber"));
                this.setSuspended( (boolean) jsonObj.get("suspend"));
-               
-               JSONObject links = (JSONObject) jsonObj.get("links");
-               String url = (String) links.get("feed");
-               this.setFeedId( url.substring( url.lastIndexOf('/')+1, url.length() ));
-               url = (String) links.get("self");
-               this.setSubId( url.substring( url.lastIndexOf('/')+1, url.length() ));
-               logger.info( "feedid="+ this.getFeedId() );
-               this.setLogURL( (String) links.get("log") );
-               
+
+               try {
+                       JSONObject links = (JSONObject) jsonObj.get("links");
+                       String url = (String) links.get("feed");
+                       this.setFeedId( url.substring( url.lastIndexOf('/')+1, url.length() ));
+                       url = (String) links.get("self");
+                       this.setSubId( url.substring( url.lastIndexOf('/')+1, url.length() ));
+                       logger.info( "feedid="+ this.getFeedId() );
+                       this.setLogURL( (String) links.get("log") );
+               } catch (NullPointerException npe ) {
+
+               }
+               try {
+                       this.setGuaranteedDelivery( (boolean) jsonObj.get("guaranteed_delivery"));
+               } catch( NullPointerException npe ) {
+                       this.setGuaranteedDelivery(false);
+               }
+               try {
+                       this.setGuaranteedSequence( (boolean) jsonObj.get("guaranteed_sequence"));
+               } catch( NullPointerException npe ) {
+                       this.setGuaranteedSequence(false);
+               }
+               try {
+                       this.setPrivilegedSubscriber((boolean) jsonObj.get("privilegedSubscriber"));
+               } catch( NullPointerException npe ) {
+                       this.setPrivilegedSubscriber(false);
+               }
+               try {
+                       this.setDecompressData((boolean) jsonObj.get("decompressData"));
+               } catch( NullPointerException npe ) {
+                       this.setDecompressData(false);
+               }
+
                JSONObject del = (JSONObject) jsonObj.get("delivery");
-               this.setDeliveryURL( (String) del.get("url") ); 
+               this.setDeliveryURL( (String) del.get("url") );
                this.setUsername( (String) del.get("user"));
                this.setUserpwd( (String) del.get( "password"));
                this.setUse100((boolean) del.get( "use100"));
@@ -99,7 +131,7 @@ public class DR_Sub extends DmaapObject {
 
                logger.info( "new DR_Sub returning");
        }
-       
+
        public String getOwner() {
                return owner;
        }
@@ -183,6 +215,53 @@ public class DR_Sub extends DmaapObject {
        }
 
 
+       public boolean isGuaranteedDelivery() {
+               return guaranteedDelivery;
+       }
+
+       public void setGuaranteedDelivery(boolean guaranteedDelivery) {
+               this.guaranteedDelivery = guaranteedDelivery;
+       }
+
+       public boolean isGuaranteedSequence() {
+               return guaranteedSequence;
+       }
+
+       public void setGuaranteedSequence(boolean guaranteedSequence) {
+               this.guaranteedSequence = guaranteedSequence;
+       }
+
+       public boolean isPrivilegedSubscriber() {
+               return privilegedSubscriber;
+       }
+
+       public void setPrivilegedSubscriber(boolean privilegedSubscriber) {
+               this.privilegedSubscriber = privilegedSubscriber;
+       }
+
+       public boolean isDecompressData() {
+               return decompressData;
+       }
+
+       public void setDecompressData(boolean decompressData) {
+               this.decompressData = decompressData;
+       }
+
+       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)) {
@@ -191,28 +270,32 @@ public class DR_Sub extends DmaapObject {
                return toProvJSON().getBytes(StandardCharsets.UTF_8);
        }
        // returns the DR_Sub object in JSON that conforms to ONAP DR Prov Server expectations
-       public String toProvJSON() {    
+       public String toProvJSON() {
                // this is the original DR API that was contributed to ONAP
-               String postJSON = String.format("{\"suspend\": \"%s\", \"delivery\": "
-                               + "{\"url\": \"%s\", \"user\": \"%s\", \"password\": \"%s\", \"use100\":  \"%s\"}"
+               String postJSON = String.format("{\"suspend\": %s, \"delivery\":"
+                               + "{\"url\": \"%s\", \"user\": \"%s\", \"password\": \"%s\", \"use100\":  %s }"
                                + ", \"metadataOnly\": %s, \"groupid\": \"%s\", \"follow_redirect\": %s "
-                               + "}", 
-                               this.suspended,
-                               this.getDeliveryURL(), 
-                               this.getUsername(),
-                               this.getUserpwd(),
-                               this.isUse100(),
-                               "false",
-                               "0",
-                               "true");        
-               
+                               + ", \"privilegedSubscriber\": %s, \"decompress\": %s "
+                               + "}"
+                               ,this.suspended
+                               ,this.getDeliveryURL()
+                               ,this.getUsername()
+                               ,this.getUserpwd()
+                               ,this.isUse100()
+                               ,"false"
+                               ,"0"
+                               ,"true"
+                               ,this.isPrivilegedSubscriber()
+                               ,this.isDecompressData()
+                       );
+
                logger.info( postJSON );
                return postJSON;
        }
        // returns the DR_Sub object in JSON that conforms to AT&T DR Prov Server expectations
        // In Jan, 2019, the DR API used internally at AT&T diverged, so this function can be used in
        // that runtime environment
-       public String toProvJSONforATT() {      
+       public String toProvJSONforATT() {
                // in DR 3.0, API v2.1 a new groupid field is added.  We are not using this required field so just set it to 0.
                // we send this regardless of DR Release because older versions of DR seem to safely ignore it
                // and soon those versions won't be around anyway...
@@ -225,29 +308,30 @@ public class DR_Sub extends DmaapObject {
                // TODO:
                //   - introduce Bus Controller API support for these attributes
                //   - store the default values in the DB
-               String postJSON = String.format("{\"suspend\": \"%s\", \"delivery\": "
-                               + "{\"url\": \"%s\", \"user\": \"%s\", \"password\": \"%s\", \"use100\":  \"%s\"}"
+               String postJSON = String.format("{\"suspend\": %s, \"delivery\":"
+                               + "{\"url\": \"%s\", \"user\": \"%s\", \"password\": \"%s\", \"use100\":  %s}"
                                + ", \"metadataOnly\": %s, \"groupid\": \"%s\", \"follow_redirect\": %s "
-                               + ", \"guaranteed_delivery\": %s, \"guaranteed_sequence\": %s "
-                               + "}", 
-                               this.suspended,
-                               this.getDeliveryURL(), 
-                               this.getUsername(),
-                               this.getUserpwd(),
-                               this.isUse100(),
-                               "false",
-                               "0",
-                               "true",
-                               "false",
-                               "false");       
-               
+                               + ", \"guaranteed_delivery\": %s, \"guaranteed_sequence\": %s"
+                               + "}"
+                               ,this.suspended
+                               ,this.getDeliveryURL()
+                               ,this.getUsername()
+                               ,this.getUserpwd()
+                               ,this.isUse100()
+                               ,"false"
+                               ,"0"
+                               ,"true"
+                               ,this.isGuaranteedDelivery()
+                               ,this.isGuaranteedSequence()
+                               );
+
                logger.info( postJSON );
                return postJSON;
        }
-       
+
        @Override
        public String toString() {
-               String rc = String.format ( "DR_Sub: {dcaeLocationName=%s username=%s userpwd=%s feedId=%s deliveryURL=%s logURL=%s subid=%s use100=%s suspended=%s owner=%s}",
+               return String.format ( "DR_Sub: {dcaeLocationName=%s username=%s userpwd=%s feedId=%s deliveryURL=%s logURL=%s subid=%s use100=%s suspended=%s owner=%s}",
                                dcaeLocationName,
                                username,
                                userpwd,
@@ -259,6 +343,49 @@ public class DR_Sub extends DmaapObject {
                                suspended,
                                owner
                                );
-               return rc;
+       }
+
+       @Override
+       public boolean equals(Object o) {
+               if (this == o) {
+                       return true;
+               }
+               if (o == null || getClass() != o.getClass()) {
+                       return false;
+               }
+
+               DR_Sub drSub = (DR_Sub) o;
+
+               if (use100 != drSub.use100) {
+                       return false;
+               }
+               if (suspended != drSub.suspended) {
+                       return false;
+               }
+               if (!dcaeLocationName.equals(drSub.dcaeLocationName)) {
+                       return false;
+               }
+               if (!username.equals(drSub.username)) {
+                       return false;
+               }
+               if (!userpwd.equals(drSub.userpwd)) {
+                       return false;
+               }
+               if (!feedId.equals(drSub.feedId)) {
+                       return false;
+               }
+               return subId.equals(drSub.subId);
+       }
+
+       @Override
+       public int hashCode() {
+               int result = dcaeLocationName.hashCode();
+               result = 31 * result + username.hashCode();
+               result = 31 * result + userpwd.hashCode();
+               result = 31 * result + feedId.hashCode();
+               result = 31 * result + subId.hashCode();
+               result = 31 * result + (use100 ? 1 : 0);
+               result = 31 * result + (suspended ? 1 : 0);
+               return result;
        }
 }