Project

General

Profile

« Previous | Next » 

Revision 2648

Added by Jing Tao about 19 years ago

Add code to guess the docid's revision in read action.

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
1354 1354
    {
1355 1355

  
1356 1356
        try {
1357

  
1357
            
1358
            // here is hack for handle docid=john.10(in order to tell mike.jim.10.1
1359
            // mike.jim.10, we require to provide entire docid with rev). But
1360
            // some old client they only provide docid without rev, so we need
1361
            // to handle this suituation. First we will check how many
1362
            // seperator here, if only one, we will append the rev in xml_documents
1363
            // to the id.
1364
            docid = appendRev(docid);
1365
         
1358 1366
            DocumentImpl doc = new DocumentImpl(docid);
1359 1367

  
1360 1368
            //check the permission for read
......
2907 2915
    {
2908 2916
        return sessionHash;
2909 2917
    }
2918
    
2919
    /*
2920
     * If the given docid only have one seperter, we need 
2921
     * append rev for it. The rev come from xml_documents
2922
     */
2923
    private static String appendRev(String docid) throws Exception
2924
    {
2925
        String newAccNum = null;
2926
        String separator = MetaCatUtil.getOption("accNumSeparator");
2927
        int firstIndex = docid.indexOf(separator);
2928
        int lastIndex = docid.lastIndexOf(separator);
2929
        if (firstIndex == lastIndex)
2930
        {
2931
            
2932
           //only one seperater
2933
            int rev = DBUtil.getLatestRevisionInDocumentTable(docid);
2934
            if (rev == -1)
2935
            {
2936
                throw new Exception("Couldn't find the document "+docid);
2937
            }
2938
            else
2939
            {
2940
                newAccNum = docid+ separator+ rev;
2941
            }
2942
        }
2943
        else
2944
        {
2945
            // in other suituation we don't change the docid
2946
            newAccNum = docid;
2947
        }
2948
        MetaCatUtil.debugMessage("The docid will be read is "+newAccNum, 20);
2949
        return newAccNum;
2950
    }
2910 2951
}

Also available in: Unified diff