Project

General

Profile

« Previous | Next » 

Revision 2337

Added by Jing Tao almost 20 years ago

Add a new method to get newest version of a given document.

View differences:

src/edu/ucsb/nceas/metacat/client/MetacatClient.java
623 623
    {
624 624
        this.sessionId = sessionId;
625 625
    }
626
    
627
    /**
628
     * The method will return the lasted revision in metacat server 
629
     * for a given document id. If some error happent, this method will throw
630
     * a exception.   
631
     * @param docId String  the given docid you want to use. the docid it self
632
     *                      can have or haven't revision number
633
     * @throws MetacatException
634
     */
635
     public int getNewestDocRevision(String docId) throws MetacatException
636
     {
637
       int rev = 0;
638
       //set up properties
639
       Properties prop = new Properties();
640
       prop.put("action", "getrevisionanddoctype");
641
       prop.put("docid", docId);
642
       
643
       String response = null;
644
        try 
645
        {
646
            response = sendDataForString(prop, null, null, 0);
647
            String revStr = parserRevisionResponse(response);
648
            Integer revObj = new Integer(revStr);
649
            rev = revObj.intValue();
650
            // Check for an error condition
651
           if (response.indexOf("<error>") != -1) 
652
           {
653
              throw new MetacatException(response);
654
           }
626 655

  
656
        } 
657
        catch (Exception e) 
658
        {
659
            throw new MetacatException(e.getMessage());
660
        }
661
        return rev;
662
     }
663

  
664

  
627 665
    /************************************************************************
628 666
     * PRIVATE METHODS
629 667
     ************************************************************************/
......
746 784
        }
747 785
        return response;
748 786
    }
787
    
788
    /*
789
     * "getversionanddoctype" action will return a string from metacat server.
790
     * The string format is "revision;doctype"(This is bad idea, we should use xml)
791
     * This method will get revision string from the response string
792
     */
793
    private String parserRevisionResponse(String response) throws Exception
794
    {
795
      String revision = null;
796
      if (response != null)
797
      {
798
        int firstSemiCol = response.indexOf(";");
799
        revision = response.substring(0, firstSemiCol);
800
      }
801
      return revision;
802
    }
749 803
}

Also available in: Unified diff