Changeset 27324


Ignore:
Timestamp:
05/09/13 20:31:59 (8 years ago)
Author:
ak19
Message:

Added _get_archives_metadata_array and tested it. Otherwise it remains unused at present (added for completion).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/cgiactions/metadataaction.pm

    r27315 r27324  
    267267    }
    268268    elsif($where =~ m/archives/) {
    269 #   $self->_get_archives_metadata_array(@_);
     269    $self->_get_archives_metadata_array(@_);
    270270    }
    271271    elsif($where =~ m/import/) {
     
    275275#       $self->_get_live_metadata_array(@_);
    276276    }
     277}
     278
     279
     280# Unused method, but included for completion. Tested, works. Takes a JSON string and returns a JSON string.
     281# For more information on the format of the output, see _get_index_metadata_array, which is in use.
     282sub _get_archives_metadata_array {
     283
     284    my $self = shift @_;
     285
     286    my $collect   = $self->{'collect'};
     287    my $gsdl_cgi  = $self->{'gsdl_cgi'};
     288    my $site = $self->{'site'};
     289    my $collect_dir = $gsdl_cgi->get_collection_dir($site);
     290
     291    # look up additional args   
     292    my $infodbtype = $self->{'infodbtype'};
     293
     294    my $archive_dir = &util::filename_cat($collect_dir, $collect, "archives");
     295    my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir);
     296
     297    my $json_str      = $self->{'json'};
     298    my $doc_array = decode_json $json_str;
     299
     300    my $json_result_str = "[";
     301    my $first_doc_rec = 1;
     302    foreach my $doc_array_rec ( @$doc_array ) {
     303   
     304    my $docid     = $doc_array_rec->{'docid'};
     305   
     306    if($first_doc_rec) {
     307        $first_doc_rec = 0;
     308    } else {
     309        $json_result_str .= ",";
     310    }
     311    $json_result_str = $json_result_str . "{\"docid\":\"" . $docid . "\""; 
     312
     313    my $metatable = $doc_array_rec->{'metatable'}; # a subarray, or need to generate an error saying JSON structure is wrong
     314    $json_result_str = $json_result_str . ",\"metatable\":[";
     315
     316    my $first_rec = 1;
     317    foreach my $metatable_rec ( @$metatable ) { # the subarray metatable is an array of hashmaps       
     318
     319        my ($docid, $docid_secnum) = ($doc_array_rec->{'docid'} =~ m/^(.*?)(\..*)?$/);
     320        $docid_secnum = "" if (!defined $docid_secnum);
     321
     322        # Read the docid entry     
     323        my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $docid);
     324        # This now stores the full pathname
     325        my $doc_filename = $doc_rec->{'doc-file'}->[0];
     326        $doc_filename = &util::filename_cat($archive_dir, $doc_filename);
     327
     328        if($first_rec) {
     329        $first_rec = 0;
     330        } else {
     331        $json_result_str .= ",";       
     332        }
     333       
     334        my $metaname  = $metatable_rec->{'metaname'};
     335        $json_result_str .= "{\"metaname\":\"$metaname\",\"metavals\":[";
     336
     337        my $metapos   = $metatable_rec->{'metapos'}; # 0... 1|all|undefined
     338        if(!defined $metapos) {
     339        $metapos = 0;
     340        }
     341
     342
     343        # Obtain the specified metadata value(s)
     344        my $metavalue;
     345
     346        if($metapos ne "all") { # get the value at a single metapos
     347
     348        $metavalue = $self->get_metadata_from_archive_xml($gsdl_cgi, $doc_filename, $metaname, $metapos, $docid_secnum);
     349        #print STDERR "**** Docname, metaname, metapos, sec_num: $doc_filename, $metaname, $metapos, $docid_secnum\n";
     350       
     351        $json_result_str .= "{\"metapos\":\"$metapos\",\"metavalue\":\"$metavalue\"}";
     352
     353        } else {
     354        my $first_metaval = 1;
     355        $metapos = 0;
     356        $metavalue = $self->get_metadata_from_archive_xml($gsdl_cgi, $doc_filename, $metaname, $metapos, $docid_secnum);
     357
     358        while (defined $metavalue && $metavalue ne "") {
     359            if($first_metaval) {       
     360            $first_metaval = 0;
     361            } else {
     362            $json_result_str .= ",";
     363            }
     364       
     365            $json_result_str .= "{\"metapos\":\"$metapos\",\"metavalue\":\"$metavalue\"}";
     366
     367            $metapos++;
     368            $metavalue = $self->get_metadata_from_archive_xml($gsdl_cgi, $doc_filename, $metaname, $metapos, $docid_secnum);
     369        }
     370        }
     371
     372        $json_result_str .= "]}"; # close metavals array and metatable record
     373    }
     374   
     375    $json_result_str .= "]}"; # close metatable array and docid record
     376    }
     377
     378    $json_result_str .= "]"; # close array of docids
     379    $gsdl_cgi->generate_ok_message($json_result_str."\n");
    277380}
    278381
     
    383486    $json_result_str .= "]"; # close array of docids
    384487
    385     $gsdl_cgi->generate_ok_message($json_result_str);   
     488    $gsdl_cgi->generate_ok_message($json_result_str."\n");   
    386489}
    387490
     
    565668    my $collect   = $self->{'collect'};
    566669    my $gsdl_cgi  = $self->{'gsdl_cgi'};
    567     my $gsdlhome  = $self->{'gsdlhome'};
     670#   my $gsdlhome  = $self->{'gsdlhome'};
    568671    my $infodbtype = $self->{'infodbtype'};
    569672
     
    14941597    my $new_depth = scalar(@$contextArray);
    14951598
    1496     print STDERR "**** START SECTION \n";
     1599#   print STDERR "**** START SECTION \n";
    14971600   
    14981601    if ($new_depth == 1) {
Note: See TracChangeset for help on using the changeset viewer.