X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdbcapi%2Fservice%2FDR_SubService.java;h=99c8f31227e9475f8c22cbcf64bd3fa163882219;hb=4a75a26ddd9d7192e162cf3dc6a04e8a80fcce06;hp=09bf8fdbc886dad1325ec57d93d1a728b80727fb;hpb=a05efb7b7b3cfc77f5e3fda11e8434834829f56a;p=dmaap%2Fdbcapi.git diff --git a/src/main/java/org/onap/dmaap/dbcapi/service/DR_SubService.java b/src/main/java/org/onap/dmaap/dbcapi/service/DR_SubService.java index 09bf8fd..99c8f31 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/service/DR_SubService.java +++ b/src/main/java/org/onap/dmaap/dbcapi/service/DR_SubService.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. @@ -26,12 +28,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 +44,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 getDR_Subs() { logger.debug( "enter getDR_Subs()"); @@ -56,11 +65,11 @@ public class DR_SubService extends BaseLoggingClass { public List getAllDr_Subs() { logger.debug( "enter getAllDR_Subs()"); - return new ArrayList(dr_subs.values()); + return new ArrayList<>(dr_subs.values()); } public ArrayList getDr_SubsByFeedId( String pubId ) { - ArrayList someSubs = new ArrayList(); + ArrayList someSubs = new ArrayList<>(); for( DR_Sub sub : dr_subs.values() ) { if ( pubId.equals( sub.getFeedId() )) { someSubs.add( sub ); @@ -87,7 +96,11 @@ public class DR_SubService extends BaseLoggingClass { prov = new DrProvConnection(); prov.makeSubPostConnection( provURL ); String resp = prov.doPostDr_Sub( sub, apiError ); - logger.debug( "resp=" + resp ); + if ( "Yes".equals(unit_test) ) { + resp = simulateResp( sub, "POST" ); + apiError.setCode(200); + } + logger.debug( "addDr_Sub resp=" + resp ); DR_Sub snew = null; @@ -137,6 +150,10 @@ public class DR_SubService extends BaseLoggingClass { DrProvConnection prov = new DrProvConnection(); prov.makeSubPutConnection( obj.getSubId() ); String resp = prov.doPutDr_Sub( obj, apiError ); + if ( unit_test.equals( "Yes" ) ) { + resp = simulateResp( obj, "PUT" ); + apiError.setCode(200); + } logger.debug( "resp=" + resp ); DR_Sub snew = null; @@ -157,17 +174,46 @@ 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() || unit_test.equals( "Yes" ) ) { + 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("{\"suspend\": false, \"delivery\": {\"url\": \"https://%s/delivery/%s\", \"user\": \"%s\", \"password\": \"%s\", \"use100\": true}, \"metadataOnly\": false, \"groupid\": \"0\" , \"follow_redirect\": true, ", + server, subid, sub.getUsername(), sub.getUserpwd()); + String links = String.format( "\"links\": {\"feed\": \"https://dr-prov/feedlog/%s\", \"self\": \"https://dr-prov/sub/%s\", \"log\": \"https://dr-prov/sublog/%s\" }", + sub.getFeedId(), + sub.getSubId(), + sub.getSubId() ); + ret += links + "}"; + logger.info( "DR_SubService:simulateResp=" + ret); + + return ret; + } }