Project

General

Profile

« Previous | Next » 

Revision 531fc7bc

Added by Andreas Müller almost 8 years ago

Remove generics from Reference in cdmlib (except for cdmlib-model) #5830

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/sdd/in/SDDDataSetImport.java
1 1
/**
2 2
 * Copyright (C) 2007 EDIT
3
 * European Distributed Institute of Taxonomy 
3
 * European Distributed Institute of Taxonomy
4 4
 * http://www.e-taxonomy.eu
5
 * 
5
 *
6 6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
 * See LICENSE.TXT at the top of this package for the full license terms.
8 8
 */
......
90 90

  
91 91
/**
92 92
 * This class is not used yet. It is meant for refactoring the SDD import.
93
 * 
93
 *
94 94
 * @author a.mueller
95 95
 * @created 06.01.2011
96 96
 * @version 1.0
......
119 119
	private Map<String,NamedArea> namedAreas = new HashMap<String,NamedArea>();
120 120
	private Map<String,DerivedUnit> specimens = new HashMap<String,DerivedUnit>();
121 121
	private Map<String,DefinedTerm> modifiers = new HashMap<String,DefinedTerm>();
122
	
122

  
123 123
	private Set<MarkerType> markerTypes = new HashSet<MarkerType>();
124 124
	private Set<TermVocabulary> vocabularies = new HashSet<TermVocabulary>();
125 125

  
......
137 137

  
138 138
	private String generatorName = "";
139 139
	private String generatorVersion = "";
140
	
140

  
141 141

  
142 142
	private Set<StatisticalMeasure> statisticalMeasures = new HashSet<StatisticalMeasure>();
143 143
	private Set<VersionableEntity> featureData = new HashSet<VersionableEntity>();
......
149 149
	private int taxonNamesCount = 0;
150 150

  
151 151
	protected Class<ICdmIO>[] ioClassList;
152
	
152

  
153 153
	public SDDDataSetImport(){
154 154
		super();
155 155
	}
......
159 159
				SDDImport.class
160 160
		};
161 161
	};
162
	
162

  
163 163
	@Override
164 164
	public boolean doCheck(SDDImportState state){
165 165
		boolean result = true;
......
172 172
	//	public boolean doInvoke(IImportConfigurator config, Map<String, MapWrapper<? extends CdmBase>> stores){
173 173
	@Override
174 174
	public void doInvoke(SDDImportState state){
175
		
175

  
176 176
		TransactionStatus ts = startTransaction();
177 177
		SDDImportConfigurator sddConfig = state.getConfig();
178 178
		IProgressMonitor progressMonitor = sddConfig.getProgressMonitor();
179
				
179

  
180 180
		logger.info("start Datasets ...");
181
		
181

  
182 182
		// <Datasets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://rs.tdwg.org/UBIF/2006/" xsi:schemaLocation="http://rs.tdwg.org/UBIF/2006/ ../SDD.xsd">
183 183
		Element root = sddConfig.getSourceRoot();
184 184
		Namespace sddNamespace = sddConfig.getSddNamespace();
......
193 193
		logger.info("start Dataset ...");
194 194
		progressMonitor.beginTask("Importing SDD data", elDatasets.size());
195 195
		for (Element elDataset : elDatasets){
196
			importDataset(elDataset, sddNamespace, state);			
196
			importDataset(elDataset, sddNamespace, state);
197 197
//			if ((++i % modCount) == 0){ logger.info("dataset(s) handled: " + i);}
198 198
//			logger.info(i + " dataset(s) handled");
199 199
			progressMonitor.worked(1);
......
207 207
	/* (non-Javadoc)
208 208
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
209 209
	 */
210
	protected boolean isIgnore(SDDImportState state){
210
	@Override
211
    protected boolean isIgnore(SDDImportState state){
211 212
		return false;
212 213
	}
213 214

  
......
238 239
	       </Representation>
239 240
		 */
240 241

  
241
		
242
		
242

  
243

  
243 244
		Element elRepresentation = parent.getChild("Representation",sddNamespace);
244 245
		String label = (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace);
245 246
		String detail = (String)ImportHelper.getXmlInputValue(elRepresentation, "Detail",sddNamespace);
246
		
247

  
247 248
		//new
248 249
		Representation representation = Representation.NewInstance(detail, label, null, datasetLanguage);
249 250
		workingSet.addRepresentation(representation);
250
		
251

  
251 252

  
252 253
		//old
253 254
//		sec.setTitleCache(label, true);
......
257 258
//			annotation.setAnnotationType(AnnotationType.EDITORIAL());
258 259
//			sec.addAnnotation(annotation);
259 260
//		}
260
		
261

  
261 262

  
262 263
		List<Element> listMediaObjects = elRepresentation.getChildren("MediaObject",sddNamespace);
263 264

  
......
281 282
	// imports the representation (label, detail, lang) of a particular SDD element
282 283
	protected void importRepresentation(Element parent, Namespace sddNamespace, VersionableEntity ve, String id, SDDImportState state){
283 284
		Element elRepresentation = parent.getChild("Representation",sddNamespace);
284
		
285

  
285 286
		Map<Language,List<String>> langLabDet = new HashMap<Language,List<String>>();
286 287

  
287 288
		handleRepresentationLabels(sddNamespace, elRepresentation, langLabDet);
......
342 343
			langLabDet.put(language, labDet);
343 344
		}
344 345
	}
345
	
346

  
346 347
	/**
347
	 * 
348
	 *
348 349
	 * @param media
349 350
	 * @param langLabDet
350 351
	 */
......
362 363

  
363 364
	/**
364 365
	 * Handles representations for terms. Adds one representation per language in langLabDet.
365
	 * 
366
	 *
366 367
	 * @param ve
367 368
	 * @param langLabDet
368 369
	 */
......
402 403
					if (td.getSources().size() > 0) {
403 404
						this.associateImageWithCdmBase(ref, td.getSources().iterator().next().getCitation());
404 405
					} else {
405
						Reference<?> descriptionSource = ReferenceFactory.newGeneric();
406
						Reference descriptionSource = ReferenceFactory.newGeneric();
406 407
						sources.add(descriptionSource);
407 408
						//TODO type
408 409
						td.addSource(OriginalSourceType.Unknown, null, null, descriptionSource, null);
......
462 463
	 * @param langLabDet
463 464
	 * @return
464 465
	 */
465
	private void makeRepresentationForIdentifiableEntity(Namespace sddNamespace, IdentifiableEntity<?> ie, 
466
	private void makeRepresentationForIdentifiableEntity(Namespace sddNamespace, IdentifiableEntity<?> ie,
466 467
					Element elRepresentation, Map<Language, List<String>> langLabDet) {
467 468
		List<String> labDet = null;
468 469

  
......
511 512
		}
512 513
		return language;
513 514
	}
514
	
515

  
515 516

  
516 517
	// imports the representation (label, detail, lang) of a particular SDD element
517 518
	protected void importTechnicalMetadata(Element root, Namespace sddNamespace, SDDImportConfigurator sddConfig){
......
557 558
		importDescriptiveConcepts(elDataset, sddNamespace, state);
558 559
		importCharacters(elDataset, sddNamespace, state);
559 560
		importCharacterTrees(elDataset, sddNamespace, state);
560
		
561

  
561 562
		MarkerType editorMarkerType = getMarkerType(state, SDDTransformer.uuidMarkerEditor, "editor", "Editor", "edt");
562
		MarkerType geographicAreaMarkerType = getMarkerType(state, SDDTransformer.uuidMarkerSDDGeographicArea, "SDDGeographicArea", "SDDGeographicArea", "ga"); 
563
		MarkerType geographicAreaMarkerType = getMarkerType(state, SDDTransformer.uuidMarkerSDDGeographicArea, "SDDGeographicArea", "SDDGeographicArea", "ga");
563 564
		MarkerType descriptiveConceptMarkerType = getMarkerType(state, SDDTransformer.uuidMarkerDescriptiveConcept, "DescriptiveConcept", "Descriptive Concept", "DC");
564 565
		markerTypes.add(editorMarkerType);
565 566
		markerTypes.add(geographicAreaMarkerType);
566 567
		markerTypes.add(descriptiveConceptMarkerType);
567
		
568

  
568 569
		//saving of all imported data into the CDM db
569 570
		saveVocabularies();
570 571
		saveFeatures();
571 572
		saveModifiers();
572 573
		saveStates();
573 574
		saveMarkerType();
574
		saveAreas(geographicAreaMarkerType);		
575
		saveAreas(geographicAreaMarkerType);
575 576
		saveUnits();
576
		saveStatisticalMeasure();		
577
		saveStatisticalMeasure();
577 578
		saveAnnotationType();
578 579

  
579 580
		importCodedDescriptions(elDataset, sddNamespace, state);
......
583 584
		importTaxonHierarchies(elDataset, sddNamespace, state);
584 585
		importGeographicAreas(elDataset, sddNamespace, state);
585 586
		importSpecimens(elDataset,sddNamespace, state);
586
		
587
		
587

  
588

  
588 589
		if ((authors != null)||(editors != null)) {
589 590
			Team team = Team.NewInstance();
590 591
			if (authors != null) {
......
609 610
			sourceReference.addRights(copyright);
610 611
			sec.addRights(copyright);
611 612
		}
612
		
613

  
613 614
		// Returns a CdmApplicationController created by the values of this configuration.
614 615
		IDescriptionService descriptionService = getDescriptionService();
615
		
616

  
616 617
		for (TaxonDescription taxonDescription : taxonDescriptions.values()){
617 618
			// Persists a Description
618 619
			descriptionService.save(taxonDescription);
619 620
		}
620
		
621

  
621 622
		for (String ref : taxonDescriptions.keySet()){
622 623
			TaxonDescription td = taxonDescriptions.get(ref);
623 624
			if (citations.containsKey(ref)) {
624
				Reference<?> publication = publications.get(citations.get(ref));
625
				Reference publication = publications.get(citations.get(ref));
625 626
				if (locations.containsKey(ref)) {
626 627
					Annotation location = Annotation.NewInstance(locations.get(ref), datasetLanguage);
627 628
					AnnotationType annotationType = AnnotationType.NewInstance("", "location", "");
......
643 644
			}
644 645
		}
645 646
		saveFeatures();
646
		
647

  
647 648
		for (Reference publication : publications.values()){
648
			getReferenceService().save(publication); 
649
			getReferenceService().save(publication);
649 650
		}
650
		
651

  
651 652
		for (Reference source : sources){
652
			getReferenceService().save(source); 
653
			getReferenceService().save(source);
653 654
		}
654 655

  
655 656
		for (FeatureTree featureTree : featureTrees) {
......
663 664
			getOccurrenceService().save(specimen);
664 665
		}
665 666
		logger.info("end of persistence ...");
666
		
667

  
667 668
		return;
668 669
	}
669 670

  
670 671
	/**
671
	 * 
672
	 *
672 673
	 */
673 674
	private void saveVocabularies() {
674 675
		for (TermVocabulary vocabulary : vocabularies ){
675 676
			getVocabularyService().save(vocabulary);
676 677
		}
677
		
678

  
678 679
	}
679 680

  
680 681
	private void saveAnnotationType() {
681 682
		for (AnnotationType annotationType: annotationTypes){
682
			getTermService().save(annotationType); 
683
			getTermService().save(annotationType);
683 684
		}
684 685
	}
685 686

  
686 687
	private void saveStatisticalMeasure() {
687 688
		for (StatisticalMeasure sm : statisticalMeasures){
688
			getTermService().save(sm); 
689
			getTermService().save(sm);
689 690
		}
690 691
	}
691 692

  
......
693 694
		if (units != null) {
694 695
			for (MeasurementUnit unit : units.values()){
695 696
				if (unit != null) {
696
					getTermService().save(unit); 
697
					getTermService().save(unit);
697 698
				}
698 699
			}
699 700
		}
......
746 747
			datasetLanguage = Language.DEFAULT();
747 748
		}
748 749
	}
749
	
750

  
750 751
	// imports the specimens
751 752
	protected void importSpecimens(Element elDataset, Namespace sddNamespace, SDDImportState cdmState) {
752 753
		logger.info("start Specimens ...");
......
933 934
		/*for (Iterator<Feature> f = features.values().iterator() ; f.hasNext() ;){
934 935
			featureSet.add(f.next()); //XIM Why this line ?
935 936
		}*/
936
		
937

  
937 938
		return;
938 939

  
939 940
	}
......
962 963
				// <StateDefinition id="s1">
963 964
				List<Element> elStateDefinitions = elStates.getChildren("StateDefinition",sddNamespace);
964 965
				TermVocabulary<State> termVocabularyState = TermVocabulary.NewInstance(TermType.State, null, null, null, null);
965
				
966

  
966 967
				vocabularies.add(termVocabularyState);
967
				
968

  
968 969
				int k = 0;
969 970
				//for each StateDefinition
970 971
				for (Element elStateDefinition : elStateDefinitions){
......
1112 1113

  
1113 1114
	// imports the descriptions of taxa
1114 1115
	protected void importCodedDescriptions(Element elDataset, Namespace sddNamespace, SDDImportState cdmState){
1115
		
1116

  
1116 1117
		// <CodedDescriptions>
1117 1118
		logger.info("start CodedDescriptions ...");
1118 1119
		Element elCodedDescriptions = elDataset.getChild("CodedDescriptions",sddNamespace);
1119
		
1120

  
1120 1121
		// <CodedDescription id="D101">
1121 1122
		if (elCodedDescriptions != null) {
1122 1123
			List<Element> listCodedDescriptions = elCodedDescriptions.getChildren("CodedDescription", sddNamespace);
......
1175 1176
			if (taxon != null) {
1176 1177
				taxon.addDescription(taxonDescription);
1177 1178
			}
1178
//			
1179
//
1179 1180
			workingSet.addDescription(taxonDescription);
1180
			
1181

  
1181 1182
//OLD			taxonDescription.setDescriptiveSystem(featureSet);
1182 1183

  
1183 1184
			taxonDescriptions.put(idCD, taxonDescription);//FIXME
......
1204 1205
		String id = new String("" + taxonNamesCount);
1205 1206
		IdentifiableSource source = IdentifiableSource.NewDataImportInstance( id, "TaxonName");
1206 1207
		importRepresentation(elCodedDescription, sddNamespace, nonViralName, id, cdmState);
1207
		
1208

  
1208 1209
		if(cdmState.getConfig().isReuseExistingTaxaWhenPossible()){
1209 1210
			taxon = getTaxonService().findBestMatchingTaxon(nonViralName.getTitleCache());
1210 1211
		}
1211
		
1212

  
1212 1213
		if(taxon != null){
1213 1214
			nonViralName = HibernateProxyHelper.deproxy(taxon.getName(), NonViralName.class);
1214 1215
//							taxonNameBases.put(id ,tnb);
......
1217 1218
		} else {
1218 1219
			nonViralName.addSource(source);
1219 1220
			taxonNameBases.put(id ,nonViralName);
1220
			taxonNamesCount++;						
1221
			taxonNamesCount++;
1221 1222
			logger.info("creating new Taxon from TaxonName " + nonViralName.getTitleCache());
1222 1223
			taxon = Taxon.NewInstance(nonViralName, sec);
1223 1224
		}
......
1232 1233
	 * @param taxon
1233 1234
	 * @return
1234 1235
	 */
1235
	private Taxon handleCDScope(Namespace sddNamespace, SDDImportState cdmState, 
1236
	private Taxon handleCDScope(Namespace sddNamespace, SDDImportState cdmState,
1236 1237
			String idCD, Element elScope) {
1237 1238
		Taxon taxon = null;
1238 1239
		Element elTaxonName = elScope.getChild("TaxonName", sddNamespace);
1239 1240
		String ref = elTaxonName.getAttributeValue("ref");
1240 1241
		NonViralName nonViralName = taxonNameBases.get(ref);
1241
		
1242

  
1242 1243
		if(cdmState.getConfig().isReuseExistingTaxaWhenPossible()){
1243 1244
			taxon = getTaxonService().findBestMatchingTaxon(nonViralName.getTitleCache());
1244 1245
		}
1245
		
1246

  
1246 1247
		if(taxon != null){
1247 1248
			logger.info("using existing Taxon" + taxon.getTitleCache());
1248 1249
			if(!nonViralName.getUuid().equals(taxon.getName().getUuid())){
1249 1250
				logger.warn("TaxonNameBase entity of existing taxon does not match Name in list -> replacing Name in list");
1250 1251
				nonViralName = HibernateProxyHelper.deproxy(taxon.getName(), NonViralName.class);
1251
			}				
1252
		} else {							
1252
			}
1253
		} else {
1253 1254
			logger.info("creating new Taxon from TaxonName '" + nonViralName.getTitleCache()+"'");
1254 1255
			taxon = Taxon.NewInstance(nonViralName, sec);
1255 1256
		}
1256
		
1257

  
1257 1258
		//citation
1258 1259
		Element elCitation = elScope.getChild("Citation",sddNamespace);
1259 1260
		if (elCitation != null) {
......
1330 1331
			// <Measure type="Min" value="2.3"/>
1331 1332
			List<Element> elMeasures = elQuantitative.getChildren("Measure", sddNamespace);
1332 1333
			int l = 0;
1333
			
1334

  
1334 1335
			//for each State
1335 1336
			for (Element elMeasure : elMeasures){
1336 1337
				if ((++l % modCount) == 0){ logger.info("States handled: " + (l-1));}
......
1395 1396
			// <State ref="s3"/>
1396 1397
			List<Element> elStates = elCategorical.getChildren("State", sddNamespace);
1397 1398
			int l = 0;
1398
			
1399

  
1399 1400
			//for each State
1400 1401
			for (Element elState : elStates){
1401 1402
				if ((++l % modCount) == 0){ logger.info("States handled: " + (l-1));}
......
1468 1469
							} catch (Exception e) {
1469 1470
								//FIXME
1470 1471
								logger.warn("Import of Link " + k + " failed.");
1471
								success = false; 
1472
								success = false;
1472 1473
							}
1473 1474

  
1474 1475
							if ((++k % modCount) == 0){ logger.info("Links handled: " + k);}
......
1573 1574
						if (href.substring(0,7).equals("http://")) {
1574 1575
							try{
1575 1576
								URL url = new URL(href);
1576
								
1577

  
1577 1578
								imageMetaData = ImageInfo.NewInstance(url.toURI(), 0);
1578 1579
								image = ImageFile.NewInstance(url.toURI(), null, imageMetaData);
1579 1580
							} catch (MalformedURLException e) {
......
1736 1737
					}
1737 1738
					featureTrees.add(featureTree);
1738 1739
					if (workingSet.getDescriptiveSystem() != null){
1739
						//TODO how to handle multiple 
1740
						//TODO how to handle multiple
1740 1741
						logger.warn("Multiple feature trees not yet supported");
1741 1742
					}else{
1742 1743
						workingSet.setDescriptiveSystem(featureTree);
......
1807 1808
				Element elCharacter = elCharNode.getChild("Character", sddNamespace);
1808 1809
				Element elDependencyRules = elCharNode.getChild("DependencyRules", sddNamespace);
1809 1810
				FeatureNode fn = FeatureNode.NewInstance();
1810
				
1811

  
1811 1812
				if (elDependencyRules!=null){
1812 1813
					Element elInapplicableIf = elCharNode.getChild("InapplicableIf", sddNamespace);
1813 1814
					if (elInapplicableIf!=null){
......
1832 1833
						}
1833 1834
					}
1834 1835
				}
1835
				
1836

  
1836 1837
				if (elParent!=null){
1837 1838
					String refP = elParent.getAttributeValue("ref");
1838 1839
					if ((refP!=null)&&(!refP.equals(""))) {
......
1849 1850
					fn.setFeature(character);
1850 1851
					featureNodes.put(refC, fn);
1851 1852
				}
1852
			}		
1853
			}
1853 1854
		}
1854 1855
	}
1855 1856

  
......
1868 1869
					String label = (String)ImportHelper.getXmlInputValue(elRepresentation,"Label",sddNamespace);
1869 1870
						Classification classification =  Classification.NewInstance(label);
1870 1871
						importRepresentation(elTaxonHierarchy, sddNamespace, classification, "", cdmState);
1871
					
1872

  
1872 1873
						List<TaxonNode> root = classification.getChildNodes();
1873 1874
						Element elNodes = elTaxonHierarchy.getChild("Nodes", sddNamespace); // There can be only one <Nodes> block for TaxonHierarchies
1874 1875
						List<Element> listNodes = elNodes.getChildren("Node", sddNamespace);
1875
						
1876

  
1876 1877
						for (Element elNode : listNodes){
1877 1878
							String idN = elNode.getAttributeValue("id");
1878 1879
							TaxonNameBase tnb = null;
......
1914 1915

  
1915 1916
		}
1916 1917
	}
1917
	
1918
	
1919
	// imports the <GeographicAreas> block 
1918

  
1919

  
1920
	// imports the <GeographicAreas> block
1920 1921
	protected void importGeographicAreas(Element elDataset, Namespace sddNamespace, SDDImportState cdmState) {
1921 1922
		Element elGeographicAreas = elDataset.getChild("GeographicAreas",sddNamespace);
1922 1923
		if (elGeographicAreas != null) {
1923 1924
			List<Element> listGeographicAreas = elGeographicAreas.getChildren("GeographicArea", sddNamespace);
1924 1925
			int j = 0;
1925
						
1926

  
1926 1927
			for (Element elGeographicArea : listGeographicAreas){
1927 1928

  
1928 1929
				String id = elGeographicArea.getAttributeValue("id");

Also available in: Unified diff