Revision b3273569
Added by Andreas Müller about 4 years ago
cdm-pesi/src/main/java/eu/etaxonomy/cdm/app/pesi/merging/FaunaEuErmsMergeActivator.java | ||
---|---|---|
1 | 1 |
package eu.etaxonomy.cdm.app.pesi.merging; |
2 | 2 |
|
3 |
import java.io.BufferedReader; |
|
4 |
import java.io.File; |
|
5 |
import java.io.FileReader; |
|
6 |
import java.io.IOException; |
|
7 | 3 |
import java.util.ArrayList; |
8 | 4 |
import java.util.HashSet; |
9 | 5 |
import java.util.Iterator; |
10 | 6 |
import java.util.List; |
11 | 7 |
import java.util.Set; |
12 |
import java.util.StringTokenizer; |
|
13 | 8 |
import java.util.UUID; |
14 | 9 |
|
15 | 10 |
import org.apache.log4j.Logger; |
... | ... | |
39 | 34 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
40 | 35 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
41 | 36 |
|
42 |
public class FaunaEuErmsMergeActivator { |
|
37 |
public class FaunaEuErmsMergeActivator extends PesiMergeBase{
|
|
43 | 38 |
|
44 |
// static final ICdmDataSource faunaEuropaeaSource = CdmDestinations.cdm_test_patricia(); |
|
45 | 39 |
static final ICdmDataSource faunaEuropaeaSource = CdmDestinations.localH2(); |
46 | 40 |
|
47 | 41 |
static final int faunaEuUuid = 0; |
48 | 42 |
static final int ermsUuid = 9; |
49 | 43 |
static final int rankFaunaEu = 4; |
50 | 44 |
static final int rankErms = 13; |
51 |
Classification faunaEuClassification; |
|
52 |
Classification ermsClassification; |
|
45 |
private Classification faunaEuClassification;
|
|
46 |
private Classification ermsClassification;
|
|
53 | 47 |
|
54 |
CdmApplicationController appCtrInit; |
|
48 |
private CdmApplicationController appCtrInit;
|
|
55 | 49 |
|
56 | 50 |
private static final Logger logger = Logger.getLogger(FaunaEuErmsMergeActivator.class); |
57 | 51 |
|
... | ... | |
73 | 67 |
|
74 | 68 |
//set the ranks of Agnatha and Gnathostomata to 50 instead of 45 |
75 | 69 |
List<TaxonBase> taxaToChangeRank = new ArrayList<>(); |
70 |
|
|
76 | 71 |
Pager<TaxonBase> agnatha = sc.appCtrInit.getTaxonService().findTaxaByName(TaxonBase.class, "Agnatha", null, null, null, "*", Rank.INFRAPHYLUM(), 10, 0, null); |
77 | 72 |
List<TaxonBase> agnathaList = agnatha.getRecords(); |
78 | 73 |
taxaToChangeRank.addAll(agnathaList); |
74 |
|
|
79 | 75 |
Pager<TaxonBase> gnathostomata = sc.appCtrInit.getTaxonService().findTaxaByName(TaxonBase.class, "Gnathostomata", null, null, null, "*", Rank.INFRAPHYLUM(), 10, 0, null); |
80 | 76 |
List<TaxonBase> gnathostomataList = gnathostomata.getRecords(); |
81 | 77 |
taxaToChangeRank.addAll(gnathostomataList); |
82 | 78 |
|
83 | 79 |
sc.setSpecificRank(taxaToChangeRank, Rank.SUPERCLASS()); |
84 | 80 |
|
85 |
//ermsTaxon is accepted, fauna eu taxon is synonym
|
|
81 |
//ermsTaxon is accepted, faunaEu taxon is synonym
|
|
86 | 82 |
//ermsTaxon is synonym, faunaEu is accepted |
87 | 83 |
|
88 | 84 |
sc.mergeDiffStatus(); |
... | ... | |
93 | 89 |
|
94 | 90 |
} |
95 | 91 |
|
96 |
private static List<List<String>> readCsvFile(String fileName){ |
|
97 |
|
|
98 |
List<List<String>> result = new ArrayList<>(); |
|
99 |
File file = new File(fileName); |
|
100 |
BufferedReader bufRdr; |
|
101 |
try { |
|
102 |
bufRdr = new BufferedReader(new FileReader(file)); |
|
103 |
String line = null; |
|
104 |
//read each line of text file |
|
105 |
while((line = bufRdr.readLine()) != null){ |
|
106 |
StringTokenizer st = new StringTokenizer(line,","); |
|
107 |
List<String> rowList = new ArrayList<>(); |
|
108 |
while (st.hasMoreTokens()){ |
|
109 |
//get next token and store it in the array |
|
110 |
rowList.add(st.nextToken()); |
|
111 |
} |
|
112 |
result.add(rowList); |
|
113 |
} |
|
114 |
//close the file |
|
115 |
bufRdr.close(); |
|
116 |
} catch (IOException e) { |
|
117 |
e.printStackTrace(); |
|
118 |
} |
|
119 |
return result; |
|
120 |
} |
|
121 |
|
|
122 |
|
|
123 | 92 |
private void mergeAuthors(){ |
124 | 93 |
List<List<String>> authors = readCsvFile(sFileName + "_authors.csv"); |
125 | 94 |
//authors: get firstAuthor if isFauEu = 1 otherwise get secondAuthor |
126 | 95 |
|
127 | 96 |
Iterator<List<String>> authorIterator = authors.iterator(); |
128 |
List<String> row; |
|
129 |
TaxonBase<?> taxonFaunaEu; |
|
130 |
TaxonBase<?> taxonErms; |
|
131 |
List<TaxonBase<?>> taxaToSave = new ArrayList<>(); |
|
97 |
List<TaxonBase<?>> taxaToSave = new ArrayList<>(); //TODO: needed? |
|
132 | 98 |
while (authorIterator.hasNext()){ |
133 |
row = authorIterator.next();
|
|
99 |
List<String> row = authorIterator.next();
|
|
134 | 100 |
UUID uuidFaunaEu = UUID.fromString(row.get(faunaEuUuid)); |
135 | 101 |
UUID uuidErms = UUID.fromString(row.get(ermsUuid)); |
136 |
taxonFaunaEu = appCtrInit.getTaxonService().find(uuidFaunaEu); |
|
137 |
taxonErms = appCtrInit.getTaxonService().find(uuidErms); |
|
102 |
TaxonBase<?> taxonFaunaEu = appCtrInit.getTaxonService().find(uuidFaunaEu);
|
|
103 |
TaxonBase<?> taxonErms = appCtrInit.getTaxonService().find(uuidErms);
|
|
138 | 104 |
// which information should be used can be found in last row -> needs to be done manually |
139 | 105 |
if (Integer.parseInt(row.get(18)) == 1){ |
140 | 106 |
//isFaunaEu = 1 -> copy the author of Fauna Europaea to Erms |
... | ... | |
169 | 135 |
List<List<String>> diffStatus = readCsvFile(sFileName + "_status.csv"); |
170 | 136 |
|
171 | 137 |
//find all taxa accepted in erms, but synonyms in FauEu and the same rank |
172 |
List<List<String>> accErmsSynFaunaEu = new ArrayList<List<String>>();
|
|
138 |
List<List<String>> accErmsSynFaunaEu = new ArrayList<>(); |
|
173 | 139 |
for (List<String> rowList: diffStatus){ |
174 | 140 |
if ((rowList.get(5).equals("synonym")) && (rowList.get(rankFaunaEu).equals(rowList.get(rankErms)))){ |
175 | 141 |
//both conditions are true |
Also available in: Unified diff
ref #1447 implement PESI commandline merger