Commit 581d0ae3 authored by Matija Obreza's avatar Matija Obreza
Browse files

Expanded GenesysFilter with FilterType, DataType

parent 912417f5
......@@ -32,9 +32,12 @@ public interface GenesysFilterService {
public static interface GenesysFilter {
public enum FilterType {
public enum DataType {
FIXEDSTRING, STRING, NUMERIC, BOOLEAN
}
public enum FilterType {
EXACT, RANGE, LIST
}
}
}
......@@ -32,8 +32,8 @@ import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.persistence.domain.AccessionRepository;
import org.genesys2.server.persistence.domain.TraitValueRepository;
import org.genesys2.server.service.GenesysFilterService;
import org.genesys2.server.service.GenesysFilterService.GenesysFilter.DataType;
import org.genesys2.server.service.TraitService;
import org.genesys2.server.service.GenesysFilterService.GenesysFilter.FilterType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
......@@ -77,18 +77,19 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
public GenesysFilterServiceImpl() {
this.availableFilters = new ArrayList<GenesysFilter>();
// "origin", "institute", "lat", "lon", "alt", "genus"
this.availableFilters.add(new GenesysFilterImpl("origin", FilterType.FIXEDSTRING, 3));
this.availableFilters.add(new GenesysFilterImpl("institute", FilterType.FIXEDSTRING, 6));
this.availableFilters.add(new GenesysFilterImpl("organization", FilterType.STRING));
this.availableFilters.add(new GenesysFilterImpl("lat", FilterType.NUMERIC));
this.availableFilters.add(new GenesysFilterImpl("lon", FilterType.NUMERIC));
this.availableFilters.add(new GenesysFilterImpl("elevation", FilterType.NUMERIC));
this.availableFilters.add(new GenesysFilterImpl("genus", FilterType.STRING));
this.availableFilters.add(new GenesysFilterImpl("taxon", FilterType.STRING));
this.availableFilters.add(new GenesysFilterImpl("crop", FilterType.STRING));
this.availableFilters.add(new GenesysFilterImpl("inSvalbard", FilterType.BOOLEAN));
this.availableFilters.add(new GenesysFilterImpl("mls", FilterType.BOOLEAN));
this.availableFilters.add(new GenesysFilterImpl("available", FilterType.BOOLEAN));
this.availableFilters.add(new GenesysFilterImpl("accenumb", DataType.NUMERIC));
this.availableFilters.add(new GenesysFilterImpl("origin", DataType.FIXEDSTRING, 3));
this.availableFilters.add(new GenesysFilterImpl("institute", DataType.FIXEDSTRING, 6));
this.availableFilters.add(new GenesysFilterImpl("organization", DataType.STRING));
this.availableFilters.add(new GenesysFilterImpl("lat", DataType.NUMERIC));
this.availableFilters.add(new GenesysFilterImpl("lon", DataType.NUMERIC));
this.availableFilters.add(new GenesysFilterImpl("elevation", DataType.NUMERIC));
this.availableFilters.add(new GenesysFilterImpl("genus", DataType.STRING));
this.availableFilters.add(new GenesysFilterImpl("taxon", DataType.STRING));
this.availableFilters.add(new GenesysFilterImpl("crop", DataType.STRING));
this.availableFilters.add(new GenesysFilterImpl("inSvalbard", DataType.BOOLEAN));
this.availableFilters.add(new GenesysFilterImpl("mls", DataType.BOOLEAN));
this.availableFilters.add(new GenesysFilterImpl("available", DataType.BOOLEAN));
}
@Override
......@@ -121,6 +122,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
}
StringBuffer sbf = new StringBuffer();
createQuery(sbf, "a.acceNumb", jsonTree.get("accenumb"), params);
createQuery(sbf, "a.orgCty", jsonTree.get("origin"), params);
createQuery(sbf, "a.instCode", jsonTree.get("institute"), params);
createQuery(sbf, "a.inSGSV", jsonTree.get("inSvalbard"), params);
......@@ -371,18 +373,27 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
public static class GenesysFilterImpl implements GenesysFilter {
private String name;
private FilterType type;
private DataType dataType;
private FilterType filterType;
private Integer maxLength;
public GenesysFilterImpl(String name, FilterType type) {
public GenesysFilterImpl(String name, DataType type) {
this.name = name;
this.type = type;
this.dataType = type;
if (this.dataType == DataType.NUMERIC)
this.filterType = FilterType.RANGE;
else
this.filterType = FilterType.EXACT;
this.maxLength = null;
}
public GenesysFilterImpl(String name, FilterType type, int i) {
public GenesysFilterImpl(String name, DataType type, int i) {
this.name = name;
this.type = type;
this.dataType = type;
if (this.dataType == DataType.NUMERIC)
this.filterType = FilterType.RANGE;
else
this.filterType = FilterType.EXACT;
this.maxLength = i;
}
......@@ -390,8 +401,12 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
return name;
}
public FilterType getType() {
return type;
public DataType getDataType() {
return dataType;
}
public FilterType getFilterType() {
return filterType;
}
public Integer getMaxLength() {
......
......@@ -82,7 +82,7 @@ import org.genesys2.server.persistence.domain.TraitValueRepository;
import org.genesys2.server.security.AuthUserDetails;
import org.genesys2.server.service.AclService;
import org.genesys2.server.service.DatasetService;
import org.genesys2.server.service.GenesysFilterService.GenesysFilter.FilterType;
import org.genesys2.server.service.GenesysFilterService.GenesysFilter.DataType;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.HtmlSanitizer;
import org.genesys2.server.service.TraitService;
......@@ -1190,7 +1190,7 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
continue;
}
filters.add(new GenesysFilterServiceImpl.GenesysFilterImpl("gm:" + method.getId(),
method.getFieldType() == 1 || method.getFieldType() == 2 ? FilterType.NUMERIC : FilterType.STRING));
method.getFieldType() == 1 || method.getFieldType() == 2 ? DataType.NUMERIC : DataType.STRING));
}
return filters;
}
......
......@@ -16,10 +16,10 @@
<div class="pull-left filter-name"><spring:message code="filter.${filter.name}" /></div>
<div class="pull-left" id="filter-${filter.name.replace(':', '_')}">
<c:choose>
<c:when test="${filter.type=='NUMERIC'}">
<c:when test="${filter.dataType=='NUMERIC'}">
<div class="filter-new form-group pull-left input-group"><span class="input-group-btn"><input class="span1 form-control" type="text" /><input class="span1 form-control" type="text" /><button class="btn notimportant">+</button></span></div>
</c:when>
<c:when test="${filter.type=='BOOLEAN'}">
<c:when test="${filter.dataType=='BOOLEAN'}">
<div class="filter-new pull-left"><select><option value="true"><spring:message code="boolean.true" /></option><option value="false"><spring:message code="boolean.false" /></option><option value="null"><spring:message code="boolean.null" /></option></select><button class="notimportant">+</button></div>
</c:when>
<c:otherwise>
......@@ -46,7 +46,7 @@ jQuery(document).ready(function() {
// alert('${jsonString}');
var filters={};
try {
// filters=$.parseJSON('${jsonString}');
filters=$.parseJSON('${jsonString}');
} catch (e) {filters={}; console.error(e);}
// debugger;
console.log("Filters: " +JSON.stringify(filters));
......
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