Revision 6782
Added by ben leinfelder almost 13 years ago
src/edu/ucsb/nceas/metacat/replication/ReplicationService.java | ||
---|---|---|
723 | 723 |
dbaction = ((String[]) params.get("dbaction"))[0]; |
724 | 724 |
} else//default value is update |
725 | 725 |
{ |
726 |
dbaction = "update"; |
|
726 |
// dbaction = "update"; |
|
727 |
dbaction = null; |
|
727 | 728 |
} |
728 | 729 |
|
729 | 730 |
logReplication.info("ReplicationService.handleForceReplicateDataFileRequest - Force replication request from: " + server); |
... | ... | |
760 | 761 |
|
761 | 762 |
logReplication.info("ReplicationService.handleForceReplicateDataFileRequest - docHomeServer of datafile: " + docHomeServer); |
762 | 763 |
|
763 |
if (dbaction.equals("insert") || dbaction.equals("update")) { |
|
764 |
// in case we have a write exception, we still want to track access and sysmeta |
|
765 |
Exception writeException = null; |
|
766 |
|
|
767 |
// do we need the object content? |
|
768 |
if (dbaction != null && (dbaction.equals("insert") || dbaction.equals("update"))) { |
|
764 | 769 |
//Get data file and store it into local file system. |
765 | 770 |
// sending back readdata request to server |
766 | 771 |
URL url = new URL("https://" + server + "?server=" |
... | ... | |
771 | 776 |
|
772 | 777 |
InputStream inputStream = getURLStream(url); |
773 | 778 |
|
774 |
Exception writeException = null; |
|
775 | 779 |
//register data file into xml_documents table and write data file |
776 | 780 |
//into file system |
777 | 781 |
try { |
... | ... | |
782 | 786 |
} catch (Exception e) { |
783 | 787 |
writeException = e; |
784 | 788 |
} |
785 |
|
|
786 |
// process the real owner and updater |
|
787 |
DBConnection dbConn = DBConnectionPool.getDBConnection("ReplicationService.handleForceDataFileRequest"); |
|
788 |
int serialNumber = dbConn.getCheckOutSerialNumber(); |
|
789 |
dbConn.setAutoCommit(false); |
|
790 |
String user = (String) docinfoHash.get("user_owner"); |
|
791 |
String updated = (String) docinfoHash.get("user_updated"); |
|
792 |
updateUserOwner(dbConn, docid, user, updated); |
|
793 |
DBConnectionPool.returnDBConnection(dbConn, serialNumber); |
|
794 |
|
|
795 |
// process system metadata |
|
796 |
if (systemMetadataXML != null) { |
|
797 |
SystemMetadata sysMeta = |
|
798 |
TypeMarshaller.unmarshalTypeFromStream( |
|
799 |
SystemMetadata.class, |
|
800 |
new ByteArrayInputStream(systemMetadataXML.getBytes("UTF-8"))); |
|
801 |
|
|
802 |
// need the guid-to-docid mapping |
|
803 |
boolean mappingExists = true; |
|
804 |
mappingExists = IdentifierManager.getInstance().identifierExists(sysMeta.getIdentifier().getValue()); |
|
805 |
if (!mappingExists) { |
|
806 |
IdentifierManager.getInstance().createMapping(sysMeta.getIdentifier().getValue(), docid); |
|
807 |
} |
|
808 |
// save the system metadata |
|
809 |
HazelcastService.getInstance().getSystemMetadataMap().put(sysMeta.getIdentifier(), sysMeta); |
|
810 |
} |
|
811 |
|
|
812 |
// process the access control |
|
813 |
Vector<XMLAccessDAO> accessControlList = dih.getAccessControlList(); |
|
814 |
if (accessControlList != null) { |
|
815 |
AccessControlForSingleFile acfsf = new AccessControlForSingleFile(docid); |
|
816 |
for (XMLAccessDAO xmlAccessDAO : accessControlList) { |
|
817 |
if (!acfsf.accessControlExists(xmlAccessDAO)) { |
|
818 |
acfsf.insertPermissions(xmlAccessDAO); |
|
819 |
logReplication.info("ReplicationService.handleForceReplicateRequest - document " + docid |
|
820 |
+ " permissions added to DB"); |
|
821 |
} |
|
822 |
} |
|
823 |
} |
|
824 | 789 |
|
825 |
// throw the write exception now -- this happens when access changes on an object |
|
826 |
if (writeException != null) { |
|
827 |
throw writeException; |
|
828 |
} |
|
829 |
|
|
830 |
logReplication.info("ReplicationService.handleForceReplicateDataFileRequest - datafile " + docid + " added to DB with " |
|
831 |
+ "action " + dbaction); |
|
832 |
EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), REPLICATIONUSER, |
|
833 |
docid, dbaction); |
|
834 | 790 |
} |
791 |
|
|
792 |
// process the real owner and updater |
|
793 |
DBConnection dbConn = DBConnectionPool.getDBConnection("ReplicationService.handleForceDataFileRequest"); |
|
794 |
int serialNumber = dbConn.getCheckOutSerialNumber(); |
|
795 |
dbConn.setAutoCommit(false); |
|
796 |
String user = (String) docinfoHash.get("user_owner"); |
|
797 |
String updated = (String) docinfoHash.get("user_updated"); |
|
798 |
updateUserOwner(dbConn, docid, user, updated); |
|
799 |
DBConnectionPool.returnDBConnection(dbConn, serialNumber); |
|
800 |
|
|
801 |
// process system metadata |
|
802 |
if (systemMetadataXML != null) { |
|
803 |
SystemMetadata sysMeta = |
|
804 |
TypeMarshaller.unmarshalTypeFromStream( |
|
805 |
SystemMetadata.class, |
|
806 |
new ByteArrayInputStream(systemMetadataXML.getBytes("UTF-8"))); |
|
807 |
|
|
808 |
// need the guid-to-docid mapping |
|
809 |
boolean mappingExists = true; |
|
810 |
mappingExists = IdentifierManager.getInstance().identifierExists(sysMeta.getIdentifier().getValue()); |
|
811 |
if (!mappingExists) { |
|
812 |
IdentifierManager.getInstance().createMapping(sysMeta.getIdentifier().getValue(), docid); |
|
813 |
} |
|
814 |
// save the system metadata |
|
815 |
HazelcastService.getInstance().getSystemMetadataMap().put(sysMeta.getIdentifier(), sysMeta); |
|
816 |
} |
|
817 |
|
|
818 |
// process the access control |
|
819 |
Vector<XMLAccessDAO> accessControlList = dih.getAccessControlList(); |
|
820 |
if (accessControlList != null) { |
|
821 |
AccessControlForSingleFile acfsf = new AccessControlForSingleFile(docid); |
|
822 |
for (XMLAccessDAO xmlAccessDAO : accessControlList) { |
|
823 |
if (!acfsf.accessControlExists(xmlAccessDAO)) { |
|
824 |
acfsf.insertPermissions(xmlAccessDAO); |
|
825 |
logReplication.info("ReplicationService.handleForceReplicateRequest - document " + docid |
|
826 |
+ " permissions added to DB"); |
|
827 |
} |
|
828 |
} |
|
829 |
} |
|
830 |
|
|
831 |
// throw the write exception now -- this happens when access changes on an object |
|
832 |
if (writeException != null) { |
|
833 |
throw writeException; |
|
834 |
} |
|
835 | 835 |
|
836 |
logReplication.info("ReplicationService.handleForceReplicateDataFileRequest - datafile " + docid + " added to DB with " |
|
837 |
+ "action " + dbaction); |
|
838 |
EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), REPLICATIONUSER, |
|
839 |
docid, dbaction); |
|
840 |
|
|
836 | 841 |
} catch (Exception e) { |
837 | 842 |
e.printStackTrace(); |
838 | 843 |
logMetacat.error("ReplicationService.handleForceReplicateDataFileRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG, e); |
Also available in: Unified diff
do not treat access change as an update -- it should not attempt to retrieve the contents of the object
http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5520