Skip to content
This repository has been archived by the owner on Jul 29, 2021. It is now read-only.

Commit

Permalink
feat(pages): set a page as an api homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasGeraud authored and brasseld committed Mar 27, 2017
1 parent 9a34ce7 commit 5d1f878
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -33,10 +33,10 @@

<properties>
<jedis.version>2.9.0</jedis.version>
<gravitee-repository.version>1.4.0</gravitee-repository.version>
<gravitee-repository.version>1.5.0-SNAPSHOT</gravitee-repository.version>
<spring-data-redis.version>1.7.4.RELEASE</spring-data-redis.version>

<gravitee-repository-test.version>1.4.0</gravitee-repository-test.version>
<gravitee-repository-test.version>1.5.0-SNAPSHOT</gravitee-repository-test.version>
<maven-dependency-plugin.version>2.10</maven-dependency-plugin.version>
</properties>

Expand Down
Expand Up @@ -42,16 +42,16 @@ public class RedisPageRepository implements PageRepository {
private PageRedisRepository pageRedisRepository;

@Override
public Collection<Page> findByApi(String apiId) throws TechnicalException {
public Collection<Page> findApiPageByApiId(String apiId) throws TechnicalException {
return pageRedisRepository.findByApi(apiId)
.stream()
.map(this::convert)
.collect(Collectors.toSet());
}

@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
Expand All @@ -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);
}
Expand All @@ -77,6 +85,12 @@ public void delete(String pageId) throws TechnicalException {
pageRedisRepository.delete(pageId);
}

@Override
public Collection<Page> findApiPageByApiIdAndHomepage(String apiId, boolean isHomepage) throws TechnicalException {
Collection<Page> pages = findApiPageByApiId(apiId);
return pages.stream().filter(page -> page.isHomepage() == isHomepage).collect(Collectors.toList());
}

private Page convert(RedisPage redisPage) {
if (redisPage == null) {
return null;
Expand All @@ -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();
Expand Down Expand Up @@ -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());
Expand Down
Expand Up @@ -37,6 +37,7 @@ public class RedisPage {
private String sourceConfiguration;
private boolean configurationTryIt;
private String configurationTryItURL;
private boolean homepage;

public String getApi() {
return api;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5d1f878

Please sign in to comment.