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

- add rsv support

parent a2f7c6a7
Branches
Tags
No related merge requests found
......@@ -5,6 +5,13 @@ use warnings;
use feature qw(say);
use SLUB::LZA::TA::Archivematica::Elasticsearch;
use Data::Printer;
use constant VALUE_TERMINATOR => 0xff;
use constant NULL => 0xfe;
use constant ROW_TERMINATOR => 0xfd;
use constant CHR_VALUE_TERMINATOR => chr(VALUE_TERMINATOR);
use constant CHR_NULL => chr(NULL);
use constant CHR_ROW_TERMINATOR => chr(ROW_TERMINATOR);
use List::Util qw(any none);
# VERSION
......@@ -43,40 +50,42 @@ sub description {
"$description"
}
sub opt_spec {
return(
["target-version|V" => "get current elasticsearch version", {shortcircuit => 1}],
["debug" => "enable user agent debug output"],
["output-format" => hidden => {
return (
[ "target-version|V" => "get current elasticsearch version", { shortcircuit => 1 } ],
[ "debug" => "enable user agent debug output" ],
[ "output-format" => hidden => {
one_of => [
["output-as-rsv|r" => "prints output as Raw Strings Values (RSV) [default]"],
["output-as-csv|C" => "prints output as Comma Separated Values (CSV)"],
["verbose|v" => "enable verbose output, returns full elasticsearch response"],
]
}
[ "output-as-rsv|r" => "prints output as Raw Strings Values (RSV) [default]" ],
[ "output-as-csv|C" => "prints output as Comma Separated Values (CSV)" ],
[ "verbose|v" => "enable verbose output, returns full elasticsearch response" ],
],
}
],
["with-lzaid" => "also returns lzaid"],
["with-path" => "also returns AIP path"],
["with-size" => "also returns AIP size"],
["with-filecount" => "also returns AIPs file count"],
["with-export2archive-date" => "also returns AIP export to archive date"],
["with-creationdate" => "also returns AIP creation date"],
["datemode" => hidden => {
[ "with-lzaid" => "also returns lzaid" ],
[ "with-path" => "also returns AIP path" ],
[ "with-size" => "also returns AIP size" ],
[ "with-filecount" => "also returns AIPs file count" ],
[ "with-export2archive-date" => "also returns AIP export to archive date" ],
[ "with-creationdate" => "also returns AIP creation date" ],
[ "datemode" => hidden => {
one_of => [
["creationdate|c=s" => "search based on creationdate string"],
["modificationdate|m=s" => "search based on modificationdate string"]
[ "creationdate|c=s" => "search based on creationdate string" ],
[ "modificationdate|m=s" => "search based on modificationdate string" ]
]
}
}
],
["lzaid|l=s", "search a specific AIP by given LZA id"],
["descriptive|d=s", "search descriptive metadata (dc identifier)"],
["source|s=s", "search source metadata"],
["aip|a=s" => "search a specific AIP by given AIP id"],
["maxrecords=i", "set maxrecords, default is 10"],
["startrecord=i", "set startrecord, default is 1"],
["format" => hidden => {one_of => [
["pronom-id=s" => "with pronom format id"],
[ "lzaid|l=s", "search a specific AIP by given LZA id" ],
[ "descriptive|d=s", "search descriptive metadata (dc identifier)" ],
[ "source|s=s", "search source metadata" ],
[ "aip|a=s" => "search a specific AIP by given AIP id" ],
[ "maxrecords=i", "set maxrecords, default is 10", { default => 10 } ],
[ "startrecord=i", "set startrecord, default is 1" ],
[ "format" => hidden => { one_of => [
[ "pronom-id=s" => "with pronom format id" ],
#["without-format=s" => "without pronom format id"],
] } ],
[ 'help|h', "print usage message and exit", { shortcircuit => 1 } ],
[ 'version|i', "print version information", { shortcircuit => 1 } ],
);
}
sub validate_args {
......@@ -86,6 +95,19 @@ sub validate_args {
1;
}
sub line_result_mapper {
my ($partial_result, $opt) = @_;
my %line;
$line{aipid}= $partial_result->{_source}->{uuid};
if (defined $opt->{with_lzaid}) { $line{lzaid} = $partial_result->{_source}->{transferMetadata}->[0]->{'SLUBArchiv-lzaId'} };
if (defined $opt->{with_path}) { $line{path}= $partial_result->{_source}->{filePath} };
if (defined $opt->{with_size}) { $line{size}= $partial_result->{_source}->{size} };
if (defined $opt->{with_filecount}) { $line{filecount} = $partial_result->{_source}->{file_count} };
if (defined $opt->{with_export2archive_date}) { $line{export2archive_date}=$partial_result->{_source}->{transferMetadata}->[0]->{'SLUBArchiv-exportToArchiveDate'} };
if (defined $opt->{with_creation_date}) { $line{creation_date} = $partial_result->{_source}->{created} };
\%line;
}
sub execute {
my ($self, $opt, $args) = @_;
if ($opt->{target_version}) {
......@@ -104,7 +126,34 @@ sub execute {
'aips', # indexname
$query, # query_hash ref
);
say np($response);
my @result = map {
line_result_mapper($_, $opt);
} @{$response->{hits}->{hits} };
my @headers = sort keys %{$result[0]};
my $aip_only = List::Util::none {$_ =~ m/^with/} keys %{ $opt };
p($opt);
if ($opt->{output_format} eq 'verbose') {
say np($response);
} elsif ($aip_only or ($opt->{output_format} eq 'output_as_csv') ) {
say join(",", @headers);
say join("\n", map {
my $line = $_;
my $res_line = join(
",",
map { $line->{$_} } @headers
);
$res_line;
} @result
);
} elsif ($opt->{output_format} eq 'output_as_rsv') {
binmode(STDOUT, ':bytes');
print join(CHR_VALUE_TERMINATOR, @headers);
print CHR_ROW_TERMINATOR;
print join(CHR_ROW_TERMINATOR, map { join(CHR_VALUE_TERMINATOR,values %{ $_ }); } @result);
print CHR_ROW_TERMINATOR;
binmode(STDOUT, ':encoding(UTF-8)');
}
return 1;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment