From f3581a594e77ebd282be560d20775e2d7a16259f Mon Sep 17 00:00:00 2001 From: Henri-Damien LAURENT Date: Fri, 26 Feb 2010 21:37:46 +0100 Subject: [PATCH] ILS-DI Messages uniformization [MT2306_2271] ILS-DI Message codes consistence The services now returns ILSDI error codes in a tag, plus details in a tag. Exemple: MissingParameter The required parameter patron_id is missing. [MT2306_2271] Minor changes in HTML Signed-off-by: Galen Charlton --- C4/ILSDI/Services.pm | 138 +++++++++++++++++- .../opac-tmpl/prog/en/modules/ilsdi.tmpl | 14 +- opac/ilsdi.pl | 21 +-- 3 files changed, 154 insertions(+), 19 deletions(-) diff --git a/C4/ILSDI/Services.pm b/C4/ILSDI/Services.pm index a47503ac5f..9284885a51 100644 --- a/C4/ILSDI/Services.pm +++ b/C4/ILSDI/Services.pm @@ -170,7 +170,7 @@ sub GetRecords { # Check if the schema is supported. For now, GetRecords only supports MARCXML if ( $cgi->param('schema') and $cgi->param('schema') ne "MARCXML" ) { - return { message => 'UnsupportedSchema' }; + return { code => 'UnsupportedSchema' }; } my @records; @@ -214,7 +214,17 @@ sub GetRecords { map { $biblioitem->{$_} = encode_entities( $biblioitem->{$_}, '&' ) } grep( !/marcxml/, keys %$biblioitem ); +<<<<<<< HEAD:C4/ILSDI/Services.pm push @records, $biblioitem; +======= + $_ = encode_entities( $$biblioitem{$_}, '&' ) for @$biblioitem{ grep {!/marcxml/} keys %$biblioitem }; + + push @records, $biblioitem; + + } else { + push @records, { code => 'RecordNotFound' }; + } +>>>>>>> [MT2306_2271] ILS-DI Message codes consistence:C4/ILSDI.pm } return { record => \@records }; @@ -241,7 +251,7 @@ sub GetAuthorityRecords { # If the user asks for an unsupported schema, return an error code if ( $cgi->param('schema') and $cgi->param('schema') ne "MARCXML" ) { - return { message => 'UnsupportedSchema' }; + return { code => 'UnsupportedSchema' }; } my $records; @@ -250,8 +260,12 @@ sub GetAuthorityRecords { foreach my $authid ( split( / /, $cgi->param('id') ) ) { # Get the record as XML string, or error code +<<<<<<< HEAD:C4/ILSDI/Services.pm my $record = GetAuthorityXML($authid) || "RecordNotFound"; - $record =~ s/<\?xml version="1.0" encoding="UTF-8"\?>//go; +======= + my $record = GetAuthorityXML( $_ ) || "RecordNotFound"; +>>>>>>> [MT2306_2271] ILS-DI Message codes consistence:C4/ILSDI.pm + $record =~ s/<\?xml(.*)\?>//go; $records .= $record; } @@ -279,6 +293,7 @@ sub LookupPatron { my ($cgi) = @_; # Get the borrower... +<<<<<<< HEAD:C4/ILSDI/Services.pm my $borrower = GetMember($cgi->param('id_type') => $cgi->param('id')); if ( not $borrower->{'borrowernumber'} ) { return { message => 'PatronNotFound' }; @@ -286,6 +301,10 @@ sub LookupPatron { # Build the hashref my $patron->{'id'} = $borrower->{'borrowernumber'}; +======= + my $borrower = GetMember( $cgi->param('id'), $cgi->param('id_type') ); + return { code => 'PatronNotFound' } unless $$borrower{borrowernumber}; +>>>>>>> [MT2306_2271] ILS-DI Message codes consistence:C4/ILSDI.pm # ...and return his ID return $patron; @@ -308,9 +327,15 @@ sub LookupPatron { sub AuthenticatePatron { my ($cgi) = @_; +<<<<<<< HEAD:C4/ILSDI/Services.pm # Check if borrower exists, using a C4::ILSDI::Utility function... if ( not( BorrowerExists( $cgi->param('username'), $cgi->param('password') ) ) ) { return { message => 'PatronNotFound' }; +======= + # Check if borrower exists, using a C4::Auth function... + unless( checkpw( C4::Context->dbh, $cgi->param('username'), $cgi->param('password') ) ) { + return { code => 'PatronNotFound' }; +>>>>>>> [MT2306_2271] ILS-DI Message codes consistence:C4/ILSDI.pm } # Get the borrower @@ -349,10 +374,15 @@ sub GetPatronInfo { # Get Member details my $borrowernumber = $cgi->param('patron_id'); +<<<<<<< HEAD:C4/ILSDI/Services.pm my $borrower = GetMemberDetails( $borrowernumber, undef ); if ( not $borrower->{'borrowernumber'} ) { return { message => 'PatronNotFound' }; } +======= + my $borrower = GetMemberDetails( $borrowernumber ); + return { code => 'PatronNotFound' } unless $$borrower{borrowernumber}; +>>>>>>> [MT2306_2271] ILS-DI Message codes consistence:C4/ILSDI.pm # Cleaning the borrower hashref $borrower->{'charges'} = $borrower->{'flags'}->{'CHARGES'}->{'amount'}; @@ -436,6 +466,7 @@ sub GetPatronStatus { # Get Member details my $borrowernumber = $cgi->param('patron_id'); +<<<<<<< HEAD:C4/ILSDI/Services.pm my $borrower = GetMemberDetails( $borrowernumber, undef ); if ( not $borrower->{'borrowernumber'} ) { return { message => 'PatronNotFound' }; @@ -448,6 +479,17 @@ sub GetPatronStatus { $patron->{'expiry'} = $borrower->{'dateexpiry'}; return $patron; +======= + my $borrower = GetMemberDetails( $borrowernumber ); + return { code => 'PatronNotFound' } unless $$borrower{borrowernumber}; + + # Return the results + return { + type => $$borrower{categorycode}, + status => 0, # TODO + expiry => $$borrower{dateexpiry}, + }; +>>>>>>> [MT2306_2271] ILS-DI Message codes consistence:C4/ILSDI.pm } =head2 GetServices @@ -468,6 +510,7 @@ sub GetServices { # Get the member, or return an error code if not found my $borrowernumber = $cgi->param('patron_id'); +<<<<<<< HEAD:C4/ILSDI/Services.pm my $borrower = GetMemberDetails( $borrowernumber, undef ); if ( not $borrower->{'borrowernumber'} ) { return { message => 'PatronNotFound' }; @@ -479,6 +522,15 @@ sub GetServices { if ( not $item->{'itemnumber'} ) { return { message => 'RecordNotFound' }; } +======= + my $borrower = GetMemberDetails( $borrowernumber ); + return { code => 'PatronNotFound' } unless $$borrower{borrowernumber}; + + # Get the item, or return an error code if not found + my $itemnumber = $cgi->param('item_id'); + my $item = GetItem( $itemnumber ); + return { code => 'RecordNotFound' } unless $$item{itemnumber}; +>>>>>>> [MT2306_2271] ILS-DI Message codes consistence:C4/ILSDI.pm my @availablefor; @@ -544,17 +596,27 @@ sub RenewLoan { # Get borrower infos or return an error code my $borrowernumber = $cgi->param('patron_id'); +<<<<<<< HEAD:C4/ILSDI/Services.pm my $borrower = GetMemberDetails( $borrowernumber, undef ); if ( not $borrower->{'borrowernumber'} ) { return { message => 'PatronNotFound' }; } +======= + my $borrower = GetMemberDetails( $borrowernumber ); + return { code => 'PatronNotFound' } unless $$borrower{borrowernumber}; +>>>>>>> [MT2306_2271] ILS-DI Message codes consistence:C4/ILSDI.pm # Get the item, or return an error code my $itemnumber = $cgi->param('item_id'); +<<<<<<< HEAD:C4/ILSDI/Services.pm my $item = GetItem( $itemnumber, undef, undef ); if ( not $item->{'itemnumber'} ) { return { message => 'RecordNotFound' }; } +======= + my $item = GetItem( $itemnumber ); + return { code => 'RecordNotFound' } unless $$item{itemnumber}; +>>>>>>> [MT2306_2271] ILS-DI Message codes consistence:C4/ILSDI.pm # Add renewal if possible my @renewal = CanBookBeRenewed( $borrowernumber, $itemnumber ); @@ -598,6 +660,7 @@ sub HoldTitle { # Get the borrower or return an error code my $borrowernumber = $cgi->param('patron_id'); +<<<<<<< HEAD:C4/ILSDI/Services.pm my $borrower = GetMemberDetails( $borrowernumber, undef ); if ( not $borrower->{'borrowernumber'} ) { return { message => 'PatronNotFound' }; @@ -616,18 +679,39 @@ sub HoldTitle { if ( not $canbereserved ) { return { message => 'NotHoldable' }; } +======= + my $borrower = GetMemberDetails( $borrowernumber ); + return { code => 'PatronNotFound' } unless $$borrower{borrowernumber}; + + # Get the biblio record, or return an error code + my $biblionumber = $cgi->param('bib_id'); + my ( $count, $biblio ) = GetBiblio( $biblionumber ); + return { code => 'RecordNotFound' } unless $$biblio{biblionumber}; + + my $title = $$biblio{title}; + + # Check if the biblio can be reserved + return { code => 'NotHoldable' } unless CanBookBeReserved( $borrowernumber, $biblionumber ); +>>>>>>> [MT2306_2271] ILS-DI Message codes consistence:C4/ILSDI.pm my $branch; # Pickup branch management if ( $cgi->param('pickup_location') ) { $branch = $cgi->param('pickup_location'); +<<<<<<< HEAD:C4/ILSDI/Services.pm my $branches = GetBranches(); if ( not $branches->{$branch} ) { return { message => 'LocationNotFound' }; } } else { # if user provide no branch, use his own $branch = $borrower->{'branchcode'}; +======= + my $branches = GetBranches; + return { code => 'LocationNotFound' } unless $$branches{$branch}; + } else { # if the request provide no branch, use the borrower's branch + $branch = $$borrower{branchcode}; +>>>>>>> [MT2306_2271] ILS-DI Message codes consistence:C4/ILSDI.pm } # Add the reserve @@ -671,14 +755,20 @@ sub HoldItem { # Get the borrower or return an error code my $borrowernumber = $cgi->param('patron_id'); +<<<<<<< HEAD:C4/ILSDI/Services.pm my $borrower = GetMemberDetails( $borrowernumber, undef ); if ( not $borrower->{'borrowernumber'} ) { return { message => 'PatronNotFound' }; } +======= + my $borrower = GetMemberDetails( $borrowernumber ); + return { code => 'PatronNotFound' } unless $$borrower{borrowernumber}; +>>>>>>> [MT2306_2271] ILS-DI Message codes consistence:C4/ILSDI.pm # Get the biblio or return an error code my $biblionumber = $cgi->param('bib_id'); my ( $count, $biblio ) = GetBiblio($biblionumber); +<<<<<<< HEAD:C4/ILSDI/Services.pm if ( not $biblio->{'biblionumber'} ) { return { message => 'RecordNotFound' }; } @@ -702,6 +792,24 @@ sub HoldItem { if ( ( not $canbookbereserved ) or not($canitembereserved) ) { return { message => 'NotHoldable' }; } +======= + return { code => 'RecordNotFound' } unless $$biblio{biblionumber}; + + my $title = $$biblio{title}; + + # Get the item or return an error code + my $itemnumber = $cgi->param('item_id'); + my $item = GetItem( $itemnumber ); + return { code => 'RecordNotFound' } unless $$item{itemnumber}; + + # If the biblio does not match the item, return an error code + return { code => 'RecordNotFound' } if $$item{biblionumber} ne $$biblio{biblionumber}; + + # Check for item disponibility + my $canitembereserved = CanItemBeReserved( $borrowernumber, $itemnumber ); + my $canbookbereserved = CanBookBeReserved( $borrowernumber, $biblionumber ); + return { code => 'NotHoldable' } unless $canbookbereserved and $canitembereserved; +>>>>>>> [MT2306_2271] ILS-DI Message codes consistence:C4/ILSDI.pm my $branch; @@ -709,11 +817,17 @@ sub HoldItem { if ( $cgi->param('pickup_location') ) { $branch = $cgi->param('pickup_location'); my $branches = GetBranches(); +<<<<<<< HEAD:C4/ILSDI/Services.pm if ( not $branches->{$branch} ) { return { message => 'LocationNotFound' }; } } else { # if user provide no branch, use his own $branch = $borrower->{'branchcode'}; +======= + return { code => 'LocationNotFound' } unless $$branches{$branch}; + } else { # if the request provide no branch, use the borrower's branch + $branch = $$borrower{branchcode}; +>>>>>>> [MT2306_2271] ILS-DI Message codes consistence:C4/ILSDI.pm } my $rank; @@ -756,6 +870,7 @@ sub CancelHold { # Get the borrower or return an error code my $borrowernumber = $cgi->param('patron_id'); +<<<<<<< HEAD:C4/ILSDI/Services.pm my $borrower = GetMemberDetails( $borrowernumber, undef ); if ( not $borrower->{'borrowernumber'} ) { return { message => 'PatronNotFound' }; @@ -767,6 +882,15 @@ sub CancelHold { if ( not $item->{'itemnumber'} ) { return { message => 'RecordNotFound' }; } +======= + my $borrower = GetMemberDetails( $borrowernumber ); + return { code => 'PatronNotFound' } unless $$borrower{borrowernumber}; + + # Get the item or return an error code + my $itemnumber = $cgi->param('item_id'); + my $item = GetItem( $itemnumber ); + return { code => 'RecordNotFound' } unless $$item{itemnumber}; +>>>>>>> [MT2306_2271] ILS-DI Message codes consistence:C4/ILSDI.pm # Get borrower's reserves my @reserves = GetReservesFromBorrowernumber( $borrowernumber, undef ); @@ -778,15 +902,23 @@ sub CancelHold { } # if the item was not reserved by the borrower, returns an error code +<<<<<<< HEAD:C4/ILSDI/Services.pm if ( not grep { $itemnumber eq $_ } @reserveditems ) { return { message => 'NotCanceled' }; } +======= + return { code => 'NotCanceled' } unless any { $itemnumber eq $_ } @reserveditemnumbers; +>>>>>>> [MT2306_2271] ILS-DI Message codes consistence:C4/ILSDI.pm # Cancel the reserve CancelReserve( $itemnumber, undef, $borrowernumber ); +<<<<<<< HEAD:C4/ILSDI/Services.pm return { message => 'Canceled' }; +======= + return { code => 'Canceled' }; +>>>>>>> [MT2306_2271] ILS-DI Message codes consistence:C4/ILSDI.pm } 1; diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/ilsdi.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/ilsdi.tmpl index ffae61ddea..dfe14959eb 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/ilsdi.tmpl +++ b/koha-tmpl/opac-tmpl/prog/en/modules/ilsdi.tmpl @@ -1,4 +1,4 @@ - Catalog › ISBD + › ILS-DI @@ -697,11 +697,11 @@
  • HarvestAuthorityRecords (Use OAI-PMH instead)
  • HarvestHoldingsRecords (Use OAI-PMH instead)
  • GetRecords
  • -
  • Search
  • -
  • Scan
  • +
  • Search (Use SRU instead)
  • +
  • Scan (Use SRU instead)
  • GetAuthorityRecords
  • -
  • OutputRewritablePage
  • -
  • OutputIntermediateFormat
  • +
  • OutputRewritablePage (Not supported yet)
  • +
  • OutputIntermediateFormat (Not supported yet)
  • Level 3: Elementary OPAC alternative

      @@ -719,8 +719,8 @@

    Level 4: Robust/domain specific discovery platforms

      -
    • SearchCourseReserves
    • -
    • Explain
    • +
    • SearchCourseReserves (Not supported yet)
    • +
    • Explain (Not supported yet)
    diff --git a/opac/ilsdi.pl b/opac/ilsdi.pl index fa58296de6..4f4b17736e 100755 --- a/opac/ilsdi.pl +++ b/opac/ilsdi.pl @@ -141,10 +141,12 @@ if ( $cgi->param('service') eq "Describe" and any { $cgi->param('verb') eq $_ } exit 0; } +my $out; + # If ILS-DI module is disabled in System->Preferences, redirect to 404 unless ( C4::Context->preference('ILS-DI') ) { - print $cgi->redirect("/cgi-bin/koha/errors/404.pl"); - exit 1; + $out->{'code'} = "NotAllowed"; + $out->{'message'} = "ILS-DI is disabled."; } # If the remote address is not allowed, redirect to 403 @@ -152,14 +154,12 @@ my @AuthorizedIPs = split(/,/, C4::Context->preference('ILS-DI:AuthorizedIPs')); if ( @AuthorizedIPs # If no filter set, allow access to everybody and not any { $ENV{'REMOTE_ADDR'} eq $_ } @AuthorizedIPs # IP Check ) { - print $cgi->redirect("/cgi-bin/koha/errors/403.pl"); - exit 1; + $out->{'code'} = "NotAllowed"; + $out->{'message'} = "Unauthorized IP address: ".$ENV{'REMOTE_ADDR'}."."; } my $service = $cgi->param('service') || "ilsdi"; -my $out; - # Check if the requested service is in the list if ( $service and any { $service eq $_ } @services ) { @@ -173,7 +173,8 @@ if ( $service and any { $service eq $_ } @services ) { # check for missing parameters for ( @parmsrequired ) { unless ( exists $paramhash{$_} ) { - $out->{'message'} = "missing $_ parameter"; + $out->{'code'} = "MissingParameter"; + $out->{'message'} = "The required parameter ".$_." is missing."; } } @@ -186,7 +187,8 @@ if ( $service and any { $service eq $_ } @services ) { } } if ( $found == 0 && $name ne 'service' ) { - $out->{'message'} = "$name is an illegal parameter"; + $out->{'code'} = "IllegalParameter"; + $out->{'message'} = "The parameter ".$name." is illegal."; } } @@ -194,7 +196,8 @@ if ( $service and any { $service eq $_ } @services ) { for ( @names ) { my @values = $cgi->param($_); if ( $#values != 0 ) { - $out->{'message'} = "multiple values are not allowed for the $_ parameter"; + $out->{'code'} = "MultipleValuesNotAllowed"; + $out->{'message'} = "Multiple values not allowed for the parameter ".$_."."; } } -- 2.39.5