Merge "Modified resp topicConfig and add getTopicName()"
diff --git a/components/datalake-handler/feeder/src/assembly/scripts/init_db.sql b/components/datalake-handler/feeder/src/assembly/scripts/init_db.sql
index 8a91427..3f495e2 100644
--- a/components/datalake-handler/feeder/src/assembly/scripts/init_db.sql
+++ b/components/datalake-handler/feeder/src/assembly/scripts/init_db.sql
@@ -2,7 +2,7 @@
 * ============LICENSE_START=======================================================

 * ONAP : DATALAKE

 * ================================================================================

-* Copyright 2019 China Mobile

+* Copyright 2019-2020 China Mobile

 *=================================================================================

 * Licensed under the Apache License, Version 2.0 (the "License");

 * you may not use this file except in compliance with the License.

@@ -98,7 +98,7 @@
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

 

 CREATE TABLE `topic` (

-  `id` int(11) NOT NULL,

+  `id` int(11) NOT NULL AUTO_INCREMENT,

   `aggregate_array_path` varchar(255) DEFAULT NULL,

   `correlate_cleared_message` bit(1) NOT NULL DEFAULT b'0',

   `data_format` varchar(255) DEFAULT NULL,

diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/TopicNameController.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/TopicNameController.java
new file mode 100644
index 0000000..570dcd1
--- /dev/null
+++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/TopicNameController.java
@@ -0,0 +1,54 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : DataLake
+ * ================================================================================
+ * Copyright 2019-2020 China Mobile
+ *=================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.datalake.feeder.controller;
+
+import io.swagger.annotations.ApiOperation;
+import org.onap.datalake.feeder.domain.TopicName;
+import org.onap.datalake.feeder.repository.TopicNameRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RestController
+@RequestMapping(value = "/topicNames", produces = { MediaType.APPLICATION_JSON_VALUE })
+public class TopicNameController {
+
+    @Autowired
+    private TopicNameRepository topicNameRepository;
+
+    @GetMapping("")
+    @ResponseBody
+    @ApiOperation(value="List all topicNames")
+    public List<String> list() {
+        Iterable<TopicName> ret = topicNameRepository.findAll();
+        List<String> retString = new ArrayList<>();
+        for(TopicName item : ret) {
+                retString.add(item.getId());
+        }
+        return retString;
+    }
+}
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Topic.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Topic.java
index 0de004d..fcbe613 100644
--- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Topic.java
+++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Topic.java
@@ -2,7 +2,7 @@
 * ============LICENSE_START=======================================================
 * ONAP : DataLake
 * ================================================================================
-* Copyright 2019 China Mobile
+* Copyright 2019-2020 China Mobile
 *=================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -23,6 +23,8 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.Map;
+import java.util.HashMap;
 
 import javax.persistence.Column;
 import javax.persistence.Entity;
@@ -33,6 +35,8 @@
 import javax.persistence.ManyToMany;
 import javax.persistence.ManyToOne;
 import javax.persistence.Table;
+import javax.persistence.GenerationType;
+import javax.persistence.GeneratedValue;
 
 import org.apache.commons.lang3.StringUtils;
 import org.json.JSONObject;
@@ -57,6 +61,7 @@
 public class Topic {
 	@Id
     @Column(name = "`id`")
+	@GeneratedValue(strategy = GenerationType.IDENTITY)
     private Integer id;
 
 	@ManyToOne(fetch = FetchType.EAGER)
@@ -201,16 +206,27 @@
 		Set<Db> topicDb = getDbs();
 		List<Integer> dbList = new ArrayList<>();
 		List<Integer> enabledDbList = new ArrayList<>();
+		List<String> enabledDbList2 = new ArrayList<>();
 		if (topicDb != null) {
 			for (Db item : topicDb) {
 				dbList.add(item.getId());
 				if(item.isEnabled()) {
 					enabledDbList.add(item.getId());
+					enabledDbList2.add(item.getDbType().getId());
 				}
 			}
 		}
 		tConfig.setSinkdbs(dbList);
 		tConfig.setEnabledSinkdbs(enabledDbList);
+		Map<String,Integer> map = new HashMap<>();
+		for (String string : enabledDbList2) {
+			if(map.containsKey(string)) {
+				map.put(string, map.get(string).intValue()+1);
+			}else {
+				map.put(string, new Integer(1));
+			}
+		}
+		tConfig.setCountsDb(map);
 
 		Set<Kafka> topicKafka = getKafkas();
 		List<Integer> kafkaList = new ArrayList<>();
@@ -220,6 +236,7 @@
 			}
 		}
 		tConfig.setKafkas(kafkaList);
+		tConfig.setCountsKafka(kafkaList.size());
 		return tConfig;
 	}
 
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/TopicConfig.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/TopicConfig.java
index 1bdad2e..c865ec9 100644
--- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/TopicConfig.java
+++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/TopicConfig.java
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP : DataLake
  * ================================================================================
- * Copyright 2019 QCT
+ * Copyright 2019-2020 QCT
  *=================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
 import lombok.Setter;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * JSON request body for Topic manipulation.
@@ -37,7 +38,7 @@
 
 public class TopicConfig {
 
-	private int id;
+	private Integer id;
 	private String name;
 	private String login;
 	private String password;
@@ -52,7 +53,9 @@
 	private String aggregateArrayPath;
 	private String flattenArrayPath;
 	private List<Integer> kafkas;
-	
+	private Map<String,Integer> countsDb;
+	private int countsKafka;
+
 	@Override
 	public String toString() {
 		return String.format("TopicConfig %s(enabled=%s, enabledSinkdbs=%s)", name, enabled, enabledSinkdbs);
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 b6466a8..c26d980 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
@@ -2,7 +2,7 @@
 * ============LICENSE_START=======================================================
 * ONAP : DATALAKE
 * ================================================================================
-* Copyright 2019 China Mobile
+* Copyright 2019-2020 China Mobile
 *=================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@
 import org.onap.datalake.feeder.domain.EffectiveTopic;
 import org.onap.datalake.feeder.domain.Kafka;
 import org.onap.datalake.feeder.domain.Topic;
+import org.onap.datalake.feeder.domain.TopicName;
 import org.onap.datalake.feeder.repository.DbRepository;
 import org.onap.datalake.feeder.repository.KafkaRepository;
 import org.onap.datalake.feeder.repository.TopicNameRepository;
@@ -149,7 +150,10 @@
 	private void fillTopic(TopicConfig tConfig, Topic topic) {
 		Set<Db> relateDb = new HashSet<>();
 		topic.setId(tConfig.getId());
-		topic.setTopicName(topicNameRepository.findById(tConfig.getName()).get());
+		Optional<TopicName> t = topicNameRepository.findById(tConfig.getName());
+		if (!t.isPresent())
+			throw new IllegalArgumentException("Can not find topicName in TopicName, topic name " + tConfig.getName());
+		topic.setTopicName(t.get());
 		topic.setLogin(tConfig.getLogin());
 		topic.setPass(tConfig.getPassword());
 		topic.setEnabled(tConfig.isEnabled());