Changeset 3128 for exist/trunk


Ignore:
Timestamp:
07/12/07 14:09:53 (12 years ago)
Author:
lawrence
Message:

The dif2moles round tripping is in place (but the comparison doesn't
work and needs analysis).

Location:
exist/trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • exist/trunk/python/ndgUtils/eXistConnector.py

    r3110 r3128  
    105105        return r 
    106106     
     107    def removeCollection(self,collectionPath): 
     108        ''' Remove a collection in the eXist database ''' 
     109        r=self.xmlrpc.removeCollection(collectionPath) 
     110        return r 
     111     
     112    def createCollection(self,collectionPath): 
     113        ''' Create a collection in the eXist database at collectionPath ''' 
     114        r=self.xmlrpc.createCollection(collectionPath) 
     115        return r 
     116     
     117    def storeXML(self,xml,path,overwrite=0): 
     118        ''' Store some XML into the databse at path ''' 
     119        return self.xmlrpc.parse(xml,path) 
     120         
    107121  
  • exist/trunk/python/ndgUtils/test_eXistInterface.py

    r3110 r3128  
    3131            for i in range(summary['hits']): print host,xmldb.retrieveNext(id,i) 
    3232            xmldb.release(id) 
     33             
     34    def test_manipulateCollections(self): 
     35        ''' Test we can create a collection ''' 
     36        dummy='/db/scratchBNL' 
     37        #just use the first one in our file ... 
     38        hosts=self.pw.keys() 
     39        xmldb=ndg_eXist(db=hosts[0]) 
     40        r=xmldb.createCollection(dummy) 
     41        self.assertEqual(True,r,'unable to create collection') 
     42        r=xmldb.removeCollection(dummy) 
     43        self.assertEqual(True,r,'unable to remove collection') 
    3344 
    3445    #def test_xqueryLib(self): 
  • exist/trunk/python/ndgUtils/test_xqueries.py

    r3127 r3128  
     1 
     2##  
     3## This test file has the more sophisticated, data aware tests  
     4## 
     5 
    16import unittest 
    2 import ndgXqueries 
     7from ndgXqueries import ndgXqueries 
    38from eXistInterface import ndg_eXist 
    49from ndgObject import ndgObject 
    510import ConfigParser 
     11from xmlrpclib import Fault 
    612 
    713class TestCase(unittest.TestCase): 
     
    1117        self.c=ConfigParser.ConfigParser() 
    1218        self.c.read(f) 
    13         self.xq=ndgXqueries.ndgXqueries() 
     19        self.xq=ndgXqueries() 
    1420        self.xmldb=ndg_eXist(db='glue.badc.rl.ac.uk') 
    1521        self.testDElist=['badc.nerc.ac.uk__NDG-B1__dataent_COAPEC'] 
     22     
     23    def _getmoles(uri,targetCollection): 
     24        ''' Returns a moles document by URI from targetCollection ''' 
     25        n=ndgObject(uri) 
     26        xq=self.xq.actual('moles',targetCollection,n.repository,n.localID) 
     27        id,s=self.xmldb.executeQuery(xq) 
     28        self.assertEqual(s['hits'],1,'Unable to get unique %s'%uri) 
     29        return self.retrieve(id,1) 
    1630         
     31    def test_DIFlist(self): 
     32        ''' Test the DIF listing query on glue ''' 
     33        xq=self.xq['DIFList'] 
     34        xq=xq.replace('TargetCollection','/db/discovery/original/DIF') 
     35        r=self.xmldb.executeChunkedQuery(xq,1,1) 
     36        print r 
     37 
    1738    def test_moles2difRoundTrip(self): 
    1839        ''' Tests the moles 2 dif round tripping ''' 
     40        # start by choosing an existing NDG moles data entity 
    1941        moles1=self.testDElist[0] 
    2042        dif1=moles1.replace('NDG-B1','DIF') 
     43        n=ndgObject(dif1) 
     44         
     45        # handling the DIF 
     46        targetCollection='/db/discovery/original/DIF/%s'%n.repository 
     47        difName=n.uri+'.xml' 
     48        dif1_original=self.xmldb.getDoc(targetCollection,difName) 
     49        self.assertEqual(dif1_original[0:4],'<DIF','unable to load raw dif file %s'%difName) 
     50         
     51        # now sort out the output ID stuff ... 
     52        xquery=self.xq.actual('dif2moles',targetCollection,n.repository,n.localID) 
     53        # and then sort out the input ID stuff 
     54        difid=n.uri.replace('__',':') 
     55        xquery=xquery.replace('Input_Entry_ID',difid) 
     56        xquery=xquery.replace('repository_localid','badc') 
     57        #xquery='''for $s in xmldb:get-child-collections('%s') return <collection>{$s}</collection>'''%targetCollection 
     58         
     59        # and deliver the xquery ... 
     60        id,s=self.xmldb.executeQuery(xquery) 
     61        self.assertEqual(1,s['hits'],'Should have had one moles document returned!') 
     62        moles_from_dif1=self.xmldb.retrieve(id,0) 
     63        self.xmldb.release(id) 
     64         
     65        # now load it back into exist 
     66        dummyCollection='/db/scratchUtilTest' 
     67        # but first check the dummyCollection doesn't exist, and if it does, get rid of it 
     68        xq='''for $s in xmldb:get-child-collections('/db') return <collection>/db/{$s}</collection>''' 
     69        id,s=self.xmldb.executeQuery(xq) 
     70        collections=[self.xmldb.retrieveNext(id,i) for i in range(s['hits'])] 
     71        self.xmldb.release(id) 
     72        if '<collection>%s</collection>'%dummyCollection in collections:  
     73            ok=self.xmldb.removeCollection(dummyCollection) 
     74            self.assertEqual(True,ok,'We needed to delete the scratch collection!') 
     75        #ok, now we can goahed and create the collection and stuff the file into it 
     76        ok=self.xmldb.createCollection(dummyCollection) 
     77        self.assertEqual(True,ok,'Unable to createCollection') 
     78        moles2=ndgObject(n.uri.replace('DIF','NDG-B0')) 
     79        dummyFile='%s/%s'%(dummyCollection,moles2.uri) 
     80        ok=self.xmldb.storeXML(moles_from_dif1,dummyFile) 
     81        self.assertEqual(True,ok,'Unable to upload xml file') 
     82         
     83        # now let's see what we get for a dif back from that moles document! 
     84        xquery=self.xq.actual('moles2dif',dummyCollection,moles2.repository,moles2.localID) 
     85        id,s=self.xmldb.executeQuery(xquery) 
     86        self.assertEqual(1,s['hits'],'Should have had one dif document returned!') 
     87        dif1_from_moles=self.xmldb.retrieve(id,0) 
     88         
     89        #are they the same? 
     90        self.assertEqual(dif1_from_moles,dif1_original) 
    2191         
    2292         
    23          
    24          
     93      
    2594if __name__=="__main__": 
    2695    unittest.main() 
  • exist/trunk/xquery/dif2moles.xq

    r3100 r3128  
    1 (: Version for one DIF per dgMetadata instance :) 
     1(: This query produces one MOLES data entity plus one organisation entry for a given DIF instance 
     2   Input is TargetCollection (where the DIF exists), RepositoryID, where the existing DIF lies, and 
     3   expected to be the output RepositoryID (fix it in the output xml if it's wrong), and Input_EntryID 
     4   which is the DIF entryID, and LocalID which is the output localID for the data entity. We also 
     5   need the localID for the organisation entity, which appears as repository_localid 
     6   :) 
    27(: Note algoritm for creating non-pre-existing organisations :) 
    38(: dgPersons are not created as one can't tell automatically which are people and which are orgs, and orgs are simpler :)   
     
    813declare namespace xsi='http://www.w3.org/2001/XMLSchema-instance';  
    914 
     15(: Keep as an example, but note the entryID in the dif is an 
     16   NDG format ID, so the example isn't as obvious .... 
     17declare variable $targetCollection as xs:string {'/db/discovery/original/ndg.noc.soton.ac.uk'}; 
     18declare variable $input_repository as xs:string {'ndg.noc.soton.ac.uk'}; 
     19declare variable $input_repository_local as xs:string {'nocs'}; 
     20declare variable $input_entry_id as xs:string {'ndg.noc.soton.ac.uk__DIF__NOCSDAT110'}; 
     21declare variable $output_local_id as xs:string {'NOCS_DAT110'}; 
     22:) 
    1023(: Replacable parameters :) 
    11 declare variable $targetCollection as xs:string {'/db/discovery'}; 
    12 declare variable $input_repository as xs:string {'Input_Repository_Code'}; 
    13 declare variable $input_repository_local as xs:string {'Input_Repository_LocalID'}; 
    14 declare variable $input_entry_id as xs:string {'ndg.noc.soton.ac.uk__DIF__NOCSDAT110'}; 
    15 declare variable $localIdentifier as xs:string {'ndg.noc.soton.ac.uk__DIF__NOCSDAT110'}; 
     24declare variable $targetCollection as xs:string {'TargetCollection'}; 
     25declare variable $input_repository as xs:string {'RepositoryID'}; 
     26declare variable $input_repository_local as xs:string {'repository_localid'}; 
     27declare variable $input_entry_id as xs:string {'Input_Entry_ID'}; 
     28declare variable $output_local_id as xs:string {'LocalID'}; 
    1629 
    17 declare variable $output_local_id as xs:string {'Output_LocalID'}; 
    18 (: Keep 
    19 declare variable $targetCollection as xs:string {'TargetCollection'}; 
    20 declare variable $input_repository as xs:string {'Input_Repository_Code'}; 
    21 declare variable $input_repository_local as xs:string {'Input_Repository_LocalID'}; 
    22 declare variable $input_entry_id as xs:string {'Input_Entry_ID'}; 
    23 declare variable $output_local_id as xs:string {'Output_LocalID'}; 
    24 :) 
    2530for $DIF in collection($targetCollection)/dif:DIF[dif:Entry_ID=$input_entry_id] 
    2631return 
Note: See TracChangeset for help on using the changeset viewer.