- Timestamp:
- 2013-05-14T20:45:03+12:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/cgiactions/metadataaction.pm
r27333 r27336 259 259 } 260 260 261 # Only when setting metadata do we perform authentication and do we lock the collection 261 # Only when setting metadata do we perform authentication and do we lock the collection, 262 262 # not when getting metadata 263 263 … … 273 273 } 274 274 elsif($where =~ m/live/) { 275 # $self->_get_live_metadata_array(@_); 276 } 277 } 278 275 $self->_get_live_metadata_array(@_); 276 } 277 } 278 279 # Unused at present. Added for completion. Tested. 279 280 sub _get_import_metadata_array { 280 281 … … 480 481 } 481 482 482 # takes a JSON string and returns a JSON string 483 # resulting string is of the form: 484 # [{"docid":"HASHc5bce2d6d3e5b04e470ec9","metatable":[{"metaname":"username","metavals":[{"metapos":"0","metavalue":"me"},{"metapos":"1","metavalue":"admin"}]},{"metaname":"usertimestamp","metavals":[{"metapos":"0","metavalue":"1367900586888"},{"metapos":"1","metavalue":"1367900616574"}]},{"metaname":"usercomment","metavals":[{"metapos":"0","metavalue":"Hi"},{"metapos":"1","metavalue":"Hello"}]}]}] 485 sub _get_index_metadata_array 483 484 # Unused at present. Added for completion. Tested, but not sure if it retrieves metadata in the manner it's expected to. 485 sub _get_live_metadata_array 486 486 { 487 487 my $self = shift @_; … … 498 498 # Obtain the path to the database 499 499 my $collect_tail = $collect; 500 $collect_tail =~ s/^.*[\/ \\]//;500 $collect_tail =~ s/^.*[\/|\\]//; 501 501 my $index_text_directory = &util::filename_cat($collect_dir,$collect,"index","text"); 502 my $infodb_file_path = &dbutil::get_infodb_file_path($infodbtype, $collect_tail, $index_text_directory);502 my $infodb_file_path = &dbutil::get_infodb_file_path($infodbtype, "live-$collect_tail", $index_text_directory); 503 503 504 504 my $json_str = $self->{'json'}; … … 518 518 } 519 519 $json_result_str = $json_result_str . "{\"docid\":\"" . $docid . "\""; 520 520 521 521 my $metatable = $doc_array_rec->{'metatable'}; # a subarray, or need to generate an error saying JSON structure is wrong 522 522 $json_result_str = $json_result_str . ",\"metatable\":["; 523 523 524 524 my $first_rec = 1; 525 525 foreach my $metatable_rec ( @$metatable ) { # the subarray metatable is an array of hashmaps … … 532 532 my $metaname = $metatable_rec->{'metaname'}; 533 533 $json_result_str .= "{\"metaname\":\"$metaname\",\"metavals\":["; 534 535 # Generate the dbkey 536 my $dbkey = "$docid.$metaname"; 537 538 # metapos for get_live_metadata is always assumed to be "all". 539 # It's always going to get all the lines of metavalues associated with a metaname 540 # (It's the metaname itself that should contain an increment number, if there are to be multiple values). 541 #my $metapos = "all"; 542 my $metapos = $metatable_rec->{'metapos'} || 0; # Can be 0... 1|all|undefined. Defaults to 0 if undefined/false 543 my $metavalue = ""; 544 545 # Obtain the content of the key 546 my $cmd = "gdbmget $infodb_file_path $dbkey"; 547 if (open(GIN,"$cmd |") != 0) { # Success. 548 549 binmode(GIN,":utf8"); 550 # Read everything in and concatenate them into $metavalue 551 my $line; 552 my $first_metaval = 1; 553 my $pos = 0; 554 while (defined ($line=<GIN>)) { 555 chomp($line); # Get rid off the tailing newlines 556 557 if($metapos eq "all") { 558 if($first_metaval) { 559 $first_metaval = 0; 560 } else { 561 $json_result_str .= ","; 562 } 563 $metavalue = $line; 564 $json_result_str .= "{\"metapos\":\"$pos\",\"metavalue\":\"$metavalue\"}"; 565 } elsif($metapos == $pos) { 566 $metavalue = $line; 567 $json_result_str .= "{\"metapos\":\"$metapos\",\"metavalue\":\"$metavalue\"}"; 568 last; 569 } # else, the current $pos is not the required $metapos 570 $pos += 1; 571 } 572 close(GIN); 573 } # else open cmd == 0 (failed) and metavals array will be empty [] for this metaname 574 575 $json_result_str .= "]}"; # close metavals array and metatable record 576 } 577 578 $json_result_str .= "]}"; # close metatable array and docid record 579 } 580 581 $json_result_str .= "]"; # close array of docids 582 583 $gsdl_cgi->generate_ok_message($json_result_str."\n"); 584 } 585 586 587 # Takes a JSON string and returns a JSON string 588 # Request string is of the form: 589 # http://localhost:8283/greenstone/cgi-bin/metadata-server.pl?a=get-metadata-array&c=demo&where=index&json=[{"docid":"HASHc5bce2d6d3e5b04e470ec9","metatable":[{"metaname":"username","metapos":"all"},{"metaname":"usertimestamp","metapos":"all"}, {"metaname":"usercomment","metapos":"all"}]}] 590 # Resulting string is of the form: 591 # [{"docid":"HASHc5bce2d6d3e5b04e470ec9","metatable":[{"metaname":"username","metavals":[{"metapos":"0","metavalue":"me"},{"metapos":"1","metavalue":"admin"}]},{"metaname":"usertimestamp","metavals":[{"metapos":"0","metavalue":"1367900586888"},{"metapos":"1","metavalue":"1367900616574"}]},{"metaname":"usercomment","metavals":[{"metapos":"0","metavalue":"Hi"},{"metapos":"1","metavalue":"Hello"}]}]}] 592 sub _get_index_metadata_array 593 { 594 my $self = shift @_; 595 596 my $collect = $self->{'collect'}; 597 my $gsdl_cgi = $self->{'gsdl_cgi'}; 598 my $site = $self->{'site'}; 599 my $collect_dir = $gsdl_cgi->get_collection_dir($site); 600 601 # look up additional args 602 my $infodbtype = $self->{'infodbtype'}; 603 604 # To people who know $collect_tail please add some comments 605 # Obtain the path to the database 606 my $collect_tail = $collect; 607 $collect_tail =~ s/^.*[\/|\\]//; 608 my $index_text_directory = &util::filename_cat($collect_dir,$collect,"index","text"); 609 my $infodb_file_path = &dbutil::get_infodb_file_path($infodbtype, $collect_tail, $index_text_directory); 610 611 my $json_str = $self->{'json'}; 612 my $doc_array = decode_json $json_str; 613 614 my $json_result_str = "["; 615 my $first_doc_rec = 1; 616 617 foreach my $doc_array_rec ( @$doc_array ) { 618 619 my $docid = $doc_array_rec->{'docid'}; 620 621 if($first_doc_rec) { 622 $first_doc_rec = 0; 623 } else { 624 $json_result_str .= ","; 625 } 626 $json_result_str = $json_result_str . "{\"docid\":\"" . $docid . "\""; 627 628 my $metatable = $doc_array_rec->{'metatable'}; # a subarray, or need to generate an error saying JSON structure is wrong 629 $json_result_str = $json_result_str . ",\"metatable\":["; 630 631 my $first_rec = 1; 632 foreach my $metatable_rec ( @$metatable ) { # the subarray metatable is an array of hashmaps 633 if($first_rec) { 634 $first_rec = 0; 635 } else { 636 $json_result_str .= ","; 637 } 638 639 my $metaname = $metatable_rec->{'metaname'}; 640 $json_result_str .= "{\"metaname\":\"$metaname\",\"metavals\":["; 534 641 535 642 my $metapos = $metatable_rec->{'metapos'}; # 0... 1|all|undefined … … 613 720 # Obtain path to the database 614 721 my $collect_tail = $collect; 615 $collect_tail =~ s/^.*[\/ \\]//;722 $collect_tail =~ s/^.*[\/|\\]//; 616 723 my $index_text_directory = &util::filename_cat($collect_dir,$collect,"index","text"); 617 724 my $infodb_file_path = &dbutil::get_infodb_file_path($infodbtype, $collect_tail, $index_text_directory); … … 898 1005 # Obtain path to the database 899 1006 my $collect_tail = $collect; 900 $collect_tail =~ s/^.*[\/ \\]//;1007 $collect_tail =~ s/^.*[\/|\\]//; 901 1008 my $index_text_directory = &util::filename_cat($collect_dir,$collect,"index","text"); 902 1009 my $infodb_file_path = &dbutil::get_infodb_file_path($infodbtype, "live-$collect_tail", $index_text_directory); … … 953 1060 # Obtain path to the database 954 1061 my $collect_tail = $collect; 955 $collect_tail =~ s/^.*[\/ \\]//;1062 $collect_tail =~ s/^.*[\/|\\]//; 956 1063 my $index_text_directory = &util::filename_cat($collect_dir,$collect,"index","text"); 957 1064 my $infodb_file_path = &dbutil::get_infodb_file_path($infodbtype, $collect_tail, $index_text_directory); … … 1434 1541 # Obtain path to the database 1435 1542 my $collect_tail = $collect; 1436 $collect_tail =~ s/^.*[\/ \\]//;1543 $collect_tail =~ s/^.*[\/|\\]//; 1437 1544 my $index_text_directory = &util::filename_cat($collect_dir,$collect,"index","text"); 1438 1545 my $infodb_file_path = &dbutil::get_infodb_file_path($infodbtype, "live-$collect_tail", $index_text_directory); … … 2978 3085 # Obtain the live gdbm_db path 2979 3086 my $collect_tail = $collect; 2980 $collect_tail =~ s/^.*[\/ \\]//;3087 $collect_tail =~ s/^.*[\/|\\]//; 2981 3088 my $index_text_directory = &util::filename_cat($collect_dir,$collect,"index","text"); 2982 3089 my $infodb_file_path = &dbutil::get_infodb_file_path($infodbtype, "live-$collect_tail", $index_text_directory); … … 3089 3196 # Obtain the path to the database 3090 3197 my $collect_tail = $collect; 3091 $collect_tail =~ s/^.*[\/ \\]//;3198 $collect_tail =~ s/^.*[\/|\\]//; 3092 3199 my $index_text_directory = &util::filename_cat($collect_dir,$collect,"index","text"); 3093 3200 my $infodb_file_path = &dbutil::get_infodb_file_path($infodbtype, $collect_tail, $index_text_directory); … … 3285 3392 # Obtain path to the database 3286 3393 my $collect_tail = $collect; 3287 $collect_tail =~ s/^.*[\/ \\]//;3394 $collect_tail =~ s/^.*[\/|\\]//; 3288 3395 my $index_text_directory = &util::filename_cat($collect_dir,$collect,"index","text"); 3289 3396 my $infodb_file_path = &dbutil::get_infodb_file_path($infodbtype, $collect_tail, $index_text_directory);
Note:
See TracChangeset
for help on using the changeset viewer.