-
Notifications
You must be signed in to change notification settings - Fork 477
/
ImportDDIServiceBean.java
2058 lines (1845 loc) · 104 KB
/
ImportDDIServiceBean.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package edu.harvard.iq.dataverse.api.imports;
import edu.harvard.iq.dataverse.DatasetFieldConstant;
import edu.harvard.iq.dataverse.DatasetFieldServiceBean;
import edu.harvard.iq.dataverse.DatasetFieldType;
import edu.harvard.iq.dataverse.DatasetVersion;
import edu.harvard.iq.dataverse.DatasetVersion.VersionState;
import edu.harvard.iq.dataverse.api.dto.*;
import edu.harvard.iq.dataverse.api.dto.FieldDTO;
import edu.harvard.iq.dataverse.api.dto.MetadataBlockDTO;
import edu.harvard.iq.dataverse.api.imports.ImportUtil.ImportType;
import static edu.harvard.iq.dataverse.export.ddi.DdiExportUtil.NOTE_TYPE_CONTENTTYPE;
import static edu.harvard.iq.dataverse.export.ddi.DdiExportUtil.NOTE_TYPE_TERMS_OF_ACCESS;
import edu.harvard.iq.dataverse.util.StringUtil;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.StringReader;
import java.util.*;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.ejb.EJBException;
import javax.ejb.Stateless;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLInputFactory;
import edu.harvard.iq.dataverse.util.json.ControlledVocabularyException;
import org.apache.commons.lang.StringUtils;
/**
*
* @author ellenk
*/
// TODO:
// does this need to be a service bean/stateless? - could be transformed into
// a util with static methods.
// (it would need to be passed the fields service beans as arguments)
// -- L.A. 4.5
@Stateless
public class ImportDDIServiceBean {
public static final String SOURCE_DVN_3_0 = "DVN_3_0";
public static final String NAMING_PROTOCOL_HANDLE = "hdl";
public static final String NAMING_PROTOCOL_DOI = "doi";
public static final String AGENCY_HANDLE = "handle";
public static final String AGENCY_DOI = "DOI";
public static final String AGENCY_DARA = "dara"; // da|ra - http://www.da-ra.de/en/home/
public static final String REPLICATION_FOR_TYPE = "replicationFor";
public static final String VAR_WEIGHTED = "wgtd";
public static final String VAR_INTERVAL_CONTIN = "contin";
public static final String VAR_INTERVAL_DISCRETE = "discrete";
public static final String CAT_STAT_TYPE_FREQUENCY = "freq";
public static final String VAR_FORMAT_TYPE_NUMERIC = "numeric";
public static final String VAR_FORMAT_SCHEMA_ISO = "ISO";
public static final String EVENT_START = "start";
public static final String EVENT_END = "end";
public static final String EVENT_SINGLE = "single";
public static final String LEVEL_DVN = "dvn";
public static final String LEVEL_DV = "dv";
public static final String LEVEL_STUDY = "study";
public static final String LEVEL_FILE = "file";
public static final String LEVEL_VARIABLE = "variable";
public static final String LEVEL_CATEGORY = "category";
public static final String NOTE_TYPE_UNF = "VDC:UNF";
public static final String NOTE_SUBJECT_UNF = "Universal Numeric Fingerprint";
public static final String NOTE_TYPE_TERMS_OF_USE = "DVN:TOU";
public static final String NOTE_SUBJECT_TERMS_OF_USE = "Terms Of Use";
public static final String NOTE_TYPE_CITATION = "DVN:CITATION";
public static final String NOTE_SUBJECT_CITATION = "Citation";
public static final String NOTE_TYPE_VERSION_NOTE = "DVN:VERSION_NOTE";
public static final String NOTE_SUBJECT_VERSION_NOTE= "Version Note";
public static final String NOTE_TYPE_ARCHIVE_NOTE = "DVN:ARCHIVE_NOTE";
public static final String NOTE_SUBJECT_ARCHIVE_NOTE= "Archive Note";
public static final String NOTE_TYPE_ARCHIVE_DATE = "DVN:ARCHIVE_DATE";
public static final String NOTE_SUBJECT_ARCHIVE_DATE= "Archive Date";
public static final String NOTE_TYPE_EXTENDED_METADATA = "DVN:EXTENDED_METADATA";
public static final String NOTE_TYPE_LOCKSS_CRAWL = "LOCKSS:CRAWLING";
public static final String NOTE_SUBJECT_LOCKSS_PERM = "LOCKSS Permission";
public static final String NOTE_TYPE_REPLICATION_FOR = "DVN:REPLICATION_FOR";
private static final String HARVESTED_FILE_STORAGE_PREFIX = "http://";
private XMLInputFactory xmlInputFactory = null;
private static final Logger logger = Logger.getLogger(ImportDDIServiceBean.class.getName());
@EJB CustomFieldServiceBean customFieldService;
@EJB DatasetFieldServiceBean datasetFieldService;
// TODO: stop passing the xml source as a string; (it could be huge!) -- L.A. 4.5
// TODO: what L.A. Said.
public DatasetDTO doImport(ImportType importType, String xmlToParse) throws XMLStreamException, ImportException {
xmlInputFactory = javax.xml.stream.XMLInputFactory.newInstance();
xmlInputFactory.setProperty("javax.xml.stream.isCoalescing", java.lang.Boolean.TRUE); DatasetDTO datasetDTO = this.initializeDataset();
// Read docDescr and studyDesc into DTO objects.
// TODO: the fileMap is likely not needed.
Map<String, String> fileMap = mapDDI(importType, xmlToParse, datasetDTO);
return datasetDTO;
}
public void importFileMetadata(DatasetVersion dv, String xmlToParse) {
}
private boolean isHarvestImport(ImportType importType) {
return importType.equals(ImportType.HARVEST);
}
private boolean isNewImport(ImportType importType) {
return importType.equals(ImportType.NEW);
}
public Map<String, String> mapDDI(ImportType importType, String xmlToParse, DatasetDTO datasetDTO) throws XMLStreamException, ImportException {
Map<String, String> filesMap = new HashMap<>();
StringReader reader = new StringReader(xmlToParse);
XMLStreamReader xmlr = null;
XMLInputFactory xmlFactory = javax.xml.stream.XMLInputFactory.newInstance();
xmlFactory.setProperty("javax.xml.stream.isCoalescing", true); // allows the parsing of a CDATA segment into a single event
xmlr = xmlFactory.createXMLStreamReader(reader);
processDDI(importType, xmlr, datasetDTO, filesMap);
return filesMap;
}
public Map<String, String> mapDDI(ImportType importType, File ddiFile, DatasetDTO datasetDTO ) throws ImportException {
FileInputStream in = null;
XMLStreamReader xmlr = null;
Map<String, String> filesMap = new HashMap<>();
try {
in = new FileInputStream(ddiFile);
xmlr = xmlInputFactory.createXMLStreamReader(in);
processDDI(importType, xmlr, datasetDTO , filesMap );
} catch (FileNotFoundException ex) {
Logger.getLogger("global").log(Level.SEVERE, null, ex);
throw new EJBException("ERROR occurred in mapDDI: File Not Found!");
} catch (XMLStreamException ex) {
Logger.getLogger("global").log(Level.SEVERE, null, ex);
throw new EJBException("ERROR occurred in mapDDI.", ex);
} finally {
try {
if (xmlr != null) { xmlr.close(); }
} catch (XMLStreamException ex) {}
try {
if (in != null) { in.close();}
} catch (IOException ex) {}
}
return filesMap;
}
private void processDDI(ImportType importType, XMLStreamReader xmlr, DatasetDTO datasetDTO, Map<String, String> filesMap) throws XMLStreamException, ImportException {
// make sure we have a codeBook
//while ( xmlr.next() == XMLStreamConstants.COMMENT ); // skip pre root comments
try {
xmlr.nextTag();
xmlr.require(XMLStreamConstants.START_ELEMENT, null, "codeBook");
} catch( XMLStreamException e) {
throw new XMLStreamException("It doesn't start with the XML element <codeBook>");
}
// Some DDIs provide an ID in the <codeBook> section.
// We are going to treat it as just another otherId.
// (we've seen instances where this ID was the only ID found in
// in a harvested DDI).
String codeBookLevelId = xmlr.getAttributeValue(null, "ID");
// (but first we will parse and process the entire DDI - and only
// then add this codeBook-level id to the list of identifiers; i.e.,
// we don't want it to be the first on the list, if one or more
// ids are available in the studyDscr section - those should take
// precedence!)
// In fact, we should only use these IDs when no ID is available down
// in the study description section!
processCodeBook(importType, xmlr, datasetDTO, filesMap);
MetadataBlockDTO citationBlock = datasetDTO.getDatasetVersion().getMetadataBlocks().get("citation");
if (codeBookLevelId != null && !codeBookLevelId.isEmpty()) {
if (citationBlock.getField("otherId")==null) {
// this means no ids were found during the parsing of the
// study description section. we'll use the one we found in
// the codeBook entry:
FieldDTO otherIdValue = FieldDTO.createPrimitiveFieldDTO("otherIdValue", codeBookLevelId);
FieldDTO otherId = FieldDTO.createCompoundFieldDTO("otherId", otherIdValue);
citationBlock.getFields().add(otherId);
}
}
if (isHarvestImport(importType)) {
datasetDTO.getDatasetVersion().setVersionState(VersionState.RELEASED);
}
else {
datasetDTO.getDatasetVersion().setVersionState(VersionState.DRAFT);
}
}
public DatasetDTO initializeDataset() {
DatasetDTO datasetDTO = new DatasetDTO();
DatasetVersionDTO datasetVersionDTO = new DatasetVersionDTO();
datasetDTO.setDatasetVersion(datasetVersionDTO);
HashMap<String, MetadataBlockDTO> metadataBlocks = new HashMap<>();
datasetVersionDTO.setMetadataBlocks(metadataBlocks);
datasetVersionDTO.getMetadataBlocks().put("citation", new MetadataBlockDTO());
datasetVersionDTO.getMetadataBlocks().get("citation").setFields(new ArrayList<>());
datasetVersionDTO.getMetadataBlocks().put("socialscience", new MetadataBlockDTO());
datasetVersionDTO.getMetadataBlocks().get("socialscience").setFields(new ArrayList<>());
datasetVersionDTO.getMetadataBlocks().put("geospatial", new MetadataBlockDTO());
datasetVersionDTO.getMetadataBlocks().get("geospatial").setFields(new ArrayList<>());
return datasetDTO;
}
// Read the XMLStream, and populate datasetDTO and filesMap
private void processCodeBook(ImportType importType, XMLStreamReader xmlr, DatasetDTO datasetDTO, Map<String, String> filesMap) throws XMLStreamException, ImportException {
for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
if (event == XMLStreamConstants.START_ELEMENT) {
if (xmlr.getLocalName().equals("docDscr")) {
processDocDscr(xmlr, datasetDTO);
} else if (xmlr.getLocalName().equals("stdyDscr")) {
processStdyDscr(importType, xmlr, datasetDTO);
} else if (xmlr.getLocalName().equals("otherMat") && (isNewImport(importType) || isHarvestImport(importType)) ) {
processOtherMat(xmlr, datasetDTO);
} else if (xmlr.getLocalName().equals("fileDscr") && isHarvestImport(importType)) {
// If this is a harvesting import, we'll attempt to extract some minimal
// file-level metadata information from the fileDscr sections as well.
// TODO: add more info here... -- 4.6
processFileDscrMinimal(xmlr, datasetDTO);
} else if (xmlr.getLocalName().equals("fileDscr") && isNewImport(importType)) {
// this is a "full" fileDscr section - Dataverses use it
// to encode *tabular* files only. It will contain the information
// about variables, observations, etc. It will be complemented
// by a number of <var> entries in the dataDscr section.
// Dataverses do not use this section for harvesting exports, since
// we don't harvest tabular metadata. And all the "regular"
// file-level metadata is encoded in otherMat sections.
// The goal is to one day be able to import such tabular
// metadata using the direct (non-harvesting) import API.
// EMK TODO: add this back in for ImportType.NEW
//processFileDscr(xmlr, datasetDTO, filesMap);
}
} else if (event == XMLStreamConstants.END_ELEMENT) {
if (xmlr.getLocalName().equals("codeBook")) return;
}
}
}
private void processDocDscr(XMLStreamReader xmlr, DatasetDTO datasetDTO) throws XMLStreamException {
for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
if (event == XMLStreamConstants.START_ELEMENT) {
if (xmlr.getLocalName().equals("IDNo") && StringUtil.isEmpty(datasetDTO.getIdentifier()) ) {
// this will set a StudyId if it has not yet been set; it will get overridden by a metadata
// id in the StudyDscr section, if one exists
if ( AGENCY_HANDLE.equals( xmlr.getAttributeValue(null, "agency") ) ) {
parseStudyIdHandle( parseText(xmlr), datasetDTO );
}
// EMK TODO: we need to save this somewhere when we add harvesting infrastructure
} /*else if ( xmlr.getLocalName().equals("holdings") && StringUtil.isEmpty(datasetDTO..getHarvestHoldings()) ) {
metadata.setHarvestHoldings( xmlr.getAttributeValue(null, "URI") );
}*/
} else if (event == XMLStreamConstants.END_ELEMENT) {
if (xmlr.getLocalName().equals("docDscr")) return;
}
}
}
private String parseText(XMLStreamReader xmlr) throws XMLStreamException {
return parseText(xmlr,true);
}
private String parseText(XMLStreamReader xmlr, boolean scrubText) throws XMLStreamException {
String tempString = getElementText(xmlr);
if (scrubText) {
tempString = tempString.trim().replace('\n',' ');
}
return tempString;
}
private String parseDate (XMLStreamReader xmlr, String endTag) throws XMLStreamException {
String date = xmlr.getAttributeValue(null, "date");
if (date == null) {
date = parseText(xmlr);
}
return date;
}
/* We had to add this method because the ref getElementText has a bug where it
* would append a null before the text, if there was an escaped apostrophe; it appears
* that the code finds an null ENTITY_REFERENCE in this case which seems like a bug;
* the workaround for the moment is to comment or handling ENTITY_REFERENCE in this case
*/
private String getElementText(XMLStreamReader xmlr) throws XMLStreamException {
if(xmlr.getEventType() != XMLStreamConstants.START_ELEMENT) {
throw new XMLStreamException("parser must be on START_ELEMENT to read next text", xmlr.getLocation());
}
int eventType = xmlr.next();
StringBuilder content = new StringBuilder();
while(eventType != XMLStreamConstants.END_ELEMENT ) {
if(eventType == XMLStreamConstants.CHARACTERS
|| eventType == XMLStreamConstants.CDATA
|| eventType == XMLStreamConstants.SPACE
/* || eventType == XMLStreamConstants.ENTITY_REFERENCE*/) {
content.append(xmlr.getText());
} else if(eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
|| eventType == XMLStreamConstants.COMMENT
|| eventType == XMLStreamConstants.ENTITY_REFERENCE) {
// skipping
} else if(eventType == XMLStreamConstants.END_DOCUMENT) {
throw new XMLStreamException("unexpected end of document when reading element text content");
} else if(eventType == XMLStreamConstants.START_ELEMENT) {
throw new XMLStreamException("element text content may not contain START_ELEMENT", xmlr.getLocation());
} else {
throw new XMLStreamException("Unexpected event type "+eventType, xmlr.getLocation());
}
eventType = xmlr.next();
}
return content.toString();
}
private void processStdyDscr(ImportType importType, XMLStreamReader xmlr, DatasetDTO datasetDTO) throws XMLStreamException, ImportException {
for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
if (event == XMLStreamConstants.START_ELEMENT) {
if (xmlr.getLocalName().equals("citation")) processCitation(importType, xmlr, datasetDTO);
else if (xmlr.getLocalName().equals("stdyInfo")) processStdyInfo(xmlr, datasetDTO.getDatasetVersion());
else if (xmlr.getLocalName().equals("method")) processMethod(xmlr, datasetDTO.getDatasetVersion());
else if (xmlr.getLocalName().equals("dataAccs")) processDataAccs(xmlr, datasetDTO.getDatasetVersion());
else if (xmlr.getLocalName().equals("notes")) processStdyNotes(xmlr, datasetDTO.getDatasetVersion());
else if (xmlr.getLocalName().equals("othrStdyMat")) processOthrStdyMat(xmlr, datasetDTO.getDatasetVersion());
else if (xmlr.getLocalName().equals("notes")) processNotes(xmlr, datasetDTO.getDatasetVersion());
} else if (event == XMLStreamConstants.END_ELEMENT) {
if (xmlr.getLocalName().equals("stdyDscr")) return;
}
}
}
private void processOthrStdyMat(XMLStreamReader xmlr, DatasetVersionDTO dvDTO) throws XMLStreamException {
List<HashSet<FieldDTO>> publications = new ArrayList<>();
boolean replicationForFound = false;
for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
if (event == XMLStreamConstants.START_ELEMENT) {
if (xmlr.getLocalName().equals("relMat")) {
// this code is still here to handle imports from old DVN created ddis
if (!replicationForFound && REPLICATION_FOR_TYPE.equals(xmlr.getAttributeValue(null, "type"))) {
if (!SOURCE_DVN_3_0.equals(xmlr.getAttributeValue(null, "source"))) {
// this is a ddi from pre 3.0, so we should add a publication
/* StudyRelPublication rp = new StudyRelPublication();
metadata.getStudyRelPublications().add(rp);
rp.setMetadata(metadata);
rp.setText( parseText( xmlr, "relMat" ) );
rp.setReplicationData(true);
replicationForFound = true;*/
HashSet<FieldDTO> set = new HashSet<>();
addToSet(set, DatasetFieldConstant.publicationCitation, parseText(xmlr, "relMat"));
if (!set.isEmpty()) {
publications.add(set);
}
if (publications.size()>0)
getCitation(dvDTO).addField(FieldDTO.createMultipleCompoundFieldDTO(DatasetFieldConstant.publication, publications));
}
} else {
List<String> relMaterial = new ArrayList<>();
relMaterial.add(parseText(xmlr, "relMat"));
getCitation(dvDTO).addField(FieldDTO.createMultiplePrimitiveFieldDTO(DatasetFieldConstant.relatedMaterial, relMaterial));
}
}
else if (xmlr.getLocalName().equals("relStdy")) {
List<String> relStudy = new ArrayList<>();
relStudy.add(parseText(xmlr, "relStdy"));
getCitation(dvDTO).addField(FieldDTO.createMultiplePrimitiveFieldDTO(DatasetFieldConstant.relatedDatasets, relStudy));
} else if (xmlr.getLocalName().equals("relPubl")) {
processRelPubl(xmlr, dvDTO, publications);
} else if (xmlr.getLocalName().equals("othRefs")) {
List<String> otherRefs = new ArrayList<>();
otherRefs.add(parseText(xmlr, "othRefs"));
getCitation(dvDTO).addField(FieldDTO.createMultiplePrimitiveFieldDTO(DatasetFieldConstant.otherReferences, otherRefs));
}
} else if (event == XMLStreamConstants.END_ELEMENT) {
if (publications.size()>0) {
getCitation(dvDTO).addField(FieldDTO.createMultipleCompoundFieldDTO(DatasetFieldConstant.publication, publications));
}
if (xmlr.getLocalName().equals("othrStdyMat")) {
return;
}
}
}
}
private void processRelPubl(XMLStreamReader xmlr, DatasetVersionDTO dvDTO, List<HashSet<FieldDTO>> publications) throws XMLStreamException {
HashSet<FieldDTO> set = new HashSet<>();
for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
if (event == XMLStreamConstants.START_ELEMENT) {
if (xmlr.getLocalName().equals("citation")) {
for (int event2 = xmlr.next(); event2 != XMLStreamConstants.END_DOCUMENT; event2 = xmlr.next()) {
if (event2 == XMLStreamConstants.START_ELEMENT) {
if (xmlr.getLocalName().equals("titlStmt")) {
int event3 = xmlr.next();
if (event3 == XMLStreamConstants.START_ELEMENT) {
if (xmlr.getLocalName().equals("IDNo")) {
set.add(FieldDTO.createVocabFieldDTO(DatasetFieldConstant.publicationIDType, xmlr.getAttributeValue(null, "agency")));
addToSet(set, DatasetFieldConstant.publicationIDNumber, parseText(xmlr));
}
}
} else if (xmlr.getLocalName().equals("biblCit")) {
if (event2 == XMLStreamConstants.START_ELEMENT) {
if (xmlr.getLocalName().equals("biblCit")) {
addToSet(set, DatasetFieldConstant.publicationCitation, parseText(xmlr));
}
}
}
} else if (event2 == XMLStreamConstants.END_ELEMENT) {
if (xmlr.getLocalName().equals("citation")) {
break;
}
}
}
} else if (xmlr.getLocalName().equals("ExtLink")) {
addToSet(set, DatasetFieldConstant.publicationURL, xmlr.getAttributeValue(null, "URI"));
}
} else if (event == XMLStreamConstants.END_ELEMENT) {
if (xmlr.getLocalName().equals("relPubl")) {
if (set.size() > 0) {
publications.add(set);
}
return;
}
}
}
}
private void processCitation(ImportType importType, XMLStreamReader xmlr, DatasetDTO datasetDTO) throws XMLStreamException, ImportException {
DatasetVersionDTO dvDTO = datasetDTO.getDatasetVersion();
MetadataBlockDTO citation=datasetDTO.getDatasetVersion().getMetadataBlocks().get("citation");
boolean distStatementProcessed = false;
for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
if (event == XMLStreamConstants.START_ELEMENT) {
if (xmlr.getLocalName().equals("titlStmt")) processTitlStmt(xmlr, datasetDTO);
else if (xmlr.getLocalName().equals("rspStmt")) processRspStmt(xmlr,citation);
else if (xmlr.getLocalName().equals("prodStmt")) processProdStmt(xmlr,citation);
else if (xmlr.getLocalName().equals("distStmt")) {
if (distStatementProcessed) {
// We've already encountered one Distribution Statement in
// this citation, we'll just skip any consecutive ones.
// This is a defensive check against duplicate distStmt
// in some DDIs (notably, from ICPSR)
} else {
processDistStmt(xmlr,citation);
distStatementProcessed = true;
}
}
else if (xmlr.getLocalName().equals("serStmt")) processSerStmt(xmlr,citation);
else if (xmlr.getLocalName().equals("verStmt")) processVerStmt(importType, xmlr,dvDTO);
else if (xmlr.getLocalName().equals("notes")) {
String _note = parseNoteByType( xmlr, NOTE_TYPE_UNF );
if (_note != null) {
datasetDTO.getDatasetVersion().setUNF( parseUNF( _note ) );
} else {
processNotes(xmlr,dvDTO);
}
}
} else if (event == XMLStreamConstants.END_ELEMENT) {
if (xmlr.getLocalName().equals("citation")) return;
}
}
}
/**
*
*
* @param xmlr
* @param citation
* @throws XMLStreamException
*/
private void processStdyInfo(XMLStreamReader xmlr, DatasetVersionDTO dvDTO) throws XMLStreamException {
List<HashSet<FieldDTO>> descriptions = new ArrayList<>();
for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
if (event == XMLStreamConstants.START_ELEMENT) {
if (xmlr.getLocalName().equals("subject")) {
processSubject(xmlr, getCitation(dvDTO));
} else if (xmlr.getLocalName().equals("abstract")) {
HashSet<FieldDTO> set = new HashSet<>();
addToSet(set,"dsDescriptionDate", xmlr.getAttributeValue(null, "date"));
Map<String, String> dsDescriptionDetails = parseCompoundText(xmlr, "abstract");
addToSet(set,"dsDescriptionValue", dsDescriptionDetails.get("name"));
if (!set.isEmpty()) {
descriptions.add(set);
}
} else if (xmlr.getLocalName().equals("sumDscr")) processSumDscr(xmlr, dvDTO);
else if (xmlr.getLocalName().equals("notes")) processNotes(xmlr,dvDTO);
} else if (event == XMLStreamConstants.END_ELEMENT) {
if (xmlr.getLocalName().equals("stdyInfo") ) {
if (descriptions.size()>0) {
getCitation(dvDTO).getFields().add(FieldDTO.createMultipleCompoundFieldDTO("dsDescription", descriptions));
}
return;
}
}
}
}
private void processSubject(XMLStreamReader xmlr, MetadataBlockDTO citation) throws XMLStreamException {
List<HashSet<FieldDTO>> keywords = new ArrayList<>();
List<HashSet<FieldDTO>> topicClasses = new ArrayList<>();
for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
if (event == XMLStreamConstants.START_ELEMENT) {
if (xmlr.getLocalName().equals("keyword")) {
HashSet<FieldDTO> set = new HashSet<>();
addToSet(set,"keywordVocabulary", xmlr.getAttributeValue(null, "vocab"));
addToSet(set, "keywordVocabularyURI", xmlr.getAttributeValue(null, "vocabURI") );
addToSet(set,"keywordValue", parseText(xmlr));
if (!set.isEmpty()) {
keywords.add(set);
}
} else if (xmlr.getLocalName().equals("topcClas")) {
HashSet<FieldDTO> set = new HashSet<>();
addToSet(set,"topicClassVocab", xmlr.getAttributeValue(null, "vocab"));
addToSet(set,"topicClassVocabURI", xmlr.getAttributeValue(null, "vocabURI") );
addToSet(set,"topicClassValue",parseText(xmlr));
if (!set.isEmpty()) {
topicClasses.add(set);
}
}
} else if (event == XMLStreamConstants.END_ELEMENT) {
if (xmlr.getLocalName().equals("subject")) {
if (keywords.size()>0) {
citation.getFields().add(FieldDTO.createMultipleCompoundFieldDTO("keyword", keywords));
}
if (topicClasses.size()>0) {
citation.getFields().add(FieldDTO.createMultipleCompoundFieldDTO("topicClassification", topicClasses));
}
return;
}
} else {
// citation.getFields().add(FieldDTO.createPrimitiveFieldDTO( "subject",xmlr.getElementText()));
}
}
}
/**
* Process the notes portion of the DDI doc -- if there is one
* Return a formatted string
*
* @param xmlr
* @return
*/
private String formatNotesfromXML(XMLStreamReader xmlr) throws XMLStreamException{
if (xmlr==null){
throw new NullPointerException("XMLStreamReader xmlr cannot be null");
}
//System.out.println("formatNotesfromXML");
// Initialize array of strings
List<String> noteValues = new ArrayList<>();
String attrVal;
// Check for "subject"
attrVal = xmlr.getAttributeValue(null, "subject");
if (attrVal != null){
noteValues.add("Subject: " + attrVal);
}
// Check for "type"
attrVal = xmlr.getAttributeValue(null, "type");
if (attrVal != null){
noteValues.add("Type: " + attrVal);
}
// Add notes, if they exist
attrVal = parseText(xmlr, "notes");
if ((attrVal != null) && (!attrVal.isEmpty())){
noteValues.add("Notes: " + attrVal);
}
// Nothing to add
if (noteValues.isEmpty()){
//System.out.println("nuthin'");
return null;
}
//System.out.println(StringUtils.join(noteValues, " ") + ";");
return StringUtils.join(noteValues, " ") + ";";
/*
Examples of xml:
<notes type="Statistics" subject="Babylon"> </notes>
<notes type="Note Type" subject="Note Subject">Note Text</notes>
<notes type="Note Type 2" subject="Note Subject 2">Note Text 2</notes>
<notes>Note Text 3</notes>
*/
/*
// Original, changed b/c of string 'null' appearing in final output
String note = " Subject: "+xmlr.getAttributeValue(null, "subject")+" "
+ " Type: "+xmlr.getAttributeValue(null, "type")+" "
+ " Notes: "+parseText(xmlr, "notes")+";";
addNote(note, dvDTO);
*/
}
private void processNotes (XMLStreamReader xmlr, DatasetVersionDTO dvDTO) throws XMLStreamException {
String formattedNotes = this.formatNotesfromXML(xmlr);
if (formattedNotes != null){
this.addNote(formattedNotes, dvDTO);
}
}
private void processStdyNotes(XMLStreamReader xmlr, DatasetVersionDTO dvDTO) throws XMLStreamException {
FieldDTO notesText = null;
// Add notes, if they exist
String attrVal = parseText(xmlr, "notes");
if ((attrVal != null) && (!attrVal.isEmpty())){
notesText = FieldDTO.createPrimitiveFieldDTO("datasetLevelErrorNotes", attrVal);
getSocialScience(dvDTO).addField(notesText);
}
}
private void processNotesSocialScience(XMLStreamReader xmlr, DatasetVersionDTO dvDTO) throws XMLStreamException {
//String formattedNotes = this.formatNotesfromXML(xmlr);
if (xmlr==null){
throw new NullPointerException("XMLStreamReader xmlr cannot be null");
}
FieldDTO notesSubject = null;
String attrVal;
// Check for "subject"
attrVal = xmlr.getAttributeValue(null, "subject");
if (attrVal != null){
notesSubject = FieldDTO.createPrimitiveFieldDTO("socialScienceNotesSubject", attrVal);
}
FieldDTO notesType = null;
// Check for "type"
attrVal = xmlr.getAttributeValue(null, "type");
if (attrVal != null){
notesType = FieldDTO.createPrimitiveFieldDTO("socialScienceNotesType", attrVal);
}
FieldDTO notesText = null;
// Add notes, if they exist
attrVal = parseText(xmlr, "notes");
if ((attrVal != null) && (!attrVal.isEmpty())){
notesText = FieldDTO.createPrimitiveFieldDTO("socialScienceNotesText", attrVal);
}
if (notesSubject != null || notesType != null || notesText != null ){
//this.addNoteSocialScience(formattedNotes, dvDTO);
getSocialScience(dvDTO).addField(FieldDTO.createCompoundFieldDTO("socialScienceNotes", notesSubject, notesType, notesText ));
}
}
private void addNote(String noteText, DatasetVersionDTO dvDTO ) {
MetadataBlockDTO citation = getCitation(dvDTO);
FieldDTO field = citation.getField("notesText");
if (field==null) {
field = FieldDTO.createPrimitiveFieldDTO("notesText", "");
citation.getFields().add(field);
}
String noteValue = field.getSinglePrimitive();
noteValue+= noteText;
field.setSinglePrimitive(noteValue);
}
private void processSumDscr(XMLStreamReader xmlr, DatasetVersionDTO dvDTO) throws XMLStreamException {
List<String> geoUnit = new ArrayList<>();
List<String> unitOfAnalysis = new ArrayList<>();
List<String> universe = new ArrayList<>();
List<String> kindOfData = new ArrayList<>();
List<HashSet<FieldDTO>> geoBoundBox = new ArrayList<>();
List<HashSet<FieldDTO>> geoCoverages = new ArrayList<>();
List<FieldDTO> timePeriod = new ArrayList<>();
List<FieldDTO> dateOfCollection = new ArrayList<>();
FieldDTO timePeriodStart = null;
FieldDTO timePeriodEnd = null;
FieldDTO dateOfCollectionStart = null;
FieldDTO dateOfCollectionEnd = null;
HashSet<FieldDTO> geoCoverageSet = null;
String otherGeographicCoverage = null;
for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
if (event == XMLStreamConstants.START_ELEMENT) {
if (xmlr.getLocalName().equals("timePrd")) {
String eventAttr = xmlr.getAttributeValue(null, "event");
if (eventAttr == null || EVENT_SINGLE.equalsIgnoreCase(eventAttr) || EVENT_START.equalsIgnoreCase(eventAttr)) {
timePeriodStart = FieldDTO.createPrimitiveFieldDTO("timePeriodCoveredStart", parseDate(xmlr, "timePrd"));
} else if (EVENT_END.equals(eventAttr)) {
timePeriodEnd = FieldDTO.createPrimitiveFieldDTO("timePeriodCoveredEnd", parseDate(xmlr, "timePrd"));
timePeriod.add(FieldDTO.createMultipleCompoundFieldDTO("timePeriodCovered", timePeriodStart, timePeriodEnd));
}
} else if (xmlr.getLocalName().equals("collDate")) {
String eventAttr = xmlr.getAttributeValue(null, "event");
if (eventAttr == null || EVENT_SINGLE.equalsIgnoreCase(eventAttr) || EVENT_START.equalsIgnoreCase(eventAttr)) {
dateOfCollectionStart = FieldDTO.createPrimitiveFieldDTO("dateOfCollectionStart", parseDate(xmlr, "collDate"));
} else if (EVENT_END.equals(eventAttr)) {
dateOfCollectionEnd = FieldDTO.createPrimitiveFieldDTO("dateOfCollectionEnd", parseDate(xmlr, "collDate"));
dateOfCollection.add(FieldDTO.createMultipleCompoundFieldDTO("dateOfCollection", dateOfCollectionStart, dateOfCollectionEnd ));
}
} else if (xmlr.getLocalName().equals("nation")) {
if (otherGeographicCoverage != null && !otherGeographicCoverage.equals("")) {
geoCoverageSet.add(FieldDTO.createPrimitiveFieldDTO("otherGeographicCoverage", otherGeographicCoverage));
otherGeographicCoverage = null;
}
if (geoCoverageSet != null && geoCoverageSet.size() > 0) {
geoCoverages.add(geoCoverageSet);
}
geoCoverageSet = new HashSet<>();
//HashSet<FieldDTO> set = new HashSet<>();
//set.add(FieldDTO.createVocabFieldDTO("country", parseText(xmlr)));
geoCoverageSet.add(FieldDTO.createVocabFieldDTO("country", parseText(xmlr)));
} else if (xmlr.getLocalName().equals("geogCover")) {
if (geoCoverageSet == null) {
geoCoverageSet = new HashSet<>();
}
if (otherGeographicCoverage != null) {
otherGeographicCoverage = otherGeographicCoverage + "; " + parseText(xmlr);
} else {
otherGeographicCoverage = parseText(xmlr);
}
} else if (xmlr.getLocalName().equals("geogUnit")) {
geoUnit.add(parseText(xmlr));
} else if (xmlr.getLocalName().equals("geoBndBox")) {
geoBoundBox.add(processGeoBndBox(xmlr));
} else if (xmlr.getLocalName().equals("anlyUnit")) {
unitOfAnalysis.add(parseText(xmlr, "anlyUnit"));
} else if (xmlr.getLocalName().equals("universe")) {
universe.add(parseText(xmlr, "universe"));
} else if (xmlr.getLocalName().equals("dataKind")) {
kindOfData.add(parseText(xmlr));
}
} else if (event == XMLStreamConstants.END_ELEMENT) {
if (xmlr.getLocalName().equals("sumDscr")) {
for (FieldDTO time : timePeriod) {
getCitation(dvDTO).addField( time);
}
for (FieldDTO date : dateOfCollection) {
getCitation(dvDTO).addField(date);
}
if (geoUnit.size() > 0) {
getGeospatial(dvDTO).addField(FieldDTO.createMultiplePrimitiveFieldDTO("geographicUnit", geoUnit));
}
if (unitOfAnalysis.size() > 0) {
getSocialScience(dvDTO).addField(FieldDTO.createMultiplePrimitiveFieldDTO("unitOfAnalysis", unitOfAnalysis));
}
if (universe.size() > 0) {
getSocialScience(dvDTO).addField(FieldDTO.createMultiplePrimitiveFieldDTO("universe", universe));
}
if (kindOfData.size() > 0) {
getCitation(dvDTO).addField(FieldDTO.createMultiplePrimitiveFieldDTO("kindOfData", kindOfData));
}
if (otherGeographicCoverage != null && !otherGeographicCoverage.equals("") ) {
geoCoverageSet.add(FieldDTO.createPrimitiveFieldDTO("otherGeographicCoverage", otherGeographicCoverage));
}
if (geoCoverageSet != null && geoCoverageSet.size() > 0) {
geoCoverages.add(geoCoverageSet);
}
if (geoCoverages.size() > 0) {
getGeospatial(dvDTO).addField(FieldDTO.createMultipleCompoundFieldDTO(DatasetFieldConstant.geographicCoverage, geoCoverages));
}
if (geoBoundBox.size()>0) {
getGeospatial(dvDTO).addField(FieldDTO.createMultipleCompoundFieldDTO("geographicBoundingBox", geoBoundBox));
}
return ;
}
}
}
}
private HashSet<FieldDTO> processGeoBndBox(XMLStreamReader xmlr) throws XMLStreamException {
HashSet<FieldDTO> set = new HashSet<>();
for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
if (event == XMLStreamConstants.START_ELEMENT) {
if (xmlr.getLocalName().equals("westBL")) {
addToSet(set,"westLongitude", parseText(xmlr));
} else if (xmlr.getLocalName().equals("eastBL")) {
addToSet(set,"eastLongitude", parseText(xmlr));
} else if (xmlr.getLocalName().equals("southBL")) {
addToSet(set,"southLongitude", parseText(xmlr));
} else if (xmlr.getLocalName().equals("northBL")) {
addToSet(set,"northLongitude", parseText(xmlr));
}
} else if (event == XMLStreamConstants.END_ELEMENT) {
if (xmlr.getLocalName().equals("geoBndBox")) break;
}
}
return set;
}
private void processMethod(XMLStreamReader xmlr, DatasetVersionDTO dvDTO ) throws XMLStreamException, ImportException {
for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
if (event == XMLStreamConstants.START_ELEMENT) {
if (xmlr.getLocalName().equals("dataColl")) {
processDataColl(xmlr, dvDTO);
} else if (xmlr.getLocalName().equals("notes")) {
String noteType = xmlr.getAttributeValue(null, "type");
if (NOTE_TYPE_EXTENDED_METADATA.equalsIgnoreCase(noteType) ) {
processCustomField(xmlr, dvDTO);
} else {
processNotesSocialScience(xmlr, dvDTO);
}
} else if (xmlr.getLocalName().equals("anlyInfo")) {
processAnlyInfo(xmlr, getSocialScience(dvDTO));
}
} else if (event == XMLStreamConstants.END_ELEMENT) {
if (xmlr.getLocalName().equals("method")) return;
}
}
}
private void processCustomField(XMLStreamReader xmlr, DatasetVersionDTO dvDTO) throws XMLStreamException, ImportException {
String subject = xmlr.getAttributeValue(null, "subject");
if (!subject.isEmpty()) {
// Syntax of subject attribute:
// TEMPLATE:Contains Custom Fields;FIELD:Customfield1
// first parse by semicolon
String template = subject.substring(subject.indexOf(":") + 1, subject.indexOf(";"));
String sourceField = subject.substring(subject.lastIndexOf(":") + 1);
String fieldValue = parseText(xmlr);
CustomFieldMap map = customFieldService.findByTemplateField(template.trim(), sourceField.trim());
if (map == null) {
throw new ImportException("Did not find mapping for template: "+template+", sourceField: "+sourceField);
}
if (map.getTargetDatasetField().endsWith("#IGNORE")) {
// if the target field is #IGNORE, that means we don't want to
// copy this field from 3.6 to 4.0
return;
}
// 1. Get datasetFieldType for the targetField
// 2. find the metadatablock for this field type
// 3. If this metadatablock doesn't exist in DTO, create it
// 4. add field to mdatadatablock
DatasetFieldType dsfType = datasetFieldService.findByName(map.getTargetDatasetField());
if (dsfType == null) {
throw new ImportException("Did not find datasetField for target: " + map.getTargetDatasetField());
}
String metadataBlockName = dsfType.getMetadataBlock().getName();
MetadataBlockDTO customBlock = dvDTO.getMetadataBlocks().get(metadataBlockName);
if (customBlock == null) {
customBlock = new MetadataBlockDTO();
customBlock.setDisplayName(metadataBlockName);
dvDTO.getMetadataBlocks().put(metadataBlockName, customBlock);
}
if (dsfType.isChild()) {
handleChildField(customBlock, dsfType, fieldValue);
} else {
if (dsfType.isAllowMultiples()) {
List<String> valList = new ArrayList<>();
valList.add(fieldValue);
if (dsfType.isAllowControlledVocabulary()) {
customBlock.addField(FieldDTO.createMultipleVocabFieldDTO(dsfType.getName(), valList));
} else if (dsfType.isPrimitive()) {
customBlock.addField(FieldDTO.createMultiplePrimitiveFieldDTO(dsfType.getName(), valList));
} else {
throw new ImportException("Unsupported custom field type: " + dsfType);
}
} else {
if (dsfType.isAllowControlledVocabulary()) {
customBlock.addField(FieldDTO.createVocabFieldDTO(dsfType.getName(), fieldValue));
} else if (dsfType.isPrimitive()) {
customBlock.addField(FieldDTO.createPrimitiveFieldDTO(dsfType.getName(), fieldValue));
} else {
throw new ImportException("Unsupported custom field type: " + dsfType);
}
}
}
}
}
private void handleChildField(MetadataBlockDTO customBlock, DatasetFieldType dsfType, String fieldValue) throws ImportException {
DatasetFieldType parent = dsfType.getParentDatasetFieldType();
// Create child Field
FieldDTO child = null;
if (dsfType.isAllowControlledVocabulary()) {
child = FieldDTO.createVocabFieldDTO(dsfType.getName(), fieldValue);
} else if (dsfType.isPrimitive()) {
child = FieldDTO.createPrimitiveFieldDTO(dsfType.getName(), fieldValue);
} else {
throw new ImportException("Unsupported custom child field type: " + dsfType);
}
// Create compound field with this child as its only element
FieldDTO compound = null;
if (parent.isAllowMultiples()) {
compound = FieldDTO.createMultipleCompoundFieldDTO(parent.getName(), child);
} else {
compound = FieldDTO.createCompoundFieldDTO(parent.getName(), child);
}
customBlock.addField(compound);
}
private void processSources(XMLStreamReader xmlr, MetadataBlockDTO citation) throws XMLStreamException {
for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
if (event == XMLStreamConstants.START_ELEMENT) {
// citation dataSources
String parsedText;
if (xmlr.getLocalName().equals("dataSrc")) {
parsedText = parseText( xmlr, "dataSrc" );
if (!parsedText.isEmpty()) {
citation.addField(FieldDTO.createMultiplePrimitiveFieldDTO("dataSources", Arrays.asList(parsedText)));
}
// citation originOfSources
} else if (xmlr.getLocalName().equals("srcOrig")) {
parsedText = parseText( xmlr, "srcOrig" );
if (!parsedText.isEmpty()) {
citation.getFields().add(FieldDTO.createPrimitiveFieldDTO("originOfSources", parsedText));
}
// citation characteristicOfSources
} else if (xmlr.getLocalName().equals("srcChar")) {
parsedText = parseText( xmlr, "srcChar" );
if (!parsedText.isEmpty()) {
citation.getFields().add(FieldDTO.createPrimitiveFieldDTO("characteristicOfSources", parsedText));
}
// citation accessToSources
} else if (xmlr.getLocalName().equals("srcDocu")) {
parsedText = parseText( xmlr, "srcDocu" );
if (!parsedText.isEmpty()) {
citation.getFields().add(FieldDTO.createPrimitiveFieldDTO("accessToSources", parsedText));
}
}
} else if (event == XMLStreamConstants.END_ELEMENT) {
if (xmlr.getLocalName().equals("sources")) return;
}
}
}
private void processAnlyInfo(XMLStreamReader xmlr, MetadataBlockDTO socialScience) throws XMLStreamException {
for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
if (event == XMLStreamConstants.START_ELEMENT) {
// socialscience responseRate
if (xmlr.getLocalName().equals("respRate")) {
socialScience.getFields().add(FieldDTO.createPrimitiveFieldDTO("responseRate", parseText( xmlr, "respRate" )));
// socialscience samplingErrorEstimates
} else if (xmlr.getLocalName().equals("EstSmpErr")) {
socialScience.getFields().add(FieldDTO.createPrimitiveFieldDTO("samplingErrorEstimates", parseText( xmlr, "EstSmpErr" )));
// socialscience otherDataAppraisal
} else if (xmlr.getLocalName().equals("dataAppr")) {
socialScience.getFields().add(FieldDTO.createPrimitiveFieldDTO("otherDataAppraisal", parseText( xmlr, "dataAppr" )));
}
} else if (event == XMLStreamConstants.END_ELEMENT) {
if (xmlr.getLocalName().equals("anlyInfo")) return;
}
}
}
private void processDataColl(XMLStreamReader xmlr, DatasetVersionDTO dvDTO) throws XMLStreamException {
MetadataBlockDTO socialScience =getSocialScience(dvDTO);
String collMode = "";
String timeMeth = "";
String weight = "";