source: mauRepo/MolesManager/trunk/src/libs/migration/processor/check/check.py @ 8147

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/MolesManager/trunk/src/libs/migration/processor/check/check.py@8147
Revision 8147, 3.2 KB checked in by mnagni, 8 years ago (diff)

Implementation of tickets #22390

Line 
1'''
2Created on 2 Feb 2012
3
4@author: mnagni
5'''
6from libs.migration.exception.exceptions import Moles3ObjectException
7def _updateParty(oldParty, newParty):
8    pass
9
10def _checkParty(oldParties, newParties): 
11    for oldParty in oldParties:
12        for newParty in newParties:
13            if oldParty.name == newParty.name:
14                #here shoud update the oldParty (CI_Individual or CI_Organization)
15                _updateParty(oldParty, newParty)
16                newParties.remove(newParty)
17
18def checkResponsiblePartyInfos(oldPartyInfos, newPartyInfos):   
19    for newPartyInfo in newPartyInfos:
20        if not newPartyInfo in oldPartyInfos:
21            oldPartyInfos.append(newPartyInfo)
22        else:       
23            for oldPartyInfo in oldPartyInfos:
24                if oldPartyInfo.role == newPartyInfo.role:
25                    _checkParty(oldPartyInfo.party, newPartyInfo.party)
26           
27def observationHasTitle(mo_observation, title):
28    for identifier in mo_observation.identifier:
29        if identifier.authority and identifier.authority.title == title:
30            return True
31    return False
32
33def observationHasQuality(mo_observation, quality):
34    for rq in mo_observation.resultQuality:
35        for res in rq.result:
36            if hasattr(res, 'explaination') and res.explaination == quality:
37                return True
38    return False
39           
40def checkLineage(ceda_observation, newLineage):
41    if ceda_observation.dataLineage != newLineage:
42        ceda_observation.dataLineage = newLineage
43
44def checkObservation(old_ceda_observation, ceda_observation):
45    if old_ceda_observation == ceda_observation:
46        return old_ceda_observation
47    else:
48        return ceda_observation
49       
50def checkObservationCollection(ceda_observationCollection, ceda_observation):
51    if hasattr(ceda_observation, 'id'):
52        for old_ceda_observation in ceda_observationCollection.member:
53            if old_ceda_observation.id == ceda_observation.id:
54                #if here the relation already exists
55                return
56
57        moles3Append(ceda_observationCollection, 'member', ceda_observation)
58       
59def moles3Append(parent, collectionAttributeName, itemToAppend):
60    """
61        Appends a new item to a Moles3 object.
62        Because of the inheritance/composition structure of the Moles3 objects the associated ORM
63        has problem to simpy append an item to an existing ORM-controlled list. This method
64        copies all the existing items in a new list then append the new item and finally assign the
65        new list to the parent proper collection
66        @param parent: the instance containing the collection to update
67        @param collectionAttributeName: the name of the collection to update
68        @param itemToAppend: the item to append to the collectionAttribute list       
69    """   
70   
71    if not hasattr(parent, collectionAttributeName):
72        raise Moles3ObjectException()
73   
74    assign = []
75    assign.extend(getattr(parent, collectionAttributeName))
76    assign.append(itemToAppend)
77    try:
78        setattr(parent, collectionAttributeName, assign)
79    except Exception as e:
80        print e
81                     
82               
83 
84               
Note: See TracBrowser for help on using the repository browser.