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
'vegX' => True,
30
'TaxonConceptType' => True
31
);
32

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

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

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

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

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

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

    
121
  }
122

    
123
  return $def;
124
}
125

    
126
$adHocAttr = array(
127
'Institution' => True,
128
'TemporalCoverage' => True,
129
'TaxonomicCoverage' => True,
130
'temporalCoverageLC' => True,
131
'taxonomicCoverageLC' => True,
132
'ScientificName' => 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 'ScientificName':
145
      $primaryKey = 'attr_id__exact';
146
      $primaryAttrName = 'id';
147
      break;
148
    case 'TemporalCoverage':
149
      $primaryKey = 'attr_id__exact';
150
      $primaryAttrName = 'id';
151
      break;
152
    case 'TaxonomicCoverage':
153
      $primaryKey = 'attr_id__exact';
154
      $primaryAttrName = 'id';
155
      break;
156
    case 'temporalCoverageLC':
157
      $primaryKey = 'TemporalCoverage_extend__attr_id__exact';
158
      $primaryAttrName = 'id';
159
      $secondaryKeys = array('attr_system__exact','attr_scope__exact');
160
      $secondaryNodeNames = array('system','scope');
161
      break;
162
    case 'taxonomicCoverageLC':
163
      $primaryKey = 'TaxonomicCoverage_extend__attr_id__exact';
164
      $primaryAttrName = 'id';
165
      $secondaryKeys = array('attr_system__exact','attr_scope__exact');
166
      $secondaryNodeNames = array('system','scope');
167
      break;
168
    case 'Institution':
169
      $primaryKey = 'attr_identifier__exact';
170
      $primaryAttrName = 'identifier';
171
      break;
172
  }
173

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

    
204
  }
205

    
206
  return $def;
207
}
208
/*
209
Article - ISSN/pageRange
210
Book - ISBN
211
Chapter - Book_extend/chapterNumber
212
ConferenceProceedings - Chapter_extend
213
AudioVisual - ISBN
214
Institution - attr_identifier
215
PlotType - plotUniqueIdentifier
216

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

    
(3-3/4)