Actually remove pubs and subs on Feed delete
[dmaap/dbcapi.git] / src / main / java / org / onap / dmaap / dbcapi / service / TopicService.java
index 244fe37..eed5022 100644 (file)
@@ -31,7 +31,7 @@ import javax.ws.rs.core.Response.Status;
 import org.onap.dmaap.dbcapi.aaf.AafService;
 import org.onap.dmaap.dbcapi.aaf.DmaapPerm;
 import org.onap.dmaap.dbcapi.aaf.AafService.ServiceType;
-import org.onap.dmaap.dbcapi.aaf.database.DatabaseClass;
+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;
@@ -43,6 +43,7 @@ import org.onap.dmaap.dbcapi.model.ReplicationType;
 import org.onap.dmaap.dbcapi.model.Topic;
 import org.onap.dmaap.dbcapi.model.DmaapObject.DmaapObject_Status;
 import org.onap.dmaap.dbcapi.util.DmaapConfig;
+import org.onap.dmaap.dbcapi.util.Fqdn;
 import org.onap.dmaap.dbcapi.util.Graph;
 
 public class TopicService extends BaseLoggingClass {
@@ -94,7 +95,9 @@ public class TopicService extends BaseLoggingClass {
 
        public Topic addTopic( Topic topic, ApiError err ) {
                logger.info( "Entry: addTopic");
-               String nFqtn =  Topic.genFqtn( topic.getTopicName() );
+               logger.info( "Topic name=" + topic.getTopicName() + " fqtnStyle=" + topic.getFqtnStyle() );
+               String nFqtn =  topic.genFqtn();
+               logger.info( "FQTN=" + nFqtn );
                if ( getTopic( nFqtn, err ) != null ) {
                        String t = "topic already exists: " + nFqtn;
                        logger.info( t );
@@ -104,7 +107,7 @@ public class TopicService extends BaseLoggingClass {
                        return null;
                }
                err.reset();  // err filled with NOT_FOUND is expected case, but don't want to litter...
-               logger.info( "fqtn: " + nFqtn );
+
                topic.setFqtn( nFqtn );
 
                AafService aaf = new AafService(ServiceType.AAF_TopicMgr);
@@ -122,6 +125,20 @@ public class TopicService extends BaseLoggingClass {
                                return null;
                        }
                }
+               if ( topic.getReplicationCase().involvesGlobal() ) {
+                       if ( topic.getGlobalMrURL() == null ) {
+                               topic.setGlobalMrURL(defaultGlobalMrHost);
+                       }
+                       if ( ! Fqdn.isValid( topic.getGlobalMrURL())) {
+                               logger.error( "GlobalMR FQDN not valid: " + topic.getGlobalMrURL());
+                               topic.setStatus( DmaapObject_Status.INVALID);
+                               err.setCode(500);
+                               err.setMessage("Value is not a valid FQDN:" +  topic.getGlobalMrURL() );
+                               err.setFields("globalMrURL");
+       
+                               return null;
+                       }
+               }
 
 
                if ( topic.getNumClients() > 0 ) {
@@ -144,11 +161,7 @@ public class TopicService extends BaseLoggingClass {
 
                        topic.setClients(clients2);
                }
-               if ( topic.getReplicationCase().involvesGlobal() ) {
-                       if ( topic.getGlobalMrURL() == null ) {
-                               topic.setGlobalMrURL(defaultGlobalMrHost);
-                       }
-               }
+
                Topic ntopic = checkForBridge( topic, err );
                if ( ntopic == null ) {
                        topic.setStatus( DmaapObject_Status.INVALID);