Modified topic and db api function

table DB's PK is now integer, instead of string.

Change-Id: Id1ceb1bcd7a0455bc55e30c875e4398d12e8cf82
Issue-ID: DCAEGEN2-1715
Signed-off-by: ZhangZihao <zhangzihao@chinamobile.com>
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DbController.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DbController.java
index 54f46e6..49439e6 100644
--- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DbController.java
+++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DbController.java
@@ -71,14 +71,13 @@
 	//list all dbs
 	@GetMapping("")
 	@ResponseBody
-	@ApiOperation(value="Get all databases name")
-	public List<String> list() {
+	@ApiOperation(value="Get all database id")
+	public List<Integer> list() {
 		Iterable<Db> ret = dbRepository.findAll();
-		List<String> retString = new ArrayList<>();
+		List<Integer> retString = new ArrayList<>();
 		for(Db db : ret)
 		{
-			log.info(db.getName());
-			retString.add(db.getName());
+			retString.add(db.getId());
 
 		}
 		return retString;
@@ -165,16 +164,13 @@
 	//Show a db
 	//the topics are missing in the return, since in we use @JsonBackReference on Db's topics 
 	//need to the the following method to retrieve the topic list 
-	@GetMapping("/{dbName}")
+	@GetMapping("/{dbId}")
 	@ResponseBody
 	@ApiOperation(value="Get a database's details.")
-	public Db getDb(@PathVariable("dbName") String dbName, HttpServletResponse response) throws IOException {
-		Db db = dbRepository.findByName(dbName);
-		if (db == null) {
-			sendError(response, 404, DB_NOT_FOUND + dbName);
-		}
-		return db;
-	}
+	public DbConfig getDb(@PathVariable("dbId") int dbId, HttpServletResponse response) throws IOException {
+  		Optional<Db> db = dbRepository.findById(dbId);
+  		return db.isPresent() ? db.get().getDbConfig() : null;
+ 	}
 
 
 	//Delete a db
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 5d0c762..0de004d 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
@@ -199,13 +199,13 @@
 		tConfig.setTtl(getTtl());
 		
 		Set<Db> topicDb = getDbs();
-		List<String> dbList = new ArrayList<>();
-		List<String> enabledDbList = new ArrayList<>();
+		List<Integer> dbList = new ArrayList<>();
+		List<Integer> enabledDbList = new ArrayList<>();
 		if (topicDb != null) {
 			for (Db item : topicDb) {
-				dbList.add(item.getName());
+				dbList.add(item.getId());
 				if(item.isEnabled()) {
-					enabledDbList.add(item.getName());
+					enabledDbList.add(item.getId());
 				}
 			}
 		}
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 6a262ca..1bdad2e 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
@@ -41,8 +41,8 @@
 	private String name;
 	private String login;
 	private String password;
-	private List<String> sinkdbs;
-	private List<String> enabledSinkdbs;//only include enabled db
+	private List<Integer> sinkdbs;
+	private List<Integer> enabledSinkdbs;//only include enabled db
 	private boolean enabled;
 	private boolean saveRaw;
 	private String dataFormat;
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 e13a5d6..2f0761a 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
@@ -160,10 +160,10 @@
 		topic.setFlattenArrayPath(tConfig.getFlattenArrayPath());
 
 		if (tConfig.getSinkdbs() != null) {
-			for (String item : tConfig.getSinkdbs()) {
-				Db sinkdb = dbRepository.findByName(item);
-				if (sinkdb != null) {
-					relateDb.add(sinkdb);
+			for (int item : tConfig.getSinkdbs()) {
+				Optional<Db> sinkdb = dbRepository.findById(item);
+				if (sinkdb.isPresent()) {
+					relateDb.add(sinkdb.get());
 				}
 			}
 			if (!relateDb.isEmpty())
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DbControllerTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DbControllerTest.java
index 3dc836c..c46a026 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DbControllerTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DbControllerTest.java
@@ -44,6 +44,7 @@
 import java.util.List;
 import java.util.Set;
 import java.util.Collections;
+import java.util.Optional;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
@@ -120,10 +121,11 @@
         assertEquals(null, db);
         //when(mockBindingResult.hasErrors()).thenReturn(false);
         String name = "Elecsticsearch";
-        when(dbRepository.findByName(name)).thenReturn(TestUtil.newDb(name));
+        int testId = 1234;
+        when(dbRepository.findById(testId)).thenReturn(Optional.of(TestUtil.newDb(name)));
         //db = dbController.updateDb(dbConfig, mockBindingResult, httpServletResponse);
         //assertEquals(200, db.getStatusCode());
-        Db elecsticsearch = dbController.getDb("Elecsticsearch", httpServletResponse);
+        DbConfig elecsticsearch = dbController.getDb(testId, httpServletResponse);
         assertNotNull(elecsticsearch);
     }
 
@@ -131,13 +133,14 @@
     public void testGetAllDbs() throws IOException, IllegalAccessException, NoSuchFieldException {
         DbController dbController = new DbController();
         String name = "Elecsticsearch";
+        int testId = 1234;
         List<Db> dbs = new ArrayList<>();
         dbs.add(TestUtil.newDb(name));
         setAccessPrivateFields(dbController);
         when(dbRepository.findAll()).thenReturn(dbs);
-        List<String> list = dbController.list();
-        for (String dbName : list) {
-            assertEquals("Elecsticsearch", dbName);
+        List<Integer> list = dbController.list();
+        for (int id : list) {
+            assertNotEquals(1234, id);
         }
         //dbController.deleteDb("Elecsticsearch", httpServletResponse);
     }
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java
index 4eebcb4..eea4750 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java
@@ -145,18 +145,18 @@
 		tConfig.setMessageIdPath("1234");
 		tConfig.setAggregateArrayPath("1234");
 		tConfig.setFlattenArrayPath("1234");
-		List<String> sinkdbs = new ArrayList<>();
-		sinkdbs.add("Elasticsearch");
+		List<Integer> sinkdbs = new ArrayList<>();
+		sinkdbs.add(1234);
 		tConfig.setSinkdbs(sinkdbs);
 
 		Db db = new Db();
-		db.setName("Elasticsearch");
+		db.setId(1234);
 
 		TopicName topicName = new TopicName();
 		topicName.setId("1234");
 
 		Optional<TopicName> optional = Optional.of(topicName);
-		when(dbRepository.findByName("Elasticsearch")).thenReturn(db);
+		when(dbRepository.findById(1234)).thenReturn(Optional.of(db));
 		when(topicNameRepository.findById(tConfig.getName())).thenReturn(optional);
 
 		topicService.fillTopicConfiguration(tConfig);