Revision 9637
Added by Jing Tao over 8 years ago
src/edu/ucsb/nceas/metacat/IdentifierManager.java | ||
---|---|---|
978 | 978 |
* If obsoletedBy is missing, we generally consider it a type 2 end except: |
979 | 979 |
* there is another object in the chain (has the same series id) that obsoletes the missing object. |
980 | 980 |
* 2. if only 1 candidate chain-end, return it as the HEAD |
981 |
* 3. otherwise return the one in the chain with the latest dateUploaded value. |
|
981 |
* 3. otherwise return the one in the chain with the latest dateUploaded value. However, we find that dateUpload doesn't refect the obsoletes information |
|
982 |
* (espically on the cn), so we will check osoletes information as well. https://redmine.dataone.org/issues/7624 |
|
982 | 983 |
* @param sid specified sid which should match. |
983 | 984 |
* @return the pid of the head version. The null will be returned if there is no pid found. |
984 | 985 |
* @throws SQLException |
... | ... | |
994 | 995 |
PreparedStatement stmt2 = null; |
995 | 996 |
ResultSet rs = null; |
996 | 997 |
ResultSet result = null; |
997 |
int endsCount = 0; |
|
998 |
//int endsCount = 0;
|
|
998 | 999 |
boolean hasError = false; |
999 | 1000 |
HashMap<String, String> obsoletesIdGuidMap = new HashMap<String, String>();//the key is an obsoletes id, the value is an guid |
1001 |
Vector<Identifier> endsList = new Vector<Identifier>();//the vector storing ends |
|
1000 | 1002 |
try { |
1001 | 1003 |
// Get a database connection from the pool |
1002 | 1004 |
dbConn = DBConnectionPool.getDBConnection("IdentifierManager.getHeadPID"); |
... | ... | |
1033 | 1035 |
if(obsoletedByStr == null || obsoletedByStr.trim().equals("")) { |
1034 | 1036 |
//type 1 end |
1035 | 1037 |
logMetacat.debug(""+guidStr+" is a type 1 end for sid "+sid.getValue()); |
1036 |
pid = guid; |
|
1037 |
endsCount++; |
|
1038 |
//pid = guid; |
|
1039 |
//endsCount++; |
|
1040 |
endsList.add(guid); |
|
1038 | 1041 |
} else { |
1039 | 1042 |
//Identifier obsoletedBy = sysmeta.getObsoletedBy(); |
1040 | 1043 |
Identifier obsoletedBy = new Identifier(); |
... | ... | |
1054 | 1057 |
// type 2 end |
1055 | 1058 |
logMetacat.debug(""+guidStr+" is a type 2 end for sid "+sid.getValue()+ "since it is obsoleted by the object "+sidInObsoletedBy+ |
1056 | 1059 |
" which has a different sid or no sids"); |
1057 |
pid = guid; |
|
1058 |
endsCount++; |
|
1060 |
//pid = guid; |
|
1061 |
//endsCount++; |
|
1062 |
endsList.add(guid); |
|
1059 | 1063 |
} |
1060 | 1064 |
} else { |
1061 | 1065 |
logMetacat.debug("The object "+obsoletedBy+" which obsoletes "+guidStr+" is missing on the host."); |
... | ... | |
1096 | 1100 |
//the exception (another object in the chain (has the same series id) that obsoletes the missing object) doesn't exist |
1097 | 1101 |
// it is a type 2 end |
1098 | 1102 |
logMetacat.debug(""+guidStr+" is a type 2 end for sid "+sid.getValue()); |
1099 |
pid = guid; |
|
1100 |
endsCount++; |
|
1103 |
//pid = guid; |
|
1104 |
//endsCount++; |
|
1105 |
endsList.add(guid); |
|
1101 | 1106 |
} |
1102 | 1107 |
} |
1103 | 1108 |
} |
1104 | 1109 |
hasNext = rs.next(); |
1105 | 1110 |
} |
1106 |
if(endsCount == 1) { |
|
1107 |
//it has one end and it is an ideal chain. We already assign the guid to the pid. So do nothing. |
|
1108 |
logMetacat.info("It is an ideal for sid "+sid.getValue()); |
|
1109 |
} |
|
1110 |
if(hasError || endsCount >1) { |
|
1111 |
// it is not an ideal chain, use the one with latest upload date(the first one in the result set since we have the desc order) |
|
1112 |
logMetacat.info("It is NOT an ideal for sid "+sid.getValue()); |
|
1111 |
if(hasError) { |
|
1112 |
logMetacat.info("The sid chain "+sid.getValue()+" was messed up and we will return the object with the latest upload date."); |
|
1113 | 1113 |
pid = firstOne; |
1114 |
} else { |
|
1115 |
if(endsList.size() == 1) { |
|
1116 |
//it has one end and it is an ideal chain. We already assign the guid to the pid. So do nothing. |
|
1117 |
logMetacat.info("It is an ideal chain for sid "+sid.getValue()); |
|
1118 |
pid = endsList.get(0); |
|
1119 |
} else if (endsList.size() ==0) { |
|
1120 |
logMetacat.info("This is weird situation and we don't find any end. We use the latest DateOfupload"); |
|
1121 |
pid=checkObsoletesChain(firstOne, obsoletesIdGuidMap); |
|
1122 |
} else if(endsList.size() >1) { |
|
1123 |
// it is not an ideal chain, use the one with latest upload date(the first one in the result set since we have the desc order) |
|
1124 |
logMetacat.info("It is NOT an ideal chain for sid "+sid.getValue()); |
|
1125 |
pid = checkObsoletesChain(endsList.get(0), obsoletesIdGuidMap); |
|
1126 |
} |
|
1114 | 1127 |
} |
1128 |
|
|
1115 | 1129 |
} else { |
1116 | 1130 |
//it is not a sid or at least we don't have anything to match it. |
1117 | 1131 |
//do nothing, so null will be returned |
1132 |
logMetacat.info("We don't find anything matching the id "+sid.getValue()+" as sid. The null will be returned since it is probably a pid"); |
|
1118 | 1133 |
} |
1119 | 1134 |
|
1120 | 1135 |
|
... | ... | |
1144 | 1159 |
} |
1145 | 1160 |
} |
1146 | 1161 |
} |
1162 |
if(pid != null && sid != null) { |
|
1163 |
logMetacat.info("The head of chain for sid "+sid.getValue()+" --is-- "+pid.getValue()); |
|
1164 |
} else if(pid == null && sid != null) { |
|
1165 |
logMetacat.info("The head of chain for sid "+sid.getValue()+" is null. So it is pid."); |
|
1166 |
} |
|
1167 |
|
|
1147 | 1168 |
return pid; |
1148 | 1169 |
} |
1149 | 1170 |
|
1171 |
/* |
|
1172 |
* For the non-ideal chain, we used to return the latest Dateupload object as the head pid. However, Dateupload |
|
1173 |
* sometimes doesn't refect the obsoletes chain. We need to check if any other objects obsoletes it recursively. |
|
1174 |
* see ticket:https://redmine.dataone.org/issues/7624 |
|
1175 |
*/ |
|
1176 |
private Identifier checkObsoletesChain(Identifier latestDateUpload, HashMap<String, String>obsoletesIdGuidMap) { |
|
1177 |
Identifier pid = latestDateUpload; |
|
1178 |
if(obsoletesIdGuidMap != null && latestDateUpload != null && obsoletesIdGuidMap.containsKey(latestDateUpload)) { |
|
1179 |
logMetacat.debug("Another object obsoletes the lasted uploaded object "+latestDateUpload.getValue()); |
|
1180 |
//another object obsoletes the lastedDateUpload object |
|
1181 |
String pidStr = obsoletesIdGuidMap.get(latestDateUpload); |
|
1182 |
while (obsoletesIdGuidMap.containsKey(pidStr)) { |
|
1183 |
pidStr = obsoletesIdGuidMap.get(pidStr); |
|
1184 |
logMetacat.debug("Another object "+pidStr+" obsoletes the object "); |
|
1185 |
} |
|
1186 |
pid = new Identifier(); |
|
1187 |
pid.setValue(pidStr); |
|
1188 |
|
|
1189 |
} |
|
1190 |
if(pid != null && latestDateUpload != null){ |
|
1191 |
logMetacat.debug("IdnetifierManager.checkObsoletesChain - The final return value is "+pid.getValue()+ " for given value "+latestDateUpload.getValue()); |
|
1192 |
} |
|
1193 |
return pid; |
|
1194 |
} |
|
1150 | 1195 |
/** |
1151 | 1196 |
* Check if the specified sid object exists on the serial id field on the system metadata table |
1152 | 1197 |
* @param sid |
Also available in: Unified diff
Check the chain end if obsoleted by another object.
See ticket https://redmine.dataone.org/issues/7624