Fixed the related api function with topic 54/98754/2
authorEkko Chang <ekko.chang@qct.io>
Fri, 22 Nov 2019 09:33:48 +0000 (09:33 +0000)
committerEkko Chang <ekko.chang@qct.io>
Tue, 26 Nov 2019 05:36:22 +0000 (05:36 +0000)
Issue-ID: DCAEGEN2-1715
Signed-off-by: Ekko Chang <ekko.chang@qct.io>
Change-Id: Iab20a1044cb953fb490f7981b6fa36e5eeea3c52

components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/config/SwaggerConfig.java
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/KafkaController.java
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/TopicController.java
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/TopicRepository.java
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/TopicService.java
components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicControllerTest.java

index dcf00a9..a9038bf 100644 (file)
@@ -55,6 +55,6 @@ public class SwaggerConfig {
        // Only select apis that matches the given Predicates.\r
        private Predicate<String> paths() {\r
                // Match all paths except /error\r
-               return Predicates.or(PathSelectors.regex("/dbs.*"), PathSelectors.regex("/topics.*"), PathSelectors.regex("/feeder.*"));\r
+               return Predicates.or(PathSelectors.regex("/dbs.*"), PathSelectors.regex("/topics.*"), PathSelectors.regex("/feeder.*"), PathSelectors.regex("/kafkas.*"));\r
        }\r
-}
\ No newline at end of file
+}\r
index 8d1bf31..41995e0 100644 (file)
@@ -36,6 +36,7 @@ import org.springframework.web.bind.annotation.*;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.util.List;
+import java.util.ArrayList;
 
 /**
  * This controller manages kafka settings
@@ -129,7 +130,17 @@ public class KafkaController {
 
     @GetMapping("")
     @ResponseBody
-    @ApiOperation(value="List all Kafkas")
+    @ApiOperation(value="List all Kafka id")
+    public List<Integer> list() {
+        Iterable<Kafka> ret = kafkaRepository.findAll();
+        List<Integer> retString = new ArrayList<>();
+        for (Kafka k : ret)
+        {
+            retString.add(k.getId());
+        }
+        return retString;
+    }
+
     public List<KafkaConfig> queryAllKafka(){
         return kafkaService.getAllKafka();
     }
index b59b2a7..2500075 100644 (file)
@@ -93,16 +93,28 @@ public class TopicController {
                return dmaapService.getTopics();
        }
 
+       @GetMapping("/default")
+       @ResponseBody
+       @ApiOperation(value = "Get default topic configuration.")
+       public TopicConfig getDefaultConfig(HttpServletResponse response) throws IOException {
+               Topic topic = topicService.getDefaultTopicFromFeeder();
+               if(topic == null) {
+                       sendError(response, 404, "Topic not found");
+                       return null;
+               }
+               return topic.getTopicConfig();
+       }
+
        @GetMapping("")
        @ResponseBody
-       @ApiOperation(value="List all topic names in database")
-       public List<String> list() {
+       @ApiOperation(value="List all topic id in database")
+       public List<Integer> list() {
                Iterable<Topic> ret = topicRepository.findAll();
-               List<String> retString = new ArrayList<>();
+               List<Integer> retString = new ArrayList<>();
                for(Topic item : ret)
                {
                        if(!topicService.isDefaultTopic(item))
-                               retString.add(item.getName());
+                               retString.add(item.getId());
                }
                return retString;
        }
index 8f72dfe..5dcee9e 100644 (file)
@@ -32,5 +32,5 @@ import org.springframework.data.repository.CrudRepository;
  */ \r
 \r
 public interface TopicRepository extends CrudRepository<Topic, Integer> {\r
-         //List<Topic> findByTopicName(String topicStr);\r
+         Topic findByTopicName_Id(String topicName);\r
 }\r
index 043cc65..e13a5d6 100644 (file)
@@ -119,6 +119,10 @@ public class TopicService {
                return ret.isPresent() ? ret.get() : null;
        }
 
+       public Topic getDefaultTopicFromFeeder() {
+               return topicRepository.findByTopicName_Id(config.getDefaultTopicName());
+       }
+
        public Topic getDefaultTopic(Kafka kafka) {
                return findTopics(kafka, config.getDefaultTopicName()).get(0);
        }
index 1a866bd..988010e 100644 (file)
@@ -163,8 +163,8 @@ public class TopicControllerTest {
                topics.add(TestUtil.newTopic(DEFAULT_TOPIC_NAME));
                when(topicRepository.findAll()).thenReturn(topics);
 
-               List<String> strings = topicController.list();
-               for (String topic : strings) {
+               List<Integer> ids = topicController.list();
+               for (Integer topic : ids) {
                        System.out.println(topic);
                }
        }