Changeset 27157


Ignore:
Timestamp:
04/04/13 18:26:18 (8 years ago)
Author:
ak19
Message:

First pass updating metadataaction.pm to create generic set_meta, remove_meta methods that still do the default of setting or removing index meta, but if the where variable is specified, they will set archives, import, index and/or live meta accordingly. For symmetry, there is now a get_index_meta. This is always called by get_meta since get_meta is not generic.

File:
1 edited

Legend:

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

    r27156 r27157  
    88# Copyright (C) 2009 New Zealand Digital Library Project
    99#
    10 # This program is free software; you can redistribute it and/or modify
     10# This program is free software; you can redistr   te it and/or modify
    1111# it under the terms of the GNU General Public License as published by
    1212# the Free Software Foundation; either version 2 of the License, or
     
    5454        'optional-args'   => [ "metapos" ] },
    5555   
    56     "get-metadata" => {
     56    "get-index-metadata" => {
    5757        'compulsory-args' => [ "d", "metaname" ],
    5858        'optional-args'   => [ "metapos" ] },
     59
     60    "get-metadata" => { # alias for get-index-metadata
     61        'compulsory-args' => [ "d", "metaname" ],
     62        'optional-args'   => [ "metapos" ] },
    5963
    6064    "get-live-metadata" => {
     
    6771        'optional-args'   => [ ] },
    6872
    69     "set-metadata" => {
     73    "set-metadata" => { # generic set-meta function. The 'where' param can be set to any combination of index|archives|import|live. docid d is still compulsory for setting index, archives and live meta
     74        'compulsory-args' => [ "metaname", "metavalue" ],
     75        'optional-args'   => [ "where", "metapos", "metamode", "prevmetavalue", "d", "f" ] },
     76
     77    "set-index-metadata" => {
    7078        'compulsory-args' => [ "d", "metaname", "metavalue" ],
    7179        'optional-args'   => [ "metapos" ] },
     
    105113        'optional-args'   => [ ] },
    106114
    107     "remove-metadata" => {
     115    "remove-index-metadata" => {
    108116        'compulsory-args' => [ "d", "metaname" ],
    109117        'optional-args'   => [ "metapos", "metavalue" ] },
     118
     119    "remove-metadata" => { # generic remove-meta function. The 'where' param can be set to any combination of index|archives|import|live. docid d is still compulsory for setting index, archives and live meta
     120        'compulsory-args' => [ "d", "metaname" ],
     121        'optional-args'   => [ "where", "metapos", "metavalue" ] },
    110122
    111123    #INSERT METHODS
     
    202214}
    203215
    204 
     216# just calls the index version
    205217sub get_metadata
     218{
     219    my $self = shift @_;
     220    $self->get_index_metadata(@_);
     221}
     222
     223sub get_index_metadata
    206224{
    207225    my $self = shift @_;
     
    493511}
    494512
    495 sub set_live_metadata
     513sub _set_live_metadata
    496514{
    497515    my $self = shift @_;
    498516
    499     my $username  = $self->{'username'};
    500517    my $collect   = $self->{'collect'};
    501518    my $gsdl_cgi  = $self->{'gsdl_cgi'};
    502     my $gsdlhome  = $self->{'gsdlhome'};
     519    #my $gsdlhome  = $self->{'gsdlhome'};
    503520    my $infodbtype = $self->{'infodbtype'};
    504  
    505     if ($baseaction::authentication_enabled) {
    506     # Ensure the user is allowed to edit this collection
    507     &authenticate_user($gsdl_cgi, $username, $collect);
    508     }
    509521
    510522    # Obtain the collect dir
    511     my $site = $self->{'site'};
    512     my $collect_dir = $gsdl_cgi->get_collection_dir($site);
     523    my $site = $self->{'site'};
     524    my $collect_dir = $gsdl_cgi->get_collection_dir($site);
    513525    ##my $collect_dir = &util::filename_cat($gsdlhome, "collect");
    514526
    515     # Make sure the collection isn't locked by someone else
    516     $self->lock_collection($username, $collect);
    517527
    518528    # look up additional args
     
    552562    $gsdl_cgi->generate_ok_message("set-live-metadata successful: Key[$metaname]=$metavalue");
    553563    }
    554    
     564
     565    #return $status; # in case calling functions have any further use for this
     566}
     567
     568sub set_live_metadata
     569{
     570    my $self = shift @_;
     571
     572    my $username  = $self->{'username'};
     573    my $collect   = $self->{'collect'};
     574    my $gsdl_cgi  = $self->{'gsdl_cgi'};
     575 
     576    if ($baseaction::authentication_enabled) {
     577    # Ensure the user is allowed to edit this collection
     578    &authenticate_user($gsdl_cgi, $username, $collect);
     579    }
     580
     581    # Make sure the collection isn't locked by someone else
     582    $self->lock_collection($username, $collect);
     583
     584    $self->_set_live_metadata(@_);
     585
    555586    # Release the lock once it is done
    556587    $self->unlock_collection($username, $collect);
     
    589620}
    590621
    591 sub set_metadata
     622sub _set_import_metadata
    592623{
    593624    my $self = shift @_;
    594625
    595     my $username  = $self->{'username'};
    596626    my $collect   = $self->{'collect'};
    597627    my $gsdl_cgi  = $self->{'gsdl_cgi'};
    598     my $gsdlhome  = $self->{'gsdlhome'};
    599 
    600     if ($baseaction::authentication_enabled) {
    601     # Ensure the user is allowed to edit this collection
    602     &authenticate_user($gsdl_cgi, $username, $collect);
    603     }
    604 
    605     my $site = $self->{'site'};
    606     my $collect_dir = $gsdl_cgi->get_collection_dir($site);
    607    
    608     $gsdl_cgi->checked_chdir($collect_dir);
    609 
    610     # Obtain the collect dir
     628    my $infodbtype = $self->{'infodbtype'};
     629#    my $gsdlhome  = $self->{'gsdlhome'};
     630     
     631    # Obtain the collect and archive dir   
     632    my $site = $self->{'site'};
     633    my $collect_dir = $gsdl_cgi->get_collection_dir($site);
    611634    ## my $collect_dir = &util::filename_cat($gsdlhome, "collect");
    612 
    613     # Make sure the collection isn't locked by someone else
    614     $self->lock_collection($username, $collect);
     635    my $archive_dir = &util::filename_cat($collect_dir,$collect,"archives");
     636   
     637    # look up additional args
     638    # want either d= or f=
     639    my $docid  = $self->{'d'};
     640    my $import_file  = $self->{'f'};
     641    if ((!defined $docid) && (!defined $import_file)) {
     642    $gsdl_cgi->generate_error("No docid (d=...) or import file (f=) specified.");
     643    }
     644
     645    # Get the parameters and set default mode to "accumulate"
     646    my $metaname   = $self->{'metaname'};
     647    my $metavalue  = $self->{'metavalue'};
     648##    $metavalue =~ s/&amp;lt;(.*?)&amp;gt;/<$1>/g;
     649    $metavalue =~ s/&lt;(.*?)&gt;/<$1>/g;
     650   
     651    my $metamode   = $self->{'metamode'};
     652    if ((!defined $metamode) || ($metamode =~ m/^\s*$/)) {
     653    # make "accumulate" the default (less destructive, as won't actually
     654    # delete any existing values)
     655    $metamode = "accumulate";
     656    }
     657
     658    # Obtain where the metadata.xml is from the archiveinfo-doc.gdb file
     659    # If the doc oid is not specified, we assume the metadata.xml is next to the specified "f"
     660    my $metadata_xml_file;
     661    my $import_filename = undef;
     662    if (defined $docid) {
     663    my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir);
     664    my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $docid);
     665
     666    # This now stores the full pathname
     667    $import_filename = $doc_rec->{'src-file'}->[0];
     668    }
     669    else {
     670        $import_filename = &util::filename_cat($collect_dir,$collect,$import_file);
     671    }
     672
     673    # figure out correct metadata.xml file [?]
     674    # Assuming the metadata.xml file is next to the source file
     675    # Note: This will not work if it is using the inherited metadata from the parent folder
     676    my ($import_tailname, $import_dirname) = File::Basename::fileparse($import_filename);
     677    my $metadata_xml_filename = &util::filename_cat($import_dirname,"metadata.xml");
     678
     679    # Edit the metadata.xml
     680    # Modified by Jeffrey from DL Consulting
     681    # Handle the case where there is one metadata.xml file for multiple FileSets
     682    # The XML filter needs to know whether it is in the right FileSet
     683    # TODO: This doesn't fix the problem where the metadata.xml is not next to the src file.
     684    # TODO: This doesn't handle the common metadata (where FileName doesn't point to a single file)
     685    $self->edit_metadata_xml($gsdl_cgi, $metadata_xml_filename,
     686                             $metaname, $metavalue, $metamode, $import_tailname);
     687
     688
     689    my $mess = "set-import-metadata successful: Key[$docid] -> $metadata_xml_filename\n";
     690    $mess .= "  $metaname";
     691    $mess .= " = $metavalue";
     692    $mess .= " ($metamode)\n";
     693
     694    $gsdl_cgi->generate_ok_message($mess);
     695
     696    #return $status; # in case calling functions have any further use for this
     697}
     698
     699# the version of set_index_meta that doesn't do authentication
     700sub _set_archives_metadata
     701{
     702    my $self = shift @_;
     703
     704    my $collect   = $self->{'collect'};
     705    my $gsdl_cgi  = $self->{'gsdl_cgi'};
     706    my $infodbtype = $self->{'infodbtype'};
     707   
     708    # Obtain the collect and archive dir   
     709    my $site = $self->{'site'};
     710    my $collect_dir = $gsdl_cgi->get_collection_dir($site);
     711    my $archive_dir = &util::filename_cat($collect_dir,$collect,"archives");
     712
     713    # look up additional args
     714    my $docid  = $self->{'d'};
     715    my $metaname   = $self->{'metaname'};
     716    my $metavalue  = $self->{'metavalue'};
     717    my $prevmetavalue = $self->{'prevmetavalue'};
     718   
     719    my $metapos    = $self->{'metapos'};
     720    $metapos = 0 if (!defined $metapos);
     721
     722    my $metamode   = $self->{'metamode'};
     723    if ((!defined $metamode) || ($metamode =~ m/^\s*$/)) {
     724    # make "accumulate" the default (less destructive, as won't actually
     725    # delete any existing values)
     726    $metamode = "accumulate";
     727    }
     728   
     729    my $status = $self->set_archives_metadata_entry($gsdl_cgi,$archive_dir, $collect_dir,$collect, $infodbtype,$docid,
     730                $metaname,$metapos,$metavalue,$metamode,$prevmetavalue);
     731   
     732    if ($status == 0) {
     733    my $mess = "set-archives-metadata successful: Key[$docid]\n";
     734    $mess .= "  $metaname";
     735    $mess .= "->[$metapos]" if (defined $metapos);
     736    $mess .= " = $metavalue";
     737    $mess .= " ($metamode)\n";
     738   
     739    $gsdl_cgi->generate_ok_message($mess); 
     740    }
     741    else {
     742    my $mess .= "Failed to set archives metadata key: $docid\n";
     743    $mess .= "Exit status: $status\n";
     744    if(defined $self->{'error_msg'}) {
     745        $mess .= "Error Message: $self->{'error_msg'}\n";
     746    } else {
     747        $mess .= "System Error Message: $!\n";
     748    }
     749    $mess .= "-" x 20 . "\n";
     750   
     751    $gsdl_cgi->generate_error($mess);
     752    }
     753
     754    #return $status; # in case calling functions have any further use for this
     755}
     756
     757
     758# the version of set_index_meta that doesn't do authentication
     759sub _set_index_metadata
     760{
     761    my $self = shift @_;
     762
     763    my $collect   = $self->{'collect'};
     764    my $gsdl_cgi  = $self->{'gsdl_cgi'};
     765
     766    my $site = $self->{'site'};
     767    my $collect_dir = $gsdl_cgi->get_collection_dir($site);
    615768
    616769    # look up additional args
     
    634787    }
    635788    else {
    636     my $mess = "set-metadata successful: Key[$docid]\n";
     789    my $mess = "set-index-metadata successful: Key[$docid]\n";
    637790    $mess .= "  $metaname";
    638791    $mess .= "->[$metapos]" if (defined $metapos);
    639     $mess .= " = $metavalue";
     792    $mess .= " = $metavalue\n";
    640793   
    641794    $gsdl_cgi->generate_ok_message($mess);
    642795    }
     796
     797    #return $status; # in case calling functions have any further use for this
     798}
     799
     800sub set_index_metadata
     801{
     802    my $self = shift @_;
     803
     804    my $username  = $self->{'username'};
     805    my $collect   = $self->{'collect'};
     806    my $gsdl_cgi  = $self->{'gsdl_cgi'};
     807    #my $gsdlhome  = $self->{'gsdlhome'};
     808
     809    if ($baseaction::authentication_enabled) {
     810    # Ensure the user is allowed to edit this collection
     811    &authenticate_user($gsdl_cgi, $username, $collect);
     812    }
     813
     814    my $site = $self->{'site'};
     815    my $collect_dir = $gsdl_cgi->get_collection_dir($site);
     816   
     817    $gsdl_cgi->checked_chdir($collect_dir);
     818
     819    # Obtain the collect dir
     820    ## my $collect_dir = &util::filename_cat($gsdlhome, "collect");
     821
     822    # Make sure the collection isn't locked by someone else
     823    $self->lock_collection($username, $collect);
     824
     825    $self->_set_index_metadata(@_);
    643826   
    644827    # Release the lock once it is done
     
    646829}
    647830
     831# call this to set the metadata for a combination of dirs archives, import or index, or live
     832# if none specified, defaults to index which was the original behaviour of set_metadata.
     833sub set_metadata
     834{
     835    my $self = shift @_;
     836
     837    # Testing that not defining a variable, setting it to "" or to "  " all return false
     838    # >perl -e 'my $whichdirs=""; if($whichdirs) {print "$whichdirs\n"};'
     839
     840    my $where = $self->{'where'};
     841    if(!$where) {   
     842    $self->set_index_metadata(@_); # call the full version of set_index_meta for the default behaviour
     843    return;
     844    }
     845
     846    # authenticate and lock collection once, even if processing multiple dirs
     847    my $username  = $self->{'username'};
     848    my $collect   = $self->{'collect'};
     849    my $gsdl_cgi  = $self->{'gsdl_cgi'};
     850   
     851    if ($baseaction::authentication_enabled) {
     852    # Ensure the user is allowed to edit this collection
     853    #&authenticate_user($gsdl_cgi, $username, $collect);
     854    $self->authenticate_user($username, $collect);
     855    }
     856   
     857    if($where =~ m/index/) {
     858    my $site = $self->{'site'};
     859    my $collect_dir = $gsdl_cgi->get_collection_dir($site);
     860    $gsdl_cgi->checked_chdir($collect_dir);
     861    }
     862
     863    # Make sure the collection isn't locked by someone else
     864    $self->lock_collection($username, $collect);
     865
     866
     867    # now at last can set the metadata. $where can specify multiple
     868    # $where is of the form: import|archives|index, or a subset thereof
     869
     870    #my @whichdirs = split('\|', $where);
     871
     872    # just check whether $where contains import/archives/index/live in turn, and
     873    # for each case, process it accordingly
     874    if($where =~ m/import/) {
     875    $self->_set_import_metadata(@_);       
     876    }
     877
     878    if($where =~ m/archives/) {
     879
     880    # look up docID arg which is optional to set_metadata because it's optional
     881    # to set_import, but which is compulsory to set_archives_metadata
     882    my $docid     = $self->{'d'};
     883    if ((!defined $docid) || ($docid =~ m/^\s*$/)) {
     884        $gsdl_cgi->generate_error("No docid (d=...) specified.");
     885    }
     886    else { # we have a docid, so can set archives meta
     887        $self->_set_archives_metadata(@_);
     888    }
     889    }
     890
     891    if($where =~ m/index/) {
     892   
     893    # look up docID arg which is optional to set_metadata because it's optional
     894    # to set_import, but which is compulsory to set_archives_metadata
     895    my $docid     = $self->{'d'};
     896    if ((!defined $docid) || ($docid =~ m/^\s*$/)) {
     897        $gsdl_cgi->generate_error("No docid (d=...) specified.");
     898    }
     899    else { # we have a docid, so can set index meta
     900        $self->_set_index_metadata(@_);
     901    }
     902    }   
     903
     904    if($where =~ m/live/) {
     905    $self->_set_live_metadata(@_); # docid param, d, is compulsory, but is checked for in subroutine
     906    }
     907
     908    # Release the lock once it is done
     909    $self->unlock_collection($username, $collect);
     910}
    648911
    649912sub set_metadata_array
     
    10701333    my $collect   = $self->{'collect'};
    10711334    my $gsdl_cgi  = $self->{'gsdl_cgi'};
    1072     my $gsdlhome  = $self->{'gsdlhome'};
    1073     my $infodbtype = $self->{'infodbtype'};
    10741335   
    10751336    if ($baseaction::authentication_enabled) {
     
    10781339    }
    10791340
    1080     my $site = $self->{'site'};
    1081        
    1082     # Obtain the collect and archive dir   
    1083     my $collect_dir = $gsdl_cgi->get_collection_dir($site);
    1084    
    1085     my $archive_dir = &util::filename_cat($collect_dir,$collect,"archives");
    1086 
    10871341    # Make sure the collection isn't locked by someone else
    10881342    $self->lock_collection($username, $collect);
    10891343
    1090     # look up additional args
    1091     my $docid  = $self->{'d'};
    1092     my $metaname   = $self->{'metaname'};
    1093     my $metavalue  = $self->{'metavalue'};
    1094     my $prevmetavalue = $self->{'prevmetavalue'};
    1095    
    1096     my $metapos    = $self->{'metapos'};
    1097     $metapos = 0 if (!defined $metapos);
    1098 
    1099     my $metamode   = $self->{'metamode'};
    1100     if ((!defined $metamode) || ($metamode =~ m/^\s*$/)) {
    1101     # make "accumulate" the default (less destructive, as won't actually
    1102     # delete any existing values)
    1103     $metamode = "accumulate";
    1104     }
    1105    
    1106     my $status = $self->set_archives_metadata_entry($gsdl_cgi,$archive_dir, $collect_dir,$collect, $infodbtype,$docid,
    1107                 $metaname,$metapos,$metavalue,$metamode,$prevmetavalue);
    1108    
     1344    $self->_set_archives_metadata(@_);
     1345
    11091346    # Release the lock once it is done
    11101347    $self->unlock_collection($username, $collect);
    1111 
    1112     if ($status == 0) {
    1113         my $mess = "set-archives-metadata successful: Key[$docid]\n";
    1114         $mess .= "  $metaname";
    1115         $mess .= "->[$metapos]" if (defined $metapos);
    1116         $mess .= " = $metavalue";
    1117         $mess .= " ($metamode)\n";
    1118    
    1119         $gsdl_cgi->generate_ok_message($mess); 
    1120     }
    1121     else {
    1122         my $mess .= "Failed to set archives metadata key: $docid\n";
    1123         $mess .= "Exit status: $status\n";
    1124         if(defined $self->{'error_msg'}) {
    1125             $mess .= "Error Message: $self->{'error_msg'}\n";
    1126         } else {
    1127             $mess .= "System Error Message: $!\n";
    1128         }
    1129         $mess .= "-" x 20 . "\n";
    1130        
    1131         $gsdl_cgi->generate_error($mess);
    1132     }
    11331348}
    11341349
     
    12191434}
    12201435
    1221 sub remove_archives_metadata
     1436sub _remove_archives_metadata
    12221437{
    12231438    my $self = shift @_;
    12241439
    1225     my $username  = $self->{'username'};
    12261440    my $collect   = $self->{'collect'};
    12271441    my $gsdl_cgi  = $self->{'gsdl_cgi'};
    1228     my $gsdlhome  = $self->{'gsdlhome'};
     1442#   my $gsdlhome  = $self->{'gsdlhome'};
    12291443    my $infodbtype = $self->{'infodbtype'};
    1230    
    1231     if ($baseaction::authentication_enabled)
    1232     {
    1233         # Ensure the user is allowed to edit this collection
    1234         &authenticate_user($gsdl_cgi, $username, $collect);
    1235     }
    12361444   
    12371445    my $site = $self->{'site'};
     
    12421450    my $archive_dir = &util::filename_cat($collect_dir,$collect,"archives");
    12431451
    1244     # Make sure the collection isn't locked by someone else
    1245     $self->lock_collection($username, $collect);
    1246    
    12471452    # look up additional args
    12481453    my ($docid, $docid_secnum) = ($self->{'d'} =~ m/^(.*?)(\..*)?$/);
     
    12601465    my $status = $self->remove_from_doc_xml($gsdl_cgi, &util::filename_cat($archive_dir, $doc_filename), $metaname, $metapos, undef, $docid_secnum);
    12611466   
    1262     # Release the lock once it is done
    1263     $self->unlock_collection($username, $collect);
    1264 
    12651467    if ($status == 0)
    12661468    {
     
    12801482        $gsdl_cgi->generate_error($mess);
    12811483    }
     1484   
     1485    #return $status; # in case calling functions have a use for this
     1486}
     1487
     1488sub remove_archives_metadata
     1489{
     1490    my $self = shift @_;
     1491
     1492    my $username  = $self->{'username'};
     1493    my $collect   = $self->{'collect'};
     1494    my $gsdl_cgi  = $self->{'gsdl_cgi'};
     1495   
     1496    if ($baseaction::authentication_enabled)
     1497    {
     1498        # Ensure the user is allowed to edit this collection
     1499        &authenticate_user($gsdl_cgi, $username, $collect);
     1500    }
     1501
     1502    # Make sure the collection isn't locked by someone else
     1503    $self->lock_collection($username, $collect);
     1504
     1505    $self->_remove_archives_metadata(@_);
     1506
     1507    # Release the lock once it is done
     1508    $self->unlock_collection($username, $collect);
    12821509}
    12831510
     
    15941821    my $collect   = $self->{'collect'};
    15951822    my $gsdl_cgi  = $self->{'gsdl_cgi'};
    1596     my $gsdlhome  = $self->{'gsdlhome'};
    1597     my $infodbtype = $self->{'infodbtype'};
    15981823   
    15991824    if ($baseaction::authentication_enabled) {
     
    16021827    }
    16031828
    1604 
    1605     # Obtain the collect and archive dir   
    1606     my $site = $self->{'site'};
    1607     my $collect_dir = $gsdl_cgi->get_collection_dir($site);
    1608 
    1609     ## my $collect_dir = &util::filename_cat($gsdlhome, "collect");
    1610     my $archive_dir = &util::filename_cat($collect_dir,$collect,"archives");
    1611 
    16121829    # Make sure the collection isn't locked by someone else
    16131830    $self->lock_collection($username, $collect);
    1614    
    1615     # look up additional args
    1616     # want either d= or f=
    1617     my $docid  = $self->{'d'};
    1618     my $import_file  = $self->{'f'};
    1619     if ((!defined $docid) && (!defined $import_file)) {
    1620     $gsdl_cgi->generate_error("No docid (d=...) or import file (f=) specified.");
    1621     }
    1622 
    1623     # Get the parameters and set default mode to "accumulate"
    1624     my $metaname   = $self->{'metaname'};
    1625     my $metavalue  = $self->{'metavalue'};
    1626 ##    $metavalue =~ s/&amp;lt;(.*?)&amp;gt;/<$1>/g;
    1627     $metavalue =~ s/&lt;(.*?)&gt;/<$1>/g;
    1628    
    1629     my $metamode   = $self->{'metamode'};
    1630     if ((!defined $metamode) || ($metamode =~ m/^\s*$/)) {
    1631     # make "accumulate" the default (less destructive, as won't actually
    1632     # delete any existing values)
    1633     $metamode = "accumulate";
    1634     }
    1635 
    1636     # Obtain where the metadata.xml is from the archiveinfo-doc.gdb file
    1637     # If the doc oid is not specified, we assume the metadata.xml is next to the specified "f"
    1638     my $metadata_xml_file;
    1639     my $import_filename = undef;
    1640     if (defined $docid) {
    1641     my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir);
    1642     my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $docid);
    1643 
    1644     # This now stores the full pathname
    1645     $import_filename = $doc_rec->{'src-file'}->[0];
    1646     }
    1647     else {
    1648         $import_filename = &util::filename_cat($collect_dir,$collect,$import_file);
    1649     }
    1650 
    1651     # figure out correct metadata.xml file [?]
    1652     # Assuming the metadata.xml file is next to the source file
    1653     # Note: This will not work if it is using the inherited metadata from the parent folder
    1654     my ($import_tailname, $import_dirname) = File::Basename::fileparse($import_filename);
    1655     my $metadata_xml_filename = &util::filename_cat($import_dirname,"metadata.xml");
    1656 
    1657     # Edit the metadata.xml
    1658     # Modified by Jeffrey from DL Consulting
    1659     # Handle the case where there is one metadata.xml file for multiple FileSets
    1660     # The XML filter needs to know whether it is in the right FileSet
    1661     # TODO: This doesn't fix the problem where the metadata.xml is not next to the src file.
    1662     # TODO: This doesn't handle the common metadata (where FileName doesn't point to a single file)
    1663     $self->edit_metadata_xml($gsdl_cgi, $metadata_xml_filename,
    1664                              $metaname, $metavalue, $metamode, $import_tailname);
     1831 
     1832    $self->_set_import_metadata(@_);
    16651833
    16661834    # Release the lock once it is done
    16671835    $self->unlock_collection($username, $collect);
    1668 
    1669     my $mess = "set-import-metadata successful: Key[$docid] -> $metadata_xml_filename\n";
    1670     $mess .= "  $metaname";
    1671     $mess .= " = $metavalue";
    1672     $mess .= " ($metamode)\n";
    1673    
    1674     $gsdl_cgi->generate_ok_message($mess);
    16751836   
    16761837}
     
    17541915}
    17551916
    1756 sub remove_import_metadata
     1917sub _remove_import_metadata
    17571918{
    17581919    my $self = shift @_;
    1759    
    1760     my $username = $self->{'username'};
     1920
    17611921    my $collect   = $self->{'collect'};
    17621922    my $gsdl_cgi  = $self->{'gsdl_cgi'};
    1763    
    1764     if ($baseaction::authentication_enabled) {
    1765         # Ensure the user is allowed to edit this collection
    1766         &authenticate_user($gsdl_cgi, $username, $collect);
    1767     }
    1768 
    17691923    my $gsdlhome  = $self->{'gsdlhome'};
    17701924    my $infodbtype = $self->{'infodbtype'};
     
    17771931    ## my $collect_dir = &util::filename_cat($gsdlhome, "collect");
    17781932    my $archive_dir = &util::filename_cat($collect_dir,$collect,"archives");
    1779    
    1780     # Make sure the collection isn't locked by someone else
    1781     $self->lock_collection($username, $collect);
    1782    
     1933
    17831934    # look up additional args
    17841935    my $docid = $self->{'d'};
     
    18181969    $self->remove_from_metadata_xml($gsdl_cgi, $metadata_xml_filename, $metaname, $metavalue, $import_tailname);
    18191970   
    1820     # Release the lock once it is done
    1821     $self->unlock_collection($username, $collect);
    1822 
    18231971    my $mess = "remove-import-metadata successful: Key[$docid] -> $metadata_xml_filename\n";
    18241972    $mess .= "  $metaname";
     
    18261974   
    18271975    $gsdl_cgi->generate_ok_message($mess);
     1976
     1977    #return $status; # in case calling functions have a use for this
     1978}
     1979
     1980sub remove_import_metadata
     1981{
     1982    my $self = shift @_;
     1983   
     1984    my $username = $self->{'username'};
     1985    my $collect   = $self->{'collect'};
     1986    my $gsdl_cgi  = $self->{'gsdl_cgi'};
     1987   
     1988    if ($baseaction::authentication_enabled) {
     1989        # Ensure the user is allowed to edit this collection
     1990        &authenticate_user($gsdl_cgi, $username, $collect);
     1991    }
     1992
     1993    # Make sure the collection isn't locked by someone else
     1994    $self->lock_collection($username, $collect);
     1995   
     1996    $self->_remove_import_metadata(@_);
     1997
     1998    # Release the lock once it is done
     1999    $self->unlock_collection($username, $collect);
     2000
    18282001}
    18292002
     
    18902063}
    18912064
    1892 sub remove_live_metadata
     2065sub _remove_live_metadata
    18932066{
    18942067    my $self = shift @_;
    18952068
    1896     my $username  = $self->{'username'};
    18972069    my $collect   = $self->{'collect'};
    18982070    my $gsdl_cgi  = $self->{'gsdl_cgi'};
    1899     my $gsdlhome  = $self->{'gsdlhome'};
     2071#    my $gsdlhome  = $self->{'gsdlhome'};
    19002072    my $infodbtype = $self->{'infodbtype'};
    1901    
    1902     if ($baseaction::authentication_enabled) {
    1903     # Ensure the user is allowed to edit this collection
    1904     &authenticate_user($gsdl_cgi, $username, $collect);
    1905     }
    19062073
    19072074    # Obtain the collect dir
    19082075    ## my $collect_dir = &util::filename_cat($gsdlhome, "collect");
    1909     my $site = $self->{'site'};
    1910     my $collect_dir = $gsdl_cgi->get_collection_dir($site);
    1911 
    1912     # Make sure the collection isn't locked by someone else
    1913     $self->lock_collection($username, $collect);
    1914 
     2076    my $site = $self->{'site'};
     2077    my $collect_dir = $gsdl_cgi->get_collection_dir($site);
     2078
     2079   
    19152080    # look up additional args
    19162081    my $docid     = $self->{'d'};
     
    19482113    }
    19492114
    1950     # Release the lock once it is done
    1951     $self->unlock_collection($username, $collect);
    1952 }
    1953 
    1954 
    1955 sub remove_metadata
     2115}
     2116
     2117sub remove_live_metadata
    19562118{
    19572119    my $self = shift @_;
     
    19612123    my $gsdl_cgi  = $self->{'gsdl_cgi'};
    19622124    my $gsdlhome  = $self->{'gsdlhome'};
    1963     my $infodbtype = $self->{'infodbtype'};
    19642125   
    19652126    if ($baseaction::authentication_enabled) {
     
    19682129    }
    19692130
    1970     # Obtain the collect dir
    1971     my $site = $self->{'site'};
    1972     my $collect_dir = $gsdl_cgi->get_collection_dir($site);
    1973     ## my $collect_dir = &util::filename_cat($gsdlhome, "collect");
    1974 
    19752131    # Make sure the collection isn't locked by someone else
    19762132    $self->lock_collection($username, $collect);
    19772133
    1978     # look up additional args
     2134    $self->_remove_live_metadata(@_);
     2135
     2136    $self->unlock_collection($username, $collect);
     2137}
     2138
     2139sub remove_metadata
     2140{
     2141    my $self = shift @_;
     2142
     2143    my $where = $self->{'where'};
     2144    if(!$where) {
     2145    $self->remove_index_metadata(@_); # call the full version of set_index_meta for the default behaviour
     2146    return;
     2147    }
     2148
     2149    my $username  = $self->{'username'};
     2150    my $collect   = $self->{'collect'};
     2151    my $gsdl_cgi  = $self->{'gsdl_cgi'};
     2152
     2153    if ($baseaction::authentication_enabled) {
     2154    # Ensure the user is allowed to edit this collection
     2155    &authenticate_user($gsdl_cgi, $username, $collect);
     2156    }
     2157
     2158    # Make sure the collection isn't locked by someone else
     2159    $self->lock_collection($username, $collect);
     2160
     2161    # check which directories need to be processed, specified in $where as
     2162    # any combination of import|archives|index|live
     2163    if($where =~ m/import/) {
     2164    $self->_remove_import_metadata(@_);     
     2165    }
     2166    if($where =~ m/archives/) {
     2167    $self->_remove_archives_metadata(@_);       
     2168   }
     2169    if($where =~ m/index/) {
     2170    $self->_remove_index_metadata(@_);     
     2171    }
     2172
     2173    # Release the lock once it is done
     2174    $self->unlock_collection($username, $collect);
     2175}
     2176
     2177# the internal version, without authentication
     2178sub _remove_index_metadata
     2179{   
     2180    my $self = shift @_;
     2181
     2182    my $collect   = $self->{'collect'};
     2183    my $gsdl_cgi  = $self->{'gsdl_cgi'};
     2184#    my $gsdlhome  = $self->{'gsdlhome'};
     2185    my $infodbtype = $self->{'infodbtype'};
     2186   
     2187    # Obtain the collect dir
     2188    my $site = $self->{'site'};
     2189    my $collect_dir = $gsdl_cgi->get_collection_dir($site);
     2190    ## my $collect_dir = &util::filename_cat($gsdlhome, "collect");
     2191
     2192        # look up additional args
    19792193    my $docid     = $self->{'d'};
    19802194    if ((!defined $docid) || ($docid =~ m/^\s*$/)) {
     
    20622276    $gsdl_cgi->generate_ok_message($mess);
    20632277    }
     2278
     2279    #return $status; # in case calling functions have a use for this
     2280}
     2281
     2282sub remove_index_metadata
     2283{
     2284    my $self = shift @_;
     2285
     2286    my $username  = $self->{'username'};
     2287    my $collect   = $self->{'collect'};
     2288    my $gsdl_cgi  = $self->{'gsdl_cgi'};
     2289#    my $gsdlhome  = $self->{'gsdlhome'};
     2290   
     2291    if ($baseaction::authentication_enabled) {
     2292    # Ensure the user is allowed to edit this collection
     2293    &authenticate_user($gsdl_cgi, $username, $collect);
     2294    }
     2295
     2296    # Obtain the collect dir
     2297    my $site = $self->{'site'};
     2298    my $collect_dir = $gsdl_cgi->get_collection_dir($site);
     2299    ## my $collect_dir = &util::filename_cat($gsdlhome, "collect");
     2300
     2301    # Make sure the collection isn't locked by someone else
     2302    $self->lock_collection($username, $collect);
     2303
     2304    $self->_remove_index_metadata(@_);
    20642305
    20652306    # Release the lock once it is done
Note: See TracChangeset for help on using the changeset viewer.