Skip to content
This repository has been archived by the owner on Nov 12, 2018. It is now read-only.

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasfranck committed May 2, 2012
1 parent 4b2e7e8 commit f4d3ffe
Show file tree
Hide file tree
Showing 29 changed files with 261 additions and 90 deletions.
3 changes: 2 additions & 1 deletion Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ my $requires = {
'Image::ExifTool' => 0,
'enum' => 0,
'Time::Seconds' => 0,
'Template::Plugin::POSIX' => 0
'Template::Plugin::POSIX' => 0,
'File::MimeInfo' => 0
};
my $recommends = {
'Starman' => 0,
Expand Down
2 changes: 1 addition & 1 deletion doc/scans.scheme
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ projects:
name: papyri
name_subproject: 1ste batch
description: 'dit is de 1ste batch van ..'
date_start: 11-04-2012
datetime_start: 11-04-2012
query: BHSL.PAP
total: 203 (totale lijst van objecten, zoals resultatenlijst van de query aangeeft) -> gecached resultaat ('s nachts gegenereerd)
done: 0 (aantal objecten die in alle platformen gepubliceerd is) -> gecached resultaat ('s nachts gegeneerd)
Expand Down
2 changes: 1 addition & 1 deletion doc/schema-scans.xml
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ Attributes of the DelimitedPayloadTokenFilterFactory :
<field name="project_name" type="lupetext" indexed="true" stored="true" />
<field name="project_name_subproject" type="lupetext" indexed="true" stored="true" />
<field name="project_description" type="lupetext" indexed="true" stored="true" />
<field name="project_date_start" type="string" indexed="true" stored="true" />
<field name="project_datetime_start" type="string" indexed="true" stored="true" />
<field name="project_query" type="lupetext" indexed="true" stored="true" />
<field name="project_total" type="int" indexed="true" stored="true" />
<field name="project_done" type="int" indexed="true" stored="true" />
Expand Down
2 changes: 1 addition & 1 deletion doc/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ Attributes of the DelimitedPayloadTokenFilterFactory :
<field name="project_name" type="lupetext" indexed="true" stored="true" />
<field name="project_name_subproject" type="lupetext" indexed="true" stored="true" />
<field name="project_description" type="lupetext" indexed="true" stored="true" />
<field name="project_date_start" type="string" indexed="true" stored="true" />
<field name="project_datetime_start" type="string" indexed="true" stored="true" />
<field name="project_query" type="lupetext" indexed="true" stored="true" />
<field name="project_total" type="int" indexed="true" stored="true" />
<field name="project_done" type="int" indexed="true" stored="true" />
Expand Down
34 changes: 18 additions & 16 deletions environments/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ mounts:
processed:
windows: "I:\\"
samba: "smb://localhost/02_processed"
ready:
windows: "J:\\"
samba: "smb://localhost/01_ready"
status:
change:
all:
Expand Down Expand Up @@ -194,31 +197,30 @@ human_readable:
profiles:
NARA:
packages:
- args: {}
class: "Imaging::Test::Dir::scan"
- class: "Imaging::Test::Dir::scan"
args: {}
on_error: "stop"
- args: {}
class: "Imaging::Test::Dir::checkPermissions"
- class: "Imaging::Test::Dir::checkPermissions"
args: {}
on_error: "continue"
- args:
patterns:
- '^\./'
class: "Imaging::Test::Dir::hasNoFiles"
- class: "Imaging::Test::Dir::checkEmpty"
args: {}
on_error: "continue"
- args: {}
class: "Imaging::Test::Dir::checkEmpty"
- class: "Imaging::Test::Dir::checkFilePattern"
args:
pattern: "(txt|tif)$"
on_error: "continue"
- args:
- class: "Imaging::Test::Dir::checkTIFF"
args:
valid_patterns:
- '^(?!manifest\.txt$)'
class: "Imaging::Test::Dir::checkTIFF"
on_error: "continue"
- args:
- class: "Imaging::Test::Dir::NARA::checkFilename"
args:
valid_patterns:
- '^(?!manifest\.txt$)'
class: "Imaging::Test::Dir::NARA::checkFilename"
on_error: "continue"
- args:
- class: "Imaging::Test::Dir::checkAleph"
args:
solr_args: *meercatindex
class: "Imaging::Test::Dir::checkAleph"
on_error: "continue"
17 changes: 0 additions & 17 deletions environments/production.yml

This file was deleted.

15 changes: 13 additions & 2 deletions lib/Imaging/Routes/logs.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,19 @@ any('/logs',sub {
start => $offset,
limit => $num
);
if($sort && $sort =~ /^\w+\s(?:asc|desc)$/o){
$opts{sort} = [$sort,"scan_id desc"];
if(is_string($sort)){
$opts{sort} = [ $sort ] if $sort =~ /^\w+\s(?:asc|desc)$/o;
}elsif(is_array_ref($sort)){
my $ok = 1;
foreach(@$sort){
if($_ !~ /^\w+\s(?:asc|desc)$/o){
$ok = 0;
last;
}
}
if($ok){
$opts{sort} = $sort;
}
}else{
$opts{sort} = ["datetime desc","scan_id desc"];
}
Expand Down
43 changes: 34 additions & 9 deletions lib/Imaging/Routes/projects.pm
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,27 @@ any('/projects',sub {
$params->{num} = $num;
my $offset = ($page - 1)*$num;

my $projects = projects->slice($offset,$num)->to_array();
my $projects = projects->to_array();

if(is_string($params->{'sort'}) && $params->{'sort'} =~ /^(\w+)\s(?:asc|desc)$/o){
my($sort_key,$sort_dir)=($1,$2);
if(is_string($projects->[0]->{$sort_key})){
our($a,$b);
$projects = [ sort {
if(is_number($a->{$sort_key})){
return ( $a->{$sort_key} <=> $b->{$sort_key} );
}else{
return ( $a->{$sort_key} cmp $b->{$sort_key} );
}
} @$projects ];
}
if($sort_dir eq "desc"){
$projects = [reverse(@$projects)];
}
}

$projects = [splice(@$projects,$offset,$num)];

my $page_info = Data::Pageset->new({
'total_entries' => projects->count,
'entries_per_page' => $num,
Expand All @@ -74,7 +93,7 @@ any('/projects/add',sub{

if($params->{submit}){
#check empty string
my @keys = qw(name name_subproject description date_start query);
my @keys = qw(name name_subproject description datetime_start query);
foreach my $key(@keys){
if(!is_string($params->{$key})){
push @errors,"$key is niet opgegeven";
Expand All @@ -94,7 +113,7 @@ any('/projects/add',sub{
}
#check format
my %check = (
date_start => sub{
datetime_start => sub{
my $value = shift;
my($success,$error)=(1,undef);
try{
Expand All @@ -115,11 +134,15 @@ any('/projects/add',sub{
}
#insert
if(scalar(@errors)==0){
$params->{datetime_start} =~ /^(\d{2})-(\d{2})-(\d{4})$/o;
say to_dumper($params);
say "day:$1, month:$2, year:$3";
my $datetime = DateTime->new( day => int($1), month => int($2), year => int($3));
my $project = projects->add({
name => $params->{name},
name_subproject => $params->{name_subproject},
description => $params->{description},
date_start => $params->{date_start},
datetime_start => $datetime->epoch,
datetime_last_modified => Time::HiRes::time,
query => $params->{query},
locked => 0,
Expand Down Expand Up @@ -153,7 +176,7 @@ any('/project/:_id/edit',sub{
if($params->{submit}){
if(!$project->{locked}){
#check empty string
my @keys = qw(name name_subproject description date_start query);
my @keys = qw(name name_subproject description datetime_start query);
foreach my $key(@keys){
if(!is_string($params->{$key})){
push @errors,"$key is niet opgegeven";
Expand All @@ -173,13 +196,13 @@ any('/project/:_id/edit',sub{
}
#check format
my %check = (
date_start => sub{
datetime_start => sub{
my $value = shift;
my($success,$error)=(1,undef);
try{
DateTime::Format::Strptime::strptime("%d-%m-%Y",$value);
my $datetime = DateTime::Format::Strptime::strptime("%d-%m-%Y",$value);

}catch{
say $_;
$success = 0;
$error = "startdatum is ongeldig (dag-maand-jaar)";
};
Expand All @@ -194,11 +217,13 @@ any('/project/:_id/edit',sub{
}
#insert
if(scalar(@errors)==0){
$params->{datetime_start} =~ /^(\d{2})-(\d{2})-(\d{4})$/o;
my $datetime = DateTime->new( day => int($1), month => int($2), year => int($3));
my $new = {
name => $params->{name},
name_subproject => $params->{name_subproject},
description => $params->{description},
date_start => $params->{date_start},
datetime_start => $datetime->epoch,
datetime_last_modified => Time::HiRes::time,
query => $params->{query}
};
Expand Down
15 changes: 14 additions & 1 deletion lib/Imaging/Routes/qa_control.pm
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,20 @@ any('/qa_control',sub {
facet => "true",
"facet.field" => "status"
);
$opts{sort} = $sort if $sort && $sort =~ /^\w+\s(?:asc|desc)$/o;
if(is_string($sort)){
$opts{sort} = [ $sort ] if $sort =~ /^\w+\s(?:asc|desc)$/o;
}elsif(is_array_ref($sort)){
my $ok = 1;
foreach(@$sort){
if($_ !~ /^\w+\s(?:asc|desc)$/o){
$ok = 0;
last;
}
}
if($ok){
$opts{sort} = $sort;
}
}
my @errors = ();
my($result);
try {
Expand Down
29 changes: 28 additions & 1 deletion lib/Imaging/Routes/scans.pm
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,20 @@ any('/scans',sub {
start => $offset,
limit => $num
);
$opts{sort} = $sort if $sort && $sort =~ /^\w+\s(?:asc|desc)$/o;
if(is_string($sort)){
$opts{sort} = [ $sort ] if $sort =~ /^\w+\s(?:asc|desc)$/o;
}elsif(is_array_ref($sort)){
my $ok = 1;
foreach(@$sort){
if($_ !~ /^\w+\s(?:asc|desc)$/o){
$ok = 0;
last;
}
}
if($ok){
$opts{sort} = $sort;
}
}
my @errors = ();
my($result);
try {
Expand Down Expand Up @@ -199,6 +212,12 @@ any('/scans/view/:_id',sub {
if($scan->{project_id}){
$project = projects->get($scan->{project_id});
}
my $files = $scan->{files} || [];
our($a,$b);
$files = [sort {
$a->{name} cmp $b->{name};
} @$files];
$scan->{files} = $files;

template('scans/view',{
scan => $scan,
Expand Down Expand Up @@ -239,6 +258,14 @@ any('/scans/edit/:_id',sub{
scan2index($scan);
}
}

my $files = $scan->{files} || [];
our($a,$b);
$files = [sort {
$a->{name} cmp $b->{name};
} @$files];
$scan->{files} = $files;

#edit - end
template('scans/edit',{
scan => $scan,
Expand Down
2 changes: 2 additions & 0 deletions lib/Imaging/Test/Dir.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use File::Find;
use File::Spec;
use Cwd qw(cwd getcwd fastcwd fastgetcwd chdir abs_path fast_abs_path realpath fast_realpath);
use Try::Tiny;
use File::MimeInfo;

sub import {
Catmandu::Sane->import;
Expand All @@ -15,6 +16,7 @@ sub import {
File::Find->import;
Cwd->import(qw(cwd getcwd fastcwd fastgetcwd chdir abs_path fast_abs_path realpath fast_realpath));
Try::Tiny->import;
File::MimeInfo->import;
}
sub _load_file_info {
my $self = shift;
Expand Down
34 changes: 34 additions & 0 deletions lib/Imaging/Test/Dir/checkFilePattern.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package Imaging::Test::Dir::checkFilePattern;
use Moo;

has pattern => (
is => 'rw',
isa => sub {
rx($_[0]);
},
default => sub{
qr/.*/;
}
);
sub is_fatal {
1;
};
sub test {
my $self = shift;
my $topdir = $self->dir();
my $file_info = $self->file_info();
my(@errors) = ();
my $pattern = $self->pattern;

foreach my $stats(@$file_info){
if($stats->{basename} !~ $pattern){
push @errors,"file $stats->{basename} has incorrect filename";
}
}

scalar(@errors) == 0,\@errors;
}

with qw(Imaging::Test::Dir);

1;
2 changes: 1 addition & 1 deletion lib/Imaging/Test/Dir/checkJPEG.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ sub test {
if($exif->{Error}){
push @errors,$stats->{path}." is not an image";
}elsif(!(uc($exif->{FileType}) eq "JPEG" && $exif->{MIMEType} eq "image/jpeg")){
push @errors,$stats->{path}." is not a jpeg (filetype found:".$exif->{FileType}.")";
push @errors,$stats->{path}." is not a jpeg (filetype found:".mimetype($stats->{path}).")";
}
}
scalar(@errors) == 0,\@errors;
Expand Down
2 changes: 1 addition & 1 deletion lib/Imaging/Test/Dir/checkTIFF.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ sub test {
if($exif->{Error}){
push @errors,$stats->{path}." is not an image";
}elsif(!(uc($exif->{FileType}) eq "TIFF" && $exif->{MIMEType} eq "image/tiff")){
push @errors,$stats->{path}." is not a tiff (filetype found:".$exif->{FileType}.")";
push @errors,$stats->{path}." is not a tiff (filetype found:".mimetype($stats->{path}).")";
}
}
scalar(@errors) == 0,\@errors;
Expand Down
Loading

0 comments on commit f4d3ffe

Please sign in to comment.