Revision 736
Added by bojilova over 23 years ago
src/edu/ucsb/nceas/metacat/DocumentIdentifier.java | ||
---|---|---|
70 | 70 |
/** |
71 | 71 |
* parses the docid into its parts |
72 | 72 |
*/ |
73 |
private void parseDocid() |
|
73 |
private void parseDocid() throws AccessionNumberException
|
|
74 | 74 |
{ |
75 |
int firstIndex = docid.indexOf(separator); |
|
76 |
int lastIndex = docid.lastIndexOf(separator); |
|
77 |
if(firstIndex != lastIndex) |
|
78 |
{ //this docid contains a revision number |
|
79 |
rev = docid.substring(lastIndex + 1); |
|
80 |
uniqueId = docid.substring(firstIndex + 1, lastIndex); |
|
81 |
siteCode = docid.substring(0, firstIndex); |
|
75 |
try { |
|
76 |
int firstIndex = docid.indexOf(separator); |
|
77 |
int lastIndex = docid.lastIndexOf(separator); |
|
78 |
if(firstIndex != lastIndex) |
|
79 |
{ //this docid contains a revision number |
|
80 |
rev = docid.substring(lastIndex + 1); |
|
81 |
uniqueId = docid.substring(firstIndex + 1, lastIndex); |
|
82 |
siteCode = docid.substring(0, firstIndex); |
|
83 |
} |
|
84 |
else |
|
85 |
{ |
|
86 |
uniqueId = docid.substring(firstIndex + 1); |
|
87 |
siteCode = docid.substring(0, firstIndex); |
|
88 |
rev = getNewestRev(); |
|
89 |
} |
|
90 |
} catch (StringIndexOutOfBoundsException e) { |
|
91 |
throw new |
|
92 |
AccessionNumberException("Error in DocumentIdentifier.parseDocid(). " + |
|
93 |
"Use accession number format as: " + |
|
94 |
"sitecode" + separator + "uniqueid" + |
|
95 |
separator + "revisionid"); |
|
96 |
} catch (SQLException e) { |
|
97 |
throw new |
|
98 |
AccessionNumberException("Error in DocumentIdentifier.parseDocid(). " + |
|
99 |
"DB Error when reading revisionid"); |
|
100 |
} catch (ClassNotFoundException e) { |
|
101 |
throw new |
|
102 |
AccessionNumberException("Error in DocumentIdentifier.parseDocid(). " + |
|
103 |
e.getMessage()); |
|
82 | 104 |
} |
83 |
else |
|
84 |
{ |
|
85 |
uniqueId = docid.substring(firstIndex + 1); |
|
86 |
siteCode = docid.substring(0, firstIndex); |
|
87 |
rev = getNewestRev(); |
|
88 |
} |
|
89 | 105 |
|
90 |
if(rev.equals("newest")) |
|
91 |
{ |
|
92 |
rev = getNewestRev(); |
|
106 |
try { |
|
107 |
if(rev.equals("newest")) { |
|
108 |
rev = getNewestRev(); |
|
109 |
} |
|
110 |
} catch (SQLException e) { |
|
111 |
throw new |
|
112 |
AccessionNumberException("Error in DocumentIdentifier.parseDocid(). " + |
|
113 |
"DB Error when reading revisionid"); |
|
114 |
} catch (ClassNotFoundException e) { |
|
115 |
throw new |
|
116 |
AccessionNumberException("Error in DocumentIdentifier.parseDocid(). " + |
|
117 |
e.getMessage()); |
|
93 | 118 |
} |
119 |
|
|
94 | 120 |
} |
95 | 121 |
|
96 | 122 |
/** |
97 | 123 |
* returns the newest revision number for a document |
98 | 124 |
*/ |
99 |
private String getNewestRev() |
|
125 |
private String getNewestRev() throws SQLException, ClassNotFoundException
|
|
100 | 126 |
{ |
101 | 127 |
PreparedStatement pstmt; |
102 | 128 |
Connection conn = null; |
103 | 129 |
|
104 |
try |
|
105 |
{ |
|
106 |
try |
|
107 |
{ //this connection is prone to error for some reason so we |
|
130 |
try { |
|
131 |
try { |
|
132 |
//this connection is prone to error for some reason so we |
|
108 | 133 |
//try to connect it three times before quiting. |
109 | 134 |
conn = util.openDBConnection(); |
110 |
} |
|
111 |
catch(SQLException sqle) |
|
112 |
{ |
|
113 |
try |
|
114 |
{ |
|
135 |
} catch(SQLException sqle) { |
|
136 |
try { |
|
115 | 137 |
conn = util.openDBConnection(); |
116 |
} |
|
117 |
catch(SQLException sqlee) |
|
118 |
{ |
|
119 |
try |
|
120 |
{ |
|
138 |
} catch(SQLException sqlee) { |
|
139 |
try { |
|
121 | 140 |
conn = util.openDBConnection(); |
122 |
} |
|
123 |
catch(SQLException sqleee) |
|
124 |
{ |
|
141 |
} catch(SQLException sqleee) { |
|
125 | 142 |
System.out.println("error getting db connection in " + |
126 | 143 |
"MetacatReplication.handleGetDocumentRequest: " + |
127 | 144 |
sqleee.getMessage()); |
128 | 145 |
} |
129 | 146 |
} |
130 | 147 |
} |
148 |
|
|
131 | 149 |
pstmt = conn.prepareStatement("select rev from xml_documents where " + |
132 | 150 |
"docid like '" + docid + "'"); |
133 | 151 |
pstmt.execute(); |
134 | 152 |
ResultSet rs = pstmt.getResultSet(); |
135 | 153 |
boolean tablehasrows = rs.next(); |
136 |
if(tablehasrows) |
|
137 |
{ |
|
154 |
if (tablehasrows) { |
|
138 | 155 |
String retStr = rs.getString(1); |
139 | 156 |
pstmt.close(); |
140 | 157 |
conn.close(); |
141 | 158 |
return retStr; |
142 | 159 |
} |
143 | 160 |
conn.close(); |
144 |
} |
|
145 |
catch(Exception e) |
|
146 |
{ |
|
161 |
} catch(SQLException e) { |
|
147 | 162 |
System.out.println("error in DocumentIdentifier.getNewestRev(): " + |
148 | 163 |
e.getMessage()); |
149 |
try |
|
150 |
{ |
|
164 |
try { |
|
151 | 165 |
conn.close(); |
152 |
} |
|
153 |
catch(Exception e2) |
|
154 |
{} |
|
166 |
} catch(SQLException e2) { throw e2; } |
|
167 |
throw e; |
|
155 | 168 |
} |
169 |
|
|
156 | 170 |
return "1"; |
157 | 171 |
} |
158 | 172 |
|
Also available in: Unified diff
put exception handler messages when acc# is not in the correct format as:
<sitecode>.<uniqueid>.[<revisionid>]