diff --git a/src/main/java/eu/hbp/mip/controllers/AppsApi.java b/src/main/java/eu/hbp/mip/controllers/AppsApi.java index 0bc610acac1c8fbc4f635f8535e318114403a314..c544d492f64f8fce437c9490f3c93c1810c15150 100644 --- a/src/main/java/eu/hbp/mip/controllers/AppsApi.java +++ b/src/main/java/eu/hbp/mip/controllers/AppsApi.java @@ -49,6 +49,8 @@ public class AppsApi { @RequestMapping(method = RequestMethod.GET) public ResponseEntity<Iterable> getApps( ) { + LOGGER.info("Get apps"); + return ResponseEntity.ok(appRepository.findAll()); } @@ -59,6 +61,8 @@ public class AppsApi { @ApiParam(value = "id", required = true) @PathVariable("id") Integer id, @ApiParam(value = "value", required = true) @PathVariable("value") Integer value ) { + LOGGER.info("Post a vote"); + User user = userRepository.findOne(securityConfiguration.getUser().getUsername()); App app = appRepository.findOne(id); Vote vote; @@ -78,6 +82,8 @@ public class AppsApi { vote.setValue(value); voteRepository.save(vote); + LOGGER.info("Vote saved"); + return new ResponseEntity<>(HttpStatus.CREATED); } diff --git a/src/main/java/eu/hbp/mip/controllers/ArticlesApi.java b/src/main/java/eu/hbp/mip/controllers/ArticlesApi.java index 0b85ff02c62df94e66c2981f121018e983b7544c..8243c377cc6f2e70d93f05a91f28a0287383a511 100644 --- a/src/main/java/eu/hbp/mip/controllers/ArticlesApi.java +++ b/src/main/java/eu/hbp/mip/controllers/ArticlesApi.java @@ -45,6 +45,7 @@ public class ArticlesApi { @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 ) { + LOGGER.info("Get articles"); User user = securityConfiguration.getUser(); Iterable<Article> articles; @@ -80,6 +81,7 @@ public class ArticlesApi { public ResponseEntity<Void> addAnArticle( @RequestBody @ApiParam(value = "Article to create", required = true) @Valid Article article ) { + LOGGER.info("Create an article"); User user = securityConfiguration.getUser(); @@ -129,6 +131,8 @@ public class ArticlesApi { } articleRepository.save(article); + LOGGER.info("Article saved"); + return new ResponseEntity<>(HttpStatus.CREATED); } @@ -139,6 +143,7 @@ public class ArticlesApi { public ResponseEntity<Article> getAnArticle( @ApiParam(value = "slug", required = true) @PathVariable("slug") String slug ) { + LOGGER.info("Get an article"); User user = securityConfiguration.getUser(); Article article; @@ -147,6 +152,7 @@ public class ArticlesApi { { return new ResponseEntity<>(HttpStatus.FORBIDDEN); } + return ResponseEntity.ok(article); } @@ -158,6 +164,7 @@ public class ArticlesApi { @ApiParam(value = "slug", required = true) @PathVariable("slug") String slug, @RequestBody @ApiParam(value = "Article to update", required = true) @Valid Article article ) { + LOGGER.info("Update an article"); User user = securityConfiguration.getUser(); @@ -189,6 +196,8 @@ public class ArticlesApi { articleRepository.save(article); + LOGGER.info("Article updated"); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); } diff --git a/src/main/java/eu/hbp/mip/controllers/DatasetsApi.java b/src/main/java/eu/hbp/mip/controllers/DatasetsApi.java index e82c226bdd43b8fcc5a752e09901f7c4abdc641b..30e562bbf56bd8543cbfe2e2e168a9edd718f81f 100644 --- a/src/main/java/eu/hbp/mip/controllers/DatasetsApi.java +++ b/src/main/java/eu/hbp/mip/controllers/DatasetsApi.java @@ -8,6 +8,7 @@ package eu.hbp.mip.controllers; import io.swagger.annotations.*; import eu.hbp.mip.model.Dataset; import eu.hbp.mip.repositories.DatasetRepository; +import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -22,6 +23,8 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; @Api(value = "/datasets", description = "the datasets API") public class DatasetsApi { + private static final Logger LOGGER = Logger.getLogger(DatasetsApi.class); + @Autowired DatasetRepository datasetRepository; @@ -31,6 +34,8 @@ public class DatasetsApi { public ResponseEntity<Dataset> getADataset( @ApiParam(value = "code", required = true) @PathVariable("code") String code ) { + LOGGER.info("Get a dataset"); + return ResponseEntity.ok(datasetRepository.findOne(code)); } diff --git a/src/main/java/eu/hbp/mip/controllers/ExperimentApi.java b/src/main/java/eu/hbp/mip/controllers/ExperimentApi.java index c472f0760e88238b60a05b1577c2d9f23143abe0..cd3f0f23a8cd4f35ef1ff24a87d062471bc0b5d2 100644 --- a/src/main/java/eu/hbp/mip/controllers/ExperimentApi.java +++ b/src/main/java/eu/hbp/mip/controllers/ExperimentApi.java @@ -72,6 +72,8 @@ public class ExperimentApi { @ApiResponses(value = { @ApiResponse(code = 200, message = "Success") }) @RequestMapping(method = RequestMethod.POST) public ResponseEntity<String> runExperiment(@RequestBody String incomingQueryString) { + LOGGER.info("Run an experiment"); + JsonObject incomingQuery = gson.fromJson(incomingQueryString, JsonObject.class); Experiment experiment = new Experiment(); @@ -85,6 +87,8 @@ public class ExperimentApi { experiment.setModel(modelRepository.findOne(incomingQuery.get("model").getAsString())); experimentRepository.save(experiment); + LOGGER.info("Experiment saved"); + try { if(isExaremeAlgo(experiment)) { @@ -103,6 +107,8 @@ public class ExperimentApi { @ApiResponses(value = { @ApiResponse(code = 200, message = "Success") }) @RequestMapping(value = "/{uuid}", method = RequestMethod.GET) public ResponseEntity<String> getExperiment(@ApiParam(value = "uuid", required = true) @PathVariable("uuid") String uuid) { + LOGGER.info("Get an experiment"); + Experiment experiment; UUID experimentUuid; try { @@ -121,10 +127,11 @@ public class ExperimentApi { return new ResponseEntity<>(gson.toJson(experiment), HttpStatus.OK); } - @ApiOperation(value = "get an experiment", response = Experiment.class) + @ApiOperation(value = "Mark an experiment as viewed", response = Experiment.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Success") }) @RequestMapping(value = "/{uuid}/markAsViewed", method = RequestMethod.GET) public ResponseEntity<String> markExperimentAsViewed(@ApiParam(value = "uuid", required = true) @PathVariable("uuid") String uuid) { + LOGGER.info("Mark an experiment as viewed"); Experiment experiment; UUID experimentUuid; @@ -142,20 +149,27 @@ public class ExperimentApi { return new ResponseEntity<>("You're not the owner of this experiment", HttpStatus.BAD_REQUEST); experiment.setResultsViewed(true); experimentRepository.save(experiment); + + LOGGER.info("Experiment updated (marked as viewed)"); + return new ResponseEntity<>(gson.toJson(experiment), HttpStatus.OK); } - @ApiOperation(value = "get an experiment", response = Experiment.class) + @ApiOperation(value = "Mark an experiment as shared", response = Experiment.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Success") }) @RequestMapping(value = "/{uuid}/markAsShared", method = RequestMethod.GET) public ResponseEntity<String> markExperimentAsShared(@ApiParam(value = "uuid", required = true) @PathVariable("uuid") String uuid) { + LOGGER.info("Mark an experiment as shared"); + return doMarkExperimentAsShared(uuid, true); } - @ApiOperation(value = "get an experiment", response = Experiment.class) + @ApiOperation(value = "Mark an experiment as unshared", response = Experiment.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Success") }) @RequestMapping(value = "/{uuid}/markAsUnshared", method = RequestMethod.GET) public ResponseEntity<String> markExperimentAsUnshared(@ApiParam(value = "uuid", required = true) @PathVariable("uuid") String uuid) { + LOGGER.info("Mark an experiment as unshared"); + return doMarkExperimentAsShared(uuid, false); } @@ -165,6 +179,8 @@ public class ExperimentApi { public ResponseEntity<String> listExperiments( @ApiParam(value = "maxResultCount", required = false) @RequestParam int maxResultCount ) { + LOGGER.info("List experiments"); + return doListExperiments(true, maxResultCount, null); } @@ -175,6 +191,7 @@ public class ExperimentApi { @ApiParam(value = "slug", required = false) @RequestParam("slug") String modelSlug, @ApiParam(value = "maxResultCount", required = false) @RequestParam("maxResultCount") int maxResultCount ) { + LOGGER.info("List experiments"); if (maxResultCount <= 0 && (modelSlug == null || "".equals(modelSlug))) { return new ResponseEntity<>("You must provide at least a slug or a limit of result", HttpStatus.BAD_REQUEST); @@ -187,6 +204,7 @@ public class ExperimentApi { @ApiResponses(value = { @ApiResponse(code = 200, message = "Success") }) @RequestMapping(path = "/methods", method = RequestMethod.GET) public ResponseEntity<String> listAvailableMethodsAndValidations() throws IOException { + LOGGER.info("List available methods and validations"); StringBuilder response = new StringBuilder(); @@ -260,6 +278,8 @@ public class ExperimentApi { experiment.setShared(shared); experimentRepository.save(experiment); + LOGGER.info("Experiment updated (marked as shared)"); + return new ResponseEntity<>(gson.toJson(experiment), HttpStatus.OK); } @@ -314,6 +334,8 @@ public class ExperimentApi { { experiment.setFinished(new Date()); experimentRepository.save(experiment); + + LOGGER.info("Experiment updated (finished)"); } private static void executeExperiment(String url, String query, Experiment experiment) throws IOException { diff --git a/src/main/java/eu/hbp/mip/controllers/GroupsApi.java b/src/main/java/eu/hbp/mip/controllers/GroupsApi.java index ead40a093f1109ee7d217449483045c11a166962..dec89f6c3b3955351b9fa785621abac70846cefe 100644 --- a/src/main/java/eu/hbp/mip/controllers/GroupsApi.java +++ b/src/main/java/eu/hbp/mip/controllers/GroupsApi.java @@ -10,6 +10,7 @@ import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; import eu.hbp.mip.model.Group; import eu.hbp.mip.repositories.GroupRepository; +import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; @@ -23,6 +24,8 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; @Api(value = "/groups", description = "the groups API") public class GroupsApi { + private static final Logger LOGGER = Logger.getLogger(GroupsApi.class); + private static final String ROOT_CODE = "root"; @Autowired @@ -32,6 +35,8 @@ public class GroupsApi { @ApiResponses(value = { @ApiResponse(code = 200, message = "Success") }) @RequestMapping(method = RequestMethod.GET) public ResponseEntity<Group> getTheRootGroup() { + LOGGER.info("Get root group and its whole sub-groups tree"); + return ResponseEntity.ok(groupRepository.findOne(ROOT_CODE)); } diff --git a/src/main/java/eu/hbp/mip/controllers/ModelsApi.java b/src/main/java/eu/hbp/mip/controllers/ModelsApi.java index 31d736d2a04ad60c7add4afafb1580a2d3466006..c2e371d85ea54ec9e44002b679e6d222d457c1f1 100644 --- a/src/main/java/eu/hbp/mip/controllers/ModelsApi.java +++ b/src/main/java/eu/hbp/mip/controllers/ModelsApi.java @@ -64,6 +64,7 @@ public class ModelsApi { @ApiParam(value = "Only ask models from own team") @RequestParam(value = "team", required = false) Boolean team, @ApiParam(value = "Only ask published models") @RequestParam(value = "valid", required = false) Boolean valid ) { + LOGGER.info("Get models"); User user = securityConfiguration.getUser(); Iterable<Model> models = null; @@ -102,6 +103,8 @@ public class ModelsApi { @RequestBody @ApiParam(value = "Model to create", required = true) Model model ) { + LOGGER.info("Create a model"); + User user = securityConfiguration.getUser(); model.setTitle(model.getConfig().getTitle().get("text")); @@ -160,6 +163,8 @@ public class ModelsApi { datasetRepository.save(model.getDataset()); modelRepository.save(model); + LOGGER.info("Model saved (also saved model.config, model.query and model.dataset)"); + return new ResponseEntity<Model>(HttpStatus.CREATED).ok(model); } @@ -169,6 +174,7 @@ public class ModelsApi { public ResponseEntity<Model> getAModel( @ApiParam(value = "slug", required = true) @PathVariable("slug") String slug ) { + LOGGER.info("Get a model"); User user = securityConfiguration.getUser(); @@ -226,6 +232,7 @@ public class ModelsApi { @ApiParam(value = "slug", required = true) @PathVariable("slug") String slug, @RequestBody @ApiParam(value = "Model to update", required = true) Model model ) { + LOGGER.info("Update a model"); User user = securityConfiguration.getUser(); @@ -267,6 +274,8 @@ public class ModelsApi { datasetRepository.save(model.getDataset()); modelRepository.save(model); + LOGGER.info("Model updated (also saved/updated model.config, model.query and model.dataset)"); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); } diff --git a/src/main/java/eu/hbp/mip/controllers/RequestsApi.java b/src/main/java/eu/hbp/mip/controllers/RequestsApi.java index c3ace60ee80811a7339f6a6e871917c7b87dce1d..3beaeb241626a0c1b1a4c3d2d9081ac381e67586 100644 --- a/src/main/java/eu/hbp/mip/controllers/RequestsApi.java +++ b/src/main/java/eu/hbp/mip/controllers/RequestsApi.java @@ -8,6 +8,7 @@ import io.swagger.annotations.*; import eu.hbp.mip.model.Dataset; import eu.hbp.mip.model.Query; import eu.hbp.mip.utils.CSVUtil; +import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestBody; @@ -22,17 +23,21 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; @Api(value = "/queries/requests", description = "the requests API") public class RequestsApi { + private static final Logger LOGGER = Logger.getLogger(RequestsApi.class); + private static final String DATA_FILE = "data/values.csv"; @Autowired CSVUtil csvUtil; - @ApiOperation(value = "Send a request", response = Dataset.class) + @ApiOperation(value = "Post a request", response = Dataset.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Success") }) @RequestMapping(method = RequestMethod.POST) public ResponseEntity<Dataset> postRequests( @RequestBody @ApiParam(value = "Query to process", required = true) Query query ) { + LOGGER.info("Post a request"); + return ResponseEntity.ok(csvUtil.parseValues(DATA_FILE, query)); } diff --git a/src/main/java/eu/hbp/mip/controllers/StatsApi.java b/src/main/java/eu/hbp/mip/controllers/StatsApi.java index 4dd13b39d0710d02675b15fe9a5163647c3256bd..015929d1145affa8c0c0cca38d077ff20b3038ca 100644 --- a/src/main/java/eu/hbp/mip/controllers/StatsApi.java +++ b/src/main/java/eu/hbp/mip/controllers/StatsApi.java @@ -12,6 +12,7 @@ import io.swagger.annotations.ApiResponses; import eu.hbp.mip.model.GeneralStats; import eu.hbp.mip.repositories.ArticleRepository; import eu.hbp.mip.repositories.UserRepository; +import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; @@ -25,6 +26,8 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; @Api(value = "/stats", description = "the stats API") public class StatsApi { + private static final Logger LOGGER = Logger.getLogger(StatsApi.class); + @Autowired UserRepository userRepository; @@ -38,6 +41,7 @@ public class StatsApi { @ApiResponses(value = {@ApiResponse(code = 200, message = "Found"), @ApiResponse(code = 404, message = "Not found") }) @RequestMapping(method = RequestMethod.GET) public ResponseEntity<GeneralStats> getGeneralStatistics() { + LOGGER.info("Get statistics (count on users, articles and variables)"); GeneralStats stats = new GeneralStats(); diff --git a/src/main/java/eu/hbp/mip/controllers/UsersApi.java b/src/main/java/eu/hbp/mip/controllers/UsersApi.java index 7859a669a8a0ba0f955f22f4096ae4dc8a17f5ba..13a8f54e560f726d6b29087ceac79f6f0a16d13e 100644 --- a/src/main/java/eu/hbp/mip/controllers/UsersApi.java +++ b/src/main/java/eu/hbp/mip/controllers/UsersApi.java @@ -7,6 +7,7 @@ package eu.hbp.mip.controllers; import io.swagger.annotations.*; import eu.hbp.mip.model.User; import eu.hbp.mip.repositories.UserRepository; +import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -21,6 +22,8 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; @Api(value = "/users", description = "the users API") public class UsersApi { + private static final Logger LOGGER = Logger.getLogger(UsersApi.class); + @Autowired UserRepository userRepository; @@ -30,6 +33,8 @@ public class UsersApi { public ResponseEntity<User> getAUser( @ApiParam(value = "username", required = true) @PathVariable("username") String username ) { + LOGGER.info("Get a user"); + return ResponseEntity.ok(userRepository.findOne(username)); } } diff --git a/src/main/java/eu/hbp/mip/controllers/VariablesApi.java b/src/main/java/eu/hbp/mip/controllers/VariablesApi.java index 77cfc404a813919b793dd1498bb8506ddd28a304..505b90bdba9a6f9ac771b259147bb3e07cda4f4e 100644 --- a/src/main/java/eu/hbp/mip/controllers/VariablesApi.java +++ b/src/main/java/eu/hbp/mip/controllers/VariablesApi.java @@ -9,6 +9,7 @@ import eu.hbp.mip.repositories.VariableRepository; import io.swagger.annotations.*; import eu.hbp.mip.model.Value; import eu.hbp.mip.model.Variable; +import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -22,6 +23,8 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; @Api(value = "/variables", description = "the variables API") public class VariablesApi { + private static final Logger LOGGER = Logger.getLogger(VariablesApi.class); + @Autowired VariableRepository variableRepository; @@ -36,6 +39,8 @@ public class VariablesApi { @ApiParam(value = "Boolean value formatted like : (\"0\") or (\"1\") or (\"false\") or (\"true\")") @RequestParam(value = "isCovariable", required = false) String isCovariable, @ApiParam(value = "Boolean value formatted like : (\"0\") or (\"1\") or (\"false\") or (\"true\")") @RequestParam(value = "isFilter", required = false) String isFilter ) { + LOGGER.info("Get variables"); + return ResponseEntity.ok(variableRepository.findAll()); } @@ -45,6 +50,8 @@ public class VariablesApi { public ResponseEntity<Variable> getAVariable( @ApiParam(value = "code of the variable ( multiple codes are allowed, separated by \",\" )", required = true) @PathVariable("code") String code ) { + LOGGER.info("Get a variable"); + return ResponseEntity.ok(variableRepository.findOne(code)); } @@ -56,6 +63,8 @@ public class VariablesApi { @ApiParam(value = "code", required = true) @PathVariable("code") String code, @ApiParam(value = "Pattern to match") @RequestParam(value = "q", required = false) String q ) { + LOGGER.info("Get values from a variable"); + return ResponseEntity.ok(variableRepository.findOne(code).getValues()); }