Skip to content

Commit

Permalink
Merge pull request #59 from folio-org/sip2-95_US811725
Browse files Browse the repository at this point in the history
sip2-95 add support for empty no block due date
  • Loading branch information
brichardEbsco authored Jun 9, 2021
2 parents b2e69b6 + 2c56ee1 commit 8e5706e
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Checkout parse(String message) {
coBuilder.transactionDate(transactionDate);

// nb due date: 18-char, fixed-length required field
final OffsetDateTime nbDueDate = parseDateTime(messageChars);
final OffsetDateTime nbDueDate = parseDateTimeNB(messageChars);
coBuilder.nbDueDate(nbDueDate);

// Variable length fields
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/folio/edge/sip2/parser/MessageParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/
public abstract class MessageParser {
private static final Logger log = LogManager.getLogger();
private static final String MISSING_NB_DUE_DATE = " ".repeat(18);

protected int position;
protected final Character delimiter;
Expand Down Expand Up @@ -62,6 +63,17 @@ protected String parseVariableLengthField(char [] messageChars, Field field) {
return new String(messageChars, startPosition, position - startPosition);
}

protected OffsetDateTime parseDateTimeNB(char [] messageChars) {
final String dateTimeString = new String(messageChars, position, 18);
position += 18;

if (MISSING_NB_DUE_DATE.equals(dateTimeString)) { // return null for 18 space nb due date
return null;
} else {
return convertFieldToDateTime(dateTimeString);
}
}

protected OffsetDateTime parseDateTime(char [] messageChars) {
final String dateTimeString = new String(messageChars, position, 18);
position += 18;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Renew parse(String message) {
rBuilder.transactionDate(transactionDate);

// nb due date: 18-char, fixed-length required field
final OffsetDateTime nbDueDate = parseDateTime(messageChars);
final OffsetDateTime nbDueDate = parseDateTimeNB(messageChars);
rBuilder.nbDueDate(nbDueDate);

// Variable length fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,32 @@ void testParse() {
assertEquals(FALSE, checkout.getFeeAcknowledged());
assertEquals(FALSE, checkout.getCancel());
}

@Test
void testParseBlankNbDueDate() {
CheckoutMessageParser parser =
new CheckoutMessageParser(valueOf('|'), TestUtils.UTCTimeZone);
final OffsetDateTime transactionDate = TestUtils.getOffsetDateTimeUtc().truncatedTo(SECONDS);
final DateTimeFormatter formatter = DateTimeFormatter
.ofPattern("yyyyMMdd HHmmss");
final String transactionDateString = formatter.format(transactionDate);
final String nbDueDateString = " ".repeat(18);
final Checkout checkout = parser.parse(
"YY" + transactionDateString + nbDueDateString
+ "AApatron_id|ABSomeBook|AC|CHAutographed"
+ "|AD1234|AOuniversity_id|BON|BIN|");

assertEquals(TRUE, checkout.getScRenewalPolicy());
assertEquals(TRUE, checkout.getNoBlock());
assertEquals(transactionDate, checkout.getTransactionDate());
assertEquals(null, checkout.getNbDueDate());
assertEquals("university_id", checkout.getInstitutionId());
assertEquals("patron_id", checkout.getPatronIdentifier());
assertEquals("SomeBook", checkout.getItemIdentifier());
assertEquals("", checkout.getTerminalPassword());
assertEquals("Autographed", checkout.getItemProperties());
assertEquals("1234", checkout.getPatronPassword());
assertEquals(FALSE, checkout.getFeeAcknowledged());
assertEquals(FALSE, checkout.getCancel());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,33 @@ void testParse() {
assertEquals("Autographed", renew.getItemProperties());
assertEquals(FALSE, renew.getFeeAcknowledged());
}

@Test
void testParseBlankNbDueDate() {
RenewMessageParser parser =
new RenewMessageParser(valueOf('|'), TestUtils.UTCTimeZone);
final OffsetDateTime transactionDate =
TestUtils.getOffsetDateTimeUtc().truncatedTo(SECONDS);
final DateTimeFormatter formatter = DateTimeFormatter
.ofPattern("yyyyMMdd HHmmss");
final String transactionDateString = formatter.format(transactionDate);
final String nbDueDateString = " ".repeat(18);
final Renew renew = parser.parse(
"YY" + transactionDateString + nbDueDateString
+ "AApatron_id|AC|AD1234|AOuniversity_id|ABSome Book|"
+ "AJSome Title|CHAutographed|BON|");

assertEquals(TRUE, renew.getThirdPartyAllowed());
assertEquals(TRUE, renew.getNoBlock());
assertEquals(transactionDate, renew.getTransactionDate());
assertEquals(null, renew.getNbDueDate());
assertEquals("university_id", renew.getInstitutionId());
assertEquals("patron_id", renew.getPatronIdentifier());
assertEquals("1234", renew.getPatronPassword());
assertEquals("Some Book", renew.getItemIdentifier());
assertEquals("Some Title", renew.getTitleIdentifier());
assertEquals("", renew.getTerminalPassword());
assertEquals("Autographed", renew.getItemProperties());
assertEquals(FALSE, renew.getFeeAcknowledged());
}
}

0 comments on commit 8e5706e

Please sign in to comment.