Commit 08779977 authored by Matija Obreza's avatar Matija Obreza

Added AccessionSourceFilter

parent 2778adee
......@@ -98,6 +98,9 @@ public class AccessionFilter extends CooperatorOwnedModelFilter<AccessionFilter,
/** The inventory filter. */
public InventoryFilter inventories;
/** Accession sources */
public AccessionSourceFilter sources;
/**
* Builds the query.
*
......@@ -175,6 +178,10 @@ public class AccessionFilter extends CooperatorOwnedModelFilter<AccessionFilter,
predicates.add(accession.inventories.isNotEmpty());
predicates.addAll(inventories.collectPredicates(accession.inventories.any()));
}
if (sources != null) {
predicates.add(accession.accessionSources.isNotEmpty());
predicates.addAll(sources.collectPredicates(accession.accessionSources.any()));
}
return predicates;
}
......
/*
* Copyright 2020 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.gringlobal.service.filter;
import java.io.Serializable;
import java.util.List;
import java.util.Set;
import org.apache.commons.collections4.CollectionUtils;
import org.gringlobal.model.AccessionInvGroup;
import org.gringlobal.model.AccessionSource;
import org.gringlobal.model.QAccessionSource;
import com.querydsl.core.types.Predicate;
/**
* Filters for {@link AccessionInvGroup}
*/
public class AccessionSourceFilter extends CooperatorOwnedModelFilter<AccessionSourceFilter, AccessionSource> implements Serializable {
private static final long serialVersionUID = 8959999560169507323L;
/** sourceTypeCodes */
public Set<String> sourceTypeCode;
/** acquisitionSource */
public Set<String> acquisitionSource;
/** Origin */
public Boolean origin;
/** Geography */
public GeographyFilter geography;
/**
* Builds the query.
*
* @return the predicate
*/
@Override
public List<Predicate> collectPredicates() {
return collectPredicates(QAccessionSource.accessionSource);
}
/**
* Builds the query.
*
* @param accessionSource the accession source
* @return the predicate
*/
public List<Predicate> collectPredicates(QAccessionSource accessionSource) {
final List<Predicate> predicates = super.collectPredicates(accessionSource, accessionSource._super);
if (CollectionUtils.isNotEmpty(sourceTypeCode)) {
predicates.add(accessionSource.sourceTypeCode.in(sourceTypeCode));
}
if (CollectionUtils.isNotEmpty(acquisitionSource)) {
predicates.add(accessionSource.acquisitionSource.in(acquisitionSource));
}
if (origin != null) {
predicates.add(accessionSource.isOrigin.eq(origin ? "Y" : "N"));
}
if (geography != null) {
predicates.addAll(geography.collectPredicates(accessionSource.geography));
}
return predicates;
}
}
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