diff options
Diffstat (limited to 'components/datalake-handler/feeder')
3 files changed, 19 insertions, 5 deletions
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 49439e60..fc709360 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 @@ -211,17 +211,17 @@ public class DbController { } //Update Db - @PutMapping("") + @PutMapping("/{id}") @ResponseBody @ApiOperation(value="Update a database.") - public PostReturnBody<DbConfig> updateDb(@RequestBody DbConfig dbConfig, BindingResult result, HttpServletResponse response) throws IOException { + public PostReturnBody<DbConfig> updateDb(@PathVariable int id, @RequestBody DbConfig dbConfig, BindingResult result, HttpServletResponse response) throws IOException { if (result.hasErrors()) { sendError(response, 400, "Error parsing DB: " + result.toString()); return null; } - Db oldDb = dbRepository.findById(dbConfig.getId()).get(); + Db oldDb = dbRepository.findById(id).get(); if (oldDb == null) { sendError(response, 404, DB_NOT_FOUND + dbConfig.getName()); return null; @@ -258,6 +258,15 @@ public class DbController { } + //get db type list + @GetMapping("/dbtypes") + @ResponseBody + @ApiOperation(value="Get a list of all db types.") + public Iterable<DbType> getDbTypes(HttpServletResponse response) throws IOException { + log.info("Get a list of all db types ......"); + Iterable<DbType> dbTypes = dbTypeRepository.findAll(); + return dbTypes; + } @PostMapping("/verify") @ResponseBody diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/DbType.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/DbType.java index 9c83a9cd..700ce8cb 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/DbType.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/DbType.java @@ -29,6 +29,9 @@ import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.Table; + +import com.fasterxml.jackson.annotation.JsonBackReference; + import lombok.Getter; import lombok.Setter; @@ -56,7 +59,8 @@ public class DbType { @Column(name="`tool`", nullable = false) private boolean tool; - + + @JsonBackReference @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "dbType") protected Set<Db> dbs = new HashSet<>(); 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 c46a026b..9318ee00 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 @@ -69,6 +69,7 @@ public class DbControllerTest { public DbConfig getDbConfig() { DbConfig dbConfig = new DbConfig(); + dbConfig.setId(1); dbConfig.setName("Elecsticsearch"); dbConfig.setHost("localhost"); dbConfig.setLogin("root"); @@ -112,7 +113,7 @@ public class DbControllerTest { DbController dbController = new DbController(); DbConfig dbConfig = getDbConfig(); when(mockBindingResult.hasErrors()).thenReturn(true); - PostReturnBody<DbConfig> db = dbController.updateDb(dbConfig, mockBindingResult, + PostReturnBody<DbConfig> db = dbController.updateDb(dbConfig.getId(), dbConfig, mockBindingResult, httpServletResponse); assertEquals(null, db); //when(mockBindingResult.hasErrors()).thenReturn(false); |