Changeset 8433 for mauRepo


Ignore:
Timestamp:
04/07/12 12:28:21 (7 years ago)
Author:
mnagni
Message:

Two main new features:
1) the migration generate a report. The report is sent by mail to the subscribers defined in the settings.py
2) require to display a missing observation adds a message on the page and hides the some fields in the html form
3) a new javascript library (commons.js)

Location:
mauRepo/MolesManager/trunk/src
Files:
1 added
14 edited

Legend:

Unmodified
Added
Removed
  • mauRepo/MolesManager/trunk/src/MolesManager/djencoder.py

    r8426 r8433  
    5151            else: 
    5252                self.__markers[id(value)] = value 
    53                 ''' 
    5453                if isinstance(value, str) or isinstance(value, unicode):                     
    5554                    self.__markers[id(value)] = escapeForJSON(value) 
    5655                else: 
    5756                    self.__markers[id(value)] = value 
    58                 ''' 
    5957        return d 
    6058 
    6159def encodeToJSON(toEncode): 
    62     return escapeForJSON(DJEncoder().encode(toEncode))     
     60    return DJEncoder().encode(toEncode)     
    6361     
    6462def escapeForJSON(toEscape): 
  • mauRepo/MolesManager/trunk/src/MolesManager/moles3epb.py

    r8430 r8433  
    104104        return EPB.searchEager(clazz, inst_id, self._session)      
    105105      
     106    def _controlledCommit(self): 
     107        try: 
     108            self._session.commit() 
     109        except Exception as e: 
     110            print e 
     111      
    106112    def persistInstance(self, instance): 
    107113        """ 
     
    111117            If None (default) a new Session is created from the underlying EPB and closed at the exit. 
    112118            @return an updated, session independent, object instance reflecting the new persisted object  
    113         """       
    114         EPB.persistInstance(instance, self._session) 
     119        """ 
     120        self._session.add(instance) 
     121        self._session.commit()      
    115122         
    116123       
     
    152159                    else: 
    153160                        setattr(coll, k, val) 
    154         self._session.commit() 
     161        self._controlledCommit() 
    155162        return coll                                       
    156163 
  • mauRepo/MolesManager/trunk/src/MolesManager/settings.py

    r8408 r8433  
    232232SERVE_STATIC_CONTENT = False 
    233233 
     234reportMigrationTo = ['maurizio.nagni@stfc.ac.uk', 'm.nagni@gmail.com'] 
     235 
    234236# Local modifications to settings are imported from settings_local.py 
    235237from settings_local import * 
  • mauRepo/MolesManager/trunk/src/MolesManager/static/js/cedaObservation.js

    r8426 r8433  
    1 define(['dojo', 'ceda/cedaol', 'dojox/lang/functional'], function(dojo, cedaol, functional){ 
     1define(['dojo', 'dojox/lang/functional', 'ceda/cedaol', 'ceda/common'], function(dojo, functional, cedaol, common){ 
    22        //console.log("loads cedaObservation.js") 
    33   // function <nameOfFunction>(parameter, parameter2..etc coming in){ 
     
    235235                } 
    236236                 
    237                  
    238237        require(['dojo/ready', 'dojo/parser', 'dijit/registry', 'dojo/_base/json', 'dojo/store/Memory', 
    239238                 'dijit/Tree', 'dijit/form/Button',  
     
    257256 
    258257                                var json = dojo.byId('coObs_id').value; 
     258                                if (json == ''){                                         
     259                                                var title_id  = new dojo.html.set(dojo.byId("title_id"),'<h3>The required item does not exist.</h3>'); 
     260                                                common.fadeOutNode("lower_section") 
     261                                                common.fadeOutNode("upper_section")                                      
     262                                                return 
     263                                } 
     264                                 
    259265                                var guid = dojo.byId('guid_id').value; 
    260266                                coObs = dojo.fromJson(json); 
     
    345351        }); 
    346352}); 
    347  
  • mauRepo/MolesManager/trunk/src/MolesManager/urls.py

    r8300 r8433  
    2121urlpatterns += patterns('MolesManager.views.cedaObservationView', 
    2222 
    23     (r'cov/(\d+)$', 'coView'), 
     23    (r'cov/(\w+)$', 'coView'), 
    2424) 
    2525 
  • mauRepo/MolesManager/trunk/src/MolesManager/views/cedaObservationView.py

    r8426 r8433  
    3434from django.core.context_processors import csrf 
    3535from MolesManager.djencoder import encodeToJSON 
    36 from django.utils.safestring import mark_safe 
     36#from django.utils.safestring import mark_safe 
    3737from ea_model.ceda_metadatamodel.ceda_observation.ceda_observation import CEDA_Observation 
    3838 
     
    4040 
    4141def coView(request, obs_id_str): 
    42     obs_id = int(obs_id_str) 
    43     return splash(request, obs_id)    
     42    record = None 
     43    try: 
     44        obs_id = int(obs_id_str) 
     45        record =  _getCedaObservation(request, obs_id)         
     46    except ValueError: 
     47        pass 
    4448 
    45 def splash(request, obs_id): 
    46     """ 
    47         Processes and display a given CEDA_Observation id 
    48         @param request: an HTTP request 
    49         @param obs_id: the CEDA_Observation id 
    50         @return: an HTTPResponse   
    51     """ 
    52     record = None 
    53     if obs_id: 
    54         record = _getCedaObservation(request, obs_id) 
    5549    return _finalizeResponse(request, record) 
    5650     
     
    5852    c = {} 
    5953    if record: 
    60         c['coObs'] = mark_safe(encodeToJSON(record)) 
     54        c['coObs'] = encodeToJSON(record) 
    6155        guid = request.moles3EPB.retrieveGUIDFromInstance(record) 
    6256        if guid: 
  • mauRepo/MolesManager/trunk/src/libs/epb.py

    r8425 r8433  
    3333from sqlalchemy.orm import subqueryload 
    3434from sqlalchemy.sql.expression import text 
    35 from sqlalchemy.orm.util import identity_key 
    3635 
    3736class EPB(object): 
     
    157156 
    158157    @classmethod 
    159     def persistInstance(cls, instance, session): 
    160         """ 
    161             Adds a new migration object. 
    162             @param migrationObj: the migration object to add 
    163             @param session: an sqlalchemy Session object. If None (default) the method creates 
    164             @return an updated, session independant, object instance reflecting the new persisted object  
    165         """         
    166         session.add(instance) 
    167         session.commit() 
    168         id_key = identity_key(instance=instance) 
    169         instance = EPB.search(id_key[0], id_key[1], session) 
    170         #instance = ret 
    171  
    172     @classmethod 
    173158    def executeNative(self, sqlNative, session): 
    174159        return session.execute(text(sqlNative))      
  • mauRepo/MolesManager/trunk/src/libs/migration/MigrationEPB.py

    r8424 r8433  
    3232    def close(self): 
    3333        return self._session.close() 
    34              
    35     def persistInstance(self, instance): 
    36         """ 
    37             Adds a new migration object. 
    38             @param migrationObj: the migration object to add 
    39             @param session: an SQLAlchemy Session object. If None (default) the method creates 
    40             @return an updated, session independent, object instance reflecting the new persisted object  
    41         """       
    42         EPB.persistInstance(instance, self._session) 
    43         #return ret 
    4434 
    4535    def getAllDeploymentsMigrationByDataEntitySortedByDate(self, dataEntity, deploymentNames): 
     
    10898                    else: 
    10999                        setattr(coll, k, val) 
    110         EPB.persistInstance(coll, self._session)                              
     100        self._session.add(coll) 
     101        self._session.commit()                             
    111102 
    112103    def search(self, clazz, inst_id): 
  • mauRepo/MolesManager/trunk/src/libs/migration/client.py

    r8358 r8433  
    3838from threading import Timer 
    3939from libs.migration.processor.EPBRepo import EPBRepo 
     40from django.core.mail import send_mail 
     41from MolesManager.settings import reportMigrationTo 
     42from datetime import datetime 
    4043 
    4144class MigrationThread(threading.Thread): 
     
    6770            if diffTime > 0: 
    6871                time.sleep(diffTime) 
    69      
    70     def _printTime(self): 
    71         print "From print_time", time.time()     
    7272 
    7373    def _migrate(self): 
    7474        lr = LoadResources(self.epbRepo) 
    7575        ex = lr.process() 
    76         for e in ex: 
    77             print e 
    7876 
    7977        mp = MigrationProcess(self.epbRepo) 
    80         ex = mp.process() 
    81         for e in ex: 
    82             print e 
     78        ex.extend(mp.process()) 
     79        generateMigrationReport(ex) 
     80             
     81def generateMigrationReport(messages): 
     82    report = "Migration Report - " + str(datetime.today())          
     83    for e in messages: 
     84        report = "%s\n\n%s" % (report, e) 
     85     
     86    send_mail('Migration Report', report, 'moles2.migration@ceda.rl.ac.uk', 
     87                  reportMigrationTo, fail_silently=False)         
  • mauRepo/MolesManager/trunk/src/libs/migration/exception/exceptions.py

    r8358 r8433  
    99        raise Exception("Migration object is None") 
    1010    try: 
    11         return "%s %s %s" % (migrationObject.doc_status, migrationObject.doc_owner, migrationObject.doc_name) 
     11        return "STATUS:%s OWNER:%s NAME:%s" % (migrationObject.doc_status, migrationObject.doc_owner, migrationObject.doc_name) 
    1212    except Exception as ex: 
    1313        print ex 
     
    4646        return "Error on migration object %s " % (migrationObjectDescription(self.migrationObject)) 
    4747 
     48class NoGeographicalExtensionException(MigrationObjectException): 
     49    """ 
     50        Raises a generic MigrationObject related exception.         
     51    """ 
     52    def __init__(self, migrationObject, comment = ''): 
     53        """ 
     54            Creates a new instance 
     55            @param migrationObject: the MigrationObject instance that raised the error 
     56            @param comment:additional comment  
     57        """ 
     58        super(NoGeographicalExtensionException, self).__init__(migrationObject, comment = '') 
     59    def __str__(self): 
     60        return "No Geographical Extension associated with migration object %s " % (migrationObjectDescription(self.migrationObject))     
     61     
     62class NoCitationException(MigrationObjectException): 
     63    """ 
     64        Raises a generic MigrationObject related exception.         
     65    """ 
     66    def __init__(self, migrationObject, comment = ''): 
     67        """ 
     68            Creates a new instance 
     69            @param migrationObject: the MigrationObject instance that raised the error 
     70            @param comment:additional comment  
     71        """ 
     72        super(NoCitationException, self).__init__(migrationObject, comment = '') 
     73    def __str__(self): 
     74        return "No cedacat:citation associated with migration object %s " % (migrationObjectDescription(self.migrationObject))     
     75 
    4876class NoAssociatedAuthor(MigrationObjectException): 
    4977    """ 
     
    5785 
    5886class NoAssociatedDeployments(Exception): 
    59     def __init__(self, data_entityMigration, deploymentName = None): 
     87    def __init__(self, migrationObject, deploymentName = None): 
    6088        """ 
    61             @param data_entityMigration: the data_entity migration associated 
     89            @param migrationObject: the associated migrationObject 
    6290            @param deploymentName: the associated deployment document name  
    6391        """ 
    64         self._migrationObject = data_entityMigration 
     92        self._migrationObject = migrationObject 
    6593        self._deploymentName = deploymentName         
    6694        super(NoAssociatedDeployments, self).__init__() 
    6795    def __str__(self): 
    6896        if self._deploymentName: 
    69             return "The DataEntity %s has no associated deployment named %s" % (migrationObjectDescription(self.migrationObject), self._deploymentName) 
     97            return "The DataEntity %s has no associated deployment named %s" % (migrationObjectDescription(self._migrationObject), self._deploymentName) 
    7098        else: 
    71             return "The DataEntity %s has no associated deployment" % (migrationObjectDescription(self.migrationObject)) 
     99            return "The DataEntity %s has no associated deployment" % (migrationObjectDescription(self._migrationObject)) 
    72100     
    73101class NoDataLineage(MigrationObjectException): 
     
    76104    """     
    77105    def __init__(self, migrationObject, comment = ''):         
    78         super(NoDataLineage, self).__init__(migrationObject, comment = '') 
     106        super(NoDataLineage, self).__init__(migrationObject, comment = '')         
  • mauRepo/MolesManager/trunk/src/libs/migration/processor/commons.py

    r8424 r8433  
    5454from ea_model.moles3_4.utilities.mo_individual import MO_Individual 
    5555from ea_model.moles3_4.utilities.mo_organisation import MO_Organisation 
    56 from ea_model.moles3_4.utilities import mo_organisation 
    5756from ea_model.iso_19115_2006_metadata_corrigendum.citation_and_responsible_party_information.ci_date import CI_Date 
    5857from ea_model.iso_19115_2006_metadata_corrigendum.citation_and_responsible_party_information.ci_citation import CI_Citation 
     
    780779        Creates a new MD_Identifier 
    781780        @param code: a String 
    782         @param authority: a CI_Citation instance 
     781        @param authority: a CI_Citation instance  
    783782    """ 
    784783    md_identifier = MD_Identifier() 
     784    if code == None: 
     785        raise NoNullableElement() 
    785786    md_identifier.code = code 
    786787    if authority: 
     
    933934    if project_resource and type(project_resource) == list: 
    934935        ceda_project.projectResource = project_resource    
    935     return ceda_project     
     936    return ceda_project 
     937     
  • mauRepo/MolesManager/trunk/src/libs/migration/processor/dataEntity.py

    r8424 r8433  
    3232''' 
    3333from libs.migration.exception.exceptions import MigrationObjectException, NoAssociatedAuthor,\ 
    34     migrationObjectDescription, NoAssociatedDeployments 
     34    migrationObjectDescription, NoAssociatedDeployments,\ 
     35    NoGeographicalExtensionException, NoCitationException 
    3536from libs.migration.processor.commons import findDeploymentsInDE,\ 
    3637    createMD_Identifier, extractContent,\ 
     
    6970        self._dataEntityHasBeenProcessed = hasMOBeenProcessed(self._dataEntityMigration)    
    7071        self.epbRepo = epbRepo 
     72        self._report = [] 
    7173 
    7274    def _assignGeographicExtent(self, ceda_observationCollection): 
     
    8486            self.epbRepo.moles3EPB.updateCedaObject(ceda_observationCollection, {'geographicExtent': geographicExtent})                         
    8587        else: 
    86             print "No Geographic Extent" 
    87         return           
     88            self._report.append(NoGeographicalExtensionException(self._dataEntityMigration))           
    8889         
    8990 
     
    109110         
    110111        if self._dataEntityHasBeenProcessed: 
     112            self._report.append('The _assignGeographicExtent update is skipped because not implemented') 
    111113            DataEntityProcessor.log.warn('The _assignGeographicExtent update is skipped because not implemented') 
    112114            return 
     
    117119        contentDict = extractContent(self._dataEntityMigration) 
    118120        if not contentDict.has_key('citation'): 
     121            self._report(NoCitationException(self._dataEntityMigration)) 
    119122            DataEntityProcessor.log.info("The migration object "+ migrationObjectDescription(self._dataEntityMigration) \ 
    120123                                         + " has not associated cedacat:citation") 
     
    199202        except NoAssociatedAuthor as ex: 
    200203            raise ex                  
    201         except Exception as ex: 
    202             #self.migrationSessions.molesSession.rollback() 
    203             #self.migrationSessions.migrationSession.rollback()                
     204        except Exception as ex:                
    204205            raise MigrationObjectException(ex)                      
    205206         
     
    219220            self._execute(obsColl)                  
    220221        except Exception as ex: 
    221             exs.append(ex) 
    222             return exs         
     222            self._report.append(ex) 
     223            return self._report       
    223224         
    224225        #retrieves the associated deployment links from the data_entity 
     
    229230     
    230231        if deploymentMigrations is None or len(deploymentMigrations) == 0: 
    231             return exs 
    232          
    233         howManydm = 0 
    234         if deploymentMigrations: 
    235             howManydm = len(deploymentMigrations) 
    236         if howManydm == 0: 
    237             exs.append(NoAssociatedDeployments(self._dataEntityMigration)) 
     232            self._report.append(NoAssociatedDeployments(self._dataEntityMigration)) 
     233            return self._report 
     234         
     235        howManydm = len(deploymentMigrations)             
    238236        for deploymentMigration in deploymentMigrations: 
    239237            try: 
     
    244242                                       
    245243            except Exception as ex: 
    246                 exs.append(ex)                 
     244                self._report.append(ex)                 
    247245        self._assignGeographicExtent(obsColl) 
    248246           
    249         return exs 
     247        return self._report 
  • mauRepo/MolesManager/trunk/src/libs/migration/processor/migrationProcess.py

    r8361 r8433  
    6767            dep = DataEntityProcessor(dataEntityMigration, self.epbRepo)             
    6868            exs.extend(dep.process()) 
    69             MigrationProcess.log.info("Done")             
    7069        return exs 
  • mauRepo/MolesManager/trunk/src/libs/migration/tests/migrationprocess.py

    r8391 r8433  
    4444from libs.migration.InfodbEPB import InfodbEPBFactory 
    4545from MolesManager.settings import EVENTS_DB 
    46 from libs.migration.client import EPBRepo 
     46from libs.migration.client import EPBRepo, generateMigrationReport 
     47from django.core.mail import send_mail 
    4748 
    4849class LoadResourceTest(TestCase): 
     
    9091         
    9192        #IASI 
    92         #self.processDataEntity(DO_NEODC, DS_pUBLISHED, 'dataent_12417810458627666.atom') 
    93         #self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_VIRTEM.atom') 
    94         #self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_12162569915925921.atom') 
     93        self.processDataEntity(DO_NEODC, DS_pUBLISHED, 'dataent_12417810458627666.atom') 
     94        self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_VIRTEM.atom') 
     95        self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_12162569915925921.atom') 
    9596               
    9697        #ECMWF 
    97         #self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_ECMWF-ERA.atom') 
    98         #self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_ECMWF-OP.atom') 
    99         #self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_12458543158227759.atom')                 
    100         #self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_ECMWF-E40.atom') 
    101         #self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_ECMWF-TRJ.atom')                 
     98        self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_ECMWF-ERA.atom') 
     99        self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_ECMWF-OP.atom') 
     100        self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_12458543158227759.atom')                 
     101        self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_ECMWF-E40.atom') 
     102        self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_ECMWF-TRJ.atom') 
     103         
     104         
     105        self.processDataEntity(DO_NEODC, DS_pUBLISHED, 'dataent_11750994700119761.atom') 
     106        self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_ECMWF-TRJ.atom') 
     107        self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_UGAMPO3.atom') 
     108        self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_12282368470627062.atom')                         
     109         
     110        #self.processDataEntity()               
    102111 
    103112         
    104     def processDataEntity(self, doc_owner, doc_status, doc_name): 
    105         dataEntity = MigrationObject() 
    106         dataEntity.doc_owner = doc_owner         
    107         dataEntity.doc_status = doc_status 
    108         dataEntity.doc_name = doc_name 
     113    def processDataEntity(self, doc_owner = None, doc_status = None, doc_name = None): 
     114        dataEntity = None 
     115        if doc_owner is not None and doc_status is not None and doc_name is not None: 
     116            dataEntity = MigrationObject() 
     117            dataEntity.doc_owner = doc_owner         
     118            dataEntity.doc_status = doc_status 
     119            dataEntity.doc_name = doc_name 
    109120        ex = self.mp.process(dataEntity) 
    110         for e in ex: 
    111             print e 
    112          
     121        generateMigrationReport(ex) 
    113122 
Note: See TracChangeset for help on using the changeset viewer.