Revision 68fa46a4
Added by Andreas Müller over 4 years ago
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/erms/validation/PesiErmsValidator.java | ||
---|---|---|
15 | 15 |
|
16 | 16 |
import eu.etaxonomy.cdm.app.pesi.PesiDestinations; |
17 | 17 |
import eu.etaxonomy.cdm.app.pesi.PesiSources; |
18 |
import eu.etaxonomy.cdm.common.CdmUtils; |
|
18 | 19 |
import eu.etaxonomy.cdm.io.common.Source; |
19 | 20 |
|
20 | 21 |
/** |
... | ... | |
77 | 78 |
ResultSet srcRS = source.getResultSet("SELECT s.* FROM sources s ORDER BY s.id "); |
78 | 79 |
ResultSet destRS = destination.getResultSet("SELECT s.* FROM Source s " |
79 | 80 |
+ " WHERE s.OriginalDB = 'erms' ORDER BY s.RefIdInSource"); // +1 for the source reference "erms" but this has no OriginalDB |
80 |
if (srcRS.next() && destRS.next()){
|
|
81 |
while (srcRS.next() && destRS.next()){
|
|
81 | 82 |
success &= testSingleReference(srcRS, destRS); |
82 | 83 |
} |
83 | 84 |
return success; |
... | ... | |
86 | 87 |
private boolean testSingleReference(ResultSet srcRS, ResultSet destRS) throws SQLException { |
87 | 88 |
//id, RefIdInSource |
88 | 89 |
boolean success = equals("Reference ID ", srcRS.getInt("id"), destRS.getInt("RefIdInSource")); |
90 |
success &= equals("Reference Name ", srcRS.getString("source_name"), destRS.getString("Name")); |
|
89 | 91 |
|
90 | 92 |
//TODO TBC |
91 | 93 |
return success; |
... | ... | |
100 | 102 |
|
101 | 103 |
private boolean equals(String messageStart, int nSrc, int nDest) { |
102 | 104 |
if (nSrc != nDest){ |
103 |
String message = messageStart + " must be equal, but was not. Source: "+ nSrc + "; Destination: " + nDest; |
|
105 |
String message = messageStart + " must be equal, but was not.\n Source: "+ nSrc + "; Destination: " + nDest;
|
|
104 | 106 |
logger.warn(message); |
105 | 107 |
return false; |
106 | 108 |
}else{ |
... | ... | |
109 | 111 |
} |
110 | 112 |
} |
111 | 113 |
|
114 |
private boolean equals(String messageStart, String strSrc, String strDest) { |
|
115 |
if (!CdmUtils.nullSafeEqual(strSrc, strDest)){ |
|
116 |
int index = diffIndex(strSrc, strDest); |
|
117 |
String message = messageStart + " must be equal, but was not at "+index+".\n Source: "+ strSrc + "\n Destination: " + strDest; |
|
118 |
logger.warn(message); |
|
119 |
return false; |
|
120 |
}else{ |
|
121 |
logger.info(messageStart + " were equal: " + strSrc); |
|
122 |
return true; |
|
123 |
} |
|
124 |
} |
|
125 |
/** |
|
126 |
* @param strSrc |
|
127 |
* @param strDest |
|
128 |
* @return |
|
129 |
*/ |
|
130 |
private int diffIndex(String strSrc, String strDest) { |
|
131 |
int i; |
|
132 |
for (i = 0; i<strSrc.length() && i<strDest.length() ;i++) { |
|
133 |
if (strSrc.charAt(i)!= strDest.charAt(i)){ |
|
134 |
return i; |
|
135 |
} |
|
136 |
} |
|
137 |
if(strSrc.length()!=strDest.length()){ |
|
138 |
return Math.max(strSrc.length(), strDest.length()); |
|
139 |
} |
|
140 |
return i; |
|
141 |
} |
|
142 |
|
|
112 | 143 |
//** ************* MAIN ********************************************/ |
113 | 144 |
|
145 |
|
|
146 |
|
|
114 | 147 |
public static void main(String[] args){ |
115 | 148 |
PesiErmsValidator validator = new PesiErmsValidator(); |
116 | 149 |
validator.invoke(defaultSource, defaultDestination); |
Also available in: Unified diff
ref #8508 add single reference diff to ERMS pipeline validation