Project

General

Profile

« Previous | Next » 

Revision 8

Added by Matt Wheeler about 14 years ago

Some bug fixes.
Slight hack in eml-coverage and veg.xsd to get around Django case-insensitivity & VegX entities that only differ by case.
Changed default db relationship to one2many from many2many

View differences:

makeVegxModel/trunk/objects/Entity.php
569 569
              "    db_table = u'$tabName'\n\n";
570 570
    }
571 571

  
572
    #there is a tablename resolution conflict between taxonNames/TaxonNames, taxonConcepts/TaxonConcepts,
573
    #temporalCoverage/TemporalCoverage in
574
    #that Django & Postgres store the table names in a case-insensitive way.  Need to force the table name
575
    #to be something different here.
576
    if($this->tableName == 'taxonNames') {
577
      $str .= "\n\n  class Meta:\n".
578
              "    db_table = u'v_taxonnames_lc'\n\n";
579
    } else if($this->tableName == 'TaxonNames') {
580
      $str .= "\n\n  class Meta:\n".
581
              "    db_table = u'v_taxonnames_uc'\n\n";
582
    } else if($this->tableName == 'taxonConcepts') {
583
      $str .= "\n\n  class Meta:\n".
584
              "    db_table = u'v_taxonconcepts_lc'\n\n";
585
    } else if($this->tableName == 'TaxonConcepts') {
586
      $str .= "\n\n  class Meta:\n".
587
              "    db_table = u'v_taxonconcepts_uc'\n\n";
588
    } else if($this->tableName == 'temporalCoverage') {
589
      $str .= "\n\n  class Meta:\n".
590
              "    db_table = u'v_temporalcoverage_lc'\n\n";
591
    } else if($this->tableName == 'TemporalCoverage') {
592
      $str .= "\n\n  class Meta:\n".
593
              "    db_table = u'v_temporalcoverage_uc'\n\n";
594
    }
595

  
572 596
    return $str;
573 597
  }
574 598

  
......
693 717
      $colDef = $this->references[$colName];
694 718

  
695 719
      if(preg_match("/(ForeignKey\(')([a-zA-Z]*)/",$colDef,$matches) > 0 &&
696
         preg_match("/Complex one2Many/",$colDef) > 0 && preg_match("/_extend/",$colDef) == 0) {
720
         preg_match("/Complex one2Many/",$colDef) > 0 && preg_match("/_extend/",$colDef) == 0 &&
721
         preg_match("/_id/",$colName) == 0) {
697 722
        $i += 1;
698 723
        $def .= "      $ifStmt cName == '$colName':\n".
699 724
                "        newEl = $matches[2]().retrieveOrNew(child)\n".
......
837 862
      $colDef = $this->references[$colName];
838 863

  
839 864
      if(preg_match("/(ForeignKey\(')([a-zA-Z]*)/",$colDef,$matches) > 0 &&
840
         (preg_match("/Complex one2Many/",$colDef) > 0 || preg_match("/_extend/",$colName) > 0)) {
865
         (preg_match("/Complex one2Many/",$colDef) > 0 || preg_match("/_extend/",$colName) > 0) &&
866
         preg_match("/_id/",$colName) == 0) {
841 867
        if(preg_match("/_extend/",$colName) == 0) {
842 868
          $def .= "    if self.$colName != None:\n".
843 869
                  "      newEl = doc.createElement('$colName')\n".
......
855 881
    }
856 882

  
857 883
    foreach(array_keys($this->referrers) as $nodeName) {
858
      $nodeNameToUse = $nodeName;
884
      $nodeNameToUse = $this->referrers[$nodeName];
859 885
      if($nodeName == 'anyAttribute') {
860
        $nodeNameToUse = 'any_attr';
861
        $relatedName = $this->tableName . '_' . $nodeNameToUse . '_' . $this->tableName . '_id';
886
        $nodeNameToUse = $this->tableName . '_any_attr';
887
        $relatedName = $nodeNameToUse . '_' . $this->tableName . '_id';
862 888
        $def .= "    for childRef in self.$relatedName.all():\n".
863 889
                "      newEl = doc.createAttribute('$nodeName')\n".
864 890
                "      myNode.setAttributeNode(childRef.exportVegX(newEl,doc))\n\n";
865 891
      } else {
866 892
        if($nodeName == 'anyNode') {
867
          $nodeNameToUse = 'any_nodes';
893
          $nodeNameToUse = $this->tableName . '_any_nodes';
868 894
        }
869
        $relatedName = $this->tableName . '_' . $nodeNameToUse . '_' . $this->tableName . '_id';
895
        $relatedName = $nodeNameToUse . '_' . $this->tableName . '_id';
870 896
        $def .= "    for childRef in self.$relatedName.all():\n".
871 897
                "      newEl = doc.createElement('$nodeName')\n".
872 898
                "      myNode.appendChild(childRef.exportVegX(newEl,doc))\n\n";
......
945 971
      $colDef = $this->references[$colName];
946 972

  
947 973
      if(preg_match("/(ForeignKey\(')([a-zA-Z]*)/",$colDef,$matches) > 0 &&
948
         (preg_match("/Complex one2Many/",$colDef) > 0 || preg_match("/_extend/",$colName) > 0)) {
974
         (preg_match("/Complex one2Many/",$colDef) > 0 || preg_match("/_extend/",$colName) > 0) &&
975
         preg_match("/_id/",$colName) == 0) {
949 976
        if(preg_match("/_extend/",$colName) == 0) {
950 977
          $def .= "    if '$matches[2]' not in usedObjectsStack:\n".
951 978
                  "      usedObjectsStack.append('$matches[2]')\n".
makeVegxModel/trunk/objects/lookups.php
23 23
'IndividualOrganismType' => True,
24 24
'ObservationType' => True,
25 25
'AbioticObservationType' => True,
26
'TemporalCoverage' => True,
27
'TaxonomicCoverage' => True,
28 26
'TaxonRelationshipAssertion' => True,
29 27
'Specimen' => True,
30 28
'Publication' => True,
......
35 33

  
36 34
//Identified by the id field of the entity they extend
37 35
$idExtend = array(
38
'temporalCoverage' => 'TemporalCoverage_extend',
39
'taxonomicCoverage' => 'TaxonomicCoverage_extend',
36
#'taxonomicCoverageLC' => 'TaxonomicCoverage_extend',
37
#'temporalCoverageLC' => 'TemporalCoverage_extend'
40 38
'personnel' => 'ResponsibleParty_extend',
41 39
'associatedParty' => 'ResponsibleParty_extend'
42 40
);
......
64 62
      $primaryKey = 'ISSN__exact';
65 63
      $primaryNodeName = 'ISSN';
66 64
      $secondaryKeys = array('pageRange__exact');
67
      $secondaryNodenames = array('pageRange');
65
      $secondaryNodeNames = array('pageRange');
68 66
      break;
69 67
    case 'Book':
70 68
    case 'AudioVisual':
......
127 125
}
128 126

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

  
133 135
function handleAdHocAttr($tName) {
......
139 141
  $secondaryNodeNames = array();
140 142

  
141 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;
142 164
    case 'Institution':
143 165
      $primaryKey = 'attr_identifier__exact';
144 166
      $primaryAttrName = 'identifier';
......
146 168
  }
147 169

  
148 170
  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";
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";
162 199

  
163 200
  }
164 201

  
makeVegxModel/trunk/objects/types.php
129 129
  "GRingPointType" => array(
130 130
                            'colDef' => 'gRingPoint = models.PointField(null=True,blank=True)',
131 131
                            'importDef' => 
132
                            "  if gRingLatitude != None and gRingLongitude != None:\n".
133
                            "      gRingPoint = Point(self.gRingLatitude,self.gRingLongitude)"
132
                            "  if self.gRingLatitude != None and self.gRingLongitude != None:\n".
133
                            "      self.gRingPoint = Point(float(self.gRingLatitude),float(self.gRingLongitude))"
134 134
                           ),
135 135
  "geospatialType" => array(
136 136
                            'colDef' => 'decimalPoint = models.PointField(null=True,blank=True)',
137 137
                            'importDef' => 
138
                            "  if geospatialType_DecimalLatitude != None and geospatialType_DecimalLongitude != None:\n".
139
                            "      decimalPoint = Point(self.geospatialType_DecimalLatitude,self.geospatialType_DecimalLongitude)"
138
                            "  if self.geospatialType_DecimalLatitude != None and self.geospatialType_DecimalLongitude != None:\n".
139
                            "      self.decimalPoint = Point(float(self.geospatialType_DecimalLatitude),float(self.geospatialType_DecimalLongitude))"
140 140
                           )
141 141
);
142 142

  
......
274 274
*/
275 275
);
276 276

  
277
$tableRenames = array(
278
  "taxonNames" => "taxonNamesLC",
279
  "taxonConcepts" => "taxonConceptsLC",
280
  "temporalCoverage" => "temporalCoverageLC"
281
);
277 282
?>
makeVegxModel/trunk/objects/EntityList.php
10 10
    }
11 11

  
12 12
    if(array_key_exists($name,$this->entities)) {
13
      if($this->entities[$name]->isInited()) {
14
        throw new Exception("Entity $name already exists!");
15
      } else {
13
      if(!$this->entities[$name]->isInited()) {
14
//        throw new Exception("Entity $name already exists!");
15
//      } else {
16 16
        $this->entities[$name]->init($name,$node);
17 17
        return $this->entities[$name];
18 18
      }
......
36 36
  }
37 37

  
38 38
  public function printAll() {
39

  
40
    // vegX has some classes that differ only by capitalzation:
41
    // taxonNames/TaxonNames, taxonConcepts/TaxonConcepts, 
42
    // In order to help Django distinguish between them, we need
43
    // to define them ahead of any classes that refrence them.
44
    print $this->entities['taxonNames']->toString() . "\n\n";
45
    print $this->entities['taxonConcepts']->toString() . "\n\n";
46
    print $this->entities['TaxonNames']->toString() . "\n\n";
47
    print $this->entities['TaxonConcepts']->toString() . "\n\n";
48

  
39 49
    foreach(array_keys($this->entities) as $k) {
50
      if($k == 'taxonNames' || $k == 'taxonConcepts' ||
51
         $k == 'TaxonNames' || $k == 'TaxonConcepts')
52
        { continue; }
40 53
      print $this->entities[$k]->toString() . "\n\n";
41 54

  
42 55
      if($k == 'vegX') {
makeVegxModel/trunk/eml-coverage.xsd
61 61
						</xs:appinfo>
62 62
					</xs:annotation>
63 63
				</xs:element>
64
				<xs:element name="temporalCoverage">
64
				<xs:element name="temporalCoverageLC">
65 65
					<xs:annotation>
66 66
						<xs:appinfo>
67 67
							<doc:tooltip>Temporal coverage</doc:tooltip>
......
77 77
						</xs:complexContent>
78 78
					</xs:complexType>
79 79
				</xs:element>
80
				<xs:element name="taxonomicCoverage">
80
				<xs:element name="taxonomicCoverageLC">
81 81
					<xs:annotation>
82 82
						<xs:appinfo>
83 83
							<doc:tooltip>Taxonomic coverage</doc:tooltip>
makeVegxModel/trunk/veg.xsd
98 98
						</xsd:sequence>
99 99
					</xsd:complexType>
100 100
				</xsd:element>
101
				<xsd:element name="TaxonNames" minOccurs="0">
101
				<xsd:element name="taxonNames" minOccurs="0">
102 102
					<xsd:annotation>
103 103
						<xsd:documentation>A container for all nomenclatural units defined for use by a dataset. This is a formal taxonomic name published under codes. Used when applying usage-published name assertions.</xsd:documentation>
104 104
					</xsd:annotation>
......
113 113
						</xsd:sequence>
114 114
					</xsd:complexType>
115 115
				</xsd:element>
116
				<xsd:element name="TaxonConcepts" minOccurs="0">
116
				<xsd:element name="taxonConcepts" minOccurs="0">
117 117
					<xsd:annotation>
118 118
						<xsd:documentation>A container for all taxon concepts defined for use by a dataset when applying name usage-taxonomic name assertions. Recommend to be used for published concepts.</xsd:documentation>
119 119
					</xsd:annotation>

Also available in: Unified diff