From 5d1f87836448545ba20d2c21b2fda8ca8def4e20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20G=C3=A9raud?= Date: Sun, 26 Feb 2017 18:42:20 +0100 Subject: [PATCH] feat(pages): set a page as an api homepage fix gravitee-io/issues#467 --- pom.xml | 4 ++-- .../redis/management/RedisPageRepository.java | 22 ++++++++++++++++--- .../redis/management/model/RedisPage.java | 9 ++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index b4b6798..3e3937b 100644 --- a/pom.xml +++ b/pom.xml @@ -33,10 +33,10 @@ 2.9.0 - 1.4.0 + 1.5.0-SNAPSHOT 1.7.4.RELEASE - 1.4.0 + 1.5.0-SNAPSHOT 2.10 diff --git a/src/main/java/io/gravitee/repository/redis/management/RedisPageRepository.java b/src/main/java/io/gravitee/repository/redis/management/RedisPageRepository.java index 3995038..38e161c 100644 --- a/src/main/java/io/gravitee/repository/redis/management/RedisPageRepository.java +++ b/src/main/java/io/gravitee/repository/redis/management/RedisPageRepository.java @@ -42,7 +42,7 @@ public class RedisPageRepository implements PageRepository { private PageRedisRepository pageRedisRepository; @Override - public Collection findByApi(String apiId) throws TechnicalException { + public Collection findApiPageByApiId(String apiId) throws TechnicalException { return pageRedisRepository.findByApi(apiId) .stream() .map(this::convert) @@ -50,8 +50,8 @@ public Collection findByApi(String apiId) throws TechnicalException { } @Override - public Integer findMaxPageOrderByApi(String apiId) throws TechnicalException { - return findByApi(apiId).stream().mapToInt(Page::getOrder).max().orElse(0); + public Integer findMaxApiPageOrderByApiId(String apiId) throws TechnicalException { + return findApiPageByApiId(apiId).stream().mapToInt(Page::getOrder).max().orElse(0); } @Override @@ -68,6 +68,14 @@ public Page create(Page page) throws TechnicalException { @Override public Page update(Page page) throws TechnicalException { + if(page == null){ + throw new IllegalArgumentException("Page must not be null"); + } + + RedisPage oldRedisPage = pageRedisRepository.find(page.getId()); + if(oldRedisPage == null){ + throw new IllegalArgumentException(String.format("No page found with id [%s]", page.getId())); + } RedisPage redisPage = pageRedisRepository.saveOrUpdate(convert(page)); return convert(redisPage); } @@ -77,6 +85,12 @@ public void delete(String pageId) throws TechnicalException { pageRedisRepository.delete(pageId); } + @Override + public Collection findApiPageByApiIdAndHomepage(String apiId, boolean isHomepage) throws TechnicalException { + Collection pages = findApiPageByApiId(apiId); + return pages.stream().filter(page -> page.isHomepage() == isHomepage).collect(Collectors.toList()); + } + private Page convert(RedisPage redisPage) { if (redisPage == null) { return null; @@ -93,6 +107,7 @@ private Page convert(RedisPage redisPage) { page.setOrder(redisPage.getOrder()); page.setPublished(redisPage.isPublished()); page.setType(PageType.valueOf(redisPage.getType())); + page.setHomepage(redisPage.isHomepage()); if (redisPage.getSourceType() != null) { PageSource pageSource = new PageSource(); @@ -121,6 +136,7 @@ private RedisPage convert(Page page) { redisPage.setOrder(page.getOrder()); redisPage.setPublished(page.isPublished()); redisPage.setType(page.getType().name()); + redisPage.setHomepage(page.isHomepage()); if (page.getSource() != null) { redisPage.setSourceType(page.getSource().getType()); diff --git a/src/main/java/io/gravitee/repository/redis/management/model/RedisPage.java b/src/main/java/io/gravitee/repository/redis/management/model/RedisPage.java index 109fb61..1b3f1fb 100644 --- a/src/main/java/io/gravitee/repository/redis/management/model/RedisPage.java +++ b/src/main/java/io/gravitee/repository/redis/management/model/RedisPage.java @@ -37,6 +37,7 @@ public class RedisPage { private String sourceConfiguration; private boolean configurationTryIt; private String configurationTryItURL; + private boolean homepage; public String getApi() { return api; @@ -150,6 +151,14 @@ public void setConfigurationTryItURL(String configurationTryItURL) { this.configurationTryItURL = configurationTryItURL; } + public boolean isHomepage() { + return homepage; + } + + public void setHomepage(boolean homepage) { + this.homepage = homepage; + } + @Override public boolean equals(Object o) { if (this == o) return true;