diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/controller/ArticleControler.java b/WebService/src/main/java/SAE/ApiREST/WebService/controller/ArticleControler.java index e914def..7c86921 100644 --- a/WebService/src/main/java/SAE/ApiREST/WebService/controller/ArticleControler.java +++ b/WebService/src/main/java/SAE/ApiREST/WebService/controller/ArticleControler.java @@ -1,6 +1,7 @@ package SAE.ApiREST.WebService.controller; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.hateoas.CollectionModel; import org.springframework.hateoas.EntityModel; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -12,7 +13,6 @@ import SAE.ApiREST.WebService.model.Article; import SAE.ApiREST.WebService.service.IArticleService; import java.util.ArrayList; -import java.util.List; import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn; @@ -179,14 +179,14 @@ public class ArticleControler { value = "/getAllArticle", produces = MediaType.APPLICATION_JSON_VALUE ) - public @ResponseBody EntityModel> getAllArticles() { + public @ResponseBody CollectionModel
getAllArticles() { ArrayList
results = (ArrayList
) articleService.getAllArticles(); if(results.isEmpty()) { throw new ArticleException("No articles available"); } - return EntityModel.of( + return CollectionModel.of( results, linkTo(methodOn(ArticleControler.class).getAllArticles()).withSelfRel() ); @@ -214,14 +214,14 @@ public class ArticleControler { value = "/getArticlesByTitle/{title}", produces = MediaType.APPLICATION_JSON_VALUE ) - public @ResponseBody EntityModel> getArticlesByTitle(@PathVariable(value = "title") String title) { + public @ResponseBody CollectionModel
getArticlesByTitle(@PathVariable(value = "title") String title) { ArrayList
results = (ArrayList
) articleService.getArticlesByTitle(title); if(results.isEmpty()) { throw new ArticleException("Undefined title"); } - return EntityModel.of( + return CollectionModel.of( results, linkTo(methodOn(ArticleControler.class).getArticlesByTitle(title)).withSelfRel(), linkTo(methodOn(ArticleControler.class).deleteArticleFromTitle(title)).withRel("deleteArticleFromTitle") @@ -232,14 +232,14 @@ public class ArticleControler { value = "/getArticlesByUrl/{url}", produces = MediaType.APPLICATION_JSON_VALUE ) - public @ResponseBody EntityModel> getArticlesByUrl(@PathVariable(value = "url") String url) { + public @ResponseBody CollectionModel
getArticlesByUrl(@PathVariable(value = "url") String url) { ArrayList
results = (ArrayList
) articleService.getArticlesByUrl(url); if(results.isEmpty()) { throw new ArticleException("Undefined title"); } - return EntityModel.of( + return CollectionModel.of( results, linkTo(methodOn(ArticleControler.class).getArticlesByUrl(url)).withSelfRel(), linkTo(methodOn(ArticleControler.class).deleteArticleFromUrl(url)).withRel("deleteArticleFromId") @@ -250,14 +250,14 @@ public class ArticleControler { value = "/getArticlesByType/{type}", produces = MediaType.APPLICATION_JSON_VALUE ) - public @ResponseBody EntityModel> getArticlesByType(@PathVariable(value = "type") Integer type) { + public @ResponseBody CollectionModel
getArticlesByType(@PathVariable(value = "type") Integer type) { ArrayList
results = (ArrayList
) articleService.getArticlesByType(type); if (results.isEmpty()) { throw new ArticleException(String.format("No content of type %d", type)); } - return EntityModel.of( + return CollectionModel.of( results, linkTo(methodOn(ArticleControler.class).getArticlesByType(type)).withSelfRel(), linkTo(methodOn(ArticleControler.class).deleteArticleFromType(type)).withRel("deleteArticleFromType") @@ -268,14 +268,14 @@ public class ArticleControler { value = "/getVisibleArticles", produces = MediaType.APPLICATION_JSON_VALUE ) - public @ResponseBody EntityModel> getVisibleArticles() { + public @ResponseBody CollectionModel
getVisibleArticles() { ArrayList
results = (ArrayList
) articleService.getVisibleArticles(); if (results.isEmpty()) { throw new ArticleException("No visible article"); } - return EntityModel.of( + return CollectionModel.of( results, linkTo(methodOn(ArticleControler.class).getVisibleArticles()).withSelfRel() ); @@ -285,14 +285,14 @@ public class ArticleControler { value = "/getInvisibleArticles", produces = MediaType.APPLICATION_JSON_VALUE ) - public @ResponseBody EntityModel> getInvisibleArticles() { + public @ResponseBody CollectionModel
getInvisibleArticles() { ArrayList
results = (ArrayList
) articleService.getInvisibleArticles(); if (results.isEmpty()) { throw new ArticleException("No invisible article"); } - return EntityModel.of( + return CollectionModel.of( results, linkTo(methodOn(ArticleControler.class).getInvisibleArticles()).withSelfRel() ); @@ -302,14 +302,14 @@ public class ArticleControler { value = "/getArticlesAddedBefore/{dateAdded}", produces = MediaType.APPLICATION_JSON_VALUE ) - public @ResponseBody EntityModel> getArticlesAddedBefore(@PathVariable(value = "dateAdded") String dateAdded) { + public @ResponseBody CollectionModel
getArticlesAddedBefore(@PathVariable(value = "dateAdded") String dateAdded) { ArrayList
results = (ArrayList
) articleService.getArticlesAddedBefore(dateAdded); if (results.isEmpty()) { throw new ArticleException(String.format("No article added before %t", dateAdded)); } - return EntityModel.of( + return CollectionModel.of( results, linkTo(methodOn(ArticleControler.class).getArticlesAddedBefore(dateAdded)).withSelfRel(), linkTo(methodOn(ArticleControler.class).deleteArticleAddedBefore(dateAdded)).withRel("deleteArticleAddedBefore") @@ -320,14 +320,14 @@ public class ArticleControler { value = "/getArticlesAddedAfter/{dateAdded}", produces = MediaType.APPLICATION_JSON_VALUE ) - public @ResponseBody EntityModel> getArticlesAddedAfter(@PathVariable(value = "dateAdded") String dateAdded) { + public @ResponseBody CollectionModel
getArticlesAddedAfter(@PathVariable(value = "dateAdded") String dateAdded) { ArrayList
results = (ArrayList
) articleService.getArticlesAddedAfter(dateAdded); if (results.isEmpty()) { throw new ArticleException(String.format("No article added after %t", dateAdded)); } - return EntityModel.of( + return CollectionModel.of( results, linkTo(methodOn(ArticleControler.class).getArticlesAddedAfter(dateAdded)).withSelfRel(), linkTo(methodOn(ArticleControler.class).deleteArticleAddedAfter(dateAdded)).withRel("deleteArticleAddedAfter") @@ -338,14 +338,14 @@ public class ArticleControler { value = "/getArticlesAddedBetween/{beginning}/{end}", produces = MediaType.APPLICATION_JSON_VALUE ) - public @ResponseBody EntityModel> getArticlesAddedBetween(@PathVariable(value = "beginning") String beginning, @PathVariable(value = "end") String end) { + public @ResponseBody CollectionModel
getArticlesAddedBetween(@PathVariable(value = "beginning") String beginning, @PathVariable(value = "end") String end) { ArrayList
results = (ArrayList
) articleService.getArticlesAddedBetween(beginning, end); if (results.isEmpty()) { throw new ArticleException(String.format("No article added between %t and %t", beginning, end)); } - return EntityModel.of( + return CollectionModel.of( results, linkTo(methodOn(ArticleControler.class).getArticlesAddedBetween(beginning, end)).withSelfRel(), linkTo(methodOn(ArticleControler.class).deleteArticleAddedBetween(beginning, end)).withRel("deleteArticleAddedBetween") @@ -356,14 +356,14 @@ public class ArticleControler { value = "/getArticlesPublishedBefore/{datePublished}", produces = MediaType.APPLICATION_JSON_VALUE ) - public @ResponseBody EntityModel> getArticlesPublishedBefore(@PathVariable(value = "datePublished") String datePublished) { + public @ResponseBody CollectionModel
getArticlesPublishedBefore(@PathVariable(value = "datePublished") String datePublished) { ArrayList
results = (ArrayList
) articleService.getArticlesPublishedBefore(datePublished); if (results.isEmpty()) { throw new ArticleException(String.format("No article published before %t", datePublished)); } - return EntityModel.of( + return CollectionModel.of( results, linkTo(methodOn(ArticleControler.class).getArticlesPublishedBefore(datePublished)).withSelfRel(), linkTo(methodOn(ArticleControler.class).deleteArticlePublishedBefore(datePublished)).withRel("deleteArticlePublishedBefore") @@ -374,14 +374,14 @@ public class ArticleControler { value = "/getArticlesPublishedAfter/{datePublished}", produces = MediaType.APPLICATION_JSON_VALUE ) - public @ResponseBody EntityModel> getArticlesPublishedAfter(@PathVariable(value = "datePublished") String datePublished) { + public @ResponseBody CollectionModel
getArticlesPublishedAfter(@PathVariable(value = "datePublished") String datePublished) { ArrayList
results = (ArrayList
) articleService.getArticlesPublishedAfter(datePublished); if (results.isEmpty()) { throw new ArticleException(String.format("No article published after %t", datePublished)); } - return EntityModel.of( + return CollectionModel.of( results, linkTo(methodOn(ArticleControler.class).getArticlesPublishedAfter(datePublished)).withSelfRel(), linkTo(methodOn(ArticleControler.class).deleteArticlePublishedAfter(datePublished)).withRel("deleteArticlePublishedAfter") @@ -392,14 +392,14 @@ public class ArticleControler { value = "/getArticlesPublishedBetween/{beginning}/{end}", produces = MediaType.APPLICATION_JSON_VALUE ) - public @ResponseBody EntityModel> getArticlesPublishedBetween(@PathVariable(value = "beginning") String beginning, @PathVariable(value = "end") String end) { + public @ResponseBody CollectionModel
getArticlesPublishedBetween(@PathVariable(value = "beginning") String beginning, @PathVariable(value = "end") String end) { ArrayList
results = (ArrayList
) articleService.getArticlesPublishedBetween(beginning, end); if (results.isEmpty()) { throw new ArticleException(String.format("No article published between %t and %t", beginning, end)); } - return EntityModel.of( + return CollectionModel.of( results, linkTo(methodOn(ArticleControler.class).getArticlesPublishedBetween(beginning, end)).withSelfRel(), linkTo(methodOn(ArticleControler.class).deleteArticlePublishedBetween(beginning, end)).withRel("getArticlesPublishedBetween")