Changeset 27176


Ignore:
Timestamp:
04/12/13 17:27:33 (8 years ago)
Author:
ak19
Message:

import_meta functions are complete and tested now in this 2nd commit for them which primarily adds metapos and prevmetavalue for all the import_meta subroutines. Further corrections and cleaning up are part of this commit as well, including removing the append flag sent to gdbmset methods called by the live_meta functions, as the live meta subroutines seem to accumulate (append) by default for new metanames else overwrite existing ones if they have matching metanames.

File:
1 edited

Legend:

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

    r27173 r27176  
    4848    "get-import-metadata" => {
    4949        'compulsory-args' => [ "d", "metaname" ],
    50         'optional-args'   => [ ] },
     50        'optional-args'   => [ "metapos" ] },
    5151
    5252    "get-archives-metadata" => {
     
    8585    "set-import-metadata" => {
    8686        'compulsory-args' => [ "metaname", "metavalue" ],
    87         'optional-args'   => [ "d", "f", "metamode" ] }, # metamode can be "accumulate", "override", or "unique-id". Also need to add the ability to specify a previous metadata value to overwrite (because we can't use metapos)
     87        'optional-args'   => [ "d", "f", "metamode", "metapos", "prevmetavalue" ] }, # metamode can be "accumulate", "override", or "unique-id". Also need to add the ability to specify a previous metadata value to overwrite (because we can't use metapos). Metapos now supported, but assumes you are working with a Simple (instead of Complex) collection
    8888                 
    8989    #SET METHODS (ARRAY)
     
    111111    "remove-import-metadata" => {
    112112        'compulsory-args' => [ "d", "metaname", "metavalue" ], #TODO: add f argument
    113         'optional-args'   => [ ] },
     113        'optional-args'   => [ "metapos" ] }, # only provide metapos arg for SIMPLE collections
    114114                     
    115115    "remove-archives-metadata" => {
     
    314314    my $docid     = $self->{'d'};
    315315    my $metaname  = $self->{'metaname'};
     316    my $metapos = $self->{'metapos'};
     317    $metapos = 0 if (!defined $metapos); # gets the first value by default since metapos defaults to 0
     318
    316319    my $infodbtype = $self->{'infodbtype'};
    317     if (!defined $docid)
     320    if (!defined $docid)
    318321    {
    319322        $gsdl_cgi->generate_error("No docid (d=...) specified.\n");
     
    339342    my $metadata_xml_filename = &util::filename_cat($import_dirname, "metadata.xml");
    340343
    341     $gsdl_cgi->generate_ok_message($self->get_metadata_from_metadata_xml($gsdl_cgi, $metadata_xml_filename, $metaname, $import_tailname));
     344    $gsdl_cgi->generate_ok_message($self->get_metadata_from_metadata_xml($gsdl_cgi, $metadata_xml_filename, $metaname, $metapos, $import_tailname));
    342345
    343346    # Release the lock once it is done
     
    348351{
    349352    my $self = shift @_;
    350     my ($gsdl_cgi, $metadata_xml_filename, $metaname, $src_file) = @_;
     353    my ($gsdl_cgi, $metadata_xml_filename, $metaname, $metapos, $src_file) = @_;
    351354   
    352355    my @rules =
     
    377380        close(MIN);
    378381
    379         $parser->parse($xml_in, {metaname => $metaname, src_file => $src_file});
     382        $parser->parse($xml_in, {metaname => $metaname, metapos => $metapos, src_file => $src_file});
    380383       
    381384        if(defined $parser->{'pad'}->{'metavalue'})
     
    394397    my ($tagname, $attrHash, $contextArray, $parentDataArray, $parser) = @_;
    395398
    396     if (($parser->{'parameters'}->{'src_file'} eq $parser->{'parameters'}->{'current_file'}) && ($attrHash->{'name'} eq $parser->{'parameters'}->{'metaname'}))
     399    # no subsection support yet in metadata.xml
     400
     401    if (($parser->{'parameters'}->{'src_file'} eq $parser->{'parameters'}->{'current_file'}) && $parser->{'parameters'}->{'metaname'} eq $attrHash->{'name'})
    397402    {
    398         $parser->{'pad'}->{'metavalue'} = $attrHash->{'_content'};
     403        if (!defined $parser->{'parameters'}->{'poscount'})
     404        {
     405            $parser->{'parameters'}->{'poscount'} = 0;
     406        }
     407        else
     408        {
     409            $parser->{'parameters'}->{'poscount'}++;
     410        }
     411   
     412        # gets the first value by default, since metapos defaults to 0
     413        if (($parser->{'parameters'}->{'poscount'} == $parser->{'parameters'}->{'metapos'}))
     414        {
     415            if($parser->{'parameters'}->{'metapos'} > 0) {
     416            print STDERR "@@@@ WARNING: non-zero metapos.\n";
     417            print STDERR "@@@@ Assuming SIMPLE collection and proceeding to retrieve the import meta at".$parser->{'parameters'}->{'metapos'}.".\n";
     418            }
     419            $parser->{'pad'}->{'metavalue'} = $attrHash->{'_content'};
     420        }
    399421    }
    400422}
     
    540562    }
    541563    my $metavalue = $self->{'metavalue'};
    542     my $metamode  = $self->{'metamode'} || "accumulate";
    543     my $append_or_not = ($metamode eq "accumulate") ? " \"append\"" : "";
    544564
    545565    # Generate the dbkey   
     
    555575
    556576    # Set the new value
    557     my $cmd = "gdbmset \"$infodb_file_path\" \"$dbkey\" \"$metavalue\"$append_or_not";
     577    my $cmd = "gdbmset \"$infodb_file_path\" \"$dbkey\" \"$metavalue\"";
    558578    my $status = system($cmd);
    559579    if ($status != 0) {
     
    624644    $doc_rec->{$metaname}->[$metapos] = $metavalue;
    625645    }
    626     elsif (defined $metamode && $metamode eq "accumulate") {
     646    elsif (defined $metamode && $metamode eq "override") {
     647    $doc_rec->{$metaname} = [ $metavalue ];
     648    }
     649    else { # default for index was to override, but because accumulate is less destructive,
     650    # and because accumulate is the default for archives and import, that's the new default for index too
    627651    if(defined $doc_rec->{$metaname}) {
    628652        push(@{$doc_rec->{$metaname}}, $metavalue); # accumulate the value for that metaname
     
    630654        $doc_rec->{$metaname} = [ $metavalue ];
    631655    }
    632 
    633     }
    634     else { # default for index was to override
    635     $doc_rec->{$metaname} = [ $metavalue ];
    636656    }
    637657 
     
    665685    # as yet no support for setting subsection metadata in metadata.xml
    666686    if ((defined $docid_secnum) && ($docid_secnum !~ m/^\s*$/)) {
    667         $gsdl_cgi->generate_ok_message("*** Unable to set import metadata for subsections at this stage.\n");
     687        $gsdl_cgi->generate_message("*** No support yet for setting import metadata at subsections level.\n");
    668688        return;
    669689    }
     
    688708    }
    689709
    690     # Obtain where the metadata.xml is from the archiveinfo-doc.gdb file
    691     # If the doc oid is not specified, we assume the metadata.xml is next to the specified "f"
    692     my $metadata_xml_file;
    693     my $import_filename = undef;
    694     if (defined $docid) {
    695     my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir);
    696     my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $docid_root);
    697 
    698     # This now stores the full pathname
    699     $import_filename = $doc_rec->{'src-file'}->[0];
    700     }
    701     else {
    702         $import_filename = &util::filename_cat($collect_dir,$collect,$import_file);
    703     }
    704 
    705     # figure out correct metadata.xml file [?]
    706     # Assuming the metadata.xml file is next to the source file
    707     # Note: This will not work if it is using the inherited metadata from the parent folder
    708     my ($import_tailname, $import_dirname) = File::Basename::fileparse($import_filename);
    709     my $metadata_xml_filename = &util::filename_cat($import_dirname,"metadata.xml");
    710 
    711     # Edit the metadata.xml
    712     # Modified by Jeffrey from DL Consulting
    713     # Handle the case where there is one metadata.xml file for multiple FileSets
    714     # The XML filter needs to know whether it is in the right FileSet
    715     # TODO: This doesn't fix the problem where the metadata.xml is not next to the src file.
    716     # TODO: This doesn't handle the common metadata (where FileName doesn't point to a single file)
    717     $self->edit_metadata_xml($gsdl_cgi, $metadata_xml_filename,
    718                  $metaname, $metavalue, $metamode, $import_tailname);
    719 
     710    # adding metapos and prevmetavalue support to import_metadata subroutines
     711    my $metapos   = $self->{'metapos'}; # don't force undef to 0. Undef has meaning when metamode=override
     712    my $prevmetavalue = $self->{'prevmetavalue'};
     713
     714    my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir);
     715    my $metadata_xml_filename = $self->set_import_metadata_entry($gsdl_cgi, $arcinfo_doc_filename, $infodbtype, $docid_root, $metaname, $metapos,$metavalue, $metamode,$prevmetavalue, $collect, $collect_dir); # at this point, docid_root = docid
    720716
    721717    my $mess = "set-import-metadata successful: Key[$docid] -> $metadata_xml_filename\n";
     
    749745    my $prevmetavalue = $self->{'prevmetavalue'};
    750746   
    751     my $metapos    = $self->{'metapos'}; # Don't append "|| undef", since if metapos=0 it will then be set to undef
    752 
    753     # Don't set metapos=0 if it's undefined, as doing so will interfere when overriding all values for a metaname
    754     # (all values for a metaname should get overridden if metamode=override combined with no user-defined metapos)
     747    my $metapos    = $self->{'metapos'}; # don't force undef to 0. Undef has meaning when metamode=override
     748                                  # Don't append "|| undef", since if metapos=0 it will then be set to undef
    755749
    756750    my $metamode   = $self->{'metamode'};
     
    804798    my $docid     = $self->{'d'};
    805799    my $metaname  = $self->{'metaname'};
    806     my $metapos   = $self->{'metapos'};
     800    my $metapos   = $self->{'metapos'}; # undef has meaning
    807801    my $metavalue = $self->{'metavalue'};
    808802    my $infodbtype = $self->{'infodbtype'};
     
    10201014    my $metaname  = $doc_array_rec->{'metaname'};
    10211015    if(defined $metaname) {
    1022         my $metapos   = $doc_array_rec->{'metapos'};
     1016        my $metapos   = $doc_array_rec->{'metapos'}; # can legitimately be undef
    10231017        my $metavalue = $doc_array_rec->{'metavalue'};
    10241018        my $metamode = $doc_array_rec->{'metamode'} || $self->{'metamode'};
     
    11391133        my $dbkey = "$docid.$metaname";
    11401134        my $metavalue = $doc_array_rec->{'metavalue'};
    1141         # no metapos for live_meta, so can default metamode to accumulate
    1142         my $metamode  = $doc_array_rec->{'metamode'} || $self->{'metamode'} || "accumulate";
    1143    
    1144         my $append_or_not = ($metamode eq "accumulate") ? " \"append\"" : "";
    11451135
    11461136        # Set the new value
    1147         my $cmd = "gdbmset \"$infodb_file_path\" \"$dbkey\" \"$metavalue\"$append_or_not";
     1137        my $cmd = "gdbmset \"$infodb_file_path\" \"$dbkey\" \"$metavalue\"";
    11481138        $status = system($cmd);
    11491139
     
    11521142        foreach my $metatable_rec ( @$metatable ) {
    11531143        $metaname  = $metatable_rec->{'metaname'};
    1154         my $metamode = $metatable_rec->{'metamode'} || $doc_array_rec->{'metamode'} || $self->{'metamode'} || "accumulate";
    1155         my $append_or_not = ($metamode eq "accumulate") ? " \"append\"" : "";
    11561144        my $dbkey = "$docid.$metaname";
    11571145
    11581146        my $metavals = $metatable_rec->{'metavals'}; # a sub-subarray
    11591147        foreach my $metavalue ( @$metavals ) {
    1160              my $cmd = "gdbmset \"$infodb_file_path\" \"$dbkey\" \"$metavalue\"$append_or_not";
     1148             my $cmd = "gdbmset \"$infodb_file_path\" \"$dbkey\" \"$metavalue\"";
    11611149             $status = system($cmd);
    1162              $append_or_not = " \"append\"";  # even if metamode=override, need to accumulate all subsequent
    1163              # metavals for this metaname, else the just-assigned metavalue for this metaname will be lost
    11641150        }
    11651151        }
     
    16211607    if(defined $metaname) {
    16221608       
    1623         my $metapos   = $doc_array_rec->{'metapos'} || 0;
     1609        my $metapos   = $doc_array_rec->{'metapos'}; # don't force undef to 0. Undef has meaning when metamode=override
     1610
    16241611        my $metamode  = $doc_array_rec->{'metamode'} || $self->{'metamode'};
    16251612        my $metavalue = $doc_array_rec->{'metavalue'};
    16261613        my $prevmetavalue = $self->{'prevmetavalue'}; # to make this sub behave as _set_archives_metadata
    16271614       
    1628         # Some sanity checks
    1629         $metapos = 0 if (!defined $metapos);
    16301615       
    16311616        if ((!defined $metamode) || ($metamode =~ m/^\s*$/)) {
     
    18821867        }
    18831868       
    1884         # if overriding but no metapos, then clear all the meta for this metaname
     1869        # if overriding (for set-meta) but no metapos, then clear all the meta for this metaname
    18851870        if ((defined $parser->{'parameters'}->{'metamode'}) && ($parser->{'parameters'}->{'metamode'} eq "override") && (!defined $parser->{'parameters'}->{'metapos'})) {         
    18861871            return [];
     
    19171902    # file. 
    19181903    # So, skip anything with a .* in it as it is too general
    1919 #   print STDERR "@@@@ Skipping entry in metadata.xml where FileName=.* as it is too general\n";
     1904##  print STDERR "@@@@ Skipping entry in metadata.xml where FileName=.* as it is too general\n";
    19201905    return [$tagname => $attrHash];
    19211906    }
     
    19291914    my $name_attr = $attrHash->{'name'};
    19301915    if (($name_attr eq $metaname) && ($metamode eq "override")) {
    1931         # Get the value and override the current value
     1916
     1917    # now metadata.xml functions need to keep track of metapos
     1918    if (!defined $parser->{'parameters'}->{'poscount'})
     1919    {
     1920        $parser->{'parameters'}->{'poscount'} = 0;
     1921    }
     1922    else
     1923    {
     1924        $parser->{'parameters'}->{'poscount'}++;
     1925    }
     1926
     1927    # If either the metapos or prevmetavalue is set,
     1928        # get the value and override the current value
    19321929    my $metavalue = $parser->{'parameters'}->{'metavalue'};
    1933     $attrHash->{'_content'} = $metavalue;
    1934 
    1935 ##  print STDERR "**** overriding metadata.xml\n";
    1936 
    1937     # Don't want it to wipe out any other pieces of metadata
    1938     $parser->{'parameters'}->{'metamode'} = "done";
    1939     }
     1930
     1931    if(defined $parser->{'parameters'}->{'prevmetavalue'} && $parser->{'parameters'}->{'prevmetavalue'} eq $attrHash->{'_content'})
     1932    {
     1933        $attrHash->{'_content'} = $metavalue;
     1934
     1935        ##  print STDERR "**** overriding metadata.xml\n";
     1936       
     1937        # Don't want it to wipe out any other pieces of metadata
     1938        $parser->{'parameters'}->{'metamode'} = "done";
     1939    }
     1940    elsif(defined $parser->{'parameters'}->{'metapos'} && $parser->{'parameters'}->{'poscount'} == $parser->{'parameters'}->{'metapos'})
     1941    {
     1942        $attrHash->{'_content'} = $metavalue;
     1943        $parser->{'parameters'}->{'metamode'} = "done";
     1944    }
     1945    }
     1946
     1947    # mxml_description will process the metadata if metadata is accumulate,
     1948    # or if we haven't found the metadata to override
    19401949
    19411950    # RAW is [$tagname => $attrHash] not $tagname => $attrHash!!
     
    19701979    # multiple FileSets, it will add to all of them
    19711980    if (($metamode eq "accumulate") || ($metamode eq "override")) {
     1981
    19721982    # if metamode was "override" but get to here then it failed to
    19731983    # find an item to override, in which case it should append its
    19741984    # value to the end, just like the "accumulate" mode
     1985
     1986    if ($metamode eq "override") {
     1987        print "No metadata value to override.  Switching 'metamode' to accumulate\n";
     1988    }
    19751989
    19761990    # tack a new metadata tag on to the end of the <Metadata>+ block
     
    21032117{
    21042118    my $self = shift @_;
    2105     my ($gsdl_cgi, $metadata_xml_filename, $metaname, $metavalue, $metamode, $src_file) = @_;
     2119    my ($gsdl_cgi, $metadata_xml_filename, $metaname, $metapos, $metavalue, $metamode, $src_file, $prevmetavalue) = @_;
    21062120
    21072121    # Set the call-back functions for the metadata tags
     
    21752189
    21762190            $parser->filter($xml_in, $MOUT, { metaname => $metaname,
     2191                              metapos => $metapos,
    21772192                      metavalue => $metavalue,
    21782193                      metamode => $metamode,
    21792194                      src_file => $src_file,
     2195                      prevmetavalue => $prevmetavalue,
    21802196                      current_file => undef} );
    21812197            close($MOUT);       
     
    22682284    my $docid = $doc_array_rec->{'docid'};
    22692285   
    2270     push(@all_docids,$docid);
     2286    my ($docid_root,$docid_secnum);
     2287    if(defined $docid) {   
     2288        ($docid_root,$docid_secnum) = ($docid =~ m/^(.*?)(\..*)?$/);   
     2289        # as yet no support for setting subsection metadata in metadata.xml
     2290        if ((defined $docid_secnum) && ($docid_secnum !~ m/^\s*$/)) {
     2291        $gsdl_cgi->generate_message("*** docid: $docid. No support yet for setting import metadata at subsections level.\n");
     2292        next; # skip this docid in for loop
     2293        }
     2294    }
     2295
     2296    push(@all_docids,$docid); # docid_root rather
    22712297   
    22722298    my $metaname = $doc_array_rec->{'metaname'};
     
    22742300        my $metamode = $doc_array_rec->{'metamode'} || $self->{'metamode'};
    22752301        my $metavalue = $doc_array_rec->{'metavalue'};
    2276        
     2302        $metavalue =~ s/&lt;(.*?)&gt;/<$1>/g;
     2303
    22772304        if ((!defined $metamode) || ($metamode =~ m/^\s*$/)) {
    22782305        # make "accumulate" the default (less destructive, as won't actually
     
    22802307        $metamode = "accumulate";
    22812308        }
    2282        
    2283         $self->set_import_metadata_entry($gsdl_cgi, $arcinfo_doc_filename, $infodbtype, $docid, $metaname, $metavalue, $metamode);
     2309
     2310        # adding metapos and prevmetavalue support to import_metadata subroutines
     2311        my $metapos   = $doc_array_rec->{'metapos'}; # don't force undef to 0. Undef has meaning when metamode=override
     2312        my $prevmetavalue = $self->{'prevmetavalue'};
     2313
     2314        $self->set_import_metadata_entry($gsdl_cgi, $arcinfo_doc_filename, $infodbtype, $docid_root, $metaname, $metapos, $metavalue, $metamode, $prevmetavalue, $collect, $collect_dir); # at this point, docid_root = docid
    22842315       
    22852316    } elsif (defined $doc_array_rec->{'metatable'}) { # if no metaname, we expect a metatable
     
    22942325            $metamode = "accumulate";
    22952326        }
    2296         # no metapos for import
     2327
     2328        # No support for metapos and prevmetavalue in the JSON metatable substructure
     2329        my $metapos = undef;
     2330        my $prevmetavalue = undef;
    22972331        my $metavals = $metatable_rec->{'metavals'}; # a sub-subarray
    22982332       
    22992333        foreach my $metavalue ( @$metavals ) {
    2300             $self->set_import_metadata_entry($gsdl_cgi, $arcinfo_doc_filename, $infodbtype, $docid, $metaname, $metavalue, $metamode);
     2334            $metavalue =~ s/&lt;(.*?)&gt;/<$1>/g;
     2335
     2336            $self->set_import_metadata_entry($gsdl_cgi, $arcinfo_doc_filename, $infodbtype, $docid_root, $metaname, $metapos, $metavalue, $metamode, $prevmetavalue, $collect, $collect_dir); # at this point, docid_root = docid
    23012337            if($metamode eq "override") { # now, having overridden the first metavalue of the metaname,
    23022338            # need to accumulate subsequent metavals for this metaname, else the just-assigned
     
    23182354{
    23192355    my $self = shift @_;
    2320     my ($gsdl_cgi, $arcinfo_doc_filename, $infodbtype, $docid, $metaname, $metavalue, $metamode) = @_;
     2356    my ($gsdl_cgi, $arcinfo_doc_filename, $infodbtype, $docid, $metaname, $metapos, $metavalue, $metamode, $prevmetavalue, $collect, $collect_dir) = @_;
     2357
     2358    my $info_mess = <<RAWEND;
     2359****************************
     2360  set_import_metadata_entry()
     2361****************************
     2362collect = $collect
     2363collect_dir = $collect_dir
     2364infodbtype = $infodbtype
     2365arcinfo_doc_filename = $arcinfo_doc_filename
     2366docid = $docid
     2367metaname = $metaname
     2368metapos = $metapos
     2369metavalue = $metavalue
     2370metamode = $metamode
     2371prevmetavalue = $prevmetavalue
     2372****************************
     2373RAWEND
     2374
     2375    $gsdl_cgi->generate_message($info_mess);
     2376
     2377    # import works with metadata.xml which can have inherited metadata
     2378    # so setting or removing at a metapos can have unintended effects for a COMPLEX collection
     2379    # (a collection that has or can have inherited metadata). Metapos has expected behaviour for
     2380    # a SIMPLE collection, which is one that doesn't have inherited metadata. Assume caller knows
     2381    # what they're doing if they provide a metapos.
     2382    if(defined $metapos) {
     2383    print STDERR "@@@@ WARNING: metapos defined.\n";
     2384    print STDERR "@@@@ Assuming SIMPLE collection and proceeding to modify the import meta at $metapos.\n";
     2385    }
    23212386
    23222387    # Obtain where the metadata.xml is from the archiveinfo-doc.gdb file
     
    23252390    my $import_filename = undef;
    23262391   
    2327     my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $docid);
    2328 
    2329     # This now stores the full pathname
    2330     $import_filename = $doc_rec->{'src-file'}->[0];
     2392    if (defined $docid) {
     2393    # my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir);
     2394    my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $docid);
     2395
     2396    # This now stores the full pathname
     2397    $import_filename = $doc_rec->{'src-file'}->[0];
     2398    } else { # only for set_import_meta, not the case when calling method is set_import_metadata_array
     2399         # as the array version of the method doesn't support the -f parameter yet
     2400    my $import_file  = $self->{'f'};
     2401    $import_filename = &util::filename_cat($collect_dir,$collect,$import_file);
     2402    }
    23312403   
    23322404    # figure out correct metadata.xml file [?]
     
    23362408    my $metadata_xml_filename = &util::filename_cat($import_dirname,"metadata.xml");
    23372409   
    2338     $self->edit_metadata_xml($gsdl_cgi, $metadata_xml_filename, $metaname, $metavalue, $metamode, $import_tailname);
    2339     return 1;
     2410    # If we're overriding everything, then $metamode=override combined with $metapos=undefined
     2411    # in which case, we need to remove all metavalues for the metaname at the given (sub)section
     2412    # Thereafter, we will finally be able to set the overriding metavalue for this metaname
     2413    if(!defined $metapos && $metamode eq "override") {
     2414##  print STDERR "@@@ REMOVING all import metadata for $metaname\n";
     2415    $self->remove_from_metadata_xml($gsdl_cgi, $metadata_xml_filename, $metaname, $metapos, undef, $import_tailname, $metamode); # we're removing all values, so metavalue=undef
     2416
     2417    }
     2418
     2419    # Edit the metadata.xml
     2420    # Modified by Jeffrey from DL Consulting
     2421    # Handle the case where there is one metadata.xml file for multiple FileSets
     2422    # The XML filter needs to know whether it is in the right FileSet
     2423    # TODO: This doesn't fix the problem where the metadata.xml is not next to the src file.
     2424    # TODO: This doesn't handle the common metadata (where FileName doesn't point to a single file)
     2425    $self->edit_metadata_xml($gsdl_cgi, $metadata_xml_filename, $metaname,
     2426                 $metapos, $metavalue, $metamode, $import_tailname, $prevmetavalue);
     2427    #return 0;
     2428    return $metadata_xml_filename;
    23402429}
    23412430
     
    23652454   
    23662455    my $metaname = $self->{'metaname'};
     2456    my $metapos = $self->{'metapos'};
    23672457    my $metavalue = $self->{'metavalue'};
    2368     $metavalue =~ s/&lt;(.*?)&gt;/<$1>/g;
     2458    if(defined $metavalue) {
     2459        $metavalue =~ s/&lt;(.*?)&gt;/<$1>/g;
     2460    } elsif (!defined $metapos) { # if given no metavalue or metapos to delete, default to deleting the 1st
     2461        $metapos = 0;
     2462    }
     2463    my $metamode = $self->{'metamode'} || undef;
     2464
     2465    # import works with metadata.xml which can have inherited metadata
     2466    # so setting or removing at a metapos can have unintended effects for a COMPLEX collection
     2467    # (a collection that has or can have inherited metadata). Metapos has expected behaviour for
     2468    # a SIMPLE collection, which is one that doesn't have inherited metadata. Assume caller knows
     2469    # what they're doing if they provide a metapos.
     2470    if(defined $metapos) {
     2471        print STDERR "@@@@ WARNING: metapos defined.\n";
     2472        print STDERR "@@@@ Assuming SIMPLE collection and proceeding to modify the import meta at $metapos.\n";
     2473    }
    23692474   
    23702475    # Obtain where the metadata.xml is from the archiveinfo-doc.gdb file
     
    23922497    my $metadata_xml_filename = &util::filename_cat($import_dirname,"metadata.xml");
    23932498   
    2394     $self->remove_from_metadata_xml($gsdl_cgi, $metadata_xml_filename, $metaname, $metavalue, $import_tailname);
     2499    $self->remove_from_metadata_xml($gsdl_cgi, $metadata_xml_filename, $metaname, $metapos, $metavalue, $import_tailname, $metamode); # metamode has no meaning for removing meta, but is used by set_meta when overriding All
    23952500   
    23962501    my $mess = "remove-import-metadata successful: Key[$docid] -> $metadata_xml_filename\n";
     
    24292534{
    24302535    my $self = shift @_;
    2431     my ($gsdl_cgi, $metadata_xml_filename, $metaname, $metavalue, $src_file) = @_;
    2432    
     2536    my ($gsdl_cgi, $metadata_xml_filename, $metaname, $metapos, $metavalue, $src_file, $metamode) = @_;
     2537    # metamode generally has no meaning for removing meta, but is used by set_meta
     2538    # when overriding all metavals for a metaname, in which case remove_meta is called with metamode
     2539
    24332540    # Set the call-back functions for the metadata tags
    24342541    my @rules =
     
    24712578        else {
    24722579            binmode($MOUT,":utf8");
    2473             $parser->filter($xml_in, $MOUT, {metaname => $metaname, metavalue => $metavalue, src_file => $src_file, current_file => undef});
     2580            $parser->filter($xml_in, $MOUT, {metaname => $metaname, metapos => $metapos, metavalue => $metavalue, src_file => $src_file, metamode => $metamode, current_file => undef});
    24742581            close($MOUT);       
    24752582        }
     
    24812588    my ($tagname, $attrHash, $contextArray, $parentDataArray, $parser) = @_;
    24822589
    2483     if ((defined $parser->{'parameters'}->{'metavalue'}) && ($parser->{'parameters'}->{'src_file'} eq $parser->{'parameters'}->{'current_file'}) && ($attrHash->{'name'} eq $parser->{'parameters'}->{'metaname'}) && ($attrHash->{'_content'} eq $parser->{'parameters'}->{'metavalue'}))
     2590    # metadata.xml does not handle subsections
     2591
     2592    # since metadata.xml now has to deal with metapos, we keep track of the metadata position
     2593    if (($parser->{'parameters'}->{'src_file'} eq $parser->{'parameters'}->{'current_file'})
     2594        && $parser->{'parameters'}->{'metaname'} eq $attrHash->{'name'})
    24842595    {
    2485         return [];
     2596        if (!defined $parser->{'parameters'}->{'poscount'})
     2597        {
     2598            $parser->{'parameters'}->{'poscount'} = 0;
     2599        }
     2600        else
     2601        {
     2602            $parser->{'parameters'}->{'poscount'}++;
     2603        }
     2604
     2605        # if overriding but no metapos, then clear all the meta for this metaname
     2606        if ((defined $parser->{'parameters'}->{'metamode'}) && ($parser->{'parameters'}->{'metamode'} eq "override") && (!defined $parser->{'parameters'}->{'metapos'})) {
     2607            return [];
     2608        }
     2609   
     2610        if ((defined $parser->{'parameters'}->{'metapos'}) && ($parser->{'parameters'}->{'poscount'} == $parser->{'parameters'}->{'metapos'}))
     2611        {
     2612            return [];
     2613        }
     2614
     2615        if ((defined $parser->{'parameters'}->{'metavalue'}) && ($attrHash->{'_content'} eq $parser->{'parameters'}->{'metavalue'}))
     2616        {
     2617            return [];
     2618        }       
    24862619    }
    24872620
     
    26602793
    26612794    # Obtain the specified metadata pos
    2662     if(!defined $metapos && !defined $metavalue) { #$metapos = 0 if (!defined $metapos);
     2795    # if no metavalue or metapos to delete, default to deleting the 1st value for the metaname
     2796    if(!defined $metapos && !defined $metavalue) {
    26632797        $metapos = 0;
    26642798    }
     
    27882922    my $metamode = "accumulate";
    27892923
     2924    # metapos/prevmetavalue were never before used in this subroutine, so set them to undefined
     2925    my $metapos   = undef;
     2926    my $prevmetavalue = undef;
     2927
    27902928    #=======================================================================#
    27912929    # set_import_metadata [START]
     
    28292967    # TODO: This doesn't fix the problem where the metadata.xml is not next to the src file.
    28302968    # TODO: This doesn't handle the common metadata (where FileName doesn't point to a single file)
    2831     $self->edit_metadata_xml($gsdl_cgi, $metadata_xml_filename,
    2832                              $metaname, $metavalue, $metamode, $import_tailname);
     2969    $self->edit_metadata_xml($gsdl_cgi, $metadata_xml_filename, $metaname,
     2970                 $metapos, $metavalue, $metamode, $import_tailname, $prevmetavalue);
    28332971    #=======================================================================#
    28342972    # set_import_metadata [END]
Note: See TracChangeset for help on using the changeset viewer.