Skip to content
Snippets Groups Projects
Select Git revision
  • 9cc95455e10389b2137677d3203b00e1eede7a26
  • master default protected
  • diag
  • version1.3-archivematica
  • version1.2-archivematica
  • version1.1-archivematica
  • version1.0-archivematica
  • version1.0-rosetta
8 results

03-report.t

Blame
  • TA.pm 16.51 KiB
    use strict;
    use warnings;
    package SLUB::LZA::Rosetta::TA;
    use App::Cmd::Setup -app;
    use Path::Tiny qw( path );
    use YAML qw(LoadFile);
    use LWP::UserAgent;
    use SOAP::Lite;
    use Carp qw( croak );
    use feature qw(say);
    use Regexp::Optimizer;
    use IO::Zlib;
    use Text::CSV_PP;
    
    # ABSTRACT: main module for ta-tool
    
    our %config;
    our %cache;
    our $cache_path;
    BEGIN{
        my $home = path($ENV{'HOME'});
        if ($home->is_dir() && !$home->is_rootdir) {
            my $config_path = $home->child('.config')->child('ta-tool.rc');
            our $config_file = $config_path;
            if ($config_path->is_file) {
                %config = YAML::LoadFile($config_path);
            }
            $cache_path = $home->child('.cache')->child('ta-tool.cache');
            if ($cache_path->is_file and -s $cache_path < 8192*1024) { # if size > 8MB, write new at end, see END{}-block
                %cache = YAML::LoadFile($cache_path);
            }
        }
    }
    
    END {
        YAML::DumpFile($cache_path, %cache);
    }
    
    sub sru_search {
        my $searchtype = shift;
        my $query = shift;
        my $startrecord = shift;
        my $maxrecords = shift;
        my $is_verbose = shift;
        my %searchpaths = (
            ie   => 'permanent/ie',
            file => 'permanent/file',
            sip  => 'operational'
        );
    
        if (!exists $searchpaths{$searchtype}){
            croak ("Code error, wrong searchtype ($searchtype) used!");
        }
        my $protocol = 'https';
        my $host = $config{host};
        my $port = '8443';
        my $searchpath = $searchpaths{$searchtype};
        my $srubase="${protocol}://${host}:${port}/search/${searchpath}/sru";
        my $sru = "${srubase}?version=1.2&operation=searchRetrieve&startRecord=$startrecord&maximumRecords=$maxrecords&recordSchema=dc&query=${query}";
        my $ua = LWP::UserAgent->new(keep_alive => 1);
        $ua->agent("MyApp/0.1 ");
        $ua->timeout(3600);#1h
        $ua->default_headers->push_header('Accept-Encoding' => 'br, lzma, bzip2, gzip, compressed, deflate');
        $ua->ssl_opts(
            verify_hostname=>1,
            # SSL_ca_path => '/etc/ssl/',
        );
        if ($is_verbose) {
            say "searchurl = $sru";
        }