727 |
727 |
String action, String docid, String user,
|
728 |
728 |
String group, int serverCode )
|
729 |
729 |
throws Exception {
|
730 |
|
System.out.println("outside of if: action: " + action + "servercode: " + serverCode);
|
|
730 |
System.out.println("action: " + action + " servercode: " +
|
|
731 |
serverCode);
|
|
732 |
|
731 |
733 |
if(serverCode != 1 && action.equals("UPDATE"))
|
732 |
734 |
{ //if this document being written is not a resident of this server then
|
733 |
735 |
//we need to try to get a lock from it's resident server. If the
|
734 |
736 |
//resident server will not give a lock then we send the user a message
|
735 |
737 |
//saying that he/she needs to download a new copy of the file and
|
736 |
738 |
//merge the differences manually.
|
737 |
|
System.out.println("in if: action: " + action + "servercode: " + serverCode);
|
738 |
|
int istreamInt;
|
|
739 |
int istreamInt;
|
739 |
740 |
char istreamChar;
|
740 |
741 |
DocumentImpl newdoc = new DocumentImpl(conn, docid);
|
741 |
742 |
String update = newdoc.getUpdateDate();
|
742 |
743 |
String server = MetacatReplication.getServer(serverCode);
|
743 |
|
|
744 |
|
URL u = new URL("http://" + server + "?action=getlock&updatedate=" + update +
|
745 |
|
"&docid=" + docid);
|
|
744 |
update = update.replace(' ', '+');
|
|
745 |
URL u = new URL("http://" + server + "?action=getlock&updatedate=" +
|
|
746 |
update + "&docid=" + docid);
|
|
747 |
//System.out.println("url: " + u.toString());
|
746 |
748 |
InputStreamReader istream = new InputStreamReader(u.openStream());
|
747 |
749 |
StringBuffer serverResponse = new StringBuffer();
|
748 |
750 |
while((istreamInt = istream.read()) != -1)
|
... | ... | |
752 |
754 |
}
|
753 |
755 |
|
754 |
756 |
String serverResStr = serverResponse.toString();
|
755 |
|
String openingtag = serverResStr.substring(0, serverResStr.indexOf(">"));
|
756 |
|
System.out.println("openingtag: " + openingtag);
|
|
757 |
System.out.println("serverResStr: " + serverResStr);
|
|
758 |
String openingtag = serverResStr.substring(0, serverResStr.indexOf(">")+1);
|
|
759 |
//System.out.println("openingtag: " + openingtag);
|
757 |
760 |
if(openingtag.equals("<lockgranted>"))
|
758 |
761 |
{//the lock was granted go ahead with the insert
|
759 |
|
|
|
762 |
System.out.println("lock granted");
|
760 |
763 |
}
|
761 |
764 |
else if(openingtag.equals("<filelocked>"))
|
762 |
765 |
{//the file is currently locked by another user
|
763 |
766 |
//notify our user to wait a few minutes, check out a new copy and try
|
764 |
767 |
//again.
|
765 |
|
|
|
768 |
System.out.println("file locked");
|
766 |
769 |
}
|
767 |
770 |
else if(openingtag.equals("<outdatedfile>"))
|
768 |
771 |
{//our file is outdated. notify our user to check out a new copy of the
|
769 |
772 |
//file and merge his version with the new version.
|
770 |
|
|
|
773 |
System.out.println("outdated file");
|
771 |
774 |
}
|
772 |
775 |
}
|
773 |
|
|
|
776 |
|
774 |
777 |
// Determine if the docid is OK for INSERT or UPDATE
|
775 |
778 |
AccessionNumber ac = new AccessionNumber(conn);
|
776 |
779 |
String newdocid = ac.generate(docid, action);
|
created locking action in replication servlet and added semi-support to documentImpl to handle documents updatedee by replicatio