Commit 262ed46a authored by COTONNEC's avatar COTONNEC
Browse files

[enh] countByFilter for TaxonName

parent 4c2190ad
......@@ -40,4 +40,6 @@ public interface TaxonNameRepository extends
List<TaxonName> getAllTaxonNameByParentIdInAndIsReferentTrue(Collection<Integer> parentIds);
Long countByFilter(TaxonNameFilterVO filter);
}
......@@ -197,6 +197,12 @@ public class TaxonNameRepositoryImpl
.getSingleResult();
}
public Long countByFilter(TaxonNameFilterVO filter) {
Preconditions.checkNotNull(filter);
return getCountQuery(toSpecification(filter), TaxonName.class).getSingleResult();
}
@Override
protected void toVO(TaxonName source, TaxonNameVO target, ReferentialFetchOptions fetchOptions, boolean copyIfNull) {
super.toVO(source, target, fetchOptions, copyIfNull);
......
......@@ -47,5 +47,8 @@ public interface TaxonNameService {
@Transactional(readOnly = true)
List<TaxonNameVO> getAllByTaxonGroupId(Integer taxonGroupId);
@Transactional(readOnly = true)
Long countByFilter(TaxonNameFilterVO filter);
TaxonNameVO save(TaxonNameVO taxonName);
}
......@@ -24,10 +24,12 @@ package net.sumaris.core.service.referential.taxon;
import com.google.common.base.Preconditions;
import lombok.extern.slf4j.Slf4j;
import net.sumaris.core.dao.referential.ReferentialDao;
import net.sumaris.core.dao.referential.taxon.ReferenceTaxonRepository;
import net.sumaris.core.dao.referential.taxon.TaxonNameRepository;
import net.sumaris.core.dao.technical.SortDirection;
import net.sumaris.core.model.referential.taxon.ReferenceTaxon;
import net.sumaris.core.model.referential.taxon.TaxonName;
import net.sumaris.core.vo.filter.TaxonNameFilterVO;
import net.sumaris.core.vo.referential.TaxonNameVO;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -45,6 +47,9 @@ public class TaxonNameServiceImpl implements TaxonNameService {
@Autowired
protected ReferenceTaxonRepository referenceTaxonRepository;
@Autowired
protected ReferentialDao referentialDao;
@Override
public TaxonNameVO get(int id) {
return taxonNameRepository.get(id);
......@@ -71,6 +76,14 @@ public class TaxonNameServiceImpl implements TaxonNameService {
return taxonNameRepository.getAllByTaxonGroupId(taxonGroupId);
}
@Override
public Long countByFilter(TaxonNameFilterVO filter) {
if (filter == null) {
return referentialDao.count(TaxonName.class.getSimpleName());
}
return taxonNameRepository.countByFilter(filter);
}
@Override
public TaxonNameVO save(TaxonNameVO source) {
Preconditions.checkNotNull(source);
......
......@@ -103,7 +103,7 @@ public class TaxonNameGraphQLService {
@GraphQLQuery(name = "taxonNameCount", description = "Get taxon name count")
@Transactional(readOnly = true)
public Long getTaxonNameCount(@GraphQLArgument(name = "filter") TaxonNameFilterVO filter) {
return referentialService.countByFilter(Program.class.getSimpleName(), filter);
return taxonNameService.countByFilter(filter);
}
/* -- Mutations -- */
......
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