| 1 | package Net::Z3950::UDDI::Database::uddi; | ||
| 2 | our @ISA = qw(Net::Z3950::UDDI::Database); | ||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use UDDI::HalfDecent; | ||
| 7 | |||
| 8 | |||
| 9 | sub rebless { | ||
| 10 | my $class = shift(); | ||
| 11 | my($this) = @_; | ||
| 12 | |||
| 13 | my $config = $this->config(); | ||
| 14 | my $endpoint = $config->property("endpoint") | ||
| 15 | or $this->_throw(1, "no endpoint specified for UDDI db '" . | ||
| 16 | $this->dbname() . "'"); | ||
| 17 | my $uddi = new UDDI::HalfDecent($endpoint); | ||
| 18 | |||
| 19 | my $levels = $config->property("log"); | ||
| 20 | $uddi->loglevel(split /[,\s]+/, $levels) | ||
| 21 | if defined $levels; | ||
| 22 | |||
| 23 | my %data = $config->properties(); | ||
| 24 | foreach my $key (grep /^option-/, keys %data) { | ||
| 25 | my $value = $data{$key}; | ||
| 26 | $key =~ s/^option-//; | ||
| 27 | $uddi->option($key, $value); | ||
| 28 | } | ||
| 29 | |||
| 30 | $this->{_uddi} = $uddi; | ||
| 31 | bless $this, $class; | ||
| 32 | } | ||
| 33 | |||
| 34 | |||
| 35 | sub search { | ||
| 36 | my $this = shift(); | ||
| 37 | my($rpn) = @_; | ||
| 38 | |||
| 39 | my $query = $rpn->{query}; | ||
| 40 | |||
| 41 | my @criteria; | ||
| 42 | my $whichop = $this->_gather_criteria($query, \@criteria); | ||
| 43 | |||
| 44 | # Generate, wrap and return the result-set | ||
| 45 | my $rs; | ||
| 46 | eval { | ||
| 47 | if (!defined $whichop || $whichop == 1) { | ||
| 48 | $rs = $this->{_uddi}->find_business(@criteria); | ||
| 49 | } elsif ($whichop == 2) { | ||
| 50 | $rs = $this->{_uddi}->find_service(@criteria); | ||
| 51 | } elsif ($whichop == 3) { | ||
| 52 | $rs = $this->{_uddi}->find_binding(@criteria); | ||
| 53 | } elsif ($whichop == 4) { | ||
| 54 | $rs = $this->{_uddi}->find_tModel(@criteria); | ||
| 55 | } else { | ||
| 56 | $this->_throw(1024, "15=$whichop"); | ||
| 57 | } | ||
| 58 | }; if ($@ && ref $@ && $@->isa("UDDIException")) { | ||
| 59 | # Translate UDDIException into ZOOM::Exception. It would be | ||
| 60 | # nice if we could do a better job of making BIB-1 diagnostic | ||
| 61 | # codes from some known values of $@->error() | ||
| 62 | $this->_throw(100, "$@"); | ||
| 63 | } elsif ($@) { | ||
| 64 | die $@; | ||
| 65 | } | ||
| 66 | |||
| 67 | return new Net::Z3950::UDDI::ResultSet::uddi($this, $rs); | ||
| 68 | } | ||
| 69 | |||
| 70 | |||
| 71 | sub _gather_criteria { | ||
| 72 | my $this = shift(); | ||
| 73 | my($query, $cref) = @_; | ||
| 74 | |||
| 75 | if ($query->isa("Net::Z3950::RPN::And")) { | ||
| 76 | my $w1 = $this->_gather_criteria($query->[0], $cref); | ||
| 77 | my $w2 = $this->_gather_criteria($query->[1], $cref); | ||
| 78 | return $w1 || $w2; | ||
| 79 | } elsif (!$query->isa("Net::Z3950::RPN::Term")) { | ||
| 80 | ### We should handle eligible subtrees consisting entirely of OR | ||
| 81 | # using a findQualifier to specify the boolean. | ||
| 82 | $this->_throw(6, "only AND booleans are supported"); | ||
| 83 | } | ||
| 84 | |||
| 85 | ### Ignore attribute set for now | ||
| 86 | my $attrs = $query->{attributes}; | ||
| 87 | my $ap = undef; | ||
| 88 | my $whichop = undef; | ||
| 89 | foreach my $attr (@$attrs) { | ||
| 90 | my $type = $attr->{attributeType}; | ||
| 91 | my $value = $attr->{attributeValue}; | ||
| 92 | if ($type == 1) { | ||
| 93 | $ap = $value; | ||
| 94 | } elsif ($type == 15) { | ||
| 95 | # Zebra defines extensions for types 7-14: see | ||
| 96 | # http://indexdata.com/zebra/doc/querymodel-zebra.tkl#querymodel-zebra-attr-search | ||
| 97 | $whichop = $value; | ||
| 98 | } else { | ||
| 99 | ### Ignore all other attributes for now. Eventually, some | ||
| 100 | # of them should be turned into additional qualifiers and | ||
| 101 | # other search criteria. | ||
| 102 | } | ||
| 103 | } | ||
| 104 | $this->_throw(116) if !defined $ap; | ||
| 105 | |||
| 106 | # For some reason, qualifiers must appear before the name: if not, | ||
| 107 | # this is diagnosed by bizarre messages such as: | ||
| 108 | # JAXRPCTIE01: caught exception while handling request: | ||
| 109 | # deserialization error: unexpected XML reader state. expected: | ||
| 110 | # END but found: START: {urn:uddi-org:api_v3}findQualifiers | ||
| 111 | # (This is from the GEOSS server.) | ||
| 112 | my $qual = $this->config()->property("qualifiers"); | ||
| 113 | if (defined $qual) { | ||
| 114 | push @$cref, qualifiers => [ split /[,\s]+/, $qual ]; | ||
| 115 | } | ||
| 116 | |||
| 117 | # There is no "indexmap" property in the configuration for UDDI | ||
| 118 | # databases, because the horrible UDDI schema requires | ||
| 119 | # fundamentally different XML for different access points -- not | ||
| 120 | # just differently named elements but differently structured -- | ||
| 121 | # and so the whole translation into UDDI has to be driven by code. | ||
| 122 | my $term = $query->{term}; | ||
| 123 | if ($ap == 4) { | ||
| 124 | # Title | ||
| 125 | push @$cref, name => $term; | ||
| 126 | } elsif ($ap == 29) { | ||
| 127 | # Keywords: see GILS->UDDI crosswalk | ||
| 128 | push @$cref, identifierBag => [ split /[\s,]+/, $term ]; | ||
| 129 | } elsif (grep { $ap eq $_ } (2002, 2074, 2036, 2061)) { | ||
| 130 | # Subject and related indexes: again, see the crosswalk | ||
| 131 | push @$cref, categoryBag => [ split /[\s,]+/, $term ]; | ||
| 132 | } elsif ($ap == 6000) { | ||
| 133 | # Special UDDI-specific attributes | ||
| 134 | push @$cref, businessKey => $term; | ||
| 135 | } elsif ($ap == 6001) { | ||
| 136 | push @$cref, serviceKey => $term; | ||
| 137 | } elsif ($ap == 6002) { | ||
| 138 | push @$cref, tModelBag => [ split /[\s,]+/, $term ]; | ||
| 139 | } else { | ||
| 140 | $this->_throw(114, $ap); | ||
| 141 | } | ||
| 142 | |||
| 143 | return $whichop; | ||
| 144 | } | ||
| 145 | |||
| 146 | |||
| 147 | package Net::Z3950::UDDI::ResultSet::uddi; | ||
| 148 | |||
| 149 | use Net::Z3950::UDDI::ResultSet; | ||
| 150 | our @ISA = qw(Net::Z3950::UDDI::ResultSet); | ||
| 151 | use strict; | ||
| 152 | use warnings; | ||
| 153 | use Carp; | ||
| 154 | |||
| 155 | sub new { | ||
| 156 | my $class = shift(); | ||
| 157 | my($db, $uddi_rs) = @_; | ||
| 158 | |||
| 159 | confess "no UDDI result-set" if !defined $uddi_rs; | ||
| 160 | my $this = $class->SUPER::new($db); | ||
| 161 | $this->{uddi_rs} = $uddi_rs; | ||
| 162 | bless $this, $class; | ||
| 163 | return $this; | ||
| 164 | } | ||
| 165 | |||
| 166 | sub count { | ||
| 167 | my $this = shift(); | ||
| 168 | |||
| 169 | return $this->{uddi_rs}->count(); | ||
| 170 | } | ||
| 171 | |||
| 172 | sub record { | ||
| 173 | my $this = shift(); | ||
| 174 | my($index0) = @_; | ||
| 175 | |||
| 176 | # Generate, wrap and return the result-set | ||
| 177 | my $rec; | ||
| 178 | eval { | ||
| 179 | $rec = $this->{uddi_rs}->record($index0); | ||
| 180 | }; if ($@) { | ||
| 181 | # Translate UDDIException into ZOOM::Exception. | ||
| 182 | $this->_throw(100, "$@"); | ||
| 183 | } | ||
| 184 | |||
| 185 | ### This currently records an unadorned back-end-specific record | ||
| 186 | # object -- in this case, a UDDI::HalfDecent::Record. In the name | ||
| 187 | # of generality, this needs to be wrapped, like back-end-specific | ||
| 188 | # result-sets. | ||
| 189 | return $rec; | ||
| 190 | } | ||
| 191 | |||
| 192 | sub record_as_xml { | ||
| 193 | my $this = shift(); | ||
| 194 | my($index0) = @_; | ||
| 195 | |||
| 196 | my $rec = $this->record($index0); | ||
| 197 | my $xml = $rec->as_xml(); | ||
| 198 | |||
| 199 | my $attrs = $this->{db}->config()->property("record-attrs"); | ||
| 200 | if (defined $attrs) { | ||
| 201 | ### This substitution is not super-rigorous, but can only fail | ||
| 202 | # in the pathological case that the existing XML fragment's | ||
| 203 | # top-level element has an attributes whose value contains an | ||
| 204 | # embedded ">". In any case, I'm not sure what else we could | ||
| 205 | # do: we can't parse the fragment and insert the new | ||
| 206 | # attributes in the resulting DOM, since our inability to | ||
| 207 | # parse fragments that are missing required namespaces is the | ||
| 208 | # reason we want to fix this up in the first place! | ||
| 209 | $xml =~ s/>/ $attrs>/; | ||
| 210 | } | ||
| 211 | |||
| 212 | return $xml; | ||
| 213 | } | ||
| 214 | |||
| 215 | 1; |