Commit 257738b7 authored by RANNOU's avatar RANNOU 👽
Browse files

[enh] Repository: add levelIds and levelLabels filters, use it in PmfmRepository

parent c9312402
...@@ -48,6 +48,8 @@ public interface ReferentialSpecifications<E extends IReferentialWithStatusEntit ...@@ -48,6 +48,8 @@ public interface ReferentialSpecifications<E extends IReferentialWithStatusEntit
String LABEL_PARAMETER = "label"; String LABEL_PARAMETER = "label";
String LEVEL_PARAMETER = "level"; String LEVEL_PARAMETER = "level";
String LEVEL_SET_PARAMETER = "levelSet"; String LEVEL_SET_PARAMETER = "levelSet";
String LEVEL_LABEL_PARAMETER = "levelLabel";
String LEVEL_LABEL_SET_PARAMETER = "levelLabelSet";
String SEARCH_TEXT_PARAMETER = "searchText"; String SEARCH_TEXT_PARAMETER = "searchText";
default Specification<E> inStatusIds(IReferentialFilter filter) { default Specification<E> inStatusIds(IReferentialFilter filter) {
...@@ -61,7 +63,7 @@ public interface ReferentialSpecifications<E extends IReferentialWithStatusEntit ...@@ -61,7 +63,7 @@ public interface ReferentialSpecifications<E extends IReferentialWithStatusEntit
criteriaBuilder.in(root.get(IReferentialWithStatusEntity.Fields.STATUS).get(Status.Fields.ID)).value(statusParam) criteriaBuilder.in(root.get(IReferentialWithStatusEntity.Fields.STATUS).get(Status.Fields.ID)).value(statusParam)
); );
}); });
specification.addBind(STATUS_SET_PARAMETER, !ArrayUtils.isEmpty(statusIds)); specification.addBind(STATUS_SET_PARAMETER, ArrayUtils.isNotEmpty(statusIds));
specification.addBind(STATUS_PARAMETER, ArrayUtils.isEmpty(statusIds) ? null : Arrays.asList(statusIds)); specification.addBind(STATUS_PARAMETER, ArrayUtils.isEmpty(statusIds) ? null : Arrays.asList(statusIds));
return specification; return specification;
} }
...@@ -92,11 +94,30 @@ public interface ReferentialSpecifications<E extends IReferentialWithStatusEntit ...@@ -92,11 +94,30 @@ public interface ReferentialSpecifications<E extends IReferentialWithStatusEntit
criteriaBuilder.in(root.join(levelProperty, JoinType.INNER).get(IEntity.Fields.ID)).value(levelParam) criteriaBuilder.in(root.join(levelProperty, JoinType.INNER).get(IEntity.Fields.ID)).value(levelParam)
); );
}); });
specification.addBind(LEVEL_SET_PARAMETER, !ArrayUtils.isEmpty(levelIds)); specification.addBind(LEVEL_SET_PARAMETER, ArrayUtils.isNotEmpty(levelIds));
specification.addBind(LEVEL_PARAMETER, ArrayUtils.isEmpty(levelIds) ? null : Arrays.asList(levelIds)); specification.addBind(LEVEL_PARAMETER, ArrayUtils.isEmpty(levelIds) ? null : Arrays.asList(levelIds));
return specification; return specification;
} }
default Specification<E> inLevelLabels(String levelProperty, IReferentialFilter filter) {
String[] levelLabels = (filter.getLevelLabel() != null) ? new String[]{filter.getLevelLabel()} : filter.getLevelLabels();
return inLevelLabels(levelProperty, levelLabels);
}
default Specification<E> inLevelLabels(String levelProperty, String[] levelLabels) {
BindableSpecification<E> specification = BindableSpecification.where((root, query, criteriaBuilder) -> {
ParameterExpression<Collection> levelParam = criteriaBuilder.parameter(Collection.class, LEVEL_LABEL_PARAMETER);
ParameterExpression<Boolean> levelSetParam = criteriaBuilder.parameter(Boolean.class, LEVEL_LABEL_SET_PARAMETER);
return criteriaBuilder.or(
criteriaBuilder.isFalse(levelSetParam),
criteriaBuilder.in(root.join(levelProperty, JoinType.INNER).get(IItemReferentialEntity.Fields.LABEL)).value(levelParam)
);
});
specification.addBind(LEVEL_LABEL_SET_PARAMETER, ArrayUtils.isNotEmpty(levelLabels));
specification.addBind(LEVEL_LABEL_PARAMETER, ArrayUtils.isEmpty(levelLabels) ? null : Arrays.asList(levelLabels));
return specification;
}
default Specification<E> searchOrJoinSearchText(IReferentialFilter filter) { default Specification<E> searchOrJoinSearchText(IReferentialFilter filter) {
String searchText = Daos.getEscapedSearchText(filter.getSearchText()); String searchText = Daos.getEscapedSearchText(filter.getSearchText());
String searchJoinProperty = filter.getSearchJoin() != null ? StringUtils.uncapitalize(filter.getSearchJoin()) : null; String searchJoinProperty = filter.getSearchJoin() != null ? StringUtils.uncapitalize(filter.getSearchJoin()) : null;
......
...@@ -39,6 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -39,6 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching; import org.springframework.cache.annotation.Caching;
import org.springframework.data.jpa.domain.Specification;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import java.util.*; import java.util.*;
...@@ -181,6 +182,14 @@ public class PmfmRepositoryImpl ...@@ -181,6 +182,14 @@ public class PmfmRepositoryImpl
target.setQualitativeValues(entities); target.setQualitativeValues(entities);
} }
@Override
protected Specification<Pmfm> toSpecification(ReferentialFilterVO filter) {
return super.toSpecification(filter)
.and(inLevelIds(Pmfm.Fields.PARAMETER, filter))
.and(inLevelLabels(Pmfm.Fields.PARAMETER, filter));
}
@Override @Override
@Cacheable(cacheNames = CacheNames.PMFM_HAS_PREFIX) @Cacheable(cacheNames = CacheNames.PMFM_HAS_PREFIX)
public boolean hasLabelPrefix(int pmfmId, String... labelPrefixes) { public boolean hasLabelPrefix(int pmfmId, String... labelPrefixes) {
......
...@@ -39,6 +39,8 @@ public class DepartmentFilterVO implements IReferentialFilter { ...@@ -39,6 +39,8 @@ public class DepartmentFilterVO implements IReferentialFilter {
private Integer levelId; private Integer levelId;
private Integer[] levelIds; private Integer[] levelIds;
private String levelLabel;
private String[] levelLabels;
private String searchJoin; private String searchJoin;
private String searchText; private String searchText;
......
...@@ -49,6 +49,14 @@ public interface IReferentialFilter extends Serializable { ...@@ -49,6 +49,14 @@ public interface IReferentialFilter extends Serializable {
void setLevelIds(Integer[] levelIds); void setLevelIds(Integer[] levelIds);
String getLevelLabel();
void setLevelLabel(String LevelLabel);
String[] getLevelLabels();
void setLevelLabels(String[] LevelLabels);
String getSearchJoin(); String getSearchJoin();
void setSearchJoin(String searchJoin); void setSearchJoin(String searchJoin);
......
...@@ -44,6 +44,8 @@ public class PersonFilterVO implements IReferentialFilter { ...@@ -44,6 +44,8 @@ public class PersonFilterVO implements IReferentialFilter {
private Integer levelId; private Integer levelId;
private Integer[] levelIds; private Integer[] levelIds;
private String levelLabel;
private String[] levelLabels;
private String searchJoin; private String searchJoin;
private String searchText; private String searchText;
......
...@@ -39,6 +39,8 @@ public class ProgramFilterVO implements IReferentialFilter { ...@@ -39,6 +39,8 @@ public class ProgramFilterVO implements IReferentialFilter {
private Integer levelId; private Integer levelId;
private Integer[] levelIds; private Integer[] levelIds;
private String levelLabel;
private String[] levelLabels;
private String searchJoin; private String searchJoin;
private String searchText; private String searchText;
......
...@@ -43,6 +43,8 @@ public class ReferentialFilterVO implements IReferentialFilter { ...@@ -43,6 +43,8 @@ public class ReferentialFilterVO implements IReferentialFilter {
private Integer levelId; private Integer levelId;
private Integer[] levelIds; private Integer[] levelIds;
private String levelLabel;
private String[] levelLabels;
private String searchJoin; private String searchJoin;
private String searchText; private String searchText;
......
...@@ -42,6 +42,8 @@ public class StrategyFilterVO implements IReferentialFilter { ...@@ -42,6 +42,8 @@ public class StrategyFilterVO implements IReferentialFilter {
private Integer levelId; private Integer levelId;
private Integer[] levelIds; private Integer[] levelIds;
private String levelLabel;
private String[] levelLabels;
private String searchJoin; private String searchJoin;
private String searchText; private String searchText;
......
...@@ -42,6 +42,8 @@ public class TaxonNameFilterVO implements IReferentialFilter { ...@@ -42,6 +42,8 @@ public class TaxonNameFilterVO implements IReferentialFilter {
private Integer levelId; private Integer levelId;
private Integer[] levelIds; private Integer[] levelIds;
private String levelLabel;
private String[] levelLabels;
private String searchJoin; private String searchJoin;
private String searchText; private String searchText;
......
...@@ -43,6 +43,8 @@ public class ExtractionProductFilterVO implements IReferentialFilter { ...@@ -43,6 +43,8 @@ public class ExtractionProductFilterVO implements IReferentialFilter {
private Integer levelId; private Integer levelId;
private Integer[] levelIds; private Integer[] levelIds;
private String levelLabel;
private String[] levelLabels;
private String searchJoin; private String searchJoin;
private String searchText; private String searchText;
......
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