Project

General

Profile

« Previous | Next » 

Revision 7409

allow getlog action to use docid parameters that do not include revision. In these cases, the latest revision will be used.

View differences:

src/edu/ucsb/nceas/metacat/EventLog.java
44 44
import edu.ucsb.nceas.metacat.database.DBConnection;
45 45
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
46 46
import edu.ucsb.nceas.metacat.properties.PropertyService;
47
import edu.ucsb.nceas.metacat.util.DocumentUtil;
47 48
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
48 49

  
49 50
/**
......
225 226
            		query.append(", ");
226 227
        		}
227 228
        		query.append("?");
228
        		paramValues.add(docid[i]);
229
        		String fullDocid = docid[i];
230
        		// allow docid without revision - look up latest version
231
        		try {
232
        			fullDocid = DocumentUtil.appendRev(fullDocid);
233
        		} catch (Exception e) {
234
					// just warn about this
235
        			logMetacat.warn("Could not check docid for revision: " + fullDocid, e);
236
				}
237
        		paramValues.add(fullDocid);
229 238
        	}
230 239
        	query.append(") ");
231 240
            clauseAdded = true;
src/edu/ucsb/nceas/metacat/MetacatHandler.java
1015 1015
        }
1016 1016
                
1017 1017
        // accomodate old clients that send docids without revision numbers
1018
        docid = appendRev(docid);
1018
        docid = DocumentUtil.appendRev(docid);
1019 1019
        
1020 1020
        DocumentImpl doc = new DocumentImpl(docid, false);
1021 1021
        
......
1243 1243
            // to handle this suituation. First we will check how many
1244 1244
            // seperator here, if only one, we will append the rev in xml_documents
1245 1245
            // to the id.
1246
            docid = appendRev(docid);
1246
            docid = DocumentUtil.appendRev(docid);
1247 1247
            
1248 1248
            DocumentImpl doc = new DocumentImpl(docid, false);
1249 1249
            
......
3418 3418
		} 
3419 3419
    }
3420 3420
    
3421
    /*
3422
     * If the given docid only have one seperter, we need
3423
     * append rev for it. The rev come from xml_documents
3424
     */
3425
    private static String appendRev(String docid) 
3426
      throws PropertyNotFoundException, SQLException, McdbDocNotFoundException {
3427
        String newAccNum = null;
3428
        String separator = PropertyService.getProperty("document.accNumSeparator");
3429
        int firstIndex = docid.indexOf(separator);
3430
        int lastIndex = docid.lastIndexOf(separator);
3431
        if (firstIndex == lastIndex) {
3432
            
3433
            //only one seperater
3434
            int rev = DBUtil.getLatestRevisionInDocumentTable(docid);
3435
            if (rev == -1) {
3436
                throw new McdbDocNotFoundException("the requested docid '"
3437
                        + docid+ "' does not exist");
3438
            } else {
3439
                newAccNum = docid+ separator+ rev;
3440
            }
3441
        } else {
3442
            // in other suituation we don't change the docid
3443
            newAccNum = docid;
3444
        }
3445
        //logMetacat.debug("The docid will be read is "+newAccNum);
3446
        return newAccNum;
3447
    }
3448
    
3449 3421
    /**
3450 3422
     * Schedule the sitemap generator to run periodically and update all
3451 3423
     * of the sitemap files for search indexing engines.
src/edu/ucsb/nceas/metacat/util/DocumentUtil.java
44 44

  
45 45
import edu.ucsb.nceas.dbadapter.AbstractDatabase;
46 46
import edu.ucsb.nceas.metacat.DBSAXHandler;
47
import edu.ucsb.nceas.metacat.DBUtil;
48
import edu.ucsb.nceas.metacat.McdbDocNotFoundException;
47 49
import edu.ucsb.nceas.metacat.McdbException;
48 50
import edu.ucsb.nceas.metacat.NodeRecord;
49 51
import edu.ucsb.nceas.metacat.PermissionController;
......
307 309

  
308 310
        return versionString;
309 311
    }//getVersionFromString
312
    
313
    /**
314
     * If the given docid only have one seperter, we need
315
     * append rev for it. The rev come from xml_documents
316
     */
317
    public static String appendRev(String docid) 
318
      throws PropertyNotFoundException, SQLException, McdbDocNotFoundException {
319
        String newAccNum = null;
320
        String separator = PropertyService.getProperty("document.accNumSeparator");
321
        int firstIndex = docid.indexOf(separator);
322
        int lastIndex = docid.lastIndexOf(separator);
323
        if (firstIndex == lastIndex) {
324
            
325
            //only one seperater
326
            int rev = DBUtil.getLatestRevisionInDocumentTable(docid);
327
            if (rev == -1) {
328
                throw new McdbDocNotFoundException("the requested docid '"
329
                        + docid+ "' does not exist");
330
            } else {
331
                newAccNum = docid+ separator+ rev;
332
            }
333
        } else {
334
            // in other suituation we don't change the docid
335
            newAccNum = docid;
336
        }
337
        //logMetacat.debug("The docid will be read is "+newAccNum);
338
        return newAccNum;
339
    }
310 340

  
311 341
    /**
312 342
     * This method will get docid from an AccessionNumber. There is no

Also available in: Unified diff