Changeset 4316


Ignore:
Timestamp:
01/21/14 13:36:47 (10 years ago)
Author:
twagoo
Message:

Merged NPE fixes from trunk to 2.18

Location:
vlo/branches/vlo-2.18
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • vlo/branches/vlo-2.18

  • vlo/branches/vlo-2.18/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/dao/SolrDao.java

    r4199 r4316  
    3434        return solrServer;
    3535    }
    36    
     36
    3737    /**
    38      * Basic sanitising of Solr queries.
    39      *
    40      * Query is based on the URL to the VLO web application. Also, explain
    41      * about the URL and ?fq=language:dutch
    42      * Assume filters have the form a:b
    43      * like for example language:dutch
    44      *
     38     * Basic sanitising of Solr queries.
     39     *
     40     * Query is based on the URL to the VLO web application. Also, explain about
     41     * the URL and ?fq=language:dutch Assume filters have the form a:b like for
     42     * example language:dutch
     43     *
    4544     * @param query
    46      * @return 
     45     * @return
    4746     */
    48     private SolrQuery sanitise (SolrQuery query){
    49        
     47    private SolrQuery sanitise(SolrQuery query) {
     48
    5049        // String [] facetsFromConfig;
    51        
    5250        // try and get the filters facets from the query
    53         String [] filtersInQuery;
     51        String[] filtersInQuery;
    5452        filtersInQuery = query.getFilterQueries();
    55  
     53
    5654        if (filtersInQuery == null) {
    5755            // the query does not contain filters
     
    6765            for (String filter : filtersInQuery) {
    6866                // split up a filter, look at the string preceeding the semicolon
    69                 String facetInFilter = filter.split(":") [0];
    70                
     67                String facetInFilter = filter.split(":")[0];
     68
    7169                if (facetsDefined.contains(facetInFilter)) {
    7270                    // facet in the filter is in the set that is defined by the config file
     
    9896
    9997    public SolrDocument getSolrDocument(String docId) {
     98        if (docId == null) {
     99            throw new NullPointerException("Cannot get SOLR document for null docId");
     100        }
    100101        SolrDocument result = null;
    101102        SolrQuery query = new SolrQuery();
  • vlo/branches/vlo-2.18/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/ShowResultPage.java

    r4311 r4316  
    2121import org.apache.wicket.Component;
    2222import org.apache.wicket.MarkupContainer;
     23import org.apache.wicket.RestartResponseException;
    2324import org.apache.wicket.ajax.AjaxRequestTarget;
    2425import org.apache.wicket.request.mapper.parameter.PageParameters;
     
    7475
    7576        final StringValue docIdParam = getPageParameters().get(PARAM_DOC_ID);
    76         if (docIdParam == null) {
    77             throw new RuntimeException("No document id was specified. Cannot construct result page.");
    78         }
    79         //Document ID is assumed to have been encoded (typcially in DocumentLinkPanel) decode here
    80         final String docId = UrlDecoder.QUERY_INSTANCE.decode(
    81                 docIdParam.toString(),
    82                 Application.get().getRequestCycleSettings().getResponseRequestEncoding()); // get current character set from request cycle
    83         SolrDocument solrDocument = DaoLocator.getSearchResultsDao().getSolrDocument(docId);
    84 
    85         if (solrDocument != null) {
    86             final SearchPageQuery query = new SearchPageQuery(currentParam);
    87 
    88             // create parameters from the query, and add them with session related parameters
    89             PageParameters newParam = new PageParameters(query.getPageParameters());
    90             // add the session persistent parameters
    91             newParam.mergeWith(VloSession.get().getVloSessionPageParameters());
    92 
    93             BookmarkablePageLink<String> backLink = new BookmarkablePageLink<String>("backLink", FacetedSearchPage.class, newParam);
    94             add(backLink);
    95             String href = getHref(docId);
    96             if (href != null) {
    97                 add(new ExternalLink("openBrowserLink", href, new ResourceModel(Resources.OPEN_IN_ORIGINAL_CONTEXT).getObject()));
     77        if (docIdParam == null || docIdParam.isNull()) {
     78            LOG.warn("No document id was specified. Cannot construct result page.");
     79            throw new RestartResponseException(new ResultNotFoundPage(currentParam));
     80        } else {
     81            //Document ID is assumed to have been encoded (typcially in DocumentLinkPanel) decode here
     82            final String docId = UrlDecoder.QUERY_INSTANCE.decode(
     83                    docIdParam.toString(),
     84                    Application.get().getRequestCycleSettings().getResponseRequestEncoding()); // get current character set from request cycle
     85
     86            final SolrDocument solrDocument = DaoLocator.getSearchResultsDao().getSolrDocument(docId);
     87            if (solrDocument != null) {
     88                final SearchPageQuery query = new SearchPageQuery(currentParam);
     89
     90                // create parameters from the query, and add them with session related parameters
     91                PageParameters newParam = new PageParameters(query.getPageParameters());
     92                // add the session persistent parameters
     93                newParam.mergeWith(VloSession.get().getVloSessionPageParameters());
     94
     95                BookmarkablePageLink<String> backLink = new BookmarkablePageLink<String>("backLink", FacetedSearchPage.class, newParam);
     96                add(backLink);
     97                String href = getHref(docId);
     98                if (href != null) {
     99                    add(new ExternalLink("openBrowserLink", href, new ResourceModel(Resources.OPEN_IN_ORIGINAL_CONTEXT).getObject()));
     100                } else {
     101                    add(new Label("openBrowserLink", new ResourceModel(Resources.ORIGINAL_CONTEXT_NOT_AVAILABLE).getObject()));
     102                }
     103                addAttributesTable(solrDocument);
     104
     105                /* If there are any, add the link or links to landing pages
     106                 * contained in the solr document.
     107                 */
     108                addLandingPageLinks(solrDocument);
     109
     110                // also, if there are any, add the link or links to search pages
     111                addSearchPageLinks(solrDocument);
     112
     113                // add the rest of the resource links to the result page
     114                addResourceLinks(solrDocument);
     115
     116                addSearchServiceForm(solrDocument);
     117
     118                addCompleteCmdiView(solrDocument);
     119
     120                add(new AjaxLazyLoadPanel("prevNextHeader") {
     121
     122                    @Override
     123                    public Component getLazyLoadComponent(String markupId) {
     124                        return new PrevNextHeaderPanel(markupId, docId, query);
     125                    }
     126
     127                    @Override
     128                    public Component getLoadingComponent(String markupId) {
     129                        return new PrevNextHeaderPanel(markupId);
     130                    }
     131                });
    98132            } else {
    99                 add(new Label("openBrowserLink", new ResourceModel(Resources.ORIGINAL_CONTEXT_NOT_AVAILABLE).getObject()));
    100             }
    101             addAttributesTable(solrDocument);
    102 
    103             /* If there are any, add the link or links to landing pages
    104              * contained in the solr document.
    105              */
    106             addLandingPageLinks(solrDocument);
    107 
    108             // also, if there are any, add the link or links to search pages
    109             addSearchPageLinks(solrDocument);
    110 
    111             // add the rest of the resource links to the result page
    112             addResourceLinks(solrDocument);
    113 
    114             addSearchServiceForm(solrDocument);
    115 
    116             addCompleteCmdiView(solrDocument);
    117 
    118             add(new AjaxLazyLoadPanel("prevNextHeader") {
    119 
    120                 @Override
    121                 public Component getLazyLoadComponent(String markupId) {
    122                     return new PrevNextHeaderPanel(markupId, docId, query);
    123                 }
    124 
    125                 @Override
    126                 public Component getLoadingComponent(String markupId) {
    127                     return new PrevNextHeaderPanel(markupId);
    128                 }
    129             });
    130         } else {
    131             setResponsePage(new ResultNotFoundPage(currentParam));
     133                setResponsePage(new ResultNotFoundPage(currentParam));
     134            }
    132135        }
    133136
  • vlo/branches/vlo-2.18/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/SolrFacetFieldDataProvider.java

    r4208 r4316  
    1717import eu.clarin.cmdi.vlo.dao.DaoLocator;
    1818import eu.clarin.cmdi.vlo.dao.SearchResultsDao;
     19import java.io.Serializable;
    1920
    2021public class SolrFacetFieldDataProvider implements IDataProvider<Count> {
     22
    2123    private final static Logger LOG = LoggerFactory.getLogger(SolrFacetFieldDataProvider.class);
    2224
    2325    private static final long serialVersionUID = 1L;
     26    private final SolrQuery query;
    2427    private FacetField facet;
    25     private SolrQuery query;
    2628
    2729    private final String selectedFacet;
     
    5860    @Override
    5961    public Iterator<? extends Count> iterator(long first, long count) {
    60         return getFacet().getValues().subList((int)first, (int)first + (int)count).iterator();
     62        return getFacet().getValues().subList((int) first, (int) first + (int) count).iterator();
    6163    }
    6264
     
    7577    }
    7678
    77     @SuppressWarnings("serial")
    78     private static class EmptyFacetField extends FacetField {
     79    private static class EmptyFacetField extends FacetField implements Serializable {
     80
    7981        public EmptyFacetField(String name) {
    8082            super(name);
    8183        }
    8284
     85        @Override
    8386        public List<Count> getValues() {
    84             return (List<Count>) Collections.EMPTY_LIST.iterator();
     87            return Collections.emptyList();
    8588        }
    8689
     90        @Override
    8791        public int getValueCount() {
    8892            return 0;
    8993        }
    90 
    9194    }
    9295}
Note: See TracChangeset for help on using the changeset viewer.