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

- add validation and conversion of some CLI options

parent 107dd963
No related branches found
No related tags found
No related merge requests found
......@@ -12,7 +12,7 @@ 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);
use Date::Calc qw(Date_to_Time);
# VERSION
......@@ -62,7 +62,7 @@ sub opt_spec {
[ 'aip|a=s' => 'search a specific AIP by given AIP id' ],
[ 'datemode' => hidden => {
one_of => [
[ 'creationdate|c=s' => 'search based on creationdate string' ],
[ 'creationdate|c=s' => 'search based on creation date, use format YYYY-MM-DD' ],
[ 'modificationdate|m=s' => 'search based on modificationdate string' ]
]
}
......@@ -113,6 +113,24 @@ sub validate_args {
my ($self, $opt, $args) = @_;
# no args allowed but options!
$self->usage_error("No args allowed") if @$args;
if (exists $opt->{creationdate}) {
if ($opt->{creationdate} =~ m/^(\d{4})-(\d{2})-(\d{2})$/ ) {
my $epoch = Date_to_Time($1, $2, $3, 0, 0, 0);
$opt->{creationdate_epoch} = $epoch;
} else {
$self->usage_error("--creationdate expects date in format yyyy-mm-dd")
}
}
if (exists $opt->{pronom_id}) {
$self->usage_error("--pronom-id expects string which is conform to PUID structure as described in https://www.nationalarchives.gov.uk/aboutapps/pronom/puid.htm")
unless ($opt->{pronom_id} =~ m/^(x-)?fmt\/[a-z0-9]+$/ );
}
if (exists $opt->{lzaid}) {
my $rx_up = qr{[A-Za-z0-9_-]+}; # archive name & internal workflow
my $rx_lw = qr{[a-z0-9_-]+}; # external workflow & external id
$self->usage_error("--lzaid expects string which is conform to SLUBArchiv internal scheme")
unless ($opt->{lzaid} =~ m/^$rx_up:$rx_up:$rx_up:$rx_lw:$rx_lw$/);
}
1;
}
......@@ -150,7 +168,7 @@ sub line_result_mapper {
p($partial_result);
if (exists($partial_result->{_source}->{transferMetadata}->[0]->{'bim:bag-info_dict'}->{ "bim:$t" }) ) {
$line{$linekey} = $partial_result->{_source}->{transferMetadata}->[0]->{'bim:bag-info_dict'}->{ "bim:$t" };
} #else {
} #else {/
# say "$t -->";
#say np($partial_result);
#}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment