8
8
import com .fasterxml .jackson .annotation .JsonTypeInfo ;
9
9
import com .fasterxml .jackson .core .JsonGenerator ;
10
10
import com .fasterxml .jackson .core .JsonParser ;
11
- import com .fasterxml .jackson .core .JsonProcessingException ;
12
11
import com .fasterxml .jackson .databind .ObjectMapper ;
13
12
import com .fasterxml .jackson .databind .ObjectReader ;
14
13
import com .fasterxml .jackson .dataformat .csv .CsvMapper ;
25
24
import com .marklogic .client .query .DeleteQueryDefinition ;
26
25
import com .marklogic .client .query .QueryManager ;
27
26
import com .marklogic .client .test .BulkReadWriteTest .CityWriter ;
28
- import org .geonames .Toponym ;
29
27
import org .junit .jupiter .api .AfterAll ;
30
28
import org .junit .jupiter .api .BeforeAll ;
31
29
import org .junit .jupiter .api .Test ;
@@ -157,41 +155,41 @@ class ToponymMixIn2 {
157
155
* via JacksonDatabindHandle with configuration provided by mix-in annotations.
158
156
**/
159
157
@ Test
160
- public void testDatabindingThirdPartyPojoWithMixinAnnotations () throws JsonProcessingException , IOException {
158
+ public void testDatabindingThirdPartyPojoWithMixinAnnotations () throws IOException {
161
159
CsvSchema schema = CsvSchema .builder ()
162
160
.setColumnSeparator ('\t' )
163
161
.addColumn ("geoNameId" )
164
- .addColumn ("name" )
165
- .addColumn ("asciiName" )
166
- .addColumn ("alternateNames" )
167
- .addColumn ("latitude" , CsvSchema .ColumnType .NUMBER )
168
- .addColumn ("longitude" , CsvSchema .ColumnType .NUMBER )
169
- .addColumn ("featureClass" )
170
- .addColumn ("featureCode" )
171
- .addColumn ("countryCode" )
172
- .addColumn ("countryCode2" )
173
- .addColumn ("adminCode1" )
174
- .addColumn ("adminCode2" )
175
- .addColumn ("adminCode3" )
176
- .addColumn ("adminCode4" )
177
- .addColumn ("population" )
178
- .addColumn ("elevation" , CsvSchema .ColumnType .NUMBER )
179
- .addColumn ("dem" , CsvSchema .ColumnType .NUMBER )
180
- .addColumn ("timezoneCode" )
181
- .addColumn ("lastModified" )
182
- .build ();
162
+ .addColumn ("name" )
163
+ .addColumn ("asciiName" )
164
+ .addColumn ("alternateNames" )
165
+ .addColumn ("latitude" , CsvSchema .ColumnType .NUMBER )
166
+ .addColumn ("longitude" , CsvSchema .ColumnType .NUMBER )
167
+ .addColumn ("featureClass" )
168
+ .addColumn ("featureCode" )
169
+ .addColumn ("countryCode" )
170
+ .addColumn ("countryCode2" )
171
+ .addColumn ("adminCode1" )
172
+ .addColumn ("adminCode2" )
173
+ .addColumn ("adminCode3" )
174
+ .addColumn ("adminCode4" )
175
+ .addColumn ("population" )
176
+ .addColumn ("elevation" , CsvSchema .ColumnType .NUMBER )
177
+ .addColumn ("dem" , CsvSchema .ColumnType .NUMBER )
178
+ .addColumn ("timezoneCode" )
179
+ .addColumn ("lastModified" )
180
+ .build ();
183
181
CsvMapper mapper = new CsvMapper ();
184
182
mapper .addMixInAnnotations (Toponym .class , ToponymMixIn1 .class );
185
183
ObjectReader reader = mapper .reader (Toponym .class ).with (schema );
186
184
try (BufferedReader cityReader = new BufferedReader (Common .testFileToReader (CITIES_FILE ))) {
187
185
GenericDocumentManager docMgr = client .newDocumentManager ();
188
186
DocumentWriteSet set = docMgr .newWriteSet ();
189
- String line = null ;
187
+ String line ;
190
188
for (int numWritten = 0 ; numWritten < MAX_TO_WRITE && (line = cityReader .readLine ()) != null ; numWritten ++ ) {
191
189
Toponym city = reader .readValue (line );
192
190
JacksonDatabindHandle handle = new JacksonDatabindHandle (city );
193
191
handle .getMapper ().addMixInAnnotations (Toponym .class , ToponymMixIn2 .class );
194
- set .add (DIRECTORY + "/thirdPartyJsonCities/" + city .getGeoNameId () + ".json" , handle );
192
+ set .add (DIRECTORY + "/thirdPartyJsonCities/" + city .geoNameId + ".json" , handle );
195
193
} docMgr .write (set );
196
194
// we can add assertions later, for now this test just serves as example code and
197
195
// ensures no exceptions are thrown
@@ -203,5 +201,199 @@ public static void cleanUp() {
203
201
DeleteQueryDefinition deleteQuery = queryMgr .newDeleteDefinition ();
204
202
deleteQuery .setDirectory (DIRECTORY );
205
203
queryMgr .delete (deleteQuery );
204
+ }
205
+
206
+ // Copy of the class from the org.geonames dependency; copied here to avoid a Black Duck warning on the
207
+ // transitive jdom dependency.
208
+ private static class Toponym {
209
+ private int geoNameId ;
210
+ private String name ;
211
+ private String alternateNames ;
212
+ private String countryCode ;
213
+ private String countryName ;
214
+ private Integer population ;
215
+ private Integer elevation ;
216
+ private String featureClass ;
217
+ private String featureClassName ;
218
+ private String featureCode ;
219
+ private String featureCodeName ;
220
+ private double latitude ;
221
+ private double longitude ;
222
+ private String adminCode1 ;
223
+ private String adminName1 ;
224
+ private String adminCode2 ;
225
+ private String adminName2 ;
226
+ private String adminCode3 ;
227
+ private String adminCode4 ;
228
+ private String timezone ;
229
+ private String style ;
230
+
231
+ public String getFeatureClass () {
232
+ return featureClass ;
233
+ }
234
+
235
+ public void setFeatureClass (String featureClass ) {
236
+ this .featureClass = featureClass ;
237
+ }
238
+
239
+ public String getTimezone () {
240
+ return timezone ;
241
+ }
242
+
243
+ public void setTimezone (String timezone ) {
244
+ this .timezone = timezone ;
245
+ }
246
+
247
+ public String getStyle () {
248
+ return style ;
249
+ }
250
+
251
+ public void setStyle (String style ) {
252
+ this .style = style ;
253
+ }
254
+
255
+ public int getGeoNameId () {
256
+ return geoNameId ;
257
+ }
258
+
259
+ public void setGeoNameId (int geoNameId ) {
260
+ this .geoNameId = geoNameId ;
261
+ }
262
+
263
+ public String getName () {
264
+ return name ;
265
+ }
266
+
267
+ public void setName (String name ) {
268
+ this .name = name ;
269
+ }
270
+
271
+ public String getAlternateNames () {
272
+ return alternateNames ;
273
+ }
274
+
275
+ public void setAlternateNames (String alternateNames ) {
276
+ this .alternateNames = alternateNames ;
277
+ }
278
+
279
+ public String getCountryCode () {
280
+ return countryCode ;
281
+ }
282
+
283
+ public void setCountryCode (String countryCode ) {
284
+ this .countryCode = countryCode ;
285
+ }
286
+
287
+ public String getCountryName () {
288
+ return countryName ;
289
+ }
290
+
291
+ public void setCountryName (String countryName ) {
292
+ this .countryName = countryName ;
293
+ }
294
+
295
+ public Integer getPopulation () {
296
+ return population ;
297
+ }
298
+
299
+ public void setPopulation (Integer population ) {
300
+ this .population = population ;
301
+ }
302
+
303
+ public Integer getElevation () {
304
+ return elevation ;
305
+ }
306
+
307
+ public void setElevation (Integer elevation ) {
308
+ this .elevation = elevation ;
309
+ }
310
+
311
+ public String getFeatureClassName () {
312
+ return featureClassName ;
313
+ }
314
+
315
+ public void setFeatureClassName (String featureClassName ) {
316
+ this .featureClassName = featureClassName ;
317
+ }
318
+
319
+ public String getFeatureCode () {
320
+ return featureCode ;
321
+ }
322
+
323
+ public void setFeatureCode (String featureCode ) {
324
+ this .featureCode = featureCode ;
325
+ }
326
+
327
+ public String getFeatureCodeName () {
328
+ return featureCodeName ;
329
+ }
330
+
331
+ public void setFeatureCodeName (String featureCodeName ) {
332
+ this .featureCodeName = featureCodeName ;
333
+ }
334
+
335
+ public double getLatitude () {
336
+ return latitude ;
337
+ }
338
+
339
+ public void setLatitude (double latitude ) {
340
+ this .latitude = latitude ;
341
+ }
342
+
343
+ public double getLongitude () {
344
+ return longitude ;
345
+ }
346
+
347
+ public void setLongitude (double longitude ) {
348
+ this .longitude = longitude ;
349
+ }
350
+
351
+ public String getAdminCode1 () {
352
+ return adminCode1 ;
353
+ }
354
+
355
+ public void setAdminCode1 (String adminCode1 ) {
356
+ this .adminCode1 = adminCode1 ;
357
+ }
358
+
359
+ public String getAdminName1 () {
360
+ return adminName1 ;
361
+ }
362
+
363
+ public void setAdminName1 (String adminName1 ) {
364
+ this .adminName1 = adminName1 ;
365
+ }
366
+
367
+ public String getAdminCode2 () {
368
+ return adminCode2 ;
369
+ }
370
+
371
+ public void setAdminCode2 (String adminCode2 ) {
372
+ this .adminCode2 = adminCode2 ;
373
+ }
374
+
375
+ public String getAdminName2 () {
376
+ return adminName2 ;
377
+ }
378
+
379
+ public void setAdminName2 (String adminName2 ) {
380
+ this .adminName2 = adminName2 ;
381
+ }
382
+
383
+ public String getAdminCode3 () {
384
+ return adminCode3 ;
385
+ }
386
+
387
+ public void setAdminCode3 (String adminCode3 ) {
388
+ this .adminCode3 = adminCode3 ;
389
+ }
390
+
391
+ public String getAdminCode4 () {
392
+ return adminCode4 ;
393
+ }
394
+
395
+ public void setAdminCode4 (String adminCode4 ) {
396
+ this .adminCode4 = adminCode4 ;
397
+ }
206
398
}
207
399
}
0 commit comments