source: vlo/branches/vlo-3.3-oeaw/vlo-importer/src/main/java/eu/clarin/cmdi/vlo/importer/CMDIData.java @ 6729

Last change on this file since 6729 was 6729, checked in by davor.ostojic@oeaw.ac.at, 9 years ago

PostProcessorWithVocabulary? implements NormalizaitonService?

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