Ignore:
Timestamp:
08/12/08 16:20:26 (11 years ago)
Author:
cbyrom
Message:

Simplify upload of CSML/CDML/granulite data by using the newly extended
granulite class for all these ops - remove unecessary code in editatom.
Add new template function to combine the upload of CSML/CDML files into
a single field - with additional inputs for time axis and dataset ID data.
Fix editor to display deployments data for DEs once again.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • MILK/trunk/milk_server/milk_server/controllers/atom_editor/editatom.py

    r4556 r4563  
    55 @author: C Byrom, Tessella Sep 2008 
    66''' 
    7 import logging, traceback, sys, cgi 
     7import logging, traceback, sys, cgi, xmlrpclib 
    88from paste.request import parse_querystring 
    99from xml.parsers.expat import ExpatError 
     
    2525from ndgUtils.lib.utilities import escapeSpecialCharacters 
    2626from ndgUtils.vocabtermdata import VocabTermData as VTD 
    27 from granulatorTool.granulite import granulite as granulite 
     27from ndgUtils.lib.granulite import granulite 
    2828 
    2929class EditatomController(BaseController): 
     
    6363        c.xml = escapeSpecialCharacters('Unexpected error loading page [%s]' \ 
    6464                                        %str(errorMessage)) 
    65         c.doc='' 
     65        c.doc = '' 
    6666         
    6767        # unpack errors, if possible - NB, the c.errors value is used by the template 
    6868        # function, displayErrors, which is used by most of the editor templates 
     69        if isinstance(e, xmlrpclib.Fault): 
     70            # strip out the exception type - NB, this is usually native library code 
     71            # and is of no real interest - and will just confuse viewers 
     72            c.errors['Unexpected error'] = e.faultString.split(':')[-1]  
    6973        if hasattr(e, 'unpack_errors'): 
    7074            c.errors.update(e.unpack_errors()) 
     75             
    7176        else: 
    7277            c.errors['Unexpected error'] = [c.xml] 
     
    98103    def upload(self, uri): 
    99104        ''' 
    100         Upload a CSML or granulite file and store it in the session variable 
     105        Upload a CSML, CDML or granulite file and store it in the session variable 
    101106        NB, if the uri is specified, we're already dealing with an atom  
    102107        (which this refers to) - so the file is not a granulite - since  
    103         this is used to create the atom 
     108        this is used to create an atom from scratch 
    104109        ''' 
    105110        logging.info("Uploading file...") 
    106111        self.__setup(uri=uri) 
    107         if uri: 
    108             file = request.POST.get('upload_CSML') 
    109         else: 
    110             file = request.POST.get('upload_granulite') 
    111  
     112        inputs = self.__getTidyInputs() 
     113         
     114        granFile = request.POST.get('upload_granulite') 
     115        csmlOrCdmlFile = request.POST.get('CSMLOrCDML') 
     116          
    112117        c.errors = {} 
    113118        try: 
    114             if file == '': 
     119            useCSMLID = True 
     120            c.atom = None 
     121            if uri: 
     122                self.prepareDataModel(uri) 
     123                useCSMLID = False 
     124 
     125            if (granFile == '' or granFile == None) and \ 
     126                (csmlOrCdmlFile == '' or csmlOrCdmlFile == None): 
    115127                errorMessage = "Error: could not load file - please try again" 
    116128                logging.error(errorMessage) 
    117129                raise IOError(errorMessage) 
    118130            else: 
    119                 logging.debug("- file name: '%s'" %file.name) 
    120  
    121131                # Prepare the basic data model 
    122132                # NB, if loading a granulite, this will create the displayed atom 
    123                 if uri: 
    124                     self.prepareDataModel(uri) 
    125                 else: 
    126                     c.atom = Atom() 
     133                # with the ID taken from the CSML file, if specified 
     134                fileContents = None 
     135                if (granFile is not None and granFile != ''): 
     136                    fileContents = granFile.value 
     137                     
     138                # use the granulite helper class to add either the full granulite 
     139                # data or just the CSML/CDML data 
     140                # NB, we'll be creating the atom in the default local eXist 
     141                eXistClient = self.__getExistClient('local') 
     142                gran = granulite(fileContents, granuleAtom = c.atom, \ 
     143                                 eXistClient = eXistClient, \ 
     144                                 csmlOrCdmlFile = csmlOrCdmlFile, \ 
     145                                 timeAxis = inputs.get('timeAxis'), \ 
     146                                 datasetID = inputs.get('datasetID'), \ 
     147                                 useCSMLID = useCSMLID) 
    127148 
    128149                # now process the input file and add any extra required data 
    129150                if uri: 
    130                     self.__processCSMLFile(file) 
     151                    c.atom = gran.processCSMLOrCDMLFile() 
    131152 
    132153                    # save new data - NB, for granulites, this is done as part of the 
     
    134155                    self.saveAtomToExist(c.atom) 
    135156                else: 
    136                     self.__processGranuliteFile(file.value) 
     157                    c.atom = gran.processGranulite() 
     158 
    137159                    # Now set up the ndgObject with the created atom's vals 
    138160                    self.__setup(uri=c.atom.ndgURI) 
    139161                    c.atom.ndgObject = self.ndgObject 
    140                  
    141162                             
    142163                # now do redirection - NB, this ensures that current atom contents are 
     
    155176        else: 
    156177            return self.createGranule() 
    157  
    158  
    159     def __processCSMLFile(self, file): 
    160         ''' 
    161         Accept the contents of a CSML file and extract and add appropriate data 
    162         to the current atom data model 
    163         @param fileContents: contents of the file uploaded 
    164         ''' 
    165         logging.info("Extracting CSML data") 
    166         csmlDoc = c.atom.addCSMLData(file.filename, file.value) 
    167         logging.info("Finished extracting CSML data") 
    168          
    169         logging.info("Adding CSML file to eXist") 
    170         eXist = self.__getExistClient(c.atom.ME.providerID) 
    171         eXist.createOrUpdateEXistFile(csmlDoc.toPrettyXML(), \ 
    172                                       eXistConnector.NDG_A_COLLECTION_PATH + \ 
    173                                       c.atom.ME.providerID + '/', \ 
    174                                       file.filename) 
    175         logging.info("CSML file added to eXist") 
    176  
    177      
    178     def __processGranuliteFile(self, fileContents): 
    179         ''' 
    180         Accept the contents of a granulite file and extract and add appropriate data 
    181         to the current atom data model 
    182         @param fileContents: contents of the file uploaded 
    183         ''' 
    184         logging.info("Processing granulite data") 
    185         # check for uploaded CSML/CDML file data 
    186         cdmlFile = request.POST.get('upload_cdml') 
    187         csmlFile = request.POST.get('upload_csml') 
    188         if cdmlFile and csmlFile: 
    189             raise ValueError("Cannot specify both CDML and CSML file - please choose a single one to ingest.") 
    190          
    191         # NB, we'll be creating the atom in the default local eXist 
    192         eXistClient = self.__getExistClient('local') 
    193         gran = granulite(fileContents, eXistClient = eXistClient, \ 
    194                          cdmlFile = cdmlFile, csmlFile = csmlFile) 
    195         c.atom = gran.processGranulite() 
    196          
    197         logging.info("Finished processing granulite data") 
    198178 
    199179 
     
    261241            g.validator.validateAtom() 
    262242            logging.info("- input valid") 
    263         except ValidationError, e: 
     243 
     244            self.saveAtomToExist(c.atom) 
     245        except Exception, e: 
    264246            self.__unpackErrors(e) 
    265247            logging.info("- input invalid") 
    266248            return self.edit(uri) 
    267  
    268         self.saveAtomToExist(c.atom) 
    269249                     
    270250        # now do redirection - NB, this ensures that current atom contents are 
     
    692672 
    693673        except Exception, e: 
     674            import pdb 
     675            pdb.set_trace() 
    694676            return self.__handleError(e) 
Note: See TracChangeset for help on using the changeset viewer.