| 1 | #!perl -wWall | ||
| 2 | use strict; | ||
| 3 | use vars qw(@ISA); | ||
| 4 | use XML::LibXML; | ||
| 5 | @ISA = qw{MOBY::Adaptor::moby::DataAdapterI}; # implements the interface | ||
| 6 | |||
| 7 | use vars qw /$VERSION/; | ||
| 8 | $VERSION = sprintf "%d.%02d", q$Revision: 1.3 $ =~ /: (\d+)\.(\d+)/; | ||
| 9 | |||
| 10 | =head1 NAME | ||
| 11 | |||
| 12 | MOBY::Adaptor::moby::impl::FetaQueryAdaptor.pm - FetaQueryAdaptor | ||
| 13 | |||
| 14 | =head1 DESCRIPTION | ||
| 15 | |||
| 16 | Todo | ||
| 17 | |||
| 18 | =head2 _queryServiceInstanceHash | ||
| 19 | |||
| 20 | Title : _queryServiceInstanceHash | ||
| 21 | Usage : my $un = $API->_queryServiceInstanceHash($xml) | ||
| 22 | Function : Parses the FETA response XML and creates a hashref of a services properties | ||
| 23 | Args : FETA response XML => => String | ||
| 24 | Returns : hashref: | ||
| 25 | {service_instance_id => Integer, | ||
| 26 | category => String, | ||
| 27 | servicename => String, | ||
| 28 | service_type_uri => String, | ||
| 29 | authority.authority_uri => String, | ||
| 30 | url => String, | ||
| 31 | service_instance.contact_email => String, | ||
| 32 | authoritative => Integer, | ||
| 33 | description => String, | ||
| 34 | signatureURL => String, | ||
| 35 | lsid => String} | ||
| 36 | |||
| 37 | =cut | ||
| 38 | |||
| 39 | sub queryServiceInstanceHash { | ||
| 40 | my ($inputString) = @_; | ||
| 41 | my %qsiHash; | ||
| 42 | my $parser = XML::LibXML->new(); | ||
| 43 | my $fetaDom = $parser->parse_string($inputString); | ||
| 44 | my ( $value, $key ); | ||
| 45 | |||
| 46 | # add the key/value pair for service_instance_id | ||
| 47 | $key = 'service_instance_id'; | ||
| 48 | $value = getValueByTagnameNS( $fetaDom, 'serviceName' ); | ||
| 49 | if ( defined $value ) { | ||
| 50 | $qsiHash{$key} = $value; | ||
| 51 | } | ||
| 52 | |||
| 53 | # add the key/value pair for category | ||
| 54 | $key = 'category'; | ||
| 55 | $value = getValueByTagnameNS( $fetaDom, 'Category' ); | ||
| 56 | if ( defined $value ) { | ||
| 57 | $qsiHash{$key} = $value; | ||
| 58 | } | ||
| 59 | |||
| 60 | # add the key/value pair for servicename | ||
| 61 | $key = 'servicename'; | ||
| 62 | $value = getValueByTagnameNS( $fetaDom, 'serviceName' ); | ||
| 63 | if ( defined $value ) { | ||
| 64 | $qsiHash{$key} = $value; | ||
| 65 | } | ||
| 66 | |||
| 67 | # add the key/value pair for service_type_uri | ||
| 68 | $key = 'service_type_uri'; | ||
| 69 | $value = getValueByTagnameNS( $fetaDom, 'operationTask' ); | ||
| 70 | if ( defined $value ) { | ||
| 71 | $qsiHash{$key} = $value; | ||
| 72 | } | ||
| 73 | |||
| 74 | # add the key/value pair for authority.authority_uri | ||
| 75 | $key = 'authority.authority_uri'; | ||
| 76 | $value = getValueByTagnameNS( $fetaDom, 'serviceName' ); | ||
| 77 | my @auth = split( /\,/, $value ); | ||
| 78 | if ( defined $auth[0] ) { | ||
| 79 | $qsiHash{$key} = $auth[0]; | ||
| 80 | } | ||
| 81 | |||
| 82 | # add the key/value pair for url | ||
| 83 | $key = 'url'; | ||
| 84 | $value = getValueByTagnameNS( $fetaDom, 'locationURL' ); | ||
| 85 | if ( defined $value ) { | ||
| 86 | $qsiHash{$key} = $value; | ||
| 87 | } | ||
| 88 | |||
| 89 | # add the key/value pair for service_instance.contact_email | ||
| 90 | $key = 'service_instance.contact_email'; | ||
| 91 | $value = getValueByTagnameNS( $fetaDom, 'email' ); | ||
| 92 | if ( defined $value ) { | ||
| 93 | $qsiHash{$key} = $value; | ||
| 94 | } | ||
| 95 | |||
| 96 | # add the key/value pair for authoritative | ||
| 97 | $key = 'authoritative'; | ||
| 98 | $value = getValueByTagnameNS( $fetaDom, 'authoritative' ); | ||
| 99 | if ( defined $value ) { | ||
| 100 | $qsiHash{$key} = $value; | ||
| 101 | } | ||
| 102 | |||
| 103 | # add the key/value pair for serviceDescriptionText | ||
| 104 | $key = 'description'; | ||
| 105 | $value = getValueByTagnameNS( $fetaDom, 'serviceDescriptionText' ); | ||
| 106 | if ( defined $value ) { | ||
| 107 | $qsiHash{$key} = $value; | ||
| 108 | } | ||
| 109 | |||
| 110 | # add the key/value pair for signatureURL | ||
| 111 | $key = 'signatureURL'; | ||
| 112 | $value = getValueByTagnameNS( $fetaDom, 'signautureURL' ); | ||
| 113 | if ( defined $value ) { | ||
| 114 | $qsiHash{$key} = $value; | ||
| 115 | } | ||
| 116 | |||
| 117 | # add the key/value pair for lsid | ||
| 118 | $key = 'lsid'; | ||
| 119 | $value = getValueByTagnameNS( $fetaDom, 'lsid' ); | ||
| 120 | if ( defined $value ) { | ||
| 121 | $qsiHash{$key} = $value; | ||
| 122 | } | ||
| 123 | |||
| 124 | #done | ||
| 125 | return \%qsiHash; | ||
| 126 | } | ||
| 127 | |||
| 128 | =head2 _querySimpleInputHash | ||
| 129 | |||
| 130 | Title : _querySimpleInputHash | ||
| 131 | Usage : my $un = $API->_querySimpleInputHash($xml) | ||
| 132 | Function : | ||
| 133 | Args : FETA response xml => String, | ||
| 134 | Returns : listref of hashrefs: | ||
| 135 | [{object_type_uri => String, | ||
| 136 | namespace_type_uris => String, | ||
| 137 | article_name => String, | ||
| 138 | service_instance_id => Integer}, ...] | ||
| 139 | =cut | ||
| 140 | |||
| 141 | sub querySimpleInputHash { | ||
| 142 | my ($inputString) = @_; | ||
| 143 | my %qsiHash; | ||
| 144 | my $parser = XML::LibXML->new(); | ||
| 145 | my $fetaDom = $parser->parse_string($inputString); | ||
| 146 | my $nodes = $fetaDom->getElementsByTagName('operationInputs/parameter'); | ||
| 147 | |||
| 148 | # <parameter > | ||
| 149 | # <parameterName>articleName1</parameterName> | ||
| 150 | # <isConfigurationParameter>false</isConfigurationParameter> | ||
| 151 | # <semanticType>http://biomoby.org/RESOURCES/MOBY-S/Objects#DNASequence</semanticType> | ||
| 152 | # <transportDataType>String</transportDataType> | ||
| 153 | # <collectionSemanticType>Simple</collectionSemanticType> | ||
| 154 | # </parameter> | ||
| 155 | |||
| 156 | } | ||
| 157 | |||
| 158 | =head2 _querySimpleOutputHash | ||
| 159 | |||
| 160 | Title : _querySimpleOutputHash | ||
| 161 | Usage : my $un = $API->_querySimpleOutputHash($xml) | ||
| 162 | Function : Parses the FETA response xml and creates a hashref describing the output simples | ||
| 163 | Args : FETA response xml => String, | ||
| 164 | Returns : listref of hashrefs: | ||
| 165 | [{object_type_uri => String, | ||
| 166 | namespace_type_uris => String, | ||
| 167 | article_name => String, | ||
| 168 | service_instance_id => Integer}, ...] | ||
| 169 | Notes : Only allows querying by lsid or type term, so service_instance_id is retrieved from lsid or term | ||
| 170 | |||
| 171 | =cut | ||
| 172 | |||
| 173 | sub _querySimpleOutputHash { | ||
| 174 | |||
| 175 | } | ||
| 176 | |||
| 177 | =head2 _queryCollectionInputHash | ||
| 178 | |||
| 179 | Title : _queryCollectionInputHash | ||
| 180 | Usage : my $un = $API->_queryCollectionInputHash($xml) | ||
| 181 | Function : get the collection input information for a given service from the FETA response XML | ||
| 182 | Args : FETA response xml => String, | ||
| 183 | Returns : listref of hashrefs: | ||
| 184 | [{collection_input_id => Integer | ||
| 185 | article_name => String}, ...] | ||
| 186 | one hashref for each collection that service consumes | ||
| 187 | |||
| 188 | =cut | ||
| 189 | |||
| 190 | sub _queryCollectionInputHash { | ||
| 191 | } | ||
| 192 | |||
| 193 | =head2 _queryCollectionOutputHash | ||
| 194 | |||
| 195 | Title : _queryCollectionOutputHash | ||
| 196 | Usage : my $un = $API->_queryCollectionOutputHash($xml) | ||
| 197 | Function : get the collection output information for a given service from the FETA response XML | ||
| 198 | Args : FETA response xml => String, | ||
| 199 | Returns : listref of hashrefs: | ||
| 200 | [{collection_output_id => Integer | ||
| 201 | article_name => String}, ...] | ||
| 202 | one hashref for each collection that service consumes | ||
| 203 | |||
| 204 | =cut | ||
| 205 | |||
| 206 | sub _queryCollectionOutputHash { | ||
| 207 | } | ||
| 208 | |||
| 209 | sub getValueByTagnameNS { | ||
| 210 | my ( $dom, $tagname, $ns ) = @_; | ||
| 211 | unless ($ns) { | ||
| 212 | $ns = ''; | ||
| 213 | } | ||
| 214 | my $node = $dom->getElementsByTagNameNS( $ns, $tagname ); | ||
| 215 | if ( $node->size == 1 ) { | ||
| 216 | my $string = $node->get_node(1)->textContent(); | ||
| 217 | return $string; | ||
| 218 | } | ||
| 219 | return undef; | ||
| 220 | } | ||
| 221 | my $string = <<END_QUOTE; | ||
| 222 | <?xml version = "1.0" encoding = "UTF-8"?> | ||
| 223 | <serviceDescriptions> | ||
| 224 | <serviceDescription > | ||
| 225 | <serviceName>test.suite.com,myfirstservice</serviceName> | ||
| 226 | <locationURL>http://illuminae/cgi-bin/service.pl</locationURL> | ||
| 227 | <serviceDescriptionText>This service is my first service and does nothing</serviceDescriptionText> | ||
| 228 | <operations > | ||
| 229 | <serviceOperation > | ||
| 230 | <operationName>test.suite.com,myfirstservice</operationName> | ||
| 231 | <operationDescriptionText>This service is my first service and does nothing</operationDescriptionText> | ||
| 232 | <operationInputs > | ||
| 233 | <parameter > | ||
| 234 | <parameterName>myInputDNASequence</parameterName> | ||
| 235 | <isConfigurationParameter>false</isConfigurationParameter> | ||
| 236 | <semanticType>http://biomoby.org/RESOURCES/MOBY-S/Objects#DNASequence</semanticType> | ||
| 237 | <transportDataType>String</transportDataType> | ||
| 238 | <collectionSemanticType>Simple</collectionSemanticType> | ||
| 239 | </parameter> | ||
| 240 | <parameter > | ||
| 241 | <parameterName>myInputGFF2</parameterName> | ||
| 242 | <isConfigurationParameter>false</isConfigurationParameter> | ||
| 243 | <semanticType>http://biomoby.org/RESOURCES/MOBY-S/Objects#GFF2</semanticType> | ||
| 244 | <transportDataType>String</transportDataType> | ||
| 245 | <collectionSemanticType>Simple</collectionSemanticType> | ||
| 246 | </parameter> | ||
| 247 | <parameter > | ||
| 248 | <parameterName>myInputCollection</parameterName> | ||
| 249 | <isConfigurationParameter>false</isConfigurationParameter> | ||
| 250 | <semanticType>http://biomoby.org/RESOURCES/MOBY-S/Objects#BasicGFFSequenceFeature</semanticType> | ||
| 251 | <transportDataType>String</transportDataType> | ||
| 252 | <collectionSemanticType>Collection</collectionSemanticType> | ||
| 253 | </parameter> | ||
| 254 | <parameter > | ||
| 255 | <parameterName>myInputCollection</parameterName> | ||
| 256 | <isConfigurationParameter>false</isConfigurationParameter> | ||
| 257 | <semanticType>http://biomoby.org/RESOURCES/MOBY-S/Objects#Integer</semanticType> | ||
| 258 | <transportDataType>String</transportDataType> | ||
| 259 | <collectionSemanticType>Collection</collectionSemanticType> | ||
| 260 | </parameter> | ||
| 261 | <parameter > | ||
| 262 | <parameterName>myInputCollectionOfObject</parameterName> | ||
| 263 | <isConfigurationParameter>false</isConfigurationParameter> | ||
| 264 | <semanticType>http://biomoby.org/RESOURCES/MOBY-S/Objects#Object</semanticType> | ||
| 265 | <transportDataType>String</transportDataType> | ||
| 266 | <collectionSemanticType>Collection</collectionSemanticType> | ||
| 267 | </parameter> | ||
| 268 | <parameter > | ||
| 269 | <parameterName>myBag</parameterName> | ||
| 270 | <isConfigurationParameter>false</isConfigurationParameter> | ||
| 271 | <semanticType>http://biomoby.org/RESOURCES/MOBY-S/Objects#BasicGFFSequenceFeature</semanticType> | ||
| 272 | <transportDataType>String</transportDataType> | ||
| 273 | <collectionSemanticType>Collection</collectionSemanticType> | ||
| 274 | </parameter> | ||
| 275 | <parameter > | ||
| 276 | <parameterName>myInputCollection</parameterName> | ||
| 277 | <isConfigurationParameter>false</isConfigurationParameter> | ||
| 278 | <semanticType>http://biomoby.org/RESOURCES/MOBY-S/Objects#Float</semanticType> | ||
| 279 | <transportDataType>String</transportDataType> | ||
| 280 | <collectionSemanticType>Collection</collectionSemanticType> | ||
| 281 | </parameter> | ||
| 282 | </operationInputs> | ||
| 283 | <operationOutputs > | ||
| 284 | <parameter > | ||
| 285 | <parameterName>myOutputCollection</parameterName> | ||
| 286 | <isConfigurationParameter>false</isConfigurationParameter> | ||
| 287 | <semanticType>http://biomoby.org/RESOURCES/MOBY-S/Objects#GFF</semanticType> | ||
| 288 | <transportDataType>String</transportDataType> | ||
| 289 | <collectionSemanticType>Collection</collectionSemanticType> | ||
| 290 | </parameter> | ||
| 291 | <parameter > | ||
| 292 | <parameterName>myOutputCollection</parameterName> | ||
| 293 | <isConfigurationParameter>false</isConfigurationParameter> | ||
| 294 | <semanticType>http://biomoby.org/RESOURCES/MOBY-S/Objects#GFF2</semanticType> | ||
| 295 | <transportDataType>String</transportDataType> | ||
| 296 | <collectionSemanticType>Collection</collectionSemanticType> | ||
| 297 | </parameter> | ||
| 298 | <parameter > | ||
| 299 | <parameterName>myOutputObject</parameterName> | ||
| 300 | <isConfigurationParameter>false</isConfigurationParameter> | ||
| 301 | <semanticType>http://biomoby.org/RESOURCES/MOBY-S/Objects#Object</semanticType> | ||
| 302 | <transportDataType>String</transportDataType> | ||
| 303 | <collectionSemanticType>Simple</collectionSemanticType> | ||
| 304 | </parameter> | ||
| 305 | </operationOutputs> | ||
| 306 | <operationTask>Retrieval</operationTask> | ||
| 307 | </serviceOperation> | ||
| 308 | </operations> | ||
| 309 | <serviceType>BioMOBY service</serviceType> | ||
| 310 | </serviceDescription> | ||
| 311 | </serviceDescriptions> | ||
| 312 | END_QUOTE | ||
| 313 | |||
| 314 | my $hash_ref = queryServiceInstanceHash($string); | ||
| 315 | while ( my ( $key, $value ) = each(%$hash_ref) ) { | ||
| 316 | print "$key => $value\n"; | ||
| 317 | } |