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,6 +30,7 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.genesys2.server.model.filters.GenesysFilter;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.model.genesys.Parameter;
......@@ -37,7 +38,6 @@ import org.genesys2.server.model.genesys.ParameterCategory;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.GenesysFilterService;
import org.genesys2.server.service.GenesysFilterService.GenesysFilter;
import org.genesys2.server.service.FilterConstants;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.InstituteService;
......@@ -151,7 +151,7 @@ public class ExplorerController extends BaseController {
_logger.error("Invalid JSON for filters", e);
}
final List<GenesysFilterService.GenesysFilter> currentFilters = filterService.selectFilters(selectedFilters);
final List<GenesysFilter> currentFilters = filterService.selectFilters(selectedFilters);
final List<GenesysFilter> availableFilters = filterService.listAvailableFilters();
_logger.debug("Filtering by: " + jsonFilter);
......@@ -191,7 +191,7 @@ public class ExplorerController extends BaseController {
public String getAdditionalFilters(ModelMap model, @RequestParam(value = "filter", required = true, defaultValue = "") String[] selectedFilters)
throws IOException {
final List<GenesysFilterService.GenesysFilter> additionalFilters = filterService.selectFilters(selectedFilters);
final List<GenesysFilter> additionalFilters = filterService.selectFilters(selectedFilters);
model.addAttribute("additionalFilters", additionalFilters);
if (ArrayUtils.contains(selectedFilters, "crops")) {
......
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