Revision 734
Added by bojilova almost 23 years ago
DocumentImpl.java | ||
---|---|---|
722 | 722 |
} |
723 | 723 |
} |
724 | 724 |
|
725 |
// DOCTITLE attr cleared from the db |
|
726 |
// /** |
|
727 |
// * Get the document title |
|
728 |
// */ |
|
729 |
// public String getTitle() { |
|
730 |
// return doctitle; |
|
731 |
// } |
|
732 |
|
|
733 |
// DOCTITLE attr cleared from the db |
|
734 |
// /** |
|
735 |
// * Set the document title |
|
736 |
// * |
|
737 |
// * @param title the new title for the document |
|
738 |
// */ |
|
739 |
// public void setTitle( String title ) { |
|
740 |
// this.doctitle = title; |
|
741 |
// try { |
|
742 |
// PreparedStatement pstmt; |
|
743 |
// pstmt = conn.prepareStatement( |
|
744 |
// "UPDATE xml_documents " + |
|
745 |
// " SET doctitle = ? " + |
|
746 |
// "WHERE docid = ?"); |
|
747 |
// |
|
748 |
// // Bind the values to the query |
|
749 |
// pstmt.setString(1, doctitle); |
|
750 |
// pstmt.setString(2, docid); |
|
751 |
// |
|
752 |
// // Do the insertion |
|
753 |
// pstmt.execute(); |
|
754 |
// pstmt.close(); |
|
755 |
// } catch (SQLException e) { |
|
756 |
// System.out.println("Error in DocumentImpl.setTitle: " + e.getMessage()); |
|
757 |
// } |
|
758 |
// } |
|
759 |
|
|
760 | 725 |
/** |
761 | 726 |
* Write an XML file to the database, given a filename |
762 | 727 |
* |
... | ... | |
840 | 805 |
* @param xml the xml stream to be loaded into the database |
841 | 806 |
* @param pub flag for public "read" access on xml document |
842 | 807 |
* @param dtd the dtd to be uploaded on server's file system |
843 |
* @param action the action to be performed (INSERT OR UPDATE)
|
|
844 |
* @param docid the docid to use for the INSERT OR UPDATE
|
|
808 |
* @param action the action to be performed (INSERT or UPDATE)
|
|
809 |
* @param accnum the docid + rev# to use on INSERT or UPDATE
|
|
845 | 810 |
* @param user the user that owns the document |
846 | 811 |
* @param group the group to which user belongs |
847 | 812 |
* @param serverCode the serverid from xml_replication on which this document |
... | ... | |
854 | 819 |
*/ |
855 | 820 |
|
856 | 821 |
public static String write( Connection conn,Reader xml,String pub,Reader dtd, |
857 |
String action, String docid, String user,
|
|
822 |
String action, String accnum, String user,
|
|
858 | 823 |
String group, int serverCode, boolean override, |
859 | 824 |
boolean validate) |
860 | 825 |
throws Exception |
861 | 826 |
{ |
862 |
//MOVED DOWN IN RelationHandler obj before write of relations |
|
863 |
//if(action.equals("UPDATE")) |
|
864 |
//{ |
|
865 |
// RelationHandler.deleteRelations(docid); |
|
866 |
//} |
|
827 |
String rev = "1"; |
|
828 |
String docid = null; |
|
829 |
MetaCatUtil util = new MetaCatUtil(); |
|
830 |
String sep = util.getOption("accNumSeparator"); |
|
867 | 831 |
|
868 |
int updaterev; |
|
869 |
MetaCatUtil util = new MetaCatUtil(); |
|
870 |
// Determine if the docid is OK for INSERT or UPDATE |
|
832 |
if ( accnum != null ) { |
|
833 |
// check the correctness of accnum; |
|
834 |
// split accnum in docid and rev in order to |
|
835 |
// preserve the current implementation of processing and storing, |
|
836 |
// but show the whole accnum to the client. |
|
837 |
DocumentIdentifier id = new DocumentIdentifier(accnum); |
|
838 |
docid = id.getIdentifier(); |
|
839 |
rev = id.getRev(); |
|
840 |
sep = id.getSeparator(); |
|
841 |
} |
|
842 |
|
|
843 |
// Determine if the docid,rev are OK for INSERT or UPDATE |
|
844 |
// Generate new docid on INSERT, if one is not provided. |
|
871 | 845 |
AccessionNumber ac = new AccessionNumber(conn); |
872 |
String newdocid = ac.generate(docid, action);
|
|
846 |
docid = ac.generate(docid, rev, action);
|
|
873 | 847 |
|
874 | 848 |
MetaCatUtil.debugMessage("action: " + action + " servercode: " + |
875 | 849 |
serverCode + " override: " + override); |
... | ... | |
882 | 856 |
//merge the differences manually. |
883 | 857 |
int istreamInt; |
884 | 858 |
char istreamChar; |
885 |
DocumentImpl newdoc = new DocumentImpl(conn, docid); |
|
886 |
updaterev = newdoc.getRev(); |
|
859 |
// NOT NEEDED |
|
860 |
//DocumentImpl newdoc = new DocumentImpl(conn, docid); |
|
861 |
//updaterev = newdoc.getRev(); |
|
862 |
String updaterev = rev; |
|
887 | 863 |
String server = MetacatReplication.getServer(serverCode); |
888 |
MetacatReplication.replLog("attempting to lock " + docid);
|
|
864 |
MetacatReplication.replLog("attempting to lock " + accnum);
|
|
889 | 865 |
URL u = new URL("http://" + server + "?action=getlock&updaterev=" + |
890 | 866 |
updaterev + "&docid=" + docid); |
891 | 867 |
System.out.println("sending message: " + u.toString()); |
... | ... | |
896 | 872 |
{//the lock was granted go ahead with the insert |
897 | 873 |
try |
898 | 874 |
{ |
899 |
MetacatReplication.replLog("lock granted for " + docid + " from " +
|
|
875 |
MetacatReplication.replLog("lock granted for " + accnum + " from " +
|
|
900 | 876 |
server); |
901 |
XMLReader parser = initializeParser(conn, action, newdocid, validate,
|
|
877 |
XMLReader parser = initializeParser(conn, action, docid, validate, |
|
902 | 878 |
user, group, pub, serverCode, dtd); |
903 | 879 |
conn.setAutoCommit(false); |
904 | 880 |
parser.parse(new InputSource(xml)); |
... | ... | |
916 | 892 |
//to come get a copy from here. |
917 | 893 |
ForceReplicationHandler frh = new ForceReplicationHandler(docid); |
918 | 894 |
|
919 |
if ( (docid != null) && !(newdocid.equals(docid)) ) |
|
920 |
{ |
|
921 |
return new String("New document ID generated:" + newdocid); |
|
922 |
} |
|
923 |
else |
|
924 |
{ |
|
925 |
return newdocid; |
|
926 |
} |
|
895 |
return (docid + sep + rev); |
|
927 | 896 |
} |
897 |
|
|
928 | 898 |
else if(openingtag.equals("<filelocked>")) |
929 | 899 |
{//the file is currently locked by another user |
930 | 900 |
//notify our user to wait a few minutes, check out a new copy and try |
931 | 901 |
//again. |
932 | 902 |
//System.out.println("file locked"); |
933 |
MetacatReplication.replLog("lock denied for " + docid + " on " +
|
|
903 |
MetacatReplication.replLog("lock denied for " + accnum + " on " +
|
|
934 | 904 |
server + " reason: file already locked"); |
935 | 905 |
throw new Exception("The file specified is already locked by another " + |
936 | 906 |
"user. Please wait 30 seconds, checkout the " + |
... | ... | |
941 | 911 |
{//our file is outdated. notify our user to check out a new copy of the |
942 | 912 |
//file and merge his version with the new version. |
943 | 913 |
//System.out.println("outdated file"); |
944 |
MetacatReplication.replLog("lock denied for " + docid + " on " +
|
|
914 |
MetacatReplication.replLog("lock denied for " + accnum + " on " +
|
|
945 | 915 |
server + " reason: local file outdated"); |
946 | 916 |
throw new Exception("The file you are trying to update is an outdated" + |
947 | 917 |
" version. Please checkout the newest document, " + |
... | ... | |
954 | 924 |
|
955 | 925 |
if ( !hasPermission(conn, user, group, docid) ) { |
956 | 926 |
throw new Exception("User " + user + |
957 |
" does not have permission to update XML Document #" + docid);
|
|
927 |
" does not have permission to update XML Document #" + accnum);
|
|
958 | 928 |
} |
959 | 929 |
} |
960 | 930 |
|
961 | 931 |
try |
962 | 932 |
{ |
963 |
XMLReader parser = initializeParser(conn, action, newdocid, validate,
|
|
933 |
XMLReader parser = initializeParser(conn, action, docid, validate, |
|
964 | 934 |
user, group, pub, serverCode, dtd); |
965 | 935 |
conn.setAutoCommit(false); |
966 | 936 |
parser.parse(new InputSource(xml)); |
... | ... | |
977 | 947 |
//force replicate out the new document to each server in our server list. |
978 | 948 |
if(serverCode == 1) |
979 | 949 |
{ //start the thread to replicate this new document out to the other servers |
980 |
ForceReplicationHandler frh = new ForceReplicationHandler(newdocid, |
|
981 |
action); |
|
950 |
ForceReplicationHandler frh = new ForceReplicationHandler(docid, action); |
|
982 | 951 |
} |
983 | 952 |
|
984 |
if ( (docid != null) && !(newdocid.equals(docid)) ) |
|
985 |
{ |
|
986 |
return new String("New document ID generated:" + newdocid); |
|
987 |
} |
|
988 |
else |
|
989 |
{ |
|
990 |
return newdocid; |
|
991 |
} |
|
953 |
return (docid + sep + rev); |
|
992 | 954 |
} |
993 | 955 |
|
994 | 956 |
/** |
... | ... | |
997 | 959 |
* |
998 | 960 |
* @param docid the ID of the document to be deleted from the database |
999 | 961 |
*/ |
1000 |
public static void delete( Connection conn, String docid,
|
|
962 |
public static void delete( Connection conn, String accnum,
|
|
1001 | 963 |
String user, String group ) |
1002 |
throws Exception { |
|
1003 |
DocumentIdentifier id = new DocumentIdentifier(docid); |
|
1004 |
docid = id.getSiteCode() + id.getSeparator() + id.getUniqueId(); |
|
964 |
throws Exception |
|
965 |
{ |
|
966 |
DocumentIdentifier id = new DocumentIdentifier(accnum); |
|
967 |
String docid = id.getIdentifier(); |
|
968 |
String rev = id.getRev(); |
|
1005 | 969 |
|
1006 |
// Determine if the docid is OK for DELETE
|
|
970 |
// Determine if the docid,rev are OK for DELETE
|
|
1007 | 971 |
AccessionNumber ac = new AccessionNumber(conn); |
1008 |
String newdocid = ac.generate(docid, "DELETE");
|
|
972 |
docid = ac.generate(docid, rev, "DELETE");
|
|
1009 | 973 |
|
1010 | 974 |
// check for 'write' permission for 'user' to delete this document |
1011 | 975 |
if ( !hasPermission(conn, user, group, docid) ) { |
1012 | 976 |
throw new Exception("User " + user + |
1013 |
" does not have permission to delete XML Document #" + docid);
|
|
977 |
" does not have permission to delete XML Document #" + accnum);
|
|
1014 | 978 |
} |
1015 | 979 |
|
1016 | 980 |
conn.setAutoCommit(false); |
... | ... | |
1033 | 997 |
//if the deleted document is a package document its relations should |
1034 | 998 |
//no longer be active if it has been deleted from the system. |
1035 | 999 |
|
1036 |
// MOVED UP IN THE TRANSACTION |
|
1037 |
// RelationHandler.deleteRelations(docid); |
|
1038 | 1000 |
} |
1039 | 1001 |
|
1040 | 1002 |
/** |
Also available in: Unified diff
- changes to expect revisionid to come from the client on INSERT/UPDATE/DELETE;
now the client should send accession# as:
sitecode.uniqueid.revisionid
INSERT checks if sitecode.uniqueid part does not exist in xml_documents and xml_revisions and revisionid=1
UPDATE/DELETE check if sitecode.uniqueid part is in xml_document and revisionid is the recent number
- keep the old implementation where the client can send accession# without revisionid