Commit 5dd0a047 authored by Matija Obreza's avatar Matija Obreza

Removed LucenePage

parent c2229e34
......@@ -34,6 +34,7 @@ import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.apache.commons.collections.ListUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.Predicate;
import org.apache.commons.lang.StringUtils;
......@@ -96,6 +97,7 @@ import org.genesys2.spring.SecurityContextUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
......@@ -524,7 +526,7 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
public Page<Accession> listAccessionsByOrganization(Organization organization, Pageable pageable) {
final List<FaoInstitute> members = organizationRepository.findInstitutesByOrganization(organization);
if (members == null || members.size() == 0) {
return new LucenePage<Accession>(0, 0);
return new PageImpl<Accession>(ListUtils.EMPTY_LIST);
}
return accessionRepository.findByInstitute(members, pageable);
}
......
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.service.impl;
import java.util.Iterator;
import java.util.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
public class LucenePage<T> implements Page<T> {
private final int number;
private final int size;
private long totalElements;
private List<T> content;
public LucenePage(int number, int size) {
this.number = number;
this.size = size;
}
@Override
public List<T> getContent() {
return content;
}
@Override
public int getNumber() {
return number;
}
@Override
public int getNumberOfElements() {
return content.size();
}
@Override
public int getSize() {
return size;
}
@Override
public Sort getSort() {
return null;
}
@Override
public long getTotalElements() {
return totalElements;
}
public void setTotalElements(long totalElements) {
this.totalElements = totalElements;
}
@Override
public int getTotalPages() {
return (int) Math.ceil((double) totalElements / (double) size);
}
@Override
public boolean hasContent() {
return content != null && content.size() > 0;
}
@Override
public boolean hasNextPage() {
return content.size() == size;
}
@Override
public boolean hasPreviousPage() {
return number > 1;
}
@Override
public boolean isFirstPage() {
return number == 0;
}
@Override
public boolean isLastPage() {
return content.size() < size;
}
@Override
public Iterator<T> iterator() {
return content.iterator();
}
public void setContent(List<T> data) {
content = data;
}
@Override
public Pageable nextPageable() {
return new PageRequest(number + 1, size, getSort());
}
@Override
public Pageable previousPageable() {
return new PageRequest(number - 1, size, getSort());
}
@Override
public boolean hasNext() {
return content.size() == size;
}
@Override
public boolean hasPrevious() {
return number > 1;
}
@Override
public boolean isFirst() {
return number == 0;
}
@Override
public boolean isLast() {
return content.size() < size;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment