source: mauRepo/CedaMolesModel/trunk/ceda_moles_model/ea_model/informative/iso_gdf/gdf_feature/gdf_featureclass.py @ 8437

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/CedaMolesModel/trunk/ceda_moles_model/ea_model/informative/iso_gdf/gdf_feature/gdf_featureclass.py@8437
Revision 8437, 3.7 KB checked in by mnagni, 7 years ago (diff)

Added a new function to ascore.utils in order to synchronize classes before committing to database

The following constraints has been added to the official model:

MO_ObservationCollection:member:CEDA_Observation
MO_ObservationCollection:phenomenonTime:TM_GeometricPrimitive
MO_Project:observationCollection:CEDA_ObservationCollection
MO_Observation:result:CEDA_Result
MO_Observation:inSupportOf:CEDA_Project
MO_Project:subProject:CEDA_Project
OM_Observation:procedure:CEDA_Process
OM_Observation:phenomenonTime:TM_GeometricPrimitive
MO_ResponsiblePartyFunctionValue:CEDA_RoleValue

  • Property svn:mime-type set to text/plain
Line 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21from ascore.utils import has_value, collectionProofHash
22
23'''
24Created on 06-Jul-2012 07:43:11
25
26@author: mnagni
27'''
28
29class GDF_FeatureClass(object):
30        '''
31                Represents a data entity defined in a UML diagram and supposed to
32                be persisted in a relational database.
33 
34                This class has been genererated automatically using the Apache Velocity project.
35        '''
36        '''
37                Please note that any access to the inner attributes should be done using
38                the given get/set methods and NOT accessing them directly.
39        '''
40        def __init__(self):
41
42                self.name = None
43                self._belongsTo_gdf_simplefeature = []
44                self._belongsTo_gdf_complexfeature = []
45                self._belongsTo = []
46                self.code = None
47                self._character_gdf_simpleattributetype = None
48                self._character_gdf_complexattributetype = None
49                self._character_gdf_restrictedsubattributetype = None
50                self._character = None
51                self.represents = []
52                self.theme = None
53                super(GDF_FeatureClass, self).__init__()
54        @property
55        def belongsTo(self):   
56                try:
57                        ret = []
58                        ret.extend(self._belongsTo_gdf_simplefeature)
59                        ret.extend(self._belongsTo_gdf_complexfeature)
60                        if not hasattr(self, '_belongsTo'):
61                                self._belongsTo = []
62                        if self._belongsTo is not None:
63                                ret.extend(self._belongsTo)
64                        del self._belongsTo[:]
65                        self._belongsTo.extend(set(ret))
66                except Exception as e:
67                        pass
68                return self._belongsTo
69
70        @property
71        def character(self):   
72                if(has_value(self._character_gdf_simpleattributetype)):
73                        return self._character_gdf_simpleattributetype
74                if(has_value(self._character_gdf_complexattributetype)):
75                        return self._character_gdf_complexattributetype
76                if(has_value(self._character_gdf_restrictedsubattributetype)):
77                        return self._character_gdf_restrictedsubattributetype
78                return  None
79
80        @character.setter
81        def character(self, value):     
82                valueClass = "%s.%s" % (type(value).__module__,type(value).__name__)
83                if valueClass == "ea_model.informative.iso_gdf.gdf_feature.gdf_simpleattributetype.GDF_SimpleAttributeType":
84                        self._character_gdf_simpleattributetype = value
85                        self._character_gdf_complexattributetype = None
86                        self._character_gdf_restrictedsubattributetype = None
87                if valueClass == "ea_model.informative.iso_gdf.gdf_feature.gdf_complexattributetype.GDF_ComplexAttributeType":
88                        self._character_gdf_complexattributetype = value
89                        self._character_gdf_simpleattributetype = None
90                        self._character_gdf_restrictedsubattributetype = None
91                if valueClass == "ea_model.informative.iso_gdf.gdf_feature.gdf_restrictedsubattributetype.GDF_RestrictedSubAttributeType":
92                        self._character_gdf_restrictedsubattributetype = value
93                        self._character_gdf_simpleattributetype = None
94                        self._character_gdf_complexattributetype = None
95
96        def synchronize(self):
97                del self._belongsTo_gdf_simplefeature[:]
98                del self._belongsTo_gdf_complexfeature[:]
99                for item in self.belongsTo:     
100                        valueClass = "%s.%s" % (type(item).__module__,type(item).__name__)
101                        if valueClass == "ea_model.informative.iso_gdf.gdf_feature.gdf_simplefeature.GDF_SimpleFeature":
102                                self._belongsTo_gdf_simplefeature.append(item)
103                                continue
104                        valueClass = "%s.%s" % (type(item).__module__,type(item).__name__)
105                        if valueClass == "ea_model.informative.iso_gdf.gdf_feature.gdf_complexfeature.GDF_ComplexFeature":
106                                self._belongsTo_gdf_complexfeature.append(item)
107                                continue
108                pass
109
110        def __key(self):
111                return (self.name, self.belongsTo, self.code, self.character, self.represents, self.theme)
112
113        def __eq__(self, y):
114                if type(self) != type(y):
115                        return False
116                '''
117                Cannot compare classes which do not define a "__key" attribute
118                '''
119                if hasattr(self, '_%s__key' % (type(self).__name__)) and hasattr(y, '_%s__key' % (type(y).__name__)):
120                        return self.__key() == y.__key()
121                return id(self) == id(y)
122
123        def __hash__(self):
124                return collectionProofHash(self.__key())
Note: See TracBrowser for help on using the repository browser.