Commit b2d9a268 authored by Matija Obreza's avatar Matija Obreza

Moved filters to model.filters package

parent 98e0f20f
/**
* 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.model.filters;
public class AutocompleteFilter extends BasicFilter {
private final String autocompleteUrl;
public AutocompleteFilter(String name, String autocompleteUrl) {
super(name, DataType.STRING, FilterType.AUTOCOMPLETE);
this.autocompleteUrl = autocompleteUrl;
}
public String getAutocompleteUrl() {
return autocompleteUrl;
}
}
\ No newline at end of file
/**
* 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.model.filters;
public class BasicFilter implements GenesysFilter {
private final String name;
private final DataType dataType;
private FilterType filterType;
private final Integer maxLength;
public boolean isCore() {
return true;
}
public BasicFilter(String name, DataType type) {
this.name = name;
this.dataType = type;
if (this.dataType == DataType.NUMERIC) {
this.filterType = FilterType.RANGE;
} else {
this.filterType = FilterType.EXACT;
}
this.maxLength = null;
}
public BasicFilter(String name, DataType type, FilterType filterType) {
this.name = name;
this.dataType = type;
this.filterType = filterType;
this.maxLength = null;
}
public BasicFilter(String name, DataType type, int i) {
this.name = name;
this.dataType = type;
if (this.dataType == DataType.NUMERIC) {
this.filterType = FilterType.RANGE;
} else {
this.filterType = FilterType.EXACT;
}
this.maxLength = i;
}
@Override
public String getKey() {
return name;
}
public String getName() {
return name;
}
public DataType getDataType() {
return dataType;
}
public FilterType getFilterType() {
return filterType;
}
public Integer getMaxLength() {
return maxLength;
}
}
\ No newline at end of file
/**
* 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.model.filters;
import java.util.Collections;
import java.util.List;
public class CodedMethodFilter extends MethodFilter {
private final List<ValueName<?>> options;
public CodedMethodFilter(String name, String title, DataType dataType, List<ValueName<?>> options) {
super(name, title, dataType, FilterType.LIST);
this.options = Collections.unmodifiableList(options);
}
public List<ValueName<?>> getOptions() {
return options;
}
}
\ No newline at end of file
/**
* 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.model.filters;
public interface GenesysFilter {
public String getKey();
public enum DataType {
FIXEDSTRING, STRING, NUMERIC, BOOLEAN
}
public enum FilterType {
EXACT, RANGE, LIST, AUTOCOMPLETE, I18NLIST
}
}
\ No newline at end of file
/**
* 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.model.filters;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.collections4.list.UnmodifiableList;
public class I18nListFilter<T> extends BasicFilter {
private List<ValueName<T>> options = new ArrayList<ValueName<T>>();
public I18nListFilter(String name, DataType dataType) {
super(name, dataType, FilterType.I18NLIST);
}
public GenesysFilter build(String prefix, @SuppressWarnings("unchecked") T... options) {
final List<ValueName<T>> opts = new ArrayList<ValueName<T>>();
for (final T opt : options) {
opts.add(new ValueName<T>(opt, prefix + "." + opt));
}
this.options = new UnmodifiableList<ValueName<T>>(opts);
return this;
}
public List<ValueName<T>> getOptions() {
return options;
}
}
\ No newline at end of file
/**
* 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.model.filters;
public class MethodFilter extends BasicFilter {
private final String title;
@Override
public boolean isCore() {
return false;
}
public MethodFilter(String name, String title, DataType dataType) {
super(name, dataType);
this.title = title;
}
public MethodFilter(String name, String title, DataType dataType, FilterType filterType) {
super(name, dataType, filterType);
this.title = title;
}
public String getTitle() {
return title;
}
}
\ No newline at end of file
package org.genesys2.server.model.filters;
public class ValueName<T> {
private final T value;
private final String name;
private Long count;
public ValueName(T value, String name) {
this.value = value;
this.name = name;
}
public ValueName(T value, String name, Long count) {
this.value = value;
this.name = name;
this.count = count;
}
public T getValue() {
return value;
}
public String getName() {
return name;
}
public Long getCount() {
return count;
}
}
\ No newline at end of file
......@@ -18,6 +18,7 @@ package org.genesys2.server.service;
import java.util.List;
import org.genesys2.server.model.filters.GenesysFilter;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.service.impl.GenesysFilterServiceImpl.LabelValue;
import org.springframework.data.domain.Page;
......@@ -35,19 +36,6 @@ public interface GenesysFilterService {
List<GenesysFilter> listAvailableFilters();
public static interface GenesysFilter {
public String getKey();
public enum DataType {
FIXEDSTRING, STRING, NUMERIC, BOOLEAN
}
public enum FilterType {
EXACT, RANGE, LIST, AUTOCOMPLETE, I18NLIST
}
}
List<GenesysFilter> selectFilters(String[] selectedFilters);
List<LabelValue<String>> autocomplete(String filter, String ac,ObjectNode jsonTree);
......
......@@ -30,10 +30,18 @@ import javax.sql.DataSource;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.Predicate;
import org.apache.commons.collections4.list.UnmodifiableList;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.filters.AutocompleteFilter;
import org.genesys2.server.model.filters.CodedMethodFilter;
import org.genesys2.server.model.filters.GenesysFilter;
import org.genesys2.server.model.filters.BasicFilter;
import org.genesys2.server.model.filters.I18nListFilter;
import org.genesys2.server.model.filters.MethodFilter;
import org.genesys2.server.model.filters.ValueName;
import org.genesys2.server.model.filters.GenesysFilter.DataType;
import org.genesys2.server.model.filters.GenesysFilter.FilterType;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.model.genesys.TraitCode;
......@@ -46,8 +54,6 @@ import org.genesys2.server.persistence.domain.TraitValueRepository;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.FilterConstants;
import org.genesys2.server.service.GenesysFilterService;
import org.genesys2.server.service.GenesysFilterService.GenesysFilter.DataType;
import org.genesys2.server.service.GenesysFilterService.GenesysFilter.FilterType;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.TaxonomyService;
......@@ -116,28 +122,28 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
public GenesysFilterServiceImpl() {
this.availableFilters = new ArrayList<GenesysFilter>();
this.availableFilters.add(new GenesysFilterImpl(FilterConstants.CROPS, DataType.STRING));
this.availableFilters.add(new GenesysI18nListFilterImpl<Integer>(FilterConstants.SAMPSTAT, DataType.NUMERIC).build("accession.sampleStatus", new Integer[] { 100,
this.availableFilters.add(new BasicFilter(FilterConstants.CROPS, DataType.STRING));
this.availableFilters.add(new I18nListFilter<Integer>(FilterConstants.SAMPSTAT, DataType.NUMERIC).build("accession.sampleStatus", new Integer[] { 100,
110, 120, 130, 200, 300, 400, 410, 411, 412, 413, 414, 415, 416, 420, 421, 422, 423, 500, 600, 999 }));
this.availableFilters.add(new GenesysAutocompleteFilterImpl(FilterConstants.TAXONOMY_GENUS, "/explore/ac/genus"));
this.availableFilters.add(new GenesysAutocompleteFilterImpl(FilterConstants.TAXONOMY_SPECIES, "/explore/ac/species"));
this.availableFilters.add(new GenesysAutocompleteFilterImpl(FilterConstants.TAXONOMY_SCINAME, "/explore/ac/taxonomy"));
this.availableFilters.add(new GenesysAutocompleteFilterImpl(FilterConstants.ORGCTY_ISO3, "/explore/ac/country"));
this.availableFilters.add(new GenesysFilterImpl(FilterConstants.GEO_LATITUDE, DataType.NUMERIC));
this.availableFilters.add(new GenesysFilterImpl(FilterConstants.GEO_LONGITUDE, DataType.NUMERIC));
this.availableFilters.add(new GenesysFilterImpl(FilterConstants.GEO_ELEVATION, DataType.NUMERIC));
this.availableFilters.add(new GenesysFilterImpl(FilterConstants.ORGANIZATION, DataType.STRING));
this.availableFilters.add(new GenesysAutocompleteFilterImpl(FilterConstants.INSTCODE, "/explore/ac/instCode"));
this.availableFilters.add(new GenesysFilterImpl(FilterConstants.ACCENUMB, DataType.STRING, FilterType.RANGE));
this.availableFilters.add(new GenesysFilterImpl(FilterConstants.ALIAS, DataType.STRING, FilterType.RANGE));
this.availableFilters.add(new GenesysFilterImpl(FilterConstants.SGSV, DataType.BOOLEAN));
this.availableFilters.add(new GenesysFilterImpl(FilterConstants.MLSSTATUS, DataType.BOOLEAN));
this.availableFilters.add(new GenesysFilterImpl(FilterConstants.ART15, DataType.BOOLEAN));
this.availableFilters.add(new GenesysFilterImpl(FilterConstants.AVAILABLE, DataType.BOOLEAN));
this.availableFilters.add(new GenesysFilterImpl(FilterConstants.COLLMISSID, DataType.STRING));
this.availableFilters.add(new GenesysI18nListFilterImpl<Integer>(FilterConstants.STORAGE, DataType.NUMERIC).build("accession.storage", new Integer[] { 10, 11, 12,
this.availableFilters.add(new AutocompleteFilter(FilterConstants.TAXONOMY_GENUS, "/explore/ac/genus"));
this.availableFilters.add(new AutocompleteFilter(FilterConstants.TAXONOMY_SPECIES, "/explore/ac/species"));
this.availableFilters.add(new AutocompleteFilter(FilterConstants.TAXONOMY_SCINAME, "/explore/ac/taxonomy"));
this.availableFilters.add(new AutocompleteFilter(FilterConstants.ORGCTY_ISO3, "/explore/ac/country"));
this.availableFilters.add(new BasicFilter(FilterConstants.GEO_LATITUDE, DataType.NUMERIC));
this.availableFilters.add(new BasicFilter(FilterConstants.GEO_LONGITUDE, DataType.NUMERIC));
this.availableFilters.add(new BasicFilter(FilterConstants.GEO_ELEVATION, DataType.NUMERIC));
this.availableFilters.add(new BasicFilter(FilterConstants.ORGANIZATION, DataType.STRING));
this.availableFilters.add(new AutocompleteFilter(FilterConstants.INSTCODE, "/explore/ac/instCode"));
this.availableFilters.add(new BasicFilter(FilterConstants.ACCENUMB, DataType.STRING, FilterType.RANGE));
this.availableFilters.add(new BasicFilter(FilterConstants.ALIAS, DataType.STRING, FilterType.RANGE));
this.availableFilters.add(new BasicFilter(FilterConstants.SGSV, DataType.BOOLEAN));
this.availableFilters.add(new BasicFilter(FilterConstants.MLSSTATUS, DataType.BOOLEAN));
this.availableFilters.add(new BasicFilter(FilterConstants.ART15, DataType.BOOLEAN));
this.availableFilters.add(new BasicFilter(FilterConstants.AVAILABLE, DataType.BOOLEAN));
this.availableFilters.add(new BasicFilter(FilterConstants.COLLMISSID, DataType.STRING));
this.availableFilters.add(new I18nListFilter<Integer>(FilterConstants.STORAGE, DataType.NUMERIC).build("accession.storage", new Integer[] { 10, 11, 12,
13, 20, 30, 40, 50, 99 }));
}
......@@ -201,9 +207,9 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
for (final TraitCode traitCode : TraitCode.parseOptions(method.getOptions())) {
options.add(new ValueName<String>(traitCode.getCode(), traitCode.getValue(), stats.get(traitCode.getCode())));
}
filter = new GenesysCodedMethodFilterImpl("gm:" + method.getId(), method.getParameter().getTitle(), dataType, options);
filter = new CodedMethodFilter("gm:" + method.getId(), method.getParameter().getTitle(), dataType, options);
} else {
filter = new GenesysMethodFilterImpl("gm:" + method.getId(), method.getParameter().getTitle(), dataType);
filter = new MethodFilter("gm:" + method.getId(), method.getParameter().getTitle(), dataType);
}
return filter;
}
......@@ -303,97 +309,6 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
return completed;
}
public static class GenesysFilterImpl implements GenesysFilter {
private final String name;
private final DataType dataType;
private FilterType filterType;
private final Integer maxLength;
public boolean isCore() {
return true;
}
public GenesysFilterImpl(String name, DataType type) {
this.name = name;
this.dataType = type;
if (this.dataType == DataType.NUMERIC) {
this.filterType = FilterType.RANGE;
} else {
this.filterType = FilterType.EXACT;
}
this.maxLength = null;
}
public GenesysFilterImpl(String name, DataType type, FilterType filterType) {
this.name = name;
this.dataType = type;
this.filterType = filterType;
this.maxLength = null;
}
public GenesysFilterImpl(String name, DataType type, int i) {
this.name = name;
this.dataType = type;
if (this.dataType == DataType.NUMERIC) {
this.filterType = FilterType.RANGE;
} else {
this.filterType = FilterType.EXACT;
}
this.maxLength = i;
}
@Override
public String getKey() {
return name;
}
public String getName() {
return name;
}
public DataType getDataType() {
return dataType;
}
public FilterType getFilterType() {
return filterType;
}
public Integer getMaxLength() {
return maxLength;
}
}
public static class ValueName<T> {
private final T value;
private final String name;
private Long count;
public ValueName(T value, String name) {
this.value = value;
this.name = name;
}
public ValueName(T value, String name, Long count) {
this.value = value;
this.name = name;
this.count = count;
}
public T getValue() {
return value;
}
public String getName() {
return name;
}
public Long getCount() {
return count;
}
}
public static class LabelValue<T> {
private final T value;
private final String label;
......@@ -412,76 +327,6 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
}
}
public static class GenesysMethodFilterImpl extends GenesysFilterImpl {
private final String title;
@Override
public boolean isCore() {
return false;
}
public GenesysMethodFilterImpl(String name, String title, DataType dataType) {
super(name, dataType);
this.title = title;
}
public GenesysMethodFilterImpl(String name, String title, DataType dataType, FilterType filterType) {
super(name, dataType, filterType);
this.title = title;
}
public String getTitle() {
return title;
}
}
public static class GenesysCodedMethodFilterImpl extends GenesysMethodFilterImpl {
private final List<ValueName<?>> options;
public GenesysCodedMethodFilterImpl(String name, String title, DataType dataType, List<ValueName<?>> options) {
super(name, title, dataType, FilterType.LIST);
this.options = Collections.unmodifiableList(options);
}
public List<ValueName<?>> getOptions() {
return options;
}
}
public static class GenesysAutocompleteFilterImpl extends GenesysFilterImpl {
private final String autocompleteUrl;
public GenesysAutocompleteFilterImpl(String name, String autocompleteUrl) {
super(name, DataType.STRING, FilterType.AUTOCOMPLETE);
this.autocompleteUrl = autocompleteUrl;
}
public String getAutocompleteUrl() {
return autocompleteUrl;
}
}
public static class GenesysI18nListFilterImpl<T> extends GenesysFilterImpl {
private List<ValueName<T>> options = new ArrayList<ValueName<T>>();
public GenesysI18nListFilterImpl(String name, DataType dataType) {
super(name, dataType, FilterType.I18NLIST);
}
public GenesysFilter build(String prefix, @SuppressWarnings("unchecked") T... options) {
final List<ValueName<T>> opts = new ArrayList<ValueName<T>>();
for (final T opt : options) {
opts.add(new ValueName<T>(opt, prefix + "." + opt));
}
this.options = new UnmodifiableList<ValueName<T>>(opts);