Changeset 4618


Ignore:
Timestamp:
03/05/14 08:34:57 (10 years ago)
Author:
Twan Goosen
Message:

added components, models and service required to show resource type counts in search results

Location:
vlo/branches/vlo-3.0/vlo-web-app/src/main
Files:
6 added
4 edited

Legend:

Unmodified
Added
Removed
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/config/VloSpringConfig.java

    r4597 r4618  
    2020import eu.clarin.cmdi.vlo.VloWicketApplication;
    2121import eu.clarin.cmdi.vlo.service.FacetFieldsService;
     22import eu.clarin.cmdi.vlo.service.ResourceTypeCountingService;
    2223import eu.clarin.cmdi.vlo.service.SearchResultsDao;
    2324import eu.clarin.cmdi.vlo.service.SolrDocumentService;
    2425import eu.clarin.cmdi.vlo.service.SolrFacetQueryFactory;
     26import eu.clarin.cmdi.vlo.service.impl.ResourceTypeCountingServiceImpl;
    2527import eu.clarin.cmdi.vlo.service.impl.SearchResultsDaoImpl;
    2628import eu.clarin.cmdi.vlo.service.impl.SolrDocumentQueryFactoryImpl;
     
    9799
    98100    @Bean
     101    public ResourceTypeCountingService resourceTypeCountingService() {
     102        return new ResourceTypeCountingServiceImpl();
     103    }
     104
     105    @Bean
    99106    public SolrServer solrServer() {
    100107        return new HttpSolrServer(vloConfig().getSolrUrl());
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/components/SearchResultItemPanel.html

    r4560 r4618  
    3434                    [DESCRIPTION]
    3535                </p>
    36                 <p class="searchresultresources">
    37                     Resources: <a href="record1.html">1 text file</a>, <a href="record1.html">1 audio file</a>, <a href="record1.html">1 annotation file</a>
    38                 </p>
     36                <div class="searchresultresources">
     37                    Resources:
     38                    <ul>
     39                        <li wicket:id="resourceCount">
     40                            <a wicket:id="recordLink" href="record1.html">
     41                                <wicket:container wicket:id="resourceCountLabel">1 text file</wicket:container>
     42                            </a>
     43                        </li>
     44                    </ul>
     45                </div>
    3946            </div>
    4047<!--
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/components/SearchResultItemPanel.java

    r4614 r4618  
    1717package eu.clarin.cmdi.vlo.wicket.components;
    1818
     19import eu.clarin.cmdi.vlo.wicket.provider.ResouceTypeCountDataProvider;
    1920import eu.clarin.cmdi.vlo.FacetConstants;
     21import eu.clarin.cmdi.vlo.pojo.ResourceTypeCount;
     22import eu.clarin.cmdi.vlo.service.ResourceTypeCountingService;
    2023import eu.clarin.cmdi.vlo.wicket.model.NullFallbackModel;
     24import eu.clarin.cmdi.vlo.wicket.model.SolrFieldModel;
    2125import eu.clarin.cmdi.vlo.wicket.model.SolrFieldStringModel;
     26import java.util.Locale;
    2227import org.apache.solr.common.SolrDocument;
    2328import org.apache.wicket.markup.html.basic.Label;
     29import org.apache.wicket.markup.html.link.Link;
    2430import org.apache.wicket.markup.html.panel.Panel;
     31import org.apache.wicket.markup.repeater.Item;
     32import org.apache.wicket.markup.repeater.data.DataView;
     33import org.apache.wicket.markup.repeater.data.IDataProvider;
    2534import org.apache.wicket.model.IModel;
     35import org.apache.wicket.spring.injection.annot.SpringBean;
     36import org.apache.wicket.util.convert.ConversionException;
     37import org.apache.wicket.util.convert.IConverter;
    2638
    2739/**
     
    3143public class SearchResultItemPanel extends Panel {
    3244
     45    @SpringBean
     46    private ResourceTypeCountingService countingService;
     47
    3348    public SearchResultItemPanel(String id, IModel<SolrDocument> model) {
    3449        super(id, model);
    3550        add(new SolrFieldLabel("title", model, FacetConstants.FIELD_NAME));
    3651        add(new SolrFieldLabel("description", model, FacetConstants.FIELD_DESCRIPTION, "<no description>"));
     52
     53        // get model for resources
     54        final SolrFieldModel<String> resourcesModel = new SolrFieldModel<String>(model, FacetConstants.FIELD_RESOURCE);
     55        final ResouceTypeCountDataProvider countProvider = new ResouceTypeCountDataProvider(resourcesModel, countingService);
     56        add(new ResourceCountDataView("resourceCount", countProvider));
    3757    }
    3858
    39 
    40     public static class SolrFieldLabel extends Label {
     59    private static class SolrFieldLabel extends Label {
    4160
    4261        public SolrFieldLabel(String id, IModel<SolrDocument> documentModel, String fieldName) {
     
    5170
    5271    }
     72
     73    private static class ResourceCountDataView extends DataView<ResourceTypeCount> {
     74
     75        private final static ResourceTypeCountConverter resourceTypeCountConverter
     76                = new ResourceTypeCountConverter();
     77
     78        public ResourceCountDataView(String id, IDataProvider<ResourceTypeCount> dataProvider) {
     79            super(id, dataProvider);
     80        }
     81
     82        @Override
     83        protected void populateItem(Item<ResourceTypeCount> item) {
     84            final Link resourceLink = new Link("recordLink") {
     85
     86                @Override
     87                public void onClick() {
     88                    throw new UnsupportedOperationException("Not supported yet.");
     89                }
     90            };
     91            final Label label = new Label("resourceCountLabel", item.getModel()) {
     92
     93                @Override
     94                public <C> IConverter<C> getConverter(Class<C> type) {
     95                    if (type == ResourceTypeCount.class) {
     96                        return (IConverter<C>) resourceTypeCountConverter;
     97                    } else {
     98                        return super.getConverter(type);
     99                    }
     100                }
     101
     102            };
     103
     104            resourceLink.add(label);
     105            item.add(resourceLink);
     106        }
     107    }
     108
     109    private static class ResourceTypeCountConverter implements IConverter<ResourceTypeCount> {
     110
     111        @Override
     112        public ResourceTypeCount convertToObject(String value, Locale locale) throws ConversionException {
     113            throw new UnsupportedOperationException("Not supported");
     114        }
     115
     116        @Override
     117        public String convertToString(ResourceTypeCount value, Locale locale) {
     118            final String resourceTypeString;
     119            if (value.getCount() == 1) {
     120                resourceTypeString = getSingularResourceTypeString(value);
     121            } else {
     122                resourceTypeString = getPluralResourceTypeString(value);
     123            }
     124            return String.format("%d %s", value.getCount(), resourceTypeString);
     125        }
     126
     127        private String getSingularResourceTypeString(ResourceTypeCount value) {
     128            //TODO: read from resource bundle
     129            switch (value.getResourceType()) {
     130                case ANNOTATION:
     131                    return "annotation file";
     132                case AUDIO:
     133                    return "audio file";
     134                case VIDEO:
     135                    return "video file";
     136                case TEXT:
     137                    return "text document";
     138                case OTHER:
     139                    return "other";
     140                default:
     141                    return "unknown";
     142            }
     143        }
     144
     145        private String getPluralResourceTypeString(ResourceTypeCount value) {
     146            //TODO: read from resource bundle
     147            switch (value.getResourceType()) {
     148                case ANNOTATION:
     149                    return "annotation files";
     150                case AUDIO:
     151                    return "audio files";
     152                case VIDEO:
     153                    return "video files";
     154                case TEXT:
     155                    return "text documents";
     156                case OTHER:
     157                    return "other";
     158                default:
     159                    return "unknown";
     160            }
     161        }
     162
     163    }
    53164}
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/webapp/style/vlo-search.css

    r4466 r4618  
    9595}
    9696
    97 p.searchresultresources {
     97.searchresultresources {
    9898    width: 70%;
    9999    float: left;
     
    101101    padding: 0px;
    102102}
     103
     104.searchresultresources ul {
     105    display: inline;
     106    padding: 0em 0em 0em .5em;
     107    margin: 0px;
     108    border-right: 1px solid;
     109}
     110
     111.searchresultresources ul li {
     112    display: inline;
     113    list-style: none;
     114    padding: 0em 0em 0em .5em;
     115    margin: 0em .5em 0em 0em;
     116    border-left: 1px solid;
     117}
     118
    103119
    104120div.searchresultattributes {
Note: See TracChangeset for help on using the changeset viewer.