Commit 657faf06 authored by RANNOU's avatar RANNOU 👽
Browse files

[enh] Service: samples count with TAG_ID and not individual count (#485)

parent b2bd4950
......@@ -99,6 +99,7 @@ public class SampleRepositoryImpl
.and(hasObservedLocationId(filter.getObservedLocationId()))
.and(inObservedLocationIds(filter.getObservedLocationIds()))
.and(hasTagId(filter.getTagId()))
.and(withTagId(filter.getWithTagId()))
.and(addJoinFetch(fetchOptions, true));
}
......
......@@ -123,6 +123,18 @@ public interface SampleSpecifications extends RootDataSpecifications<Sample> {
return specification;
}
default Specification<Sample> withTagId(Boolean withTagId) {
if (!Boolean.TRUE.equals(withTagId)) return null;
BindableSpecification<Sample> specification = BindableSpecification.where((root, query, criteriaBuilder) -> {
query.orderBy(criteriaBuilder.asc(root.get(Sample.Fields.RANK_ORDER)));
ParameterExpression<Integer> tagIdPmfmIdParam = criteriaBuilder.parameter(Integer.class, TAG_ID_PMFM_ID);
Join<Sample, SampleMeasurement> tagIdInnerJoin = root.joinList(Sample.Fields.MEASUREMENTS, JoinType.INNER);
return criteriaBuilder.equal(tagIdInnerJoin.get(SampleMeasurement.Fields.PMFM).get(IEntity.Fields.ID), tagIdPmfmIdParam);
});
specification.addBind(TAG_ID_PMFM_ID, PmfmEnum.TAG_ID.getId());
return specification;
}
default Specification<Sample> addJoinFetch(SampleFetchOptions fetchOptions, boolean addQueryDistinct) {
if (fetchOptions == null || !fetchOptions.isWithMeasurementValues()) return null;
......
......@@ -63,5 +63,6 @@ public class SampleFilterVO implements IRootDataFilter {
private Integer parentId;
private String tagId;
private Boolean withTagId;
}
......@@ -884,11 +884,9 @@ public class DataGraphQLService {
if (landing.getSamplesCount() != null) {
return landing.getSamplesCount();
}
if (landing.getSamples() != null) {
return landing.getSamples().size();
}
return sampleService.countByLandingId(landing.getId());
SampleFilterVO filter = SampleFilterVO.builder().landingId(landing.getId()).withTagId(true).build();
return sampleService.countByFilter(filter);
}
@GraphQLQuery(name = "samplesCount", description = "Get total number of samples")
......
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