Project

General

Profile

1
<?php
2

    
3
$idSysScope = array(
4
'AccessType' => True,
5
'GeographicCoverage' => True,
6
'Coverage' => True,
7
'CitationType' => True,
8
'ResponsibleParty' => True,
9
'Address' => True,
10
'ResearchProjectType' => True,
11
'DistributionType' => True,
12
'ConnectionDefinitionType' => True,
13
'connection' => True,
14
'MethodType' => True,
15
'ObservationGroupingType' => True,
16
'AttributeType' => True,
17
'ProtocolType' => True,
18
'TaxonNameUsageType' => True,
19
'AggregateOrganismObservationType' => True,
20
'StratumType' => True,
21
'StratumObservationType' => True,
22
'IndividualOrganismObservationType' => True,
23
'IndividualOrganismType' => True,
24
'ObservationType' => True,
25
'AbioticObservationType' => True,
26
'TaxonRelationshipAssertion' => True,
27
'Specimen' => True,
28
'Publication' => True,
29
'ScientificName' => True,
30
'vegX' => True,
31
'TaxonConceptType' => True
32
);
33

    
34
//Identified by the id field of the entity they extend
35
$idExtend = array(
36
#'taxonomicCoverageLC' => 'TaxonomicCoverage_extend',
37
#'temporalCoverageLC' => 'TemporalCoverage_extend'
38
'personnel' => 'ResponsibleParty_extend',
39
'associatedParty' => 'ResponsibleParty_extend'
40
);
41

    
42
//Likely needs ad hoc handling
43
$adHoc = array(
44
'Article' => True,
45
'Book' => True, 
46
'Chapter' => True, 
47
'ConferenceProceedings' => True,
48
'AudioVisual' => True,
49
'PlotType' => True
50
);
51

    
52
function handleAdHoc($tName) {
53
  $def = "    return $tName() #ad hoc\n";
54

    
55
  $primaryKey = '';
56
  $secondaryKeys = array();
57
  $primaryNodeName = '';
58
  $secondaryNodeNames = array();
59

    
60
  switch($tName) {
61
    case 'Article':
62
      $primaryKey = 'ISSN__exact';
63
      $primaryNodeName = 'ISSN';
64
      $secondaryKeys = array('pageRange__exact');
65
      $secondaryNodeNames = array('pageRange');
66
      break;
67
    case 'Book':
68
    case 'AudioVisual':
69
      $primaryKey = 'ISBN__exact';
70
      $primaryNodeName = 'ISBN';
71
      break;
72
    case 'Chapter':
73
      $primaryKey = 'Book_extend__ISBN__exact';
74
      $primaryNodeName = 'ISBN';
75
      $secondaryKeys = array('chapterNumber__exact');
76
      $secondaryNodeNames = array('chapterNumber');
77
      break;
78
    case 'ConferenceProceedings':
79
      $primaryKey = 'Chapter_extend__Book_extend__ISBN__exact';
80
      $primaryNodeName = 'ISBN';
81
      break;
82
    case 'Institution':
83
      $primaryKey = 'attr_identifier__exact';
84
      $primaryNodeName = 'attr_identifier';
85
      break;
86
    case 'PlotType':
87
      $primaryKey = 'plotUniqueIdentifier__exact';
88
      $primaryNodeName = 'plotUniqueIdentifier';
89
      break;
90
  }
91

    
92
  if($primaryNodeName != '') {
93
    $def = "    $primaryNodeName" . "_val = None #ad hoc\n";
94
    foreach($secondaryNodeNames as $skey) {
95
      $def .= "    $skey" . "_val = None\n";
96
    }
97
    $def .= "    for child in node.childNodes:\n".
98
            "      cName = child.nodeName\n".
99
            "      if cName == '$primaryNodeName':\n".
100
            "        $primaryNodeName" . "_val = child.childNodes[0].nodeValue\n";
101
    foreach($secondaryNodeNames as $skey) {
102
      $def .= "      if cName == '$skey':\n".
103
              "        $skey" . "_val = child.childNodes[0].nodeValue\n";
104
    }
105
    $def .= "\n";
106
    $def .= "    if $primaryNodeName" . "_val != None:\n".
107
            "      q = $tName.objects.filter($primaryKey = $primaryNodeName" . "_val)\n";
108
    $i = 0;
109
    foreach($secondaryNodeNames as $skey) {
110
      $secondaryKeyName = $secondaryKeys[$i];
111
      $def .= "      if $skey" . "_val != None:\n".
112
              "        q = q.filter($secondaryKeyName = $skey" . "_val)\n";
113
      $i = $i + 1;
114
    }
115
    $def .= "      if len(q) > 0:\n".
116
            "        return q[0]\n".
117
            "      else:\n".
118
            "        return $tName()\n".
119
            "    else:\n".
120
            "      return $tName()\n";
121

    
122
  }
123

    
124
  return $def;
125
}
126

    
127
$adHocAttr = array(
128
'Institution' => True,
129
'TemporalCoverage' => True,
130
'TaxonomicCoverage' => True,
131
'temporalCoverageLC' => True,
132
'taxonomicCoverageLC' => True
133
);
134

    
135
function handleAdHocAttr($tName) {
136
  $def = "    return $tName() #ad hoc attr\n";
137

    
138
  $primaryKey = '';
139
  $secondaryKeys = array();
140
  $primaryAttrName = '';
141
  $secondaryNodeNames = array();
142

    
143
  switch($tName) {
144
    case 'TemporalCoverage':
145
      $primaryKey = 'attr_id__exact';
146
      $primaryAttrName = 'id';
147
      break;
148
    case 'TaxonomicCoverage':
149
      $primaryKey = 'attr_id__exact';
150
      $primaryAttrName = 'id';
151
      break;
152
    case 'temporalCoverageLC':
153
      $primaryKey = 'TemporalCoverage_extend__attr_id__exact';
154
      $primaryAttrName = 'id';
155
      $secondaryKeys = array('attr_system__exact','attr_scope__exact');
156
      $secondaryNodeNames = array('system','scope');
157
      break;
158
    case 'taxonomicCoverageLC':
159
      $primaryKey = 'TaxonomicCoverage_extend__attr_id__exact';
160
      $primaryAttrName = 'id';
161
      $secondaryKeys = array('attr_system__exact','attr_scope__exact');
162
      $secondaryNodeNames = array('system','scope');
163
      break;
164
    case 'Institution':
165
      $primaryKey = 'attr_identifier__exact';
166
      $primaryAttrName = 'identifier';
167
      break;
168
  }
169

    
170
  if($primaryAttrName != '') {
171
    $def = "";
172
    foreach($secondaryNodeNames as $skey) {
173
      $def .= "    $skey" . "_val = None\n";
174
    }
175
    $def .= "    $primaryAttrName" . "_val = None #ad hoc attr\n".
176
            "    for attr in node.attributes.keys():\n".
177
            "      aVal = node.attributes[attr].nodeValue\n".
178
            "      if attr == '$primaryAttrName':\n".
179
            "        $primaryAttrName" . "_val = aVal\n";
180
    foreach($secondaryNodeNames as $skey) {
181
    $def .= "      if attr == '$skey':\n".
182
            "        $skey" . "_val = aVal\n";
183
    }
184
    $def .= "\n    if $primaryAttrName" . "_val != None:\n".
185
            "      q = $tName.objects.filter($primaryKey = $primaryAttrName" . "_val)\n";
186
    $i = 0;
187
    foreach($secondaryNodeNames as $skey) {
188
      $secondaryKeyName = $secondaryKeys[$i];
189
    $def .= "      if $skey" . "_val != None:\n".
190
            "        q = q.filter($secondaryKeyName = $skey" . "_val)\n";
191
      $i = $i + 1;
192
    }
193
    $def .= "      if len(q) > 0:\n".
194
            "        return q[0]\n".
195
            "      else:\n".
196
            "        return $tName()\n".
197
            "    else:\n".
198
            "      return $tName()\n";
199

    
200
  }
201

    
202
  return $def;
203
}
204
/*
205
Article - ISSN/pageRange
206
Book - ISBN
207
Chapter - Book_extend/chapterNumber
208
ConferenceProceedings - Chapter_extend
209
AudioVisual - ISBN
210
Institution - attr_identifier
211
PlotType - plotUniqueIdentifier
212

    
213
//Nothing can be done for these since the entity they reference
214
//has no way of being uniquely identified
215
FromTaxonConcept - ReferenceType_extend
216
ToTaxonConcept - ReferenceType_extend
217
TaxonRelationshipAssertion - RelationshipType_extend/attr_id
218
TaxonRelationship - RelationshipType_extend
219
*/
220
?>
221

    
(3-3/4)