{"id":1566,"date":"2012-12-04T10:09:11","date_gmt":"2012-12-04T10:09:11","guid":{"rendered":"https:\/\/copyright.lboro.ac.uk\/lorls\/?page_id=1566"},"modified":"2012-12-04T10:09:11","modified_gmt":"2012-12-04T10:09:11","slug":"setting-up-the-loans-cache-for-use-in-the-academicdashborad","status":"publish","type":"page","link":"https:\/\/blog.lboro.ac.uk\/lorls\/documentation\/installation\/setting-up-the-loans-cache-for-use-in-the-academicdashborad","title":{"rendered":"Setting up the loans cache for use in the academic dashboard"},"content":{"rendered":"<p>The academic dashboard has a number of features that are only available if the &#8220;loans cache&#8221; part of LORLS has been set up. \u00a0The installer will create the required database and install the following three scripts in the &#8220;\/usr\/local\/LUMP\/bin&#8221; directory.<\/p>\n<ul>\n<li>updateISBNMap<\/li>\n<li>updateLoanCache<\/li>\n<li>preloadLoanCache<\/li>\n<\/ul>\n<p>The &#8220;updateISBNMap&#8221; and &#8220;updateLoanCache&#8221; scripts require access to the following APIs on your Library Management System (LMS).<\/p>\n<ul>\n<li>getISBNMap<\/li>\n<li>getLoanTransactions<\/li>\n<\/ul>\n<p>You will probably have to create these APIs for your LMS. \u00a0We have example API scripts for the Aleph LMS from ExLibris that are available at the bottom of this page.<\/p>\n<p>The getISBNMap API takes no parameters and returns the XML mapping between each ISBN in the system and its local control number and at the end it should also contain a total count of the isbns.  An example of the output is:<\/p>\n<pre>&lt;isbns&gt;\n &lt;map&gt;\n  &lt;isbn&gt;155587083x&lt;\/isbn&gt;\n  &lt;sysno&gt;000281827&lt;\/sysno&gt;\n &lt;\/map&gt;\n &lt;map&gt;\n  &lt;isbn&gt;072920720x&lt;\/isbn&gt;\n  &lt;sysno&gt;000241757&lt;\/sysno&gt;\n &lt;\/map&gt;\n .\n .\n .\n &lt;map&gt;\n  &lt;isbn&gt;0116308125&lt;\/isbn&gt;\n  &lt;sysno&gt;000158641&lt;\/sysno&gt;\n &lt;\/map&gt;\n &lt;total_isbn_count&gt;398964&lt;\/total_isbn_count&gt;\n&lt;\/isbns&gt;<\/pre>\n<p>The getLoanTransactions API should take one parameter &#8220;on&#8221; which contains the date to list the loan transactions for.  The date should be in the format YYYY-MM-DD.  The XML returned should contain for each loan either issued or returned on that date the following details:<\/p>\n<ul>\n<li>lcn &#8211; the local control number for the item being issued or returned.<\/li>\n<li>isbn &#8211; the isbn of the item being issued or returned.<\/li>\n<li>issue_date &#8211; the date and time the item was issued (in the format &#8220;YYYYMMDD HHMM&#8221;)<\/li>\n<li>return_date &#8211; the date and time the item was returned (in the format &#8220;YYYYMMDD HHMM&#8221;).  If the transaction is an issue then this should be be left empty.\n<li>item_type &#8211; a local code for the type of item (e.g. 01 &#8211; long loan, 02 &#8211; week loan, 03 &#8211; short loan)<\/li>\n<li>department &#8211; the code for the department the borrower belongs to<\/li>\n<\/ul>\n<p>Again the XML file should finish with a total count of the number of loan transactions it has returned.  An example output of this API is:<\/p>\n<pre>&lt;loan_transactions&gt;\n &lt;loan&gt;\n  &lt;lcn&gt;001050151&lt;\/lcn&gt;\n  &lt;isbn&gt;0880119683&lt;\/isbn&gt;\n  &lt;issue_date&gt;20121203 1421&lt;\/issue_date&gt;\n  &lt;return_date&gt;&lt;\/return_date&gt;\n  &lt;item_type&gt;01&lt;\/item_type&gt;\n  &lt;department&gt;LB&lt;\/department&gt;\n &lt;\/loan&gt;\n &lt;loan&gt;\n  &lt;lcn&gt;000840951&lt;\/lcn&gt;\n  &lt;isbn&gt;0850361850&lt;\/isbn&gt;\n  &lt;issue_date&gt;20121203 1709&lt;\/issue_date&gt;\n  &lt;return_date&gt;&lt;\/return_date&gt;\n  &lt;item_type&gt;01&lt;\/item_type&gt;\n  &lt;department&gt;LB&lt;\/department&gt;\n &lt;\/loan&gt;\n .\n .\n .\n &lt;loan&gt;\n  &lt;lcn&gt;000224944&lt;\/lcn&gt;\n  &lt;isbn&gt;0631195203&lt;\/isbn&gt;\n  &lt;issue_date&gt;20121203 1709&lt;\/issue_date&gt;\n  &lt;return_date&gt;&lt;\/return_date&gt;\n  &lt;item_type&gt;01&lt;\/item_type&gt;\n  &lt;department&gt;LB&lt;\/department&gt;\n &lt;\/loan&gt;\n &lt;total_loan_count&gt;3237&lt;\/total_loan_count&gt;\n&lt;\/loan_transactions&gt;<\/pre>\n<p>When the APIs are available then you will need to run the updateISBNMap script which will populate a mapping between item&#8217;s ISBNs and its local control number.<\/p>\n<p>After the updateISBNMap script has completed you can then run the preloadLoanCache script which will populate the loancache with a refined version of the last years worth of loan transactions from your LMS.<\/p>\n<p>After the preloadLoanCache script has completed you will need to put entries in your cron to run the updateISBNMap and the updateLoanCache scripts each day.<\/p>\n<h3>Example getISBNMap API script for Aleph<\/h3>\n<p>You will need to replace &lt;ORACLE HOME DIR&gt;, &lt;DATABASE&gt;, &lt;DB_USERNAME&gt; and &lt;DB_PASSWORD&gt; and &lt;BIB_LIBRARY&gt; with the relevant values for your aleph configuration.<\/p>\n<pre>#!\/exlibris\/aleph\/a20_2\/product\/bin\/perl\n#\nuse strict;\nuse CGI;\nuse DBI;\n\n$ENV{\"ORACLE_HOME\"} = \"&lt;ORACLE HOME DIR&gt;\";\n\nmy $dbh = DBI-&gt;connect(\"DBI:Oracle:&lt;DATABASE&gt;\",\"&lt;DB_USERNAME&gt;\",\"&lt;DB_PASSWORD&gt;\") || die \"$!\";\n$| = 1;\nmy $q = new CGI;\n\nmy $getISBN2SysNo=$dbh-&gt;prepare(\"select Z00R_TEXT, Z00R_DOC_NUMBER from &lt;BIB_LIBRARY&gt;.Z00R where Z00R_FIELD_CODE='020'\");\n\nmy $total_number=0;\n\nprint STDOUT \"Content-type: text\/xmlnn\";\nprint STDOUT \"&lt;isbns&gt;n\";\n\n$getISBN2SysNo-&gt;execute();\nwhile (my ($isbn, $sysno) = $getISBN2SysNo-&gt;fetchrow_array) {\n        $sysno=substr($sysno,0,9);\n        $isbn=~s\/^$$a\/\/;\n        $isbn=~s\/s.*$\/\/;\n        print STDOUT \" &lt;map&gt;n\";\n        print STDOUT \"  &lt;isbn&gt;$isbn&lt;\/isbn&gt;n\";\n        print STDOUT \"  &lt;sysno&gt;$sysno&lt;\/sysno&gt;n\";\n        print STDOUT \" &lt;\/map&gt;n\";\n        $total_number++;\n}\nprint STDOUT \" &lt;total_isbn_count&gt;$total_number&lt;\/total_isbn_count&gt;n\";\nprint STDOUT \"&lt;\/isbns&gt;n\";\n\n<\/pre>\n<h3>Example getLoanTransactions API script for Aleph<\/h3>\n<p>You will need to replace &lt;ORACLE HOME DIR&gt;, &lt;DATABASE&gt;, &lt;DB_USERNAME&gt; and &lt;DB_PASSWORD&gt;, &lt;BIB_LIBRARY&gt; and &lt;ADMIN_LIBRARY&gt; with the relevant values for your aleph configuration.<\/p>\n<pre>\n#!\/exlibris\/aleph\/a20_2\/product\/bin\/perl\n#\nuse strict;\nuse CGI;\nuse DBI;\n\n$ENV{\"ORACLE_HOME\"} = \"&lt;ORACLE HOME DIR&gt;\";\n\nmy $dbh = DBI-&gt;connect(\"DBI:Oracle:&lt;DATABASE&gt;\",\"&lt;DB_USERNAME&gt;\",\"&lt;DB_PASSWORD&gt;\") || die \"$!\";\n$| = 1;\nmy $q = new CGI;\nmy $on = $q-&gt;param('on');\n\nmy ($onDate)=$on=~m\/(d{4}-d{2}-d{2})\/;\n$onDate=~s\/^(d{4})-(d{2})-(d{2})$\/$1$2$3\/;\n\nif(!$onDate){\n        print STDOUT \"Content-type: text\/xmlnn\";\n        print STDOUT \"&lt;loan_transactions&gt;n\";\n        print STDOUT \"&lt;error&gt;No Date Specified&lt;\/error&gt;n\";\n        print STDOUT \"&lt;\/loan_transactions&gt;n\";\n        exit;\n}\n\nmy $getISBN=$dbh-&gt;prepare(\"select Z00R_TEXT from &lt;BIB_LIBRARY&gt;.Z00R where Z00R_DOC_NUMBER=? and (Z00R_FIELD_CODE='020' or Z00R_F\nIELD_CODE='022')\");\n\nmy $total_number=0;\n\nprint STDOUT \"Content-type: text\/xmlnn\";\nprint STDOUT \"&lt;loan_transactions&gt;n\";\n\nmy $currentloan =\n        $dbh-&gt;prepare('select Z36_REC_KEY, Z36_LOAN_DATE, Z36_LOAN_HOUR, Z36_ITEM_STATUS, Z36_BOR_TYPE' .\n                      ' from &lt;ADMIN_LIBRARY&gt;.Z36 ' .\n                      ' where Z36_LOAN_DATE= ' . $dbh-&gt;quote($onDate)\n        );\n$currentloan-&gt;execute;\nwhile (my ($id, $date, $hour, $itemStatus, $borStatus) = $currentloan-&gt;fetchrow_array) {\n        $id=substr($id,0,9);\n        print STDOUT \" &lt;loan&gt;n\";\n        print STDOUT \"  &lt;lcn&gt;$id&lt;\/lcn&gt;n\";\n        my @ISBNs=getISBNs($id);\n        foreach my $ISBN (@ISBNs){\n                print STDOUT \"  &lt;isbn&gt;$ISBN&lt;\/isbn&gt;n\";\n        }\n        print STDOUT sprintf(\"  &lt;issue_date&gt;%08d %04d&lt;\/issue_date&gt;n\", $date, $hour);\n        print STDOUT \"  &lt;return_date&gt;&lt;\/return_date&gt;n\";\n        print STDOUT \"  &lt;item_type&gt;$itemStatus&lt;\/item_type&gt;n\";\n        print STDOUT \"  &lt;department&gt;$borStatus&lt;\/department&gt;n\";\n        print STDOUT \" &lt;\/loan&gt;n\";\n        $total_number++;\n}\n$currentloan-&gt;finish;\n\nmy $pastloans =\n        $dbh-&gt;prepare('select Z36H_REC_KEY, Z36H_LOAN_DATE, Z36H_LOAN_HOUR, Z36H_RETURNED_DATE, Z36H_RETURNED_HOUR, Z36H\n_ITEM_STATUS, Z36H_BOR_TYPE' .\n                      ' from &lt;ADMIN_LIBRARY&gt;.Z36H ' .\n                      ' where Z36H_LOAN_DATE= ' . $dbh-&gt;quote($onDate) . ' or Z36H_RETURNED_DATE= '.$dbh-&gt;quote($onDate)\n        );\n$pastloans-&gt;execute;\nwhile (my ($id, $date, $hour, $rdate, $rhour, $itemStatus, $borStatus) = $pastloans-&gt;fetchrow_array) {\n        $id=substr($id,0,9);\n        print STDOUT \" &lt;loan&gt;n\";\n        print STDOUT \"  &lt;lcn&gt;$id&lt;\/lcn&gt;n\";\n        my @ISBNs=getISBNs($id);\n        foreach my $ISBN (@ISBNs){\n                print STDOUT \"  &lt;isbn&gt;$ISBN&lt;\/isbn&gt;n\";\n        }\n        print STDOUT sprintf(\"  &lt;issue_date&gt;%08d %04d&lt;\/issue_date&gt;n\", $date, $hour);\n        print STDOUT sprintf(\"  &lt;return_date&gt;%08d %04d&lt;\/return_date&gt;n\", $rdate, $rhour);\n        print STDOUT \"  &lt;item_type&gt;$itemStatus&lt;\/item_type&lt;n\";\n        print STDOUT \"  &lt;department&gt;$borStatus&lt;\/department&lt;n\";\n        print STDOUT \" &lt;\/loan&gt;n\";\n        $total_number++;\n}\n$pastloans-&gt;finish;\n\nprint STDOUT \" &lt;total_loan_count&gt;$total_number&lt;\/total_loan_count&gt;n\";\nprint STDOUT \"&lt;\/loan_transactions&gt;n\";\n\nsub getISBNs\n{\n        my ($lcn)= @_;\n        $getISBN-&gt;execute($lcn);\n        my @isbns;\n        while(my ($t)=$getISBN-&gt;fetchrow_array){\n                if($t=~m\/^$$a([dw-]{9,13})\/){\n                        push @isbns, $1;\n                }\n        }\n        return @isbns;\n}\n\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The academic dashboard has a number of features that are only available if the &#8220;loans cache&#8221; part of LORLS has been set up. \u00a0The installer will create the required database and install the following three scripts in the &#8220;\/usr\/local\/LUMP\/bin&#8221; directory. updateISBNMap updateLoanCache preloadLoanCache The &#8220;updateISBNMap&#8221; and &#8220;updateLoanCache&#8221; scripts require access to the following APIs on [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":129,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"class_list":["post-1566","page","type-page","status-publish","hentry","count-0","even alt","author-lbjlclboro-ac-uk","last"],"_links":{"self":[{"href":"https:\/\/blog.lboro.ac.uk\/lorls\/wp-json\/wp\/v2\/pages\/1566","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.lboro.ac.uk\/lorls\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blog.lboro.ac.uk\/lorls\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blog.lboro.ac.uk\/lorls\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.lboro.ac.uk\/lorls\/wp-json\/wp\/v2\/comments?post=1566"}],"version-history":[{"count":0,"href":"https:\/\/blog.lboro.ac.uk\/lorls\/wp-json\/wp\/v2\/pages\/1566\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/blog.lboro.ac.uk\/lorls\/wp-json\/wp\/v2\/pages\/129"}],"wp:attachment":[{"href":"https:\/\/blog.lboro.ac.uk\/lorls\/wp-json\/wp\/v2\/media?parent=1566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}