From 4394b4d7fd1aaa40d7fa40e600b3b819b024ac38 Mon Sep 17 00:00:00 2001 From: Mirco Nasuti <mirco.nasuti@chuv.ch> Date: Thu, 21 Jan 2016 13:54:12 +0100 Subject: [PATCH] progress in Swagger sync --- README.md | 7 +-- .../org/hbp/mip/controllers/ArticlesApi.java | 2 +- .../org/hbp/mip/controllers/ModelsApi.java | 2 +- .../org/hbp/mip/controllers/StatsApi.java | 38 ++++++++++++ .../org/hbp/mip/controllers/VariablesApi.java | 2 +- .../java/org/hbp/mip/model/Statistics.java | 60 +++++++++++++++++++ 6 files changed, 104 insertions(+), 7 deletions(-) create mode 100644 src/main/java/org/hbp/mip/controllers/StatsApi.java create mode 100644 src/main/java/org/hbp/mip/model/Statistics.java diff --git a/README.md b/README.md index c2748b1b7..b818d1032 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,7 @@ This is the MIP implementation. ## Usage -Run `mvn clean`, `mvn package` and `java -jar target/*.jar` to compile and run a demo. -To use it, you need to configure some URLs and register an openid client on the HBP platform. +Build the project with `./build` and run it with `./run`. ## API Documentation using Swagger (Springfox) @@ -13,8 +12,8 @@ The API documentation is available at `<BASE URL>/swagger-ui.html`. A JSON versi ## TODO -* "Dockerize" the project; -* Sync backend with hand written Swagger specs; +* Externalize configuration (DB parameters, security enabled/disabled, ...) +* Sync backend with hand written Swagger specs (see Maintenance section below); * Implement logout; * Update frontend (add introduction page, hide header/footer when not logged in, remove mock authors). diff --git a/src/main/java/org/hbp/mip/controllers/ArticlesApi.java b/src/main/java/org/hbp/mip/controllers/ArticlesApi.java index 1430e00ab..3726160b4 100644 --- a/src/main/java/org/hbp/mip/controllers/ArticlesApi.java +++ b/src/main/java/org/hbp/mip/controllers/ArticlesApi.java @@ -35,7 +35,7 @@ public class ArticlesApi { @RequestMapping(value = "", produces = {"application/json"}, method = RequestMethod.GET) public ResponseEntity<List<Article>> getArticles( @ApiParam(value = "Only ask own articles") @RequestParam(value = "own", required = false) Boolean own, - @ApiParam(value = "Only ask results matching status") @RequestParam(value = "status", required = false) String status, + @ApiParam(value = "Only ask results matching status", allowableValues = "{values=[draft, published, closed]}") @RequestParam(value = "status", required = false) String status, @ApiParam(value = "Only ask articles from own team") @RequestParam(value = "team", required = false) Boolean team, @ApiParam(value = "Only ask valid articles") @RequestParam(value = "valid", required = false) Boolean valid) throws NotFoundException { diff --git a/src/main/java/org/hbp/mip/controllers/ModelsApi.java b/src/main/java/org/hbp/mip/controllers/ModelsApi.java index ae96515c5..90e6c68e6 100644 --- a/src/main/java/org/hbp/mip/controllers/ModelsApi.java +++ b/src/main/java/org/hbp/mip/controllers/ModelsApi.java @@ -124,7 +124,7 @@ public class ModelsApi { @RequestMapping(value = "/{slug}", produces = {"application/json"}, method = RequestMethod.PUT) public ResponseEntity<Void> updateAModel( @ApiParam(value = "slug", required = true) @PathVariable("slug") String slug, - @ApiParam(value = "Model to update", required = true) Model model) throws NotFoundException { + @RequestBody @ApiParam(value = "Model to update", required = true) Model model) throws NotFoundException { // do some magic! return new ResponseEntity<Void>(HttpStatus.OK); } diff --git a/src/main/java/org/hbp/mip/controllers/StatsApi.java b/src/main/java/org/hbp/mip/controllers/StatsApi.java new file mode 100644 index 000000000..8d54f00df --- /dev/null +++ b/src/main/java/org/hbp/mip/controllers/StatsApi.java @@ -0,0 +1,38 @@ +package org.hbp.mip.controllers; + +import io.swagger.annotations.*; +import org.hbp.mip.model.Statistics; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import java.util.List; + +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; + +@Controller +@RequestMapping(value = "/stats", produces = {APPLICATION_JSON_VALUE}) +@Api(value = "/stats", description = "the stats API") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.SpringMVCServerCodegen", date = "2016-01-20T14:47:53.152Z") +public class StatsApi { + @ApiOperation(value = "Get the statistics for a group or a variable", notes = "", response = Statistics.class, responseContainer = "List") + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Found"), + @ApiResponse(code = 404, message = "Not found") }) + @RequestMapping(value = "/{code}", + produces = { "application/json" }, + + method = RequestMethod.GET) + public ResponseEntity<List<Statistics>> getTheStatisticsForAGroupOrAVariable( + @ApiParam(value = "code of the group or variable",required=true ) @PathVariable("code") String code + + ) + throws NotFoundException { + // do some magic! + return new ResponseEntity<List<Statistics>>(HttpStatus.OK); + } + +} diff --git a/src/main/java/org/hbp/mip/controllers/VariablesApi.java b/src/main/java/org/hbp/mip/controllers/VariablesApi.java index 9fe57839b..80bdf4718 100644 --- a/src/main/java/org/hbp/mip/controllers/VariablesApi.java +++ b/src/main/java/org/hbp/mip/controllers/VariablesApi.java @@ -78,7 +78,7 @@ public class VariablesApi { @ApiResponse(code = 404, message = "Not found")}) @RequestMapping(value = "/{code}", produces = {"application/json"}, method = RequestMethod.GET) public ResponseEntity<Variable> getAVariable( - @ApiParam(value = "code ( multiple codes are allowed, separeted by \",\" )", required = true) @PathVariable("code") String code) throws NotFoundException { + @ApiParam(value = "code of the variable ( multiple codes are allowed, separated by \",\" )", required = true) @PathVariable("code") String code) throws NotFoundException { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); org.hibernate.Query query = session.createQuery("from Variable where code= :code"); diff --git a/src/main/java/org/hbp/mip/model/Statistics.java b/src/main/java/org/hbp/mip/model/Statistics.java new file mode 100644 index 000000000..bea5fa0e1 --- /dev/null +++ b/src/main/java/org/hbp/mip/model/Statistics.java @@ -0,0 +1,60 @@ +package org.hbp.mip.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.Objects; + + +@ApiModel(description = "") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.SpringMVCServerCodegen", date = "2016-01-20T14:47:53.152Z") +public class Statistics { + + public enum DataTypeEnum { + SummaryStatistics, DatasetStatistics, + }; + private DataTypeEnum dataType = null; + + + /** + * Type of the data + **/ + @ApiModelProperty(required = true, value = "Type of the data") + @JsonProperty("dataType") + public DataTypeEnum getDataType() { + return dataType; + } + public void setDataType(DataTypeEnum dataType) { + this.dataType = dataType; + } + + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Statistics statistics = (Statistics) o; + return Objects.equals(dataType, statistics.dataType); + } + + @Override + public int hashCode() { + return Objects.hash(dataType); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Statistics {\n"); + + sb.append(" dataType: ").append(dataType).append("\n"); + sb.append("}\n"); + return sb.toString(); + } +} -- GitLab