Skip to content
Snippets Groups Projects
Commit 7fa72082 authored by Andreas Romeyke's avatar Andreas Romeyke
Browse files

- moved debug-output to SLUB::LZA::TA::Archivematica::Elasticsearch

parent 3fc9fc5d
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ package SLUB::LZA::TA::Archivematica::Elasticsearch;
# HINT: the server is v6.x.y of elasticsearch, therefore this code is using old client
use v5.36;
use namespace::autoclean -except => qr{import};
use Data::Printer;
use Search::Elasticsearch 6.81; # install with: cpanm Search::Elasticsearch~"<7.0"
use Search::Elasticsearch::Client::6_0;
......@@ -41,22 +42,38 @@ sub query_elasticsearch($protocol, $host, $port, $index_name, $query_hash, $opti
foreach my $key (keys %{$query_hash} ) {
$local_query_hash->{$key} = $query_hash->{$key}
}
if ((defined $options) and ($options->{no_source} == 1)) {
if (defined $options) {
if (exists $options->{no_source} and defined $options->{no_source} and $options->{no_source} == 1) {
$local_query_hash->{_source} = "false"; # avoids transfering complete source tree in results
} else {
}
else {
#$local_query_hash->{_source}->{excludes}=""
}
if (exists $options->{debug} and defined $options->{debug} and $options->{debug} == 1) {
say STDERR "query:";
say STDERR "------------------------";
say STDERR np($query_hash);
say STDERR "------------------------";
}
}
my $e = _instantiate($protocol, $host, $port);
my $res = $e->search(
index => $index_name,
body => $local_query_hash, #hashref
);
if (exists $options->{debug} and defined $options->{debug} and $options->{debug} == 1) {
say STDERR "response:";
say STDERR "------------------------";
say STDERR np($res);
say STDERR "------------------------";
}
return $res;
}
sub query_elasticsearch_count($protocol, $host, $port, $index_name, $query_hash) {
my $res = query_elasticsearch($protocol, $host, $port, $index_name, $query_hash, {no_source => 1});
sub query_elasticsearch_count($protocol, $host, $port, $index_name, $query_hash, $options=undef) {
$options->{ no_source } = 1;
my $res = query_elasticsearch($protocol, $host, $port, $index_name, $query_hash, $options);
return $res->{hits}->{total};
}
......
......@@ -3,7 +3,6 @@ use SLUB::LZA::TA -command;
use v5.36;
use SLUB::LZA::TA::Archivematica::Elasticsearch;
use SLUB::LZA::TA::Archivematica::Elasticsearch::PrepareQuery;
use Data::Printer;
use Date::Calc qw(Date_to_Time);
use namespace::autoclean -except => qr{SLUB::LZA::TA::.*};
......@@ -122,19 +121,15 @@ sub validate_args {
sub execute {
my ($self, $opt, $args) = @_;
my $aips_query = SLUB::LZA::TA::Archivematica::Elasticsearch::PrepareQuery::prepare_aip_query($opt);
if (exists $opt->{debug}) {
use Data::Printer;
say STDERR "query:";
say STDERR "------------------------";
say STDERR np( $aips_query);
say STDERR "------------------------";
}
my $response = SLUB::LZA::TA::Archivematica::Elasticsearch::query_elasticsearch_count(
$SLUB::LZA::TA::config{elasticsearch_protocol},
$SLUB::LZA::TA::config{elasticsearch_host},
$SLUB::LZA::TA::config{elasticsearch_port},
'aips', # indexname
$aips_query, # query_hash ref
{
debug => $opt->{debug},
}
);
if ($opt->{verbose}) {
say np($response);
......@@ -144,7 +139,6 @@ sub execute {
return 1;
}
no Data::Printer;
no Date::Calc;
1;
......@@ -244,20 +244,15 @@ PAINLESS
}
};
$aips_query->{size}= 0; # only use aggregations
if (exists $opt->{debug}) {
use Data::Printer;
say STDERR "query:";
say STDERR "------------------------";
say STDERR np($aips_query);
say STDERR "------------------------";
}
#p($aips_query);
$aips_response = SLUB::LZA::TA::Archivematica::Elasticsearch::query_elasticsearch(
$SLUB::LZA::TA::config{elasticsearch_protocol},
$SLUB::LZA::TA::config{elasticsearch_host},
$SLUB::LZA::TA::config{elasticsearch_port},
'aips', # indexname
$aips_query, # query_hash ref
{
debug => $opt->{debug},
}
);
$aips_response->{from_date}=$opt->{creationdate_epochs}->{from_string};
$aips_response->{to_date}=$opt->{creationdate_epochs}->{to_string};
......@@ -267,20 +262,15 @@ PAINLESS
sub get_ldp_projects {
my ($self, $opt, $args) = @_;
my $query = SLUB::LZA::TA::Archivematica::Elasticsearch::PrepareQuery::prepare_ldpprojects_query(@_);
if (exists $opt->{debug}) {
use Data::Printer;
say STDERR "query:";
say STDERR "------------------------";
say STDERR np($query);
say STDERR "------------------------";
}
#p($aips_query);
my $response = SLUB::LZA::TA::Archivematica::Elasticsearch::query_elasticsearch(
$SLUB::LZA::TA::config{elasticsearch_protocol},
$SLUB::LZA::TA::config{elasticsearch_host},
$SLUB::LZA::TA::config{elasticsearch_port},
'aips', # indexname
$query, # query_hash ref
{
debug => $opt->{debug},
}
);
my %projects;
foreach my $match (@{$response->{hits}->{hits}}) {
......@@ -307,20 +297,16 @@ sub get_filestypes_by_aips {
$aips_query->{"_source"} = {
"includes" => 'uuid'
};
if (exists $opt->{debug}) {
use Data::Printer;
say STDERR "query:";
say STDERR "------------------------";
say STDERR np($aips_query);
say STDERR "------------------------";
}
#p($aips_query);
my $aips_response = SLUB::LZA::TA::Archivematica::Elasticsearch::query_elasticsearch(
$SLUB::LZA::TA::config{elasticsearch_protocol},
$SLUB::LZA::TA::config{elasticsearch_host},
$SLUB::LZA::TA::config{elasticsearch_port},
'aips', # indexname
$aips_query, # query_hash ref
{
debug => $opt->{debug},
}
);
my @aips = map { $_->{_source}->{uuid} } @{ $aips_response->{hits}->{hits} };
my %results;
......@@ -379,14 +365,10 @@ sub get_filestypes_by_aips {
$SLUB::LZA::TA::config{elasticsearch_port},
'aipfiles', # indexname
$files_query, # query_hash ref
);
if (exists $opt->{debug}) {
use Data::Printer;
say "------------------------";
say "query=",np( $files_query);
say "resp =",np($files_response);
say "------------------------";
{
debug => $opt->{debug},
}
);
foreach my $file_response (@{ $files_response->{hits}->{hits} }) {
my $pronom_id = $file_response->{_source}
->{'METS'}
......@@ -612,7 +594,4 @@ RPTHEADER
return 1;
}
1;
......@@ -185,13 +185,10 @@ sub find_aips_by_file_pronom_id {
$SLUB::LZA::TA::config{elasticsearch_port},
'aipfiles', # indexname
$files_query, # query_hash ref
);
if (exists $opt->{debug}) {
use Data::Printer;
say "------------------------";
say "query=",np( $files_query);
say "------------------------";
{
debug => $opt->{debug}
}
);
my %aips;
#p($files_response->{hits}->{hits});
foreach my $match (@{$files_response->{hits}->{hits}}) {
......@@ -215,20 +212,15 @@ sub execute {
# only index aips needed
$aips_query = SLUB::LZA::TA::Archivematica::Elasticsearch::PrepareQuery::prepare_aip_query($opt);
}
if (exists $opt->{debug}) {
use Data::Printer;
say STDERR "query:";
say STDERR "------------------------";
say STDERR np( $aips_query);
say STDERR "------------------------";
}
#p($aips_query);
$aips_response = SLUB::LZA::TA::Archivematica::Elasticsearch::query_elasticsearch(
$SLUB::LZA::TA::config{elasticsearch_protocol},
$SLUB::LZA::TA::config{elasticsearch_host},
$SLUB::LZA::TA::config{elasticsearch_port},
'aips', # indexname
$aips_query, # query_hash ref
{
debug => $opt->{debug}
}
);
#p($aips_response);
SLUB::LZA::TA::Output::print_results($aips_response, $opt);
......
......@@ -62,7 +62,7 @@ is($? >> 8, 0, 'ta-tool report, with ldp, exit status');
$testapp->run(args =>'report --output-as-csv --with-filetypes');
#say "STDOUT:",$testapp->stdout;
#say "STDERR:",$testapp->stderr;
like($testapp->stdout, qr/^"set","subset","timespan_from","timespan_to","aip_state","filter","flavour","value"\n.*pronom/s, 'ta-tool report, with filetype, stdout');
like($testapp->stdout, qr/^"set","subset","timespan_from","timespan_to","aip_state","filter","flavour","value"\n.*total/s, 'ta-tool report, with filetype, stdout');
like($testapp->stderr, qr/^reporting for period.*HINT:.*with-filetype/s, 'ta-tool report, with filetype, stderr');
is($? >> 8, 0, 'ta-tool report, with filetype, exit status');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment