1 | package eu.clarin.cmdi.vlo.importer; |
---|
2 | |
---|
3 | import eu.clarin.cmdi.vlo.FacetConstants; |
---|
4 | |
---|
5 | import java.util.ArrayList; |
---|
6 | import java.util.Collection; |
---|
7 | import java.util.List; |
---|
8 | |
---|
9 | import org.apache.solr.common.SolrInputDocument; |
---|
10 | import org.slf4j.Logger; |
---|
11 | import org.slf4j.LoggerFactory; |
---|
12 | |
---|
13 | /** |
---|
14 | * Represents a document of CMDI data. |
---|
15 | */ |
---|
16 | public 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 profileName; |
---|
45 | private String originalResourceType; |
---|
46 | |
---|
47 | public SolrInputDocument getSolrDocument() { |
---|
48 | return doc; |
---|
49 | } |
---|
50 | |
---|
51 | /** |
---|
52 | * Sets a field in the doc to a certain value. Well, at least calls another |
---|
53 | * (private) method that actually does this. |
---|
54 | * @param name |
---|
55 | * @param value |
---|
56 | * @param caseInsensitive |
---|
57 | */ |
---|
58 | public void addDocField(String name, String value, boolean caseInsensitive) { |
---|
59 | if (FacetConstants.FIELD_ID.equals(name)) { |
---|
60 | setId(value.trim()); |
---|
61 | } else { |
---|
62 | handleDocField(name, value, caseInsensitive); |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | /** |
---|
67 | * Sets a field in the doc to a certain value. |
---|
68 | * Before adding checks for duplicates. |
---|
69 | * @param name |
---|
70 | * @param value |
---|
71 | * @param caseInsensitive |
---|
72 | */ |
---|
73 | private void handleDocField(String name, String value, boolean caseInsensitive) { |
---|
74 | if (doc == null) { |
---|
75 | doc = new SolrInputDocument(); |
---|
76 | } |
---|
77 | if (value != null && !value.trim().isEmpty()) { |
---|
78 | if (caseInsensitive) { |
---|
79 | value = value.toLowerCase(); |
---|
80 | } |
---|
81 | Collection<Object> fieldValues = doc.getFieldValues(name); |
---|
82 | if (fieldValues == null || !fieldValues.contains(value)) { |
---|
83 | doc.addField(name, value); |
---|
84 | } //ignore double values don't add them |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | public List<Resource> getDataResources() { |
---|
89 | return dataResources; |
---|
90 | } |
---|
91 | |
---|
92 | public List<Resource> getMetadataResources() { |
---|
93 | return metaDataResources; |
---|
94 | } |
---|
95 | |
---|
96 | /** |
---|
97 | * Returns list of all search interfaces (preferably CQL interfaces) |
---|
98 | */ |
---|
99 | public List<Resource> getSearchResources() { |
---|
100 | return searchResources; |
---|
101 | } |
---|
102 | |
---|
103 | /** |
---|
104 | * Return the list of landing page resources. |
---|
105 | * |
---|
106 | * @return the list |
---|
107 | */ |
---|
108 | public List<Resource> getLandingPageResources() { |
---|
109 | return landingPageResources; |
---|
110 | } |
---|
111 | |
---|
112 | /** |
---|
113 | * Return the list of search page resources. |
---|
114 | * |
---|
115 | * @return the list |
---|
116 | */ |
---|
117 | public List<Resource> getSearchPageResources() { |
---|
118 | return searchPageResources; |
---|
119 | } |
---|
120 | |
---|
121 | /** |
---|
122 | * Add a meta data resource to the list of resources of that type. |
---|
123 | * |
---|
124 | * Whenever the type is not one of a type supported by the CMDI |
---|
125 | * specification, a warning is logged. |
---|
126 | * |
---|
127 | * @param resource meta data resource |
---|
128 | * @param type type of the resource |
---|
129 | * @param mimeType mime type associated with the resource |
---|
130 | */ |
---|
131 | public void addResource(String resource, String type, String mimeType) { |
---|
132 | if (METADATA_TYPE.equals(type)) { |
---|
133 | metaDataResources.add(new Resource(resource,type, mimeType)); |
---|
134 | } else if (DATA_RESOURCE_TYPE.equals(type)) { |
---|
135 | dataResources.add(new Resource(resource,type, mimeType)); |
---|
136 | } else if (SEARCH_SERVICE_TYPE.equals(type)){ |
---|
137 | searchResources.add(new Resource(resource,type, mimeType)); |
---|
138 | } else if (LANDING_PAGE_TYPE.equals(type)){ |
---|
139 | landingPageResources.add(new Resource(resource,type, mimeType)); |
---|
140 | } else if (SEARCH_PAGE_TYPE.equals(type)){ |
---|
141 | searchPageResources.add(new Resource(resource,type, mimeType)); |
---|
142 | } else { |
---|
143 | LOG.warn("Ignoring unsupported resource type " + |
---|
144 | type + ", name=" + resource); |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | public void setId(String id) { |
---|
149 | this.id = id; |
---|
150 | } |
---|
151 | |
---|
152 | public String getId() { |
---|
153 | return id; |
---|
154 | } |
---|
155 | |
---|
156 | public void setProfileId(String profileId) { |
---|
157 | this.profileId = profileId; |
---|
158 | |
---|
159 | } |
---|
160 | |
---|
161 | public String getProfileId() { |
---|
162 | return profileId; |
---|
163 | } |
---|
164 | |
---|
165 | public String getProfileName() { |
---|
166 | return profileName; |
---|
167 | } |
---|
168 | |
---|
169 | public void setProfileName(String profileName) { |
---|
170 | this.profileName = profileName; |
---|
171 | } |
---|
172 | |
---|
173 | public String getOriginalResourceType() { |
---|
174 | return originalResourceType; |
---|
175 | } |
---|
176 | |
---|
177 | public void setOriginalResourceType(String originalResourceType) { |
---|
178 | this.originalResourceType = originalResourceType; |
---|
179 | } |
---|
180 | |
---|
181 | |
---|
182 | } |
---|