Project

General

Profile

« Previous | Next » 

Revision a4947270

Added by Andreas Müller over 7 years ago

ref #3658 remove nomenclaturalCode

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/app/wp6/palmae/UseImport.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
*/
......
91 91
		ICdmDataSource destination;
92 92
		if (dbType.equals(DatabaseTypeEnum.MySQL)) {
93 93
			destination = CdmDataSource.NewMySqlInstance(cdmServer, cdmDB,
94
					port, cdmUserName, pwd, null);
94
					port, cdmUserName, pwd);
95 95
		} else if (dbType.equals(DatabaseTypeEnum.PostgreSQL)) {
96 96
			destination = CdmDataSource.NewPostgreSQLInstance(cdmServer, cdmDB,
97
					port, cdmUserName, pwd, null);
97
					port, cdmUserName, pwd);
98 98
		} else {
99 99
			// TODO others
100 100
			throw new RuntimeException("Unsupported DatabaseType");
......
104 104

  
105 105
	public boolean importFromExcelSS(String xlsPath) throws InvalidFormatException {
106 106
		boolean success = true;
107
		
107

  
108 108
		CdmApplicationController applicationController = CdmApplicationController.NewInstance(dataSource());
109 109
		ConversationHolder conversation = applicationController.NewConversation();
110 110
		conversation.startTransaction();
111
		
111

  
112 112
		ITaxonService service = applicationController.getTaxonService();
113 113
		ITermService termService = applicationController.getTermService();
114 114
		IDescriptionService descService = applicationController.getDescriptionService();
115 115
		IReferenceService referenceService = applicationController.getReferenceService();
116 116
		InputStream inputStream = null;
117
		
117

  
118 118
		try {
119 119
			inputStream = new FileInputStream(xlsPath);
120 120

  
......
125 125
		}
126 126

  
127 127
//		POIFSFileSystem fileSystem = null;
128
		
128

  
129 129
		try {
130 130
//			fileSystem = new POIFSFileSystem(inputStream);
131 131
//
132 132
//			HSSFWorkbook workBook = new HSSFWorkbook(fileSystem);
133 133
			Workbook workBook = WorkbookFactory.create(inputStream);
134 134

  
135
			
135

  
136 136
			Sheet sheet = workBook.getSheetAt(0);
137 137
			Iterator<Row> rows = sheet.rowIterator();
138 138
			// Iterator rows = sheet.rowIterator();
139 139
			ArrayList<ArrayList<String>> lstUpdates = new ArrayList<ArrayList<String>>();
140 140
			Set<Integer> lstTaxonIDs = new HashSet<Integer>();
141 141
			//Set<Integer> lstTaxonIDs;
142
		
142

  
143 143

  
144 144
			while (rows.hasNext()) {
145 145

  
......
526 526
			e.printStackTrace();
527 527
		}
528 528

  
529
	
529

  
530 530
		try {
531 531
//			POIFSFileSystem fileSystem = new POIFSFileSystem(inputStream);
532 532
//			HSSFWorkbook workBook = new HSSFWorkbook(fileSystem);
533 533

  
534 534
			Workbook workBook = WorkbookFactory.create(inputStream);
535 535

  
536
			
536

  
537 537
			Sheet sheet = workBook.getSheetAt(0);
538 538
			Iterator<Row> rows = sheet.rowIterator();
539 539

  
540 540
			ArrayList<ArrayList<String>> lstUpdates = new ArrayList<ArrayList<String>>();
541
		
541

  
542 542
			while (rows.hasNext()) {
543 543

  
544 544
				Row row = rows.next();
......
585 585
					vocabularyService.saveOrUpdate(stateVocabulary);
586 586
					conversation.commit(true);
587 587
					break;
588
				
588

  
589 589
				//case 1: = HumanGroup
590 590
				case 1:
591 591
					Pager<DefinedTerm> humanGroupPager = termService.findByRepresentationText(lstUpdate.get(1), DefinedTerm.class, null, null);
592
					
592

  
593 593
					DefinedTerm humanGroup = null;
594 594
					DefinedTerm ethnicGroup = null;
595 595
					if(humanGroupPager.getCount()>0) {
596 596
						humanGroup = humanGroupPager.getRecords().get(0);
597 597
					}
598
					
598

  
599 599
					if(humanGroup == null) {
600 600
						humanGroup = DefinedTerm.NewModifierInstance(lstUpdate.get(1), lstUpdate.get(1), null);
601 601
					}
602
					
602

  
603 603
					if(lstUpdate.size() >2) {
604 604
						ethnicGroup = DefinedTerm.NewModifierInstance(lstUpdate.get(2), lstUpdate.get(2), null);
605 605
						humanGroup.addIncludes(ethnicGroup);
......
608 608
					vocabularyService.saveOrUpdate(humanGroupVocabulary);
609 609
					conversation.commit(true);
610 610
					break;
611
				
611

  
612 612
				//case 2: = Country
613 613
				case 2:
614 614
					Pager<DefinedTerm> countryPager = termService.findByRepresentationText(lstUpdate.get(1), DefinedTerm.class, null, null);
615 615
					DefinedTermBase country = null;
616
					
616

  
617 617
					if(countryPager.getCount()>0) {
618 618
						country = countryPager.getRecords().get(0);
619 619
					}
620
					
620

  
621 621
					if(country == null) {
622 622
						country = NamedArea.NewInstance(lstUpdate.get(1), lstUpdate.get(1), null);
623 623
						countryVocabulary.addTerm(country);
......
625 625
					}
626 626
					conversation.commit(true);
627 627
					break;
628
				
628

  
629 629
				//case 3: //plantPart
630 630
				case 3:
631 631
					Pager<DefinedTerm> plantPartPager = termService.findByRepresentationText(lstUpdate.get(1), DefinedTerm.class, null, null);
632 632
					DefinedTerm plantPart = null;
633
					
633

  
634 634
					if(plantPartPager.getCount()>0) {
635 635
						plantPart = plantPartPager.getRecords().get(0);
636 636
					}
637
					
637

  
638 638
					if(plantPart == null) {
639 639
						plantPart = DefinedTerm.NewModifierInstance(lstUpdate.get(1), lstUpdate.get(1), null);
640 640
						plantPartVocabulary.addTerm(plantPart);
......
667 667
			System.out.println("File not found in the specified path.");
668 668
			e.printStackTrace();
669 669
		}
670
		
670

  
671 671
		try {
672 672
//			POIFSFileSystem fileSystem = new POIFSFileSystem(inputStream);
673 673
//			HSSFWorkbook workBook = new HSSFWorkbook(fileSystem);
674
			
674

  
675 675
			Workbook workBook = WorkbookFactory.create(inputStream);
676 676

  
677
			
677

  
678 678
			Sheet sheet = workBook.getSheetAt(0);
679 679
			Iterator<Row> rows = sheet.rowIterator();
680 680
			// Iterator rows = sheet.rowIterator();
681 681
			//Set<Integer> lstTaxonIDs;
682
		
682

  
683 683

  
684 684
			while (rows.hasNext()) {
685 685

  
......
763 763
			}
764 764
			countryVocabulary = TermVocabulary.NewInstance(TermType.NamedArea, "Country", "Country", null, termSourceUri);
765 765
			countryVocabulary.setUuid(UUID.fromString("116c51f1-e63a-46f7-a258-e1149a42868b"));
766
			
766

  
767 767
			vocabularyService.saveOrUpdate(countryVocabulary);
768 768
			conversation.commit(true);
769 769
		}
......
815 815
				FeatureNode useSumFeatureNode = FeatureNode.NewInstance(featureUseSummary);
816 816
				palmWebFeatureTree.getRoot().addChild(useSumFeatureNode);
817 817
			}
818
			
818

  
819 819
			vocabularyService.saveOrUpdate(featureVocabulary);
820 820
			featureTreeService.saveOrUpdate(palmWebFeatureTree);
821 821
			conversation.commit(true);
822
			
822

  
823 823
		}
824 824
		if(notAvailModPager.getCount() == 0) {
825 825
			DefinedTerm notAvailMod = DefinedTerm.NewInstance(TermType.Modifier, "N/A", "N/A", null);
826 826
			termService.saveOrUpdate(notAvailMod);
827 827
			conversation.commit(true);
828 828
		}
829
		
829

  
830 830
		if(notAvailStatePager.getCount() == 0) {
831 831
			State notAvailState = State.NewInstance("N/A", "N/A", null);
832 832
			termService.saveOrUpdate(notAvailState);
......
845 845
			vocabularyService.saveOrUpdate(featureVocabulary);
846 846
			featureTreeService.saveOrUpdate(palmWebFeatureTree);
847 847
			conversation.commit(true);
848
			
848

  
849 849
		}
850 850
		if(featureUseSummary == null) {
851 851
			featureUseSummary = Feature.NewInstance("Use Summary", "Use Summary", null);
......
861 861
			featureTreeService.saveOrUpdate(palmWebFeatureTree);
862 862
			conversation.commit(true);
863 863
		}*/
864
		
864

  
865 865
		conversation.close();
866 866
		applicationController.close();
867
		
867

  
868 868
		return success;
869 869
	}
870 870

  
......
872 872
		UseImport uiImport = new UseImport();
873 873
		// String xlsPath = ".//toload.xlsx";
874 874
		//String xlsPath = "C://workspace//CDM Trunk//UseImport//src//main//java//eu//etaxonomy//cdm//toLoad2.xls";
875
		
875

  
876 876
		uiImport.setupNecessaryItems();
877 877
		try {
878 878
			uiImport.loadTerms();

Also available in: Unified diff