From: <ps...@us...> - 2017-05-14 18:13:26
|
Revision: 282 http://sourceforge.net/p/vlibrary/code/282 Author: psteitz Date: 2017-05-14 18:13:23 +0000 (Sun, 14 May 2017) Log Message: ----------- Fixed error in processCheckout causing request for book being checked out not to be deleted. Modified Paths: -------------- branches/VLIBRARY_2_X/src/main/java/org/sourceforge/vlibrary/user/dao/BookDAO.java branches/VLIBRARY_2_X/src/main/java/org/sourceforge/vlibrary/user/dao/LibraryTransactionDAO.java branches/VLIBRARY_2_X/src/main/java/org/sourceforge/vlibrary/user/logic/LibraryManager.java branches/VLIBRARY_2_X/src/test/java/org/sourceforge/vlibrary/user/dao/LibraryTransactionDAOTest.java Modified: branches/VLIBRARY_2_X/src/main/java/org/sourceforge/vlibrary/user/dao/BookDAO.java =================================================================== --- branches/VLIBRARY_2_X/src/main/java/org/sourceforge/vlibrary/user/dao/BookDAO.java 2017-05-13 23:23:35 UTC (rev 281) +++ branches/VLIBRARY_2_X/src/main/java/org/sourceforge/vlibrary/user/dao/BookDAO.java 2017-05-14 18:13:23 UTC (rev 282) @@ -495,6 +495,23 @@ } /** + * Gets the ISBN of the book with the given ID if there is such a book, + * null otherwise. + * + * @param bookID ID of book + * @return ISBN of the book with the given ID + * @throws LibraryException if an error occurs searching for the book + */ + public String getIsbn(long bookID) throws LibraryException { + final Book book = retrieve(bookID); + if (null == book) { + return null; + } else { + return retrieve(bookID).getIsbn(); + } + } + + /** * Retrieves the book with the given ID, if there is such a book; * otherwise Null. * Modified: branches/VLIBRARY_2_X/src/main/java/org/sourceforge/vlibrary/user/dao/LibraryTransactionDAO.java =================================================================== --- branches/VLIBRARY_2_X/src/main/java/org/sourceforge/vlibrary/user/dao/LibraryTransactionDAO.java 2017-05-13 23:23:35 UTC (rev 281) +++ branches/VLIBRARY_2_X/src/main/java/org/sourceforge/vlibrary/user/dao/LibraryTransactionDAO.java 2017-05-14 18:13:23 UTC (rev 282) @@ -306,10 +306,11 @@ * @param book the id of the book being checked out * @param reader the id of the reader checking out the book * @param location the id of the location of the transaction + * @param isbn of the book * @exception LibraryException if the book is not checked in, or an * error occurs recording the transaction */ - public void processCheckout(long reader, long book, long location) + public void processCheckout(long reader, long book, String isbn, long location) throws LibraryException { if (logger.isDebugEnabled()) { final String message = resourceBundleMessageSource.getMessage( @@ -373,15 +374,15 @@ throw new LibraryException(errString,se); } - // Delete any pending requests for this <isbn,location> pair + // Delete any pending requests for this <isbn,reader> pair try { jdbcTemplate.update(deleteReaderBookRequestActionTransactionSQL, new Object [] { new Long(reader), - new Long(book), + isbn, new Long(Constants.REQUEST_ACTION) }, - new int[] {Types.INTEGER, Types.INTEGER, Types.INTEGER} + new int[] {Types.INTEGER, Types.VARCHAR, Types.INTEGER} ); } catch (final Exception se) { final String errString = Modified: branches/VLIBRARY_2_X/src/main/java/org/sourceforge/vlibrary/user/logic/LibraryManager.java =================================================================== --- branches/VLIBRARY_2_X/src/main/java/org/sourceforge/vlibrary/user/logic/LibraryManager.java 2017-05-13 23:23:35 UTC (rev 281) +++ branches/VLIBRARY_2_X/src/main/java/org/sourceforge/vlibrary/user/logic/LibraryManager.java 2017-05-14 18:13:23 UTC (rev 282) @@ -948,7 +948,7 @@ newPossessor = readerDAO.retrieve(newPossessor); // Perform checkout and cancel any requests that the reader has for <book.isbn, location> - libraryTransactionDAO.processCheckout(reader, book, location); + libraryTransactionDAO.processCheckout(reader, book, bookDAO.getIsbn(book), location); // send mail to current requesters final Book bk = bookDAO.retrieve(book); Modified: branches/VLIBRARY_2_X/src/test/java/org/sourceforge/vlibrary/user/dao/LibraryTransactionDAOTest.java =================================================================== --- branches/VLIBRARY_2_X/src/test/java/org/sourceforge/vlibrary/user/dao/LibraryTransactionDAOTest.java 2017-05-13 23:23:35 UTC (rev 281) +++ branches/VLIBRARY_2_X/src/test/java/org/sourceforge/vlibrary/user/dao/LibraryTransactionDAOTest.java 2017-05-14 18:13:23 UTC (rev 282) @@ -9,6 +9,8 @@ import java.util.List; +import junit.framework.Assert; + import org.apache.log4j.Logger; import org.dbunit.Assertion; import org.dbunit.database.IDatabaseConnection; @@ -21,8 +23,6 @@ import org.sourceforge.vlibrary.TestUtils; import org.sourceforge.vlibrary.user.valuebeans.LibraryTransaction; -import junit.framework.Assert; - /** * */ @@ -146,6 +146,39 @@ //instance.cancelRequest(1021, 1011); } + /* + * <BOOK ID='101' + TITLE='Greatest Book' + PUBLISHER='Wrox' + ISBN='1-111-' + OWNER='101' + PUB_DATE='Mar 2006' + /> + <BOOK ID='102' + TITLE='Greatest Book2' + PUBLISHER='Wrox' + ISBN='2-111-' + OWNER='101' + PUB_DATE='Mar 2006' + COPY='0' + /> + <BOOK ID='103' + TITLE='XGreatest Book2' + PUBLISHER='Wrox' + ISBN='3-111-' + OWNER='101' + PUB_DATE='Mar 2006' + /> + <BOOK ID='104' + TITLE='Greatest Book2' + PUBLISHER='Wrox' + ISBN='2-111-' + OWNER='101' + PUB_DATE='Mar 2006' + COPY='1' + /> + */ + public void testGetLastLocation() throws Exception { logger.info("testGetLastLocation"); @@ -155,7 +188,7 @@ instance.processCheckin(103, 104, 102); assertEquals(102, instance.getLastLocation(104)); - instance.processCheckout(103, 104, 102); + instance.processCheckout(103, 104,"2-111-", 102); assertEquals(102, instance.getLastLocation(104)); } @@ -170,7 +203,7 @@ long[] copies = instance.getCopies("2-111-", 102); assertEquals(1, copies.length); assertEquals(104, copies[0]); - instance.processCheckout(103, 104, 102); + instance.processCheckout(103, 104,"2-111-", 102); copies = instance.getCopies("2-111-", 102); assertEquals(1, copies.length); assertEquals(104, copies[0]); @@ -189,10 +222,14 @@ "LibraryTransactionDAO", LibraryTransactionDAO.class); + // Record a request transaction + instance.processRequest(103, 103, 101); + // Check the book in first, so it is available for checkout instance.processCheckin(102, 103, 101); - instance.processCheckout(103, 103, 101); + // Check it out (should delete the request transaction) + instance.processCheckout(103, 103,"3-111-", 101); // Fetch database data final IDataSet databaseDataSet = TestUtils.getConnection().createDataSet(); @@ -210,7 +247,7 @@ Assertion.assertEquals(expectedTable, filteredTable); try { - instance.processCheckout(101, 103, 101); + instance.processCheckout(101, 103,"3-111-", 101); fail("checking out book 103 (already checked out by reader 103) should have thrown an exception"); } catch(final Exception ex) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |