Revision 561
Added by berkley over 23 years ago
DocumentImpl.java | ||
---|---|---|
21 | 21 |
import java.io.Reader; |
22 | 22 |
import java.io.StringWriter; |
23 | 23 |
import java.io.Writer; |
24 |
import java.io.InputStreamReader; |
|
24 | 25 |
|
25 | 26 |
import java.util.Iterator; |
26 | 27 |
import java.util.Stack; |
... | ... | |
37 | 38 |
import org.xml.sax.SAXParseException; |
38 | 39 |
import org.xml.sax.helpers.XMLReaderFactory; |
39 | 40 |
|
41 |
import java.net.URL; |
|
42 |
|
|
40 | 43 |
/** |
41 | 44 |
* A class that represents an XML document. It can be created with a simple |
42 | 45 |
* document identifier from a database connection. It also will write an |
... | ... | |
56 | 59 |
private String createdate = null; |
57 | 60 |
private String updatedate = null; |
58 | 61 |
private String system_id = null; |
62 |
private String userowner = null; |
|
63 |
private String userupdated = null; |
|
64 |
private int serverlocation; |
|
65 |
private int publicaccess; |
|
59 | 66 |
private long rootnodeid; |
60 | 67 |
private ElementNode rootNode = null; |
61 | 68 |
private TreeSet nodeRecordList = null; |
... | ... | |
187 | 194 |
public String getDocTitle() { |
188 | 195 |
return doctitle; |
189 | 196 |
} |
197 |
|
|
198 |
public String getUserowner() { |
|
199 |
return userowner; |
|
200 |
} |
|
201 |
|
|
202 |
public String getUserupdated() { |
|
203 |
return userupdated; |
|
204 |
} |
|
205 |
|
|
206 |
public int getServerlocation() { |
|
207 |
return serverlocation; |
|
208 |
} |
|
209 |
|
|
210 |
public int getPublicaccess() { |
|
211 |
return publicaccess; |
|
212 |
} |
|
190 | 213 |
|
191 |
|
|
192 | 214 |
/** |
193 | 215 |
* Print a string representation of the XML document |
194 | 216 |
*/ |
... | ... | |
375 | 397 |
try { |
376 | 398 |
pstmt = |
377 | 399 |
conn.prepareStatement("SELECT docname, doctype, rootnodeid,doctitle, " + |
378 |
"date_created, date_updated " + |
|
400 |
"date_created, date_updated, " + |
|
401 |
"user_owner, user_updated, server_location, " + |
|
402 |
"public_access " + |
|
379 | 403 |
"FROM xml_documents " + |
380 | 404 |
"WHERE docid LIKE ?"); |
381 | 405 |
// Bind the values to the query |
... | ... | |
385 | 409 |
ResultSet rs = pstmt.getResultSet(); |
386 | 410 |
boolean tableHasRows = rs.next(); |
387 | 411 |
if (tableHasRows) { |
388 |
this.docname = rs.getString(1); |
|
389 |
this.doctype = rs.getString(2); |
|
390 |
this.rootnodeid = rs.getLong(3); |
|
391 |
this.doctitle = rs.getString(4); |
|
392 |
this.createdate = rs.getString(5); |
|
393 |
this.updatedate = rs.getString(6); |
|
412 |
this.docname = rs.getString(1); |
|
413 |
this.doctype = rs.getString(2); |
|
414 |
this.rootnodeid = rs.getLong(3); |
|
415 |
this.doctitle = rs.getString(4); |
|
416 |
this.createdate = rs.getString(5); |
|
417 |
this.updatedate = rs.getString(6); |
|
418 |
this.userowner = rs.getString(7); |
|
419 |
this.userupdated = rs.getString(8); |
|
420 |
this.serverlocation = rs.getInt(9); |
|
421 |
this.publicaccess = rs.getInt(10); |
|
394 | 422 |
} |
395 | 423 |
pstmt.close(); |
396 | 424 |
|
... | ... | |
699 | 727 |
String action, String docid, String user, |
700 | 728 |
String group, int serverCode ) |
701 | 729 |
throws Exception { |
702 |
/*
|
|
703 |
if(serverCode != 1) |
|
730 |
System.out.println("outside of if: action: " + action + "servercode: " + serverCode);
|
|
731 |
if(serverCode != 1 && action.equals("UPDATE"))
|
|
704 | 732 |
{ //if this document being written is not a resident of this server then |
705 | 733 |
//we need to try to get a lock from it's resident server. If the |
706 | 734 |
//resident server will not give a lock then we send the user a message |
707 | 735 |
//saying that he/she needs to download a new copy of the file and |
708 | 736 |
//merge the differences manually. |
737 |
System.out.println("in if: action: " + action + "servercode: " + serverCode); |
|
738 |
int istreamInt; |
|
739 |
char istreamChar; |
|
740 |
DocumentImpl newdoc = new DocumentImpl(conn, docid); |
|
741 |
String update = newdoc.getUpdateDate(); |
|
742 |
String server = MetacatReplication.getServer(serverCode); |
|
709 | 743 |
|
744 |
URL u = new URL("http://" + server + "?action=getlock&updatedate=" + update + |
|
745 |
"&docid=" + docid); |
|
746 |
InputStreamReader istream = new InputStreamReader(u.openStream()); |
|
747 |
StringBuffer serverResponse = new StringBuffer(); |
|
748 |
while((istreamInt = istream.read()) != -1) |
|
749 |
{ |
|
750 |
istreamChar = (char)istreamInt; |
|
751 |
serverResponse.append(istreamChar); |
|
752 |
} |
|
710 | 753 |
|
754 |
String serverResStr = serverResponse.toString(); |
|
755 |
String openingtag = serverResStr.substring(0, serverResStr.indexOf(">")); |
|
756 |
System.out.println("openingtag: " + openingtag); |
|
757 |
if(openingtag.equals("<lockgranted>")) |
|
758 |
{//the lock was granted go ahead with the insert |
|
759 |
|
|
760 |
} |
|
761 |
else if(openingtag.equals("<filelocked>")) |
|
762 |
{//the file is currently locked by another user |
|
763 |
//notify our user to wait a few minutes, check out a new copy and try |
|
764 |
//again. |
|
765 |
|
|
766 |
} |
|
767 |
else if(openingtag.equals("<outdatedfile>")) |
|
768 |
{//our file is outdated. notify our user to check out a new copy of the |
|
769 |
//file and merge his version with the new version. |
|
770 |
|
|
771 |
} |
|
711 | 772 |
} |
712 |
*/ |
|
773 |
|
|
713 | 774 |
// Determine if the docid is OK for INSERT or UPDATE |
714 | 775 |
AccessionNumber ac = new AccessionNumber(conn); |
715 | 776 |
String newdocid = ac.generate(docid, action); |
Also available in: Unified diff
added functionality to allow the replication servlet to assertain and insert user and group info into the local database. started implementation of insert replication handler (it is commented out in this commit)