Actually remove pubs and subs on Feed delete
[dmaap/dbcapi.git] / src / main / java / org / onap / dmaap / dbcapi / service / DR_SubService.java
index 09bf8fd..138ff57 100644 (file)
@@ -26,12 +26,14 @@ import java.util.Map;
 
 import javax.ws.rs.core.Response.Status;
 
-import org.onap.dmaap.dbcapi.aaf.client.DrProvConnection;
-import org.onap.dmaap.dbcapi.aaf.database.DatabaseClass;
+import org.onap.dmaap.dbcapi.client.DrProvConnection;
+import org.onap.dmaap.dbcapi.database.DatabaseClass;
 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
 import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum;
 import org.onap.dmaap.dbcapi.model.ApiError;
 import org.onap.dmaap.dbcapi.model.DR_Sub;
+import org.onap.dmaap.dbcapi.util.DmaapConfig;
+import org.onap.dmaap.dbcapi.util.RandomInteger;
 
 public class DR_SubService extends BaseLoggingClass {
 
@@ -40,14 +42,19 @@ public class DR_SubService extends BaseLoggingClass {
        private String provURL;
        private static DrProvConnection prov;
        
+       private String unit_test;
+       
        
        public DR_SubService(  ) {
                logger.debug( "Entry: DR_SubService (with no args)" );
-
+               DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
+               unit_test = p.getProperty( "UnitTest", "No" );
        }       
        public DR_SubService( String subURL ) {
                logger.debug( "Entry: DR_SubService " + subURL );
                provURL = subURL;
+               DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
+               unit_test = p.getProperty( "UnitTest", "No" );
        }
        public Map<String, DR_Sub> getDR_Subs() {
                logger.debug( "enter getDR_Subs()");
@@ -87,7 +94,10 @@ public class DR_SubService extends BaseLoggingClass {
                prov = new DrProvConnection();
                prov.makeSubPostConnection( provURL );
                String resp = prov.doPostDr_Sub( sub, apiError );
-               logger.debug( "resp=" + resp );
+               if ( unit_test.equals( "Yes" ) ) {
+                       resp = simulateResp( sub, "POST" );
+               }
+               logger.debug( "addDr_Sub resp=" + resp );
 
                DR_Sub snew = null;
 
@@ -157,17 +167,40 @@ public class DR_SubService extends BaseLoggingClass {
                
        public void removeDr_Sub( String key, ApiError apiError ) {
                logger.debug( "enter removeDR_Subs()");
+               
                DR_Sub sub = dr_subs.get( key );
                if ( sub == null ) {
                        apiError.setCode(Status.NOT_FOUND.getStatusCode());
                        apiError.setFields( "subId");
                        apiError.setMessage("subId " + key + " not found");
                } else {        
-                       dr_subs.remove(key);
-                       apiError.setCode(200);
+                       DrProvConnection prov = new DrProvConnection();
+                       prov.makeSubPutConnection( key );
+                       String resp = prov.doDeleteDr_Sub( sub, apiError );
+                       logger.debug( "resp=" + resp );
+                       
+                       if ( apiError.is2xx() ) {
+                               dr_subs.remove(key);
+                       }
                }
 
                return;
        }       
 
+       private String simulateResp( DR_Sub sub, String action ){
+               String server = "subscriber.onap.org";
+               String subid;
+               if ( action.equals( "POST" ) ) { 
+                       RandomInteger ran = new RandomInteger(10000);
+                       subid = Integer.toString( ran.next() );
+               } else if ( action.equals( "PUT" ) ) {
+                       subid = sub.getSubId();
+               } else {
+                       subid = "99";
+               }
+               String ret = String.format("{\"delivery\": {\"url\": \"https://%s/delivery/%s\", \"user\": \"joe\", \"password\": \"secret\", \"use100\":  true}, \"metadataOnly\": false, \"groupid\": \"0\" , \"follow_redirect\": true }", 
+                       server, subid );
+
+               return ret;
+       }
 }