Changeset 4999


Ignore:
Timestamp:
04/17/14 07:39:46 (10 years ago)
Author:
Twan Goosen
Message:

fixed issue with lost selection if fq value contains a colon

Location:
vlo/branches/vlo-3.0/vlo-web-app/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/impl/QueryFacetsSelectionParametersConverter.java

    r4983 r4999  
    1717package eu.clarin.cmdi.vlo.service.impl;
    1818
     19import com.google.common.base.Splitter;
    1920import com.google.common.collect.Maps;
    2021import static eu.clarin.cmdi.vlo.VloWebAppParameters.*;
     
    4041
    4142    public final static Logger logger = LoggerFactory.getLogger(QueryFacetsSelectionParametersConverter.class);
     43    /**
     44     * Splitter for facet query strings like "language:Dutch". Because it is
     45     * limited to two tokens, will also work for strings with a colon in their
     46     * value such as "collection:TLA: DoBeS archive".
     47     */
     48    public final static Splitter FILTER_SPLITTER = Splitter.on(":").limit(2);
    4249
    4350    @Override
     
    5259        for (StringValue selectionType : facetSelectionTypes) {
    5360            if (!selectionType.isEmpty()) {
    54                 final String[] fqType = selectionType.toString().split(":");
    55                 if (fqType.length == 2) {
    56                     final String facet = fqType[0];
    57                     final String type = fqType[1].toUpperCase();
     61                final List<String> fqType = FILTER_SPLITTER.splitToList(selectionType.toString());
     62                if (fqType.size() == 2) {
     63                    final String facet = fqType.get(0);
     64                    final String type = fqType.get(1).toUpperCase();
    5865
    5966                    try {
     
    7279        for (StringValue facetValue : facetValues) {
    7380            if (!facetValue.isEmpty()) {
    74                 final String[] fq = facetValue.toString().split(":");
    75                 if (fq.length == 2) {
     81                final List<String> fq = FILTER_SPLITTER.splitToList(facetValue.toString());
     82                if (fq.size() == 2) {
    7683                    // we have a facet - value pair
    77                     final String facet = fq[0];
    78                     final String value = fq[1];
     84                    final String facet = fq.get(0);
     85                    final String value = fq.get(1);
    7986                    if (selection.containsKey(facet)) {
    8087                        selection.get(facet).getValues().add(value);
  • vlo/branches/vlo-3.0/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/service/impl/QueryFacetsSelectionParametersConverterTest.java

    r4983 r4999  
    5858        params.add("fq", "facet1:valueA");
    5959        params.add("fq", "facet1:valueB");
    60         params.add("fq", "facet2:valueC");
     60        params.add("fq", "facet2:value:C"); // has a colon in value
    6161        params.add("fq", "illegal-no-colon"); //should get ignored
    6262        params.add("fq", ""); // not a valid facet selection
     
    7474        assertThat(result.getSelectionValues("facet1").getValues(), hasItem("valueA"));
    7575        assertThat(result.getSelectionValues("facet1").getValues(), hasItem("valueB"));
    76         assertThat(result.getSelectionValues("facet2").getValues(), hasItem("valueC"));
     76        assertThat(result.getSelectionValues("facet2").getValues(), hasItem("value:C"));
    7777        // OR explicitly set
    7878        assertEquals(FacetSelectionType.OR, result.getSelectionValues("facet1").getSelectionType());
     
    110110        final Map<String, FacetSelection> map = Maps.newHashMapWithExpectedSize(3);
    111111        map.put("facet1", new FacetSelection(FacetSelectionType.OR, Arrays.asList("valueA", "valueB")));
    112         map.put("facet2", new FacetSelection(FacetSelectionType.AND, Collections.singleton("valueC")));
     112        map.put("facet2", new FacetSelection(FacetSelectionType.AND, Collections.singleton("value:C")));
    113113        map.put("facet3", new FacetSelection(FacetSelectionType.NOT_EMPTY));
    114114
     
    122122        assertThat(fq, hasItem(StringValue.valueOf("facet1:valueA")));
    123123        assertThat(fq, hasItem(StringValue.valueOf("facet1:valueB")));
    124         assertThat(fq, hasItem(StringValue.valueOf("facet2:valueC")));
     124        assertThat(fq, hasItem(StringValue.valueOf("facet2:value:C")));
    125125
    126126        final List<StringValue> fqType = result.getValues("fqType");
Note: See TracChangeset for help on using the changeset viewer.