X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Fstemmaweb%2FController%2FMicroservice.pm;h=0b5e9a69f87edcd31ef0b9ffefcaa3232abf8794;hb=80c4b652c73cd313bc3cffd9d6e36c58e41e9833;hp=308436707efc16ce5a050a5f6af0458532a2e2bd;hpb=13c54385859b454cb76f01679488070631742b41;p=scpubgit%2Fstemmaweb.git diff --git a/lib/stemmaweb/Controller/Microservice.pm b/lib/stemmaweb/Controller/Microservice.pm index 3084367..0b5e9a6 100644 --- a/lib/stemmaweb/Controller/Microservice.pm +++ b/lib/stemmaweb/Controller/Microservice.pm @@ -27,7 +27,7 @@ following form parameters in the body: =over 4 -=item * type - Can be one of CollateX, CSV, JSON, nCritic, TEI, Tabular. +=item * type - Can be one of CollateX, CTE, CSV, JSON, nCritic, TEI, Tabular. =item * data - The collation data itself. @@ -35,6 +35,54 @@ following form parameters in the body: =head1 COLLATION URLs +=head2 parse + + GET microservice/parse + POST microservice/parse { + type: $type + file: $uploadfile + } + +Attempt a parse of the passed collation data, and return diagnostic information about whether it was successful. + +=cut + +sub parse :Local :Args(0) { + my( $self, $c ) = @_; + if( $c->req->method eq 'POST' ) { + # Get the passed options... + my $warnings = []; + $DB::single = 1; + my %newopts = ( + 'name' => $c->request->param('name') || 'Uploaded tradition', + 'file' => $c->request->upload('file')->tempname, + 'warnings_to' => $warnings, + ); + my $type = $c->request->param( 'type' ); + if( $type eq 'csv' ) { + $newopts{'input'} = 'Tabular'; + $newopts{'sep_char'} = ','; + } elsif( $type eq 'tsv' ) { + $newopts{'input'} = 'Tabular'; + $newopts{'sep_char'} = "\t"; + } elsif( $type =~ /^xls/ ) { + $newopts{'input'} = 'Tabular'; + $newopts{'excel'} = $type; + } else { + $newopts{'input'} = $type; + } + # Now try the parse. + my $tradition; + try { + $c->stash->{'result'} = Text::Tradition->new( %newopts ); + } catch ( Text::Tradition::Error $e ) { + $c->stash->{'errormsg'} = $e->message; + } + $c->stash->{'warnings'} = join( "\n", @$warnings ); + } + $c->stash->{template} = 'testparse.tt'; +} + =head2 renderSVG POST microservice/renderSVG