Revision 5286
Added by Matt Jones about 14 years ago
IdentifierManager.java | ||
---|---|---|
32 | 32 |
|
33 | 33 |
import edu.ucsb.nceas.metacat.database.DBConnection; |
34 | 34 |
import edu.ucsb.nceas.metacat.database.DBConnectionPool; |
35 |
import edu.ucsb.nceas.metacat.util.DocumentUtil; |
|
35 | 36 |
|
36 | 37 |
/** |
37 | 38 |
* Manage the relationship between Metacat local identifiers (LocalIDs) that are |
... | ... | |
186 | 187 |
DBConnectionPool.returnDBConnection(dbConn, serialNumber); |
187 | 188 |
} |
188 | 189 |
} |
190 |
|
|
191 |
/** |
|
192 |
* Given a global identifier (guid), create a suitable local identifier that |
|
193 |
* follows Metacat's docid semantics and format (scope.id.rev), and create |
|
194 |
* a mapping between these two identifiers. This effectively reserves both |
|
195 |
* the global and the local identifier, as they will now be present in the |
|
196 |
* identifier mapping table. If the incoming guid has the syntax of a |
|
197 |
* Metacat docid (scope.id.rev), then simply use it. |
|
198 |
* |
|
199 |
* @param guid the global string identifier |
|
200 |
* @param rev the revision number to be used in the localId |
|
201 |
* @return String containing the localId to be used for Metacat operations |
|
202 |
*/ |
|
203 |
public String generateLocalId(String guid, int rev) |
|
204 |
{ |
|
205 |
String localId = ""; |
|
206 |
boolean conformsToDocidFormat = false; |
|
207 |
|
|
208 |
// Check if the guid passed in is already in docid (scope.id.rev) format |
|
209 |
try { |
|
210 |
AccessionNumber acc = new AccessionNumber(guid, "NONE"); |
|
211 |
if (new Integer(acc.getRev()).intValue() > 0) { |
|
212 |
conformsToDocidFormat = true; |
|
213 |
} |
|
214 |
} catch (NumberFormatException e) { |
|
215 |
// No action needed, simply detecting invalid AccessionNumbers |
|
216 |
} catch (AccessionNumberException e) { |
|
217 |
// No action needed, simply detecting invalid AccessionNumbers |
|
218 |
} catch (SQLException e) { |
|
219 |
// No action needed, simply detecting invalid AccessionNumbers |
|
220 |
} |
|
221 |
|
|
222 |
if (conformsToDocidFormat) { |
|
223 |
// if it conforms, use it for both guid and localId |
|
224 |
localId = guid; |
|
225 |
} else { |
|
226 |
// if not, then generate a new unique localId |
|
227 |
localId = DocumentUtil.generateDocumentId(rev); |
|
228 |
} |
|
229 |
|
|
230 |
// Register this new pair in the identifier mapping table |
|
231 |
createMapping(guid, localId); |
|
232 |
|
|
233 |
return localId; |
|
234 |
} |
|
189 | 235 |
} |
Also available in: Unified diff
Added support to ResourceHandler to allow the putObject method to use
arbitrary guid strings as input. These strings are examined, and if they
match the Metacat docid format (scope.id.rev), they are used directly. If
the id is a string in another format, a new localId is generated based on
the current time. Either way, a mapping is made into the identifier table
to relate the original guid to the new localId. Modified DocumentUtil to
generate the ids, and MCTest case to use this new utility method (to stay DRY).
Tests were updated to expect these global identifiers in the putObject
method.