Revision 4450
Added by ben leinfelder about 16 years ago
src/edu/ucsb/nceas/metacat/MetacatReplication.java | ||
---|---|---|
694 | 694 |
if (accessControlList != null) { |
695 | 695 |
for (int i = 0; i < accessControlList.size(); i++) { |
696 | 696 |
AccessControlForSingleFile acfsf = (AccessControlForSingleFile) accessControlList.get(i); |
697 |
acfsf.insertPermissions(); |
|
698 |
MetacatReplication.replLog("document " + docid + " permissions added to DB"); |
|
697 |
if (!acfsf.accessControlExists()) { |
|
698 |
acfsf.insertPermissions(); |
|
699 |
MetacatReplication.replLog("document " + docid + " permissions added to DB"); |
|
700 |
} |
|
699 | 701 |
} |
700 | 702 |
} |
701 | 703 |
|
... | ... | |
865 | 867 |
if (accessControlList != null) { |
866 | 868 |
for (int i = 0; i < accessControlList.size(); i++) { |
867 | 869 |
AccessControlForSingleFile acfsf = (AccessControlForSingleFile) accessControlList.get(i); |
868 |
acfsf.insertPermissions(); |
|
869 |
MetacatReplication.replLog("datafile " + docid + " permissions added to DB"); |
|
870 |
if (!acfsf.accessControlExists()) { |
|
871 |
acfsf.insertPermissions(); |
|
872 |
MetacatReplication.replLog("datafile " + docid + " permissions added to DB"); |
|
873 |
} |
|
870 | 874 |
} |
871 | 875 |
} |
872 | 876 |
|
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
3403 | 3403 |
AccessControlForSingleFile accessControl = new AccessControlForSingleFile( |
3404 | 3404 |
accessionNumber, principal, permission, permType, |
3405 | 3405 |
permOrder); |
3406 |
accessControl.insertPermissions(); |
|
3407 |
success = "Set access control to document " |
|
3408 |
+ accessionNumber + " successfully"; |
|
3406 |
if (!accessControl.accessControlExists()) { |
|
3407 |
accessControl.insertPermissions(); |
|
3408 |
success = "Set access control to document " |
|
3409 |
+ accessionNumber + " successfully"; |
|
3410 |
} |
|
3411 |
else { |
|
3412 |
success = "Access control for document " |
|
3413 |
+ accessionNumber + " already exists"; |
|
3414 |
} |
|
3409 | 3415 |
successList.addElement(success); |
3410 | 3416 |
} catch (Exception ee) { |
3411 | 3417 |
logMetacat.error( |
src/edu/ucsb/nceas/metacat/ReplicationHandler.java | ||
---|---|---|
371 | 371 |
if (accessControlList != null) { |
372 | 372 |
for (int i = 0; i < accessControlList.size(); i++) { |
373 | 373 |
AccessControlForSingleFile acfsf = (AccessControlForSingleFile) accessControlList.get(i); |
374 |
acfsf.insertPermissions(); |
|
374 |
if (!acfsf.accessControlExists()) { |
|
375 |
acfsf.insertPermissions(); |
|
376 |
} |
|
375 | 377 |
} |
376 | 378 |
} |
377 | 379 |
|
... | ... | |
496 | 498 |
if (accessControlList != null) { |
497 | 499 |
for (int i = 0; i < accessControlList.size(); i++) { |
498 | 500 |
AccessControlForSingleFile acfsf = (AccessControlForSingleFile) accessControlList.get(i); |
499 |
acfsf.insertPermissions(); |
|
501 |
if (!acfsf.accessControlExists()) { |
|
502 |
acfsf.insertPermissions(); |
|
503 |
} |
|
500 | 504 |
} |
501 | 505 |
} |
502 | 506 |
|
src/edu/ucsb/nceas/metacat/AccessControlForSingleFile.java | ||
---|---|---|
185 | 185 |
|
186 | 186 |
} |
187 | 187 |
|
188 |
/** |
|
189 |
* |
|
190 |
* @return true if the Access Control for this file already exists in the DB |
|
191 |
* @throws SQLException |
|
192 |
*/ |
|
193 |
public boolean accessControlExists() throws SQLException |
|
194 |
{ |
|
195 |
boolean exists = false; |
|
196 |
PreparedStatement pstmt = null; |
|
197 |
DBConnection conn = null; |
|
198 |
int serialNumber = -1; |
|
199 |
try |
|
200 |
{ |
|
201 |
//check out DBConnection |
|
202 |
conn=DBConnectionPool.getDBConnection |
|
203 |
("AccessControlForSingleFiel.accessControlExists"); |
|
204 |
serialNumber=conn.getCheckOutSerialNumber(); |
|
205 |
pstmt = conn.prepareStatement( |
|
206 |
"SELECT * FROM xml_access " + |
|
207 |
"WHERE docid = ? " + |
|
208 |
"AND principal_name = ? " + |
|
209 |
"AND permission = ? " + |
|
210 |
"AND perm_type = ? " + |
|
211 |
"AND perm_order =? "); |
|
212 |
|
|
213 |
// Bind the values to the query |
|
214 |
pstmt.setString(1, docId); |
|
215 |
pstmt.setString(2, principal); |
|
216 |
pstmt.setInt(3, permission); |
|
217 |
pstmt.setString(4, permType); |
|
218 |
pstmt.setString(5, permOrder); |
|
219 |
|
|
220 |
pstmt.execute(); |
|
221 |
ResultSet rs = pstmt.getResultSet(); |
|
222 |
exists = rs.next(); |
|
223 |
|
|
224 |
}//try |
|
225 |
catch (SQLException e) |
|
226 |
{ |
|
227 |
logMetacat.error("Error in AccessControlForSingleFile.accessControlExists: " |
|
228 |
+ e.getMessage()); |
|
229 |
throw e; |
|
230 |
} |
|
231 |
finally |
|
232 |
{ |
|
233 |
try |
|
234 |
{ |
|
235 |
pstmt.close(); |
|
236 |
} |
|
237 |
finally |
|
238 |
{ |
|
239 |
DBConnectionPool.returnDBConnection(conn, serialNumber); |
|
240 |
} |
|
241 |
} |
|
242 |
|
|
243 |
return exists; |
|
244 |
|
|
245 |
} |
|
246 |
|
|
188 | 247 |
public String getAccessString() { |
189 | 248 |
StringBuffer sb = new StringBuffer(); |
190 | 249 |
sb.append("<access>"); |
Also available in: Unified diff
check for existing access control rows before inserting (we do not need duplicate rows specifying the same access control)