Revision 1026
Added by Jing Tao almost 23 years ago
src/edu/ucsb/nceas/metacat/DocumentImpl.java | ||
---|---|---|
220 | 220 |
} |
221 | 221 |
|
222 | 222 |
/** |
223 |
* This method will be call in handleUploadRequest in MetacatServlet class |
|
224 |
*/ |
|
225 |
public static void registerDocument( |
|
226 |
String docname, String doctype, String accnum, String user) |
|
227 |
throws SQLException, AccessionNumberException, Exception |
|
228 |
{ |
|
229 |
Connection dbConn = null; |
|
230 |
MetaCatUtil ut = new MetaCatUtil(); |
|
231 |
dbConn = ut.getConnection(); |
|
232 |
// get server location for this doc |
|
233 |
int serverLocation=getServerLocationNumber(dbConn,accnum); |
|
234 |
ut.returnConnection(dbConn); |
|
235 |
registerDocument(docname, doctype,accnum, user, serverLocation); |
|
236 |
|
|
237 |
} |
|
238 |
/** |
|
223 | 239 |
* Register a document that resides on the filesystem with the database. |
224 | 240 |
* (ie, just an entry in xml_documents, nothing in xml_nodes). |
225 | 241 |
* Creates a reference to a filesystem document (used for non-xml data files). |
... | ... | |
350 | 366 |
|
351 | 367 |
|
352 | 368 |
} |
369 |
|
|
370 |
public static boolean getDataFileLockGrant(String accnum) |
|
371 |
throws Exception |
|
372 |
{ |
|
373 |
Connection dbConn = null; |
|
374 |
MetaCatUtil ut= new MetaCatUtil(); |
|
375 |
dbConn = ut.getConnection(); |
|
376 |
int serverLocation=getServerLocationNumber(dbConn,accnum); |
|
377 |
ut.returnConnection(dbConn); |
|
378 |
return getDataFileLockGrant(accnum,serverLocation); |
|
379 |
} |
|
380 |
|
|
353 | 381 |
/** |
382 |
* The method will check if metacat can get data file lock grant |
|
383 |
* If server code is 1, it get. |
|
384 |
* If server code is not 1 but call replication getlock successfully, |
|
385 |
* it get |
|
386 |
* else, it didn't get |
|
387 |
* @param accnum, the ID of the document |
|
388 |
* @param action, the action to the document |
|
389 |
* @param serverCode, the server location code |
|
390 |
*/ |
|
391 |
public static boolean getDataFileLockGrant(String accnum, int serverCode) |
|
392 |
throws Exception |
|
393 |
{ |
|
394 |
boolean flag=true; |
|
395 |
MetaCatUtil util = new MetaCatUtil(); |
|
396 |
String docid = util.getDocIdFromString(accnum); |
|
397 |
int rev = util.getVersionFromString(accnum); |
|
398 |
|
|
399 |
if (serverCode == 1) |
|
400 |
{ |
|
401 |
flag=true; |
|
402 |
return flag; |
|
403 |
} |
|
404 |
|
|
405 |
//if((serverCode != 1 && action.equals("UPDATE")) ) |
|
406 |
if (serverCode != 1) |
|
407 |
{ //if this document being written is not a resident of this server then |
|
408 |
//we need to try to get a lock from it's resident server. If the |
|
409 |
//resident server will not give a lock then we send the user a message |
|
410 |
//saying that he/she needs to download a new copy of the file and |
|
411 |
//merge the differences manually. |
|
412 |
|
|
413 |
String server = MetacatReplication.getServer(serverCode); |
|
414 |
MetacatReplication.replLog("attempting to lock " + accnum); |
|
415 |
URL u = new URL("https://" + server + "?server=" |
|
416 |
+util.getLocalReplicationServerName()+"&action=getlock&updaterev=" |
|
417 |
+rev + "&docid=" + docid); |
|
418 |
//System.out.println("sending message: " + u.toString()); |
|
419 |
String serverResStr = MetacatReplication.getURLContent(u); |
|
420 |
String openingtag =serverResStr.substring(0, serverResStr.indexOf(">")+1); |
|
421 |
if(openingtag.equals("<lockgranted>")) |
|
422 |
{ |
|
423 |
//the lock was granted go ahead with the insert |
|
424 |
//System.out.println("In lockgranted"); |
|
425 |
MetacatReplication.replLog("lock granted for " + accnum + " from " + |
|
426 |
server); |
|
427 |
flag=true; |
|
428 |
return flag; |
|
429 |
}//if |
|
430 |
|
|
431 |
else if(openingtag.equals("<filelocked>")) |
|
432 |
{//the file is currently locked by another user |
|
433 |
//notify our user to wait a few minutes, check out a new copy and try |
|
434 |
//again. |
|
435 |
//System.out.println("file locked"); |
|
436 |
MetacatReplication.replLog("lock denied for " + accnum + " on " + |
|
437 |
server + " reason: file already locked"); |
|
438 |
throw new Exception("The file specified is already locked by another " + |
|
439 |
"user. Please wait 30 seconds, checkout the " + |
|
440 |
"newer document, merge your changes and try " + |
|
441 |
"again."); |
|
442 |
} |
|
443 |
else if(openingtag.equals("<outdatedfile>")) |
|
444 |
{//our file is outdated. notify our user to check out a new copy of the |
|
445 |
//file and merge his version with the new version. |
|
446 |
//System.out.println("outdated file"); |
|
447 |
MetacatReplication.replLog("lock denied for " + accnum + " on " + |
|
448 |
server + " reason: local file outdated"); |
|
449 |
throw new Exception("The file you are trying to update is an outdated" + |
|
450 |
" version. Please checkout the newest document, " + |
|
451 |
"merge your changes and try again."); |
|
452 |
}//else if |
|
453 |
}//if |
|
454 |
|
|
455 |
return flag; |
|
456 |
|
|
457 |
}//getDataFileLockGrant |
|
458 |
|
|
459 |
/** |
|
354 | 460 |
* get the document name |
355 | 461 |
*/ |
356 | 462 |
public String getDocname() { |
Also available in: Unified diff
Add method getDataFileLockGrant(). This method will check if xml-document of data file can be store into database.