source: vlo/trunk/vlo_importer/src/main/java/eu/clarin/cmdi/vlo/importer/CMDIData.java @ 2828

Last change on this file since 2828 was 2828, checked in by keeloo, 11 years ago

Added support for search page type of resources.

File size: 4.8 KB
Line 
1package eu.clarin.cmdi.vlo.importer;
2
3import eu.clarin.cmdi.vlo.FacetConstants;
4import java.util.ArrayList;
5import java.util.Collection;
6import java.util.List;
7import org.apache.solr.common.SolrInputDocument;
8import org.slf4j.Logger;
9import org.slf4j.LoggerFactory;
10
11/**
12 * Represents a document of CMDI data.
13 */
14public class CMDIData {
15    private final static Logger LOG = LoggerFactory.getLogger(CMDIData.class);
16    private static final String METADATA_TYPE = "Metadata";
17    private static final String DATA_RESOURCE_TYPE = "Resource";
18    private static final String SEARCH_SERVICE_TYPE = "SearchService";
19    //* Definition of the string denoting the landing page type. */
20    private static final String LANDING_PAGE_TYPE = "LandingPage";
21    //* Definition of the string denoting the search page type. */
22    private static final String SEARCH_PAGE_TYPE = "SearchPage";
23
24    /**
25     * The unique identifier of the cmdi file.
26     */
27    private String id;
28   
29    /**
30     * The associated solr document (not send to the solr server yet)
31     */
32    private SolrInputDocument doc;
33
34    // Lists for different types of resources.
35    private final List<Resource> metaDataResources = new ArrayList<Resource>();
36    private final List<Resource> dataResources = new ArrayList<Resource>();
37    private final List<Resource> searchResources = new ArrayList<Resource>();
38    private final List<Resource> landingPageResources = new ArrayList<Resource>();
39    private final List<Resource> searchPageResources = new ArrayList<Resource>();
40
41    public SolrInputDocument getSolrDocument() {
42        return doc;
43    }
44
45    /**
46     * Sets a field in the doc to a certain value. Well, at least calls another
47     * (private) method that actually does this.
48     * @param name
49     * @param value
50     * @param caseInsensitive
51     */
52    public void addDocField(String name, String value, boolean caseInsensitive) {
53        if (FacetConstants.FIELD_ID.equals(name)) {
54            setId(value.trim());
55        } else {
56            handleDocField(name, value, caseInsensitive);
57        }
58    }
59
60    /**
61     * Sets a field in the doc to a certain value.
62     * Before adding checks for duplicates.
63     * @param name
64     * @param value
65     * @param caseInsensitive
66     */
67    private void handleDocField(String name, String value, boolean caseInsensitive) {
68        if (doc == null) {
69            doc = new SolrInputDocument();
70        }
71        if (value != null && !value.trim().isEmpty()) {
72            if (caseInsensitive) {
73                value = value.toLowerCase();
74            }
75            Collection<Object> fieldValues = doc.getFieldValues(name);
76            if (fieldValues == null || !fieldValues.contains(value)) {
77                doc.addField(name, value);
78            } //ignore double values don't add them
79        }
80    }
81
82    public List<Resource> getDataResources() {
83        return dataResources;
84    }
85
86    public List<Resource> getMetadataResources() {
87        return metaDataResources;
88    }
89
90    /**
91     * Returns list of all search interfaces (preferably CQL interfaces)
92     */
93    public List<Resource> getSearchResources() {
94        return searchResources;
95    }
96
97    /**
98     * Return the list of landing page resources.
99     *
100     * @return the list
101     */
102    public List<Resource> getLandingPageResources() {
103        return landingPageResources;
104    }
105   
106    /**
107     * Return the  list of search page resources.
108     *
109     * @return the list
110     */
111    public List<Resource> getSearchPageResources() {
112        return searchPageResources;
113    }
114
115    /**
116     * Add a meta data resource to the list of resources of that type.
117     *
118     * Whenever the type is not one of a type supported by the CMDI
119     * specification, a warning is logged.
120     *
121     * @param resource meta data resource
122     * @param type type of the resource
123     * @param mimeType mime type associated with the resource
124     */
125    public void addResource(String resource, String type, String mimeType) {
126        if (METADATA_TYPE.equals(type)) {
127            metaDataResources.add(new Resource(resource,type, mimeType));
128        } else if (DATA_RESOURCE_TYPE.equals(type)) {
129            dataResources.add(new Resource(resource,type, mimeType));
130        } else if (SEARCH_SERVICE_TYPE.equals(type)){
131            searchResources.add(new Resource(resource,type, mimeType));
132        } else if (LANDING_PAGE_TYPE.equals(type)){
133            landingPageResources.add(new Resource(resource,type, mimeType));
134        } else if (SEARCH_PAGE_TYPE.equals(type)){
135            searchPageResources.add(new Resource(resource,type, mimeType));
136        } else {
137            LOG.warn("Ignoring unsupported resource type " + 
138                    type + ", name=" + resource);
139        }
140    }
141
142    public void setId(String id) {
143        this.id = id;
144    }
145
146    public String getId() {
147        return id;
148    }
149}
Note: See TracBrowser for help on using the repository browser.