X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=stemmaweb%2Flib%2Fstemmaweb%2FController%2FRelation.pm;h=8785d6fc108c133f4d77ae969fabada6d75f5641;hb=a7f4020a1a1fd72aba6e25dc0a8f8aa9a1891202;hp=4bae11da35765ab6735593e7aeaf7b8f3a65dab3;hpb=f8862b584dcc04728d3bff48ea7c19cb9a078772;p=scpubgit%2Fstemmatology.git diff --git a/stemmaweb/lib/stemmaweb/Controller/Relation.pm b/stemmaweb/lib/stemmaweb/Controller/Relation.pm index 4bae11d..8785d6f 100644 --- a/stemmaweb/lib/stemmaweb/Controller/Relation.pm +++ b/stemmaweb/lib/stemmaweb/Controller/Relation.pm @@ -298,12 +298,14 @@ sub reading :Chained('text') :PathPart :Args(1) { $c->stash->{'result'} = $rdg ? _reading_struct( $rdg ) : { 'error' => "No reading with ID $reading_id" }; } elsif ( $c->request->method eq 'POST' ) { + my $errmsg; # Are we re-lemmatizing? if( $c->request->param('relemmatize') ) { my $nf = $c->request->param('normal_form'); # TODO throw error unless $nf $rdg->normal_form( $nf ); # TODO throw error if lemmatization fails + # TODO skip this if normal form hasn't changed $rdg->lemmatize(); } else { # Set all the values that we have for the reading. @@ -320,9 +322,14 @@ sub reading :Chained('text') :PathPart :Args(1) { unless( defined $idx ) { # Make the word form and add it to the lexeme. $c->log->debug("Adding new form for $strrep"); - $idx = $lx->add_matching_form( $strrep ) - 1; + try { + $idx = $lx->add_matching_form( $strrep ) - 1; + } catch( Text::Tradition::Error $e ) { + $c->response->status( '403' ); + $errmsg = $e->message; + } } - $lx->disambiguate( $idx ); + $lx->disambiguate( $idx ) if defined $idx; } elsif( $read_write_keys{$p} ) { my $val = _clean_booleans( $rdg, $p, $c->request->param( $p ) ); $rdg->$p( $val ); @@ -330,7 +337,8 @@ sub reading :Chained('text') :PathPart :Args(1) { } } $m->save( $tradition ); - $c->stash->{'result'} = _reading_struct( $rdg ); + $c->stash->{'result'} = $errmsg ? { 'error' => $errmsg } + : _reading_struct( $rdg ); } $c->forward('View::JSON');