Fixed the related api function with topic
Issue-ID: DCAEGEN2-1715
Signed-off-by: Ekko Chang <ekko.chang@qct.io>
Change-Id: Iab20a1044cb953fb490f7981b6fa36e5eeea3c52
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/config/SwaggerConfig.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/config/SwaggerConfig.java
index dcf00a9..a9038bf 100644
--- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/config/SwaggerConfig.java
+++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/config/SwaggerConfig.java
@@ -55,6 +55,6 @@
// Only select apis that matches the given Predicates.
private Predicate<String> paths() {
// Match all paths except /error
- return Predicates.or(PathSelectors.regex("/dbs.*"), PathSelectors.regex("/topics.*"), PathSelectors.regex("/feeder.*"));
+ return Predicates.or(PathSelectors.regex("/dbs.*"), PathSelectors.regex("/topics.*"), PathSelectors.regex("/feeder.*"), PathSelectors.regex("/kafkas.*"));
}
-}
\ No newline at end of file
+}
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/KafkaController.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/KafkaController.java
index 8d1bf31..41995e0 100644
--- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/KafkaController.java
+++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/KafkaController.java
@@ -36,6 +36,7 @@
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 @@
@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();
}
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/TopicController.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/TopicController.java
index b59b2a7..2500075 100644
--- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/TopicController.java
+++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/TopicController.java
@@ -93,16 +93,28 @@
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;
}
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/TopicRepository.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/TopicRepository.java
index 8f72dfe..5dcee9e 100644
--- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/TopicRepository.java
+++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/TopicRepository.java
@@ -32,5 +32,5 @@
*/
public interface TopicRepository extends CrudRepository<Topic, Integer> {
- //List<Topic> findByTopicName(String topicStr);
+ Topic findByTopicName_Id(String topicName);
}
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/TopicService.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/TopicService.java
index 043cc65..e13a5d6 100644
--- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/TopicService.java
+++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/TopicService.java
@@ -119,6 +119,10 @@
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);
}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicControllerTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicControllerTest.java
index 1a866bd..988010e 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicControllerTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicControllerTest.java
@@ -163,8 +163,8 @@
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);
}
}