Revision 5195
Added by daigle over 14 years ago
ReplicationService.java | ||
---|---|---|
40 | 40 |
import edu.ucsb.nceas.metacat.DocumentImplWrapper; |
41 | 41 |
import edu.ucsb.nceas.metacat.EventLog; |
42 | 42 |
import edu.ucsb.nceas.metacat.McdbException; |
43 |
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlException; |
|
43 | 44 |
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlForSingleFile; |
45 |
import edu.ucsb.nceas.metacat.accesscontrol.PermOrderException; |
|
44 | 46 |
import edu.ucsb.nceas.metacat.accesscontrol.XMLAccessDAO; |
45 | 47 |
import edu.ucsb.nceas.metacat.database.DBConnection; |
46 | 48 |
import edu.ucsb.nceas.metacat.database.DBConnectionPool; |
... | ... | |
554 | 556 |
// write the document to local database |
555 | 557 |
DocumentImplWrapper wrapper = new DocumentImplWrapper(parserBase, false); |
556 | 558 |
//try this independently so we can set |
557 |
Exception writeException = null; |
|
559 |
// Exception writeException = null;
|
|
558 | 560 |
try { |
559 |
wrapper.writeReplication(dbConn, new StringReader(xmldoc), null, null,
|
|
561 |
wrapper.writeReplication(dbConn, xmldoc, null, null,
|
|
560 | 562 |
dbaction, docid, user, null, homeServer, server, createdDate, |
561 | 563 |
updatedDate); |
562 |
} catch (Exception e) { |
|
563 |
writeException = e; |
|
564 |
} |
|
564 |
} finally { |
|
565 |
// writeException = e; |
|
565 | 566 |
|
566 |
//process extra access rules before dealing with the write exception (doc exist already) |
|
567 |
// Vector<AccessControlForSingleFile> accessControlList = dih |
|
568 |
// .getAccessControlList(); |
|
569 |
|
|
570 |
Vector<XMLAccessDAO> accessControlList = dih.getAccessControlList(); |
|
571 |
if (accessControlList != null) { |
|
572 |
AccessControlForSingleFile acfsf = new AccessControlForSingleFile(docid); |
|
573 |
for (XMLAccessDAO xmlAccessDAO : accessControlList) { |
|
574 |
if (!acfsf.accessControlExists(xmlAccessDAO)) { |
|
575 |
acfsf.insertPermissions(xmlAccessDAO); |
|
576 |
logReplication.info("ReplicationService.handleForceReplicateRequest - document " + docid |
|
577 |
+ " permissions added to DB"); |
|
578 |
} |
|
579 |
} |
|
580 |
} |
|
581 |
// if (accessControlList != null) { |
|
582 |
// for (int i = 0; i < accessControlList.size(); i++) { |
|
583 |
// AccessControlForSingleFile acfsf = (AccessControlForSingleFile) accessControlList |
|
584 |
// .get(i); |
|
585 |
// if (!acfsf.accessControlExists()) { |
|
586 |
// acfsf.insertPermissions(); |
|
587 |
// logReplication.info("ReplicationService.handleForceReplicateRequest - document " + docid |
|
588 |
// + " permissions added to DB"); |
|
567 |
//process extra access rules before dealing with the write exception (doc exist already) |
|
568 |
Vector<XMLAccessDAO> accessControlList = dih.getAccessControlList(); |
|
569 |
if (accessControlList != null) { |
|
570 |
AccessControlForSingleFile acfsf = new AccessControlForSingleFile(docid); |
|
571 |
for (XMLAccessDAO xmlAccessDAO : accessControlList) { |
|
572 |
if (!acfsf.accessControlExists(xmlAccessDAO)) { |
|
573 |
acfsf.insertPermissions(xmlAccessDAO); |
|
574 |
logReplication.info("ReplicationService.handleForceReplicateRequest - document " + docid |
|
575 |
+ " permissions added to DB"); |
|
576 |
} |
|
577 |
} |
|
578 |
} |
|
579 |
// if (accessControlList != null) { |
|
580 |
// for (int i = 0; i < accessControlList.size(); i++) { |
|
581 |
// AccessControlForSingleFile acfsf = (AccessControlForSingleFile) accessControlList |
|
582 |
// .get(i); |
|
583 |
// if (!acfsf.accessControlExists()) { |
|
584 |
// acfsf.insertPermissions(); |
|
585 |
// logReplication.info("ReplicationService.handleForceReplicateRequest - document " + docid |
|
586 |
// + " permissions added to DB"); |
|
587 |
// } |
|
589 | 588 |
// } |
590 | 589 |
// } |
591 |
// } |
|
592 | 590 |
|
593 |
if (writeException != null) { |
|
594 |
throw writeException; |
|
591 |
// if (writeException != null) { |
|
592 |
// throw writeException; |
|
593 |
// } |
|
594 |
|
|
595 |
logReplication.info("ReplicationService.handleForceReplicateRequest - document " + docid + " added to DB with " |
|
596 |
+ "action " + dbaction); |
|
597 |
EventLog.getInstance().log(request.getRemoteAddr(), REPLICATIONUSER, docid, |
|
598 |
dbaction); |
|
595 | 599 |
} |
596 |
|
|
597 |
logReplication.info("ReplicationService.handleForceReplicateRequest - document " + docid + " added to DB with " |
|
598 |
+ "action " + dbaction); |
|
599 |
EventLog.getInstance().log(request.getRemoteAddr(), REPLICATIONUSER, docid, |
|
600 |
dbaction); |
|
601 |
}//try |
|
602 |
catch (Exception e) { |
|
600 |
} catch (SQLException sqle) { |
|
603 | 601 |
logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG); |
604 |
logReplication.error("document " + docid |
|
605 |
+ " failed to added to DB with " + "action " + dbaction + " because " |
|
606 |
+ e.getMessage()); |
|
607 |
logReplication.error("ReplicationService.handleForceReplicateRequest - " |
|
608 |
+ "error: " + e.getMessage()); |
|
609 |
|
|
610 |
}//catch |
|
611 |
finally { |
|
602 |
logReplication.error("ReplicationService.handleForceReplicateRequest - SQL error when adding doc " + docid + |
|
603 |
" to DB with action " + dbaction + ": " + sqle.getMessage()); |
|
604 |
} catch (MalformedURLException mue) { |
|
605 |
logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG); |
|
606 |
logReplication.error("ReplicationService.handleForceReplicateRequest - URL error when adding doc " + docid + |
|
607 |
" to DB with action " + dbaction + ": " + mue.getMessage()); |
|
608 |
} catch (SAXException se) { |
|
609 |
logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG); |
|
610 |
logReplication.error("ReplicationService.handleForceReplicateRequest - SAX parsing error when adding doc " + docid + |
|
611 |
" to DB with action " + dbaction + ": " + se.getMessage()); |
|
612 |
} catch (HandlerException he) { |
|
613 |
logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG); |
|
614 |
logReplication.error("ReplicationService.handleForceReplicateRequest - Handler error when adding doc " + docid + |
|
615 |
" to DB with action " + dbaction + ": " + he.getMessage()); |
|
616 |
} catch (IOException ioe) { |
|
617 |
logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG); |
|
618 |
logReplication.error("ReplicationService.handleForceReplicateRequest - I/O error when adding doc " + docid + |
|
619 |
" to DB with action " + dbaction + ": " + ioe.getMessage()); |
|
620 |
} catch (PermOrderException poe) { |
|
621 |
logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG); |
|
622 |
logReplication.error("ReplicationService.handleForceReplicateRequest - Permissions order error when adding doc " + docid + |
|
623 |
" to DB with action " + dbaction + ": " + poe.getMessage()); |
|
624 |
} catch (AccessControlException ace) { |
|
625 |
logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG); |
|
626 |
logReplication.error("ReplicationService.handleForceReplicateRequest - Permissions order error when adding doc " + docid + |
|
627 |
" to DB with action " + dbaction + ": " + ace.getMessage()); |
|
628 |
} catch (Exception e) { |
|
629 |
logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG); |
|
630 |
logReplication.error("ReplicationService.handleForceReplicateRequest - General error when adding doc " + docid + |
|
631 |
" to DB with action " + dbaction + ": " + e.getMessage()); |
|
632 |
} finally { |
|
612 | 633 |
// Return the checked out DBConnection |
613 | 634 |
DBConnectionPool.returnDBConnection(dbConn, serialNumber); |
614 | 635 |
}//finally |
Also available in: Unified diff
Pass the doc xml as a string to docImpl.write and writeRepication. This is so a reader can be create for the parsing and for the write to disk. Also created a db access class for xml query result deletion.