Changeset 6048


Ignore:
Timestamp:
02/25/15 08:34:16 (9 years ago)
Author:
Twan Goosen
Message:

merged changes from trunk

Location:
vlo/branches/vlo-3.1
Files:
1 deleted
12 edited
1 copied

Legend:

Unmodified
Added
Removed
  • vlo/branches/vlo-3.1

  • vlo/branches/vlo-3.1/CHANGES

    r6041 r6048  
    66* More fields get indexed for the autocomplete/suggestion function in the search box
    77        <https://trac.clarin.eu/ticket/624>
     8* Fixed an issue with resolving resource handles
     9        <https://trac.clarin.eu/ticket/666>
    810* Mapping improvements:
    911        * Fallback to fields defined by pattern (path) if no value is found in a field with a matching concept link
  • vlo/branches/vlo-3.1/UPGRADE

    r6017 r6048  
    2828* Update the external service running at <http://infra.clarin.eu/service/language/
    2929info.php> to select the 'languageCode' facet using ISO639-3 language codes, e.g.
    30 <http://catalog.clarin.eu/vlo/search?fq=languageCode:code:nep> for 'nep'.
     30<http://catalog.clarin.eu/vlo/search?fq=languageCode:code:nep> for 'nep'. Contact
     31Sander Maijers <sander@clarin.eu> for more information.
    3132
    3233---------------------------
  • vlo/branches/vlo-3.1/vlo-commons/src/main/java/eu/clarin/cmdi/vlo/FacetConstants.java

    r6031 r6048  
    4343     */
    4444    public static final String FIELD_SEARCHPAGE = "_searchPageRef";
    45    
     45
    4646    //Deprecated fields
    4747    public static final String DEPRECATED_FIELD_LANGUAGE = "language";
     
    7171     */
    7272    public static final String DESCRIPTION_LANGUAGE_PATTERN = "^\\{lang='([a-z]{3})'\\}";
     73
     74    /**
     75     * regular expression that matches the syntax of the 'languageCode' field
     76     * (with either a language code or a name as indicated by the prefix)
     77     */
     78    public static final String LANGUAGE_CODE_PATTERN = "(name|code):(.*)";
    7379}
  • vlo/branches/vlo-3.1/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/VloWicketApplication.java

    r5227 r6048  
    1010import eu.clarin.cmdi.vlo.wicket.pages.SimpleSearchPage;
    1111import eu.clarin.cmdi.vlo.wicket.pages.VloBasePage;
     12import eu.clarin.cmdi.vlo.wicket.provider.FieldValueConverterProvider;
    1213import javax.inject.Inject;
    1314import org.apache.wicket.Application;
     
    3738    @Inject
    3839    private XmlTransformationService cmdiTransformationService;
     40    @Inject
     41    private FieldValueConverterProvider fieldValueConverterProvider;
    3942    @Inject
    4043    private VloConfig vloConfig;
     
    145148        return cmdiTransformationService;
    146149    }
     150   
     151    public FieldValueConverterProvider getFieldValueConverterProvider() {
     152        return fieldValueConverterProvider;
     153    }
    147154
    148155}
  • vlo/branches/vlo-3.1/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/handle/impl/HandleRestApiClient.java

    r6029 r6048  
    2424import eu.clarin.cmdi.vlo.service.handle.HandleClient;
    2525import javax.ws.rs.core.MediaType;
     26import javax.ws.rs.core.Response;
    2627import org.apache.wicket.ajax.json.JSONArray;
    2728import org.apache.wicket.ajax.json.JSONException;
     
    8081                    .get(ClientResponse.class);
    8182
    82             if (response.getClientResponseStatus() != ClientResponse.Status.OK) {
    83                 logger.error("Unexpected response status {} for {}", response.getClientResponseStatus(), requestUrl);
     83            if (Response.Status.OK.getStatusCode() != response.getStatus()) {
     84                final Response.StatusType statusInfo = response.getStatusInfo();
     85                logger.error("Unexpected response status {} - {} for {}", statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), requestUrl);
    8486            } else {
    8587                final String responseString = response.getEntity(String.class);
  • vlo/branches/vlo-3.1/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/impl/AutoCompleteServiceImpl.java

    r4850 r6048  
    11package eu.clarin.cmdi.vlo.service.solr.impl;
    22
    3 import com.google.common.collect.Iterators;
    43import eu.clarin.cmdi.vlo.service.solr.AutoCompleteService;
    54import eu.clarin.cmdi.vlo.config.VloConfig;
     5import java.util.Collections;
    66import java.util.Iterator;
    77import java.util.List;
     
    5050        }
    5151
    52         return Iterators.emptyIterator();
     52        return  Collections.emptyIterator();
    5353    }
    5454}
  • vlo/branches/vlo-3.1/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/components/FieldValueLabel.java

    r6029 r6048  
    1919import eu.clarin.cmdi.vlo.wicket.provider.FieldValueConverterProvider;
    2020import eu.clarin.cmdi.vlo.wicket.provider.FieldValueConverterProviderImpl;
    21 import org.apache.solr.client.solrj.response.FacetField;
    2221import org.apache.wicket.markup.html.basic.Label;
    2322import org.apache.wicket.model.IModel;
  • vlo/branches/vlo-3.1/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/components/SolrFieldLabel.java

    r4871 r6048  
    3535     * @param documentModel model that holds document to show field of
    3636     * @param fieldName name of field to show value of
    37      */
    38     public SolrFieldLabel(String id, IModel<SolrDocument> documentModel, String fieldName) {
    39         super(id, new SolrFieldStringModel(documentModel, fieldName));
    40     }
    41 
    42     /**
    43      *
    44      * @param id id of label
    45      * @param documentModel model that holds document to show field of
    46      * @param fieldName name of field to show value of
    47      * @param maxLength maximum length to allow
    48      * @param truncatePoint point to truncate if string is too long
    49      */
    50     public SolrFieldLabel(String id, IModel<SolrDocument> documentModel, String fieldName, int maxLength, int truncatePoint) {
    51         super(id,
    52                 new TruncatingStringModel(
    53                         new SolrFieldStringModel(documentModel, fieldName), maxLength, truncatePoint));
    54     }
    55 
    56     /**
    57      *
    58      * @param id id of label
    59      * @param documentModel model that holds document to show field of
    60      * @param fieldName name of field to show value of
    6137     * @param nullFallback string to show if actual value is null
    6238     */
  • vlo/branches/vlo-3.1/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/model/SolrFieldStringModel.java

    r6029 r6048  
    1717package eu.clarin.cmdi.vlo.wicket.model;
    1818
    19 import eu.clarin.cmdi.vlo.FacetConstants;
     19import eu.clarin.cmdi.vlo.VloWicketApplication;
    2020import java.util.Collection;
    2121import java.util.Iterator;
     
    2323import org.apache.wicket.model.AbstractReadOnlyModel;
    2424import org.apache.wicket.model.IModel;
     25import org.apache.wicket.util.convert.IConverter;
    2526
    2627/**
     
    4445     */
    4546    public SolrFieldStringModel(IModel<SolrDocument> documentModel, String fieldName) {
    46         fieldModel = new SolrFieldModel<Object>(documentModel, fieldName);
     47        fieldModel = new SolrFieldModel<>(documentModel, fieldName);
    4748        field = fieldName;
    4849    }
     
    6061        final Iterator<Object> iterator = fieldValues.iterator();
    6162        if (iterator.hasNext()) {
    62             final String firstValue = postprocessValue(iterator.next().toString());
     63            final String firstValue = iterator.next().toString();
    6364            if (iterator.hasNext()) {
    6465                return getMultipleValuesString(firstValue, iterator);
     
    7273
    7374    protected String getMultipleValuesString(final String firstValue, final Iterator<Object> iterator) {
    74         final StringBuilder valuesBuilder = new StringBuilder(firstValue).append("; ");
     75        // for multiple value strings, run every individual value through the converter
     76        final StringBuilder valuesBuilder = new StringBuilder(postprocessValue(firstValue)).append("; ");
    7577        while (iterator.hasNext()) {
    76             valuesBuilder.append(iterator.next().toString());
     78            valuesBuilder.append(postprocessValue(iterator.next().toString()));
    7779            if (iterator.hasNext()) {
    7880                valuesBuilder.append("; ");
     
    9092    private String postprocessValue(String value) {
    9193        if (value != null) {
    92             if (FacetConstants.FIELD_DESCRIPTION.equals(field)) {
    93                 //remove language prefix
    94                 return value.replaceAll(FacetConstants.DESCRIPTION_LANGUAGE_PATTERN, "");
     94            final IConverter<String> converter = getFieldValueConverter();
     95            if (converter != null) {
     96                return converter.convertToString(value, null);
    9597            }
    9698        }
     
    98100    }
    99101
     102    private IConverter<String> getFieldValueConverter() {
     103        return VloWicketApplication.get().getFieldValueConverterProvider().getConverter(field);
     104    }
     105
    100106}
  • vlo/branches/vlo-3.1/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/record/FieldsTablePanel.java

    r6029 r6048  
    2626import eu.clarin.cmdi.vlo.service.PageParametersConverter;
    2727import eu.clarin.cmdi.vlo.wicket.components.FieldValueLabel;
    28 import eu.clarin.cmdi.vlo.wicket.model.DescriptionFieldModel;
     28import eu.clarin.cmdi.vlo.wicket.components.SmartLinkFieldValueLabel;
    2929import eu.clarin.cmdi.vlo.wicket.model.HandleLinkModel;
    3030import eu.clarin.cmdi.vlo.wicket.model.SolrFieldNameModel;
     
    3535import org.apache.wicket.AttributeModifier;
    3636import org.apache.wicket.Component;
    37 import org.apache.wicket.extensions.markup.html.basic.SmartLinkLabel;
    3837import org.apache.wicket.extensions.markup.html.basic.SmartLinkMultiLineLabel;
    3938import org.apache.wicket.markup.html.basic.Label;
     
    118117    }
    119118
    120     private Component createValueLabel(String id, final IModel<String> facetNameModel, final IModel<String> originalValueModel) {
     119    private Component createValueLabel(String id, final IModel<String> facetNameModel, final IModel<String> valueModel) {
    121120        final String fieldName = facetNameModel.getObject();
    122 
    123         // allow for postprocessing or wrapping of the value model depending on the field
    124         final IModel<String> valueModel = getValueModel(facetNameModel, originalValueModel);
    125121
    126122        if (FacetConstants.FIELD_LANGUAGE_CODE.equals(facetNameModel.getObject())) {
     
    128124        } else if (SMART_LINK_FIELDS.contains(fieldName)) {
    129125            // create label that generates links
    130             return new SmartLinkLabel(id, new HandleLinkModel(valueModel));
     126            return new SmartLinkFieldValueLabel(id, new HandleLinkModel(valueModel), facetNameModel);
    131127        } else {
    132128            // add a label for the facet value
     
    164160    }
    165161
    166     private IModel<String> getValueModel(IModel<String> facetNameModel, IModel<String> valueModel) {
    167         if (FacetConstants.FIELD_DESCRIPTION.equals(facetNameModel.getObject())) {
    168             //wrap in model that removes the language prefix
    169             return new DescriptionFieldModel(valueModel);
    170         }
    171         return valueModel;
    172     }
    173 
    174162}
  • vlo/branches/vlo-3.1/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/provider/FieldValueConverterProviderImpl.java

    r6029 r6048  
    3131public class FieldValueConverterProviderImpl implements FieldValueConverterProvider {
    3232
     33    private final static Pattern LANGUAGE_CODE_PATTERN = Pattern.compile(FacetConstants.LANGUAGE_CODE_PATTERN);
    3334    private final LanguageCodeUtils languageCodeUtils;
    34     private Pattern LANGUAGE_CODE_PATTERN = Pattern.compile("(name|code):(.*)");
    3535
    3636    public FieldValueConverterProviderImpl(LanguageCodeUtils languageCodeUtils) {
     
    4343            case FacetConstants.FIELD_LANGUAGE_CODE:
    4444                return languageCodeConverter;
     45            case FacetConstants.FIELD_DESCRIPTION:
     46                return descriptionConverter;
    4547            default:
    4648                return null;
     
    4951    }
    5052
     53    /**
     54     * Abstract base class for one directional string converters
     55     */
    5156    private abstract class FieldValueConverter implements IConverter<String> {
    5257
     
    5863    }
    5964
     65    /**
     66     * Converter for language code/name strings (following the pattern of
     67     * {@link #LANGUAGE_CODE_PATTERN}) into language names
     68     *
     69     * @see LanguageCodeUtils#getLanguageNameForLanguageCode(java.lang.String)
     70     */
    6071    private final FieldValueConverter languageCodeConverter = new FieldValueConverter() {
    6172
     
    7586                }
    7687            }
    77            
     88
    7889            // does not match expected pattern, return original value
    7990            return fieldValue;
     
    8293    };
    8394
     95    /**
     96     * Converter for description field values that strips out any language code
     97     * prefix
     98     */
     99    private final FieldValueConverter descriptionConverter = new FieldValueConverter() {
     100
     101        @Override
     102        public String convertToString(String fieldValue, Locale locale) throws ConversionException {
     103            return fieldValue.replaceAll(FacetConstants.DESCRIPTION_LANGUAGE_PATTERN, "");
     104        }
     105
     106    };
     107
    84108}
Note: See TracChangeset for help on using the changeset viewer.