aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authordglFromAtt <dgl@research.att.com>2019-02-18 20:00:09 -0500
committerdglFromAtt <dgl@research.att.com>2019-02-20 21:30:31 -0500
commit7ecdac335b89831e5d9043434f05beb21dff640a (patch)
treec5cb1815648bd3d8e9f43efc66c9e17733465560 /src
parent5eb10d9cfaa802e35174e99686f10510e8c7d54f (diff)
Added new fields to dr_sub API
for ONAP: privilegedSubscriber for AT&T: guaranteed_delivery, guaranteed_sequence also used this opportunity to move info about properties into README file patchset 2: increment version patchset 3: more try{}catch around reading fields from JSON . Boolean fields are fragile. Change-Id: Idc7353aaa660c180c1079f9ff61c7d55c41d4170 Signed-off-by: dglFromAtt <dgl@research.att.com> Issue-ID: DMAAP-1033 Signed-off-by: dglFromAtt <dgl@research.att.com>
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/model/DR_Sub.java115
-rw-r--r--src/main/resources/schema_12.sql30
-rw-r--r--src/test/java/org/onap/dmaap/dbcapi/model/DRSubTest.java57
3 files changed, 149 insertions, 53 deletions
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 a5d9999..dd0b85d 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
@@ -42,6 +42,9 @@ public class DR_Sub extends DmaapObject {
private boolean use100;
private boolean suspended;
private String owner;
+ private boolean guaranteedDelivery;
+ private boolean guaranteedSequence;
+ private boolean privilegedSubscriber;
public DR_Sub() {
@@ -81,13 +84,32 @@ 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);
+ }
JSONObject del = (JSONObject) jsonObj.get("delivery");
this.setDeliveryURL( (String) del.get("url") );
@@ -95,6 +117,8 @@ public class DR_Sub extends DmaapObject {
this.setUserpwd( (String) del.get( "password"));
this.setUse100((boolean) del.get( "use100"));
+
+
this.setStatus( DmaapObject_Status.VALID );
logger.info( "new DR_Sub returning");
@@ -183,6 +207,29 @@ 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 byte[] getBytes(String provApi) {
if ( "AT&T".equals(provApi)) {
@@ -193,18 +240,21 @@ public class DR_Sub extends DmaapObject {
// returns the DR_Sub object in JSON that conforms to ONAP DR Prov Server expectations
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 "
+ + "}"
+ ,this.suspended
+ ,this.getDeliveryURL()
+ ,this.getUsername()
+ ,this.getUserpwd()
+ ,this.isUse100()
+ ,"false"
+ ,"0"
+ ,"true"
+ ,this.isPrivilegedSubscriber()
+ );
logger.info( postJSON );
return postJSON;
@@ -225,21 +275,22 @@ 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;
diff --git a/src/main/resources/schema_12.sql b/src/main/resources/schema_12.sql
new file mode 100644
index 0000000..7aaab11
--- /dev/null
+++ b/src/main/resources/schema_12.sql
@@ -0,0 +1,30 @@
+---
+-- ============LICENSE_START=======================================================
+-- OpenECOMP - org.onap.dbcapi
+-- ================================================================================
+-- Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+-- ================================================================================
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+-- ============LICENSE_END=========================================================
+---
+
+
+@alter table dr_sub
+
+ add column guaranteed_delivery boolean,
+ add column guaranteed_sequence boolean,
+ add column privileged_subscriber boolean
+;
+
+
+update dmaapbc_sch_ver set version = 12 where version = 11;
diff --git a/src/test/java/org/onap/dmaap/dbcapi/model/DRSubTest.java b/src/test/java/org/onap/dmaap/dbcapi/model/DRSubTest.java
index e2e48cc..480ff07 100644
--- a/src/test/java/org/onap/dmaap/dbcapi/model/DRSubTest.java
+++ b/src/test/java/org/onap/dmaap/dbcapi/model/DRSubTest.java
@@ -66,6 +66,9 @@ public class DRSubTest {
assertTrue( ! t.isUse100() );
assertTrue( ! t.isSuspended() );
assertTrue( t.getOwner() == null );
+ assertTrue( t.isGuaranteedDelivery() == false );
+ assertTrue( t.isGuaranteedSequence() == false );
+ assertTrue( t.isPrivilegedSubscriber() == false );
}
@@ -103,36 +106,48 @@ public class DRSubTest {
assertTrue( du.equals( t.getDeliveryURL() ) );
t.setLogURL( lu );
assertTrue( lu.equals( t.getLogURL() ) );
-
+ boolean v = true;
+ t.setGuaranteedDelivery( v );
+ assertTrue( t.isGuaranteedDelivery() == v );
+ t.setGuaranteedSequence(v);
+ assertTrue( t.isGuaranteedSequence() == v );
+ t.setPrivilegedSubscriber(v);
+ assertTrue( t.isPrivilegedSubscriber() == v );
}
@Test
- public void test3() {
- String json = String.format( "{ \"%s\": \"%s\", \"%s\": false, \"%s\": { \"%s\": \"%s\", \"%s\": \"%s\", \"%s\": \"%s\" }, \"%s\": { \"%s\": \"%s\", \"%s\": \"%s\", \"%s\": \"%s\", \"%s\": true } }",
- "subscriber", "owner",
- "suspend",
- "links",
- "feed", "https://feed.onap.org/publish/22",
- "self", "https://feed.onap.org/subscriber/44",
- "log" , lu,
- "delivery" ,
- "url", du,
- "user", un,
- "password", up,
- "use100"
- );
-
-
- DR_Sub t = new DR_Sub( json );
+ public void testJSONfromONAP() {
+
+
+ DR_Sub s = new DR_Sub( d, un, up, f, du, lu, u100 );
+ String j = s.toProvJSON();
+
+ DR_Sub t = new DR_Sub( j );
assertTrue( un.equals( t.getUsername() ));
assertTrue( up.equals( t.getUserpwd() ));
- assertTrue( f.equals( t.getFeedId() ));
+ //assertTrue( f.equals( t.getFeedId() ));
assertTrue( du.equals( t.getDeliveryURL() ) );
- assertTrue( lu.equals( t.getLogURL() ) );
+ //assertTrue( lu.equals( t.getLogURL() ) );
assertTrue( ! t.isSuspended() );
- String o = t.toString();
+ }
+
+ @Test
+ public void testJSONfromATT() {
+
+
+ DR_Sub s = new DR_Sub( d, un, up, f, du, lu, u100 );
+
+ DR_Sub t = new DR_Sub( s.toProvJSONforATT() );
+
+ assertTrue( un.equals( t.getUsername() ));
+ assertTrue( up.equals( t.getUserpwd() ));
+ //assertTrue( f.equals( t.getFeedId() ));
+ assertTrue( du.equals( t.getDeliveryURL() ) );
+ // assertTrue( lu.equals( t.getLogURL() ) );
+ assertTrue( ! t.isSuspended() );
}
+
}