Merge "LoadSchema.java: Fixed sonar issue"
[dmaap/dbcapi.git] / src / main / java / org / onap / dmaap / dbcapi / resources / TopicResource.java
index 0f99fb6..cab48ca 100644 (file)
@@ -44,9 +44,11 @@ import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
 import org.onap.dmaap.dbcapi.model.ApiError;
 import org.onap.dmaap.dbcapi.model.DR_Pub;
 import org.onap.dmaap.dbcapi.model.ReplicationType;
+import org.onap.dmaap.dbcapi.model.FqtnType;
 import org.onap.dmaap.dbcapi.model.Topic;
 import org.onap.dmaap.dbcapi.service.ApiService;
 import org.onap.dmaap.dbcapi.service.TopicService;
+import org.onap.dmaap.dbcapi.util.DmaapConfig;
 
 @Path("/topics")
 @Api( value= "topics", description = "Endpoint for retreiving MR Topics" )
@@ -54,8 +56,14 @@ import org.onap.dmaap.dbcapi.service.TopicService;
 @Produces(MediaType.APPLICATION_JSON)
 @Authorization
 public class TopicResource extends BaseLoggingClass {
-
+       private static FqtnType defaultTopicStyle;
        TopicService mr_topicService = new TopicService();
+       
+       public TopicResource() {
+               DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
+               defaultTopicStyle = FqtnType.Validator( p.getProperty("MR.topicStyle", "FQTN_LEGACY_FORMAT"));
+               logger.info( "Setting defaultTopicStyle=" + defaultTopicStyle );
+       }
                
        @GET
        @ApiOperation( value = "return Topic details", 
@@ -88,7 +96,7 @@ public class TopicResource extends BaseLoggingClass {
        public Response  addTopic( 
                        Topic topic
                        ) {
-               logger.info( "addTopic request: " + String.valueOf(topic) );
+               logger.info( "addTopic request: " + topic );
                ApiService check = new ApiService();
 
                try {
@@ -96,19 +104,23 @@ public class TopicResource extends BaseLoggingClass {
                        check.required( "topicDescription", topic.getTopicDescription(), "" );
                        check.required( "owner", topic.getOwner(), "" );
                } catch( RequiredFieldException rfe ) {
+                       logger.error("Error", rfe);
                        return check.error();
                }
                
-               //String repReq = topic.getReplicationRequest();
                ReplicationType t = topic.getReplicationCase();
                if ( t == null || t == ReplicationType.REPLICATION_NOT_SPECIFIED ) {
                        topic.setReplicationCase( mr_topicService.reviewTopic(topic));
                } 
-               
+               FqtnType ft = topic.getFqtnStyle();
+               if ( ft == null || ft == FqtnType.FQTN_NOT_SPECIFIED ) {
+                       logger.info( "setting defaultTopicStyle=" + defaultTopicStyle + " for topic " + topic.getTopicName() );
+                       topic.setFqtnStyle( defaultTopicStyle );
+               }
                topic.setLastMod();
                
                Topic mrc =  mr_topicService.addTopic(topic, check.getErr());
-               if ( mrc != null && mrc.isStatusValid() ) {
+               if ( mrc != null && check.getErr().is2xx() ) {
                        return check.success(Status.CREATED.getStatusCode(), mrc);
                }
                return check.error();
@@ -151,6 +163,7 @@ public class TopicResource extends BaseLoggingClass {
                try {
                        check.required( "fqtn", id, "" );
                } catch( RequiredFieldException rfe ) {
+                       logger.error("Error", rfe);
                        return check.error();
                }
                
@@ -180,6 +193,7 @@ public class TopicResource extends BaseLoggingClass {
                try {
                        check.required( "topicName", id, "^\\S+$" );  //no white space allowed in topicName
                } catch( RequiredFieldException rfe ) {
+                       logger.error("Error", rfe);
                        return check.error();
                }
                Topic mrc =  mr_topicService.getTopic( id, check.getErr() );