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
'TemporalCoverage' => True,
27
'TaxonomicCoverage' => True,
28
'TaxonRelationshipAssertion' => True,
29
'Specimen' => True,
30
'Publication' => True,
31
'ScientificName' => True,
32
'vegX' => True,
33
'TaxonConceptType' => True
34
);
35

    
36
//Identified by the id field of the entity they extend
37
$idExtend = array(
38
'temporalCoverage' => 'TemporalCoverage_extend',
39
'taxonomicCoverage' => 'TaxonomicCoverage_extend',
40
'personnel' => 'ResponsibleParty_extend',
41
'associatedParty' => 'ResponsibleParty_extend'
42
);
43

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

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

    
57
  $primaryKey = '';
58
  $secondaryKeys = array();
59
  $primaryNodeName = '';
60
  $secondaryNodeNames = array();
61

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

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

    
124
  }
125

    
126
  return $def;
127
}
128

    
129
$adHocAttr = array(
130
'Institution' => True
131
);
132

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

    
136
  $primaryKey = '';
137
  $secondaryKeys = array();
138
  $primaryAttrName = '';
139
  $secondaryNodeNames = array();
140

    
141
  switch($tName) {
142
    case 'Institution':
143
      $primaryKey = 'attr_identifier__exact';
144
      $primaryAttrName = 'identifier';
145
      break;
146
  }
147

    
148
  if($primaryAttrName != '') {
149
    $def = "    $primaryAttrName" . "_val = None #ad hoc attr\n".
150
           "    for attr in node.attributes.keys():\n".
151
           "      aVal = node.attributes[attr].nodeValue\n".
152
           "      if attr == '$primaryAttrName':\n".
153
           "        $primaryAttrName" . "_val = aVal\n\n".
154
           "    if $primaryAttrName" . "_val != None:\n".
155
           "      q = $tName.objects.filter($primaryKey = $primaryAttrName" . "_val)\n".
156
           "      if len(q) > 0:\n".
157
           "        return q[0]\n".
158
           "      else:\n".
159
           "        return $tName()\n".
160
           "    else:\n".
161
           "      return $tName()\n";
162

    
163
  }
164

    
165
  return $def;
166
}
167
/*
168
Article - ISSN/pageRange
169
Book - ISBN
170
Chapter - Book_extend/chapterNumber
171
ConferenceProceedings - Chapter_extend
172
AudioVisual - ISBN
173
Institution - attr_identifier
174
PlotType - plotUniqueIdentifier
175

    
176
//Nothing can be done for these since the entity they reference
177
//has no way of being uniquely identified
178
FromTaxonConcept - ReferenceType_extend
179
ToTaxonConcept - ReferenceType_extend
180
TaxonRelationshipAssertion - RelationshipType_extend/attr_id
181
TaxonRelationship - RelationshipType_extend
182
*/
183
?>
184

    
(3-3/4)