source: vlo/branches/to-wicket-1.6/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/DocumentAttributesDataProvider.java @ 4199

Last change on this file since 4199 was 4199, checked in by keeloo, 10 years ago
File size: 2.2 KB
Line 
1package eu.clarin.cmdi.vlo.pages;
2
3import java.util.Collection;
4import java.util.Collections;
5import java.util.HashMap;
6import java.util.HashSet;
7import java.util.Iterator;
8import java.util.Map;
9import java.util.Set;
10
11import org.apache.solr.common.SolrDocument;
12import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
13import org.apache.wicket.model.IModel;
14import org.apache.wicket.model.Model;
15
16import eu.clarin.cmdi.vlo.FacetConstants;
17
18public class DocumentAttributesDataProvider extends SortableDataProvider<DocumentAttribute,String>{
19   
20    private static final Set<String> IGNORE_FACETS = new HashSet<String>();
21    static {
22        IGNORE_FACETS.add(FacetConstants.FIELD_FORMAT);
23    }
24
25    private static final long serialVersionUID = 1L;
26   
27    private transient DocumentAttributeList attributeList;
28
29    public DocumentAttributesDataProvider(SolrDocument solrDocument) {
30        if (solrDocument != null) {
31            Map<String, Collection<Object>> fieldMap = new HashMap<String, Collection<Object>>();
32            Map<String, Collection<Object>> fieldValuesMap = solrDocument.getFieldValuesMap();
33            for (String entry : fieldValuesMap.keySet()) {
34                if (!ignoreEntry(entry)) { //Filter out all '_' starting (internal) fields
35                    fieldMap.put(entry, fieldValuesMap.get(entry));
36                }
37            }
38            attributeList = new DocumentAttributeList(fieldMap);
39        } else {
40            attributeList = new DocumentAttributeList(Collections.singletonMap("Document not found", (Collection<Object>) null));
41        }
42    }
43   
44    private boolean ignoreEntry(String entry) {
45//        if(entry.equals(FacetConstants.FIELD_COMPLETE_METADATA)){
46//            return false; // Do not ignore the "complete metadata" entry, even though it starts with a _
47//        }
48        return entry.startsWith("_") || IGNORE_FACETS.contains(entry);
49    }
50
51    @Override
52    public Iterator<? extends DocumentAttribute> iterator(long first, long count) {
53        return attributeList;
54    }
55
56    @Override
57    public IModel<DocumentAttribute> model(DocumentAttribute object) {
58        return new Model<DocumentAttribute>(object);
59    }
60
61    @Override
62    public long size() {
63        return attributeList.size();
64    }
65
66}
Note: See TracBrowser for help on using the repository browser.