Skip to content

Commit

Permalink
PR-1821 Add option of default patron fee (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
JanisSaldabols authored Jul 22, 2024
1 parent 87d74e5 commit a86ec62
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib-ncip-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.olf.rs</groupId>
<artifactId>lib-ncip-cli</artifactId>
<version>0.23.16</version>
<version>0.23.17</version>
<name>lib-ncip-cli</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
2 changes: 1 addition & 1 deletion lib-ncip-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.olf.rs</groupId>
<artifactId>lib-ncip-client</artifactId>
<version>0.23.16</version>
<version>0.23.17</version>
<name>NCIP Client</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.olf.rs.circ.client;

import java.math.BigDecimal;
import java.util.HashMap;

import org.apache.commons.lang.NotImplementedException;
Expand All @@ -8,10 +9,14 @@
import org.extensiblecatalog.ncip.v2.service.AcceptItemInitiationData;
import org.extensiblecatalog.ncip.v2.service.AcceptItemResponseData;
import org.extensiblecatalog.ncip.v2.service.AgencyId;
import org.extensiblecatalog.ncip.v2.service.Amount;
import org.extensiblecatalog.ncip.v2.service.ApplicationProfileType;
import org.extensiblecatalog.ncip.v2.service.BibliographicDescription;
import org.extensiblecatalog.ncip.v2.service.BibliographicItemId;
import org.extensiblecatalog.ncip.v2.service.BibliographicItemIdentifierCode;
import org.extensiblecatalog.ncip.v2.service.FiscalActionType;
import org.extensiblecatalog.ncip.v2.service.FiscalTransactionInformation;
import org.extensiblecatalog.ncip.v2.service.FiscalTransactionType;
import org.extensiblecatalog.ncip.v2.service.FromAgencyId;
import org.extensiblecatalog.ncip.v2.service.InitiationHeader;
import org.extensiblecatalog.ncip.v2.service.ItemDescription;
Expand Down Expand Up @@ -46,12 +51,13 @@ public class AcceptItem extends NCIPService implements NCIPCircTransaction {
protected String fromAgency;
protected String requestedActionTypeString;
protected String applicationProfileTypeString;
protected HashMap<String, HashMap> itemOptionalFields = new HashMap<String, HashMap>();
protected boolean chargeDefaultPatronFee;
protected HashMap<String, HashMap<String, String>> itemOptionalFields = new HashMap<>();
private static final Logger logger = Logger.getLogger(AcceptItem.class);

public AcceptItem() {
itemOptionalFields.put(Constants.BIBLIOGRAPHIC_DESCRIPTION, new HashMap<String, String>());
itemOptionalFields.put(Constants.ITEM_DESCRIPTION, new HashMap<String, String>());
itemOptionalFields.put(Constants.BIBLIOGRAPHIC_DESCRIPTION, new HashMap<>());
itemOptionalFields.put(Constants.ITEM_DESCRIPTION, new HashMap<>());
}

public AcceptItem setRequestActionType(String action) {
Expand All @@ -64,6 +70,11 @@ public AcceptItem setApplicationProfileType(String profileType) {
return this;
}

public AcceptItem setChargeDefaultPatronFee(boolean chargeDefaultPatronFee) {
this.chargeDefaultPatronFee = chargeDefaultPatronFee;
return this;
}

public AcceptItem setItemId(String itemId) {
itemIdString = itemId;
return this;
Expand Down Expand Up @@ -106,7 +117,7 @@ public AcceptItem setFromAgency(String fromAgency) {

/**
* setRegistryId
* @param string - registry ID. Will be set as the 'AgencyId' on the 'ItemId' element - only for WMS
* @param registryId - registry ID. Will be set as the 'AgencyId' on the 'ItemId' element - only for WMS
* @return Instance object
* Only adding here for consistency because as this time WMS does not support AcceptItem
*/
Expand Down Expand Up @@ -237,6 +248,17 @@ public NCIPInitiationData generateNCIP2Object() {
acceptItemInitationData.setRequestId(requestId);

acceptItemInitationData.setItemOptionalFields(itemOptionalFields);

if (chargeDefaultPatronFee) {
FiscalTransactionInformation fiscalTransactionInformation = new FiscalTransactionInformation();
Amount amount = new Amount();
amount.setMonetaryValue(BigDecimal.ZERO);
fiscalTransactionInformation.setAmount(amount);
fiscalTransactionInformation.setFiscalActionType(new FiscalActionType(Constants.SCHEME, Constants.CHARGE_DEFAULT_PATRON_FEE));
fiscalTransactionInformation.setFiscalTransactionType(new FiscalTransactionType(Constants.SCHEME, Constants.ILL_FEE));
acceptItemInitationData.setFiscalTransactionInformation(fiscalTransactionInformation);
}

return acceptItemInitationData;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class Constants {
public static final String IDM_SCOPE = "SCIM:read_user";
public static final String OCLC_HOST_NAME = "https://oauth.oclc.org";
public static final String DEFAULT_TIMEOUT = "3000";
public static final String SCHEME = "Scheme";
public static final String CHARGE_DEFAULT_PATRON_FEE = "charge-default-patron-fee";
public static final String ILL_FEE = "ILL-fee";


}
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,20 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Iterator;
import java.util.UUID;
import java.util.stream.Stream;

import org.extensiblecatalog.ncip.v2.service.AcceptItemInitiationData;
import org.extensiblecatalog.ncip.v2.service.AcceptItemResponseData;
import org.extensiblecatalog.ncip.v2.service.ItemId;
import org.extensiblecatalog.ncip.v2.service.RequestId;
import org.json.JSONArray;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.parser.Parser;
import org.junit.Before;
import org.junit.Test;
import org.olf.rs.circ.client.AcceptItem;
import org.olf.rs.circ.client.CheckinItem;
import org.olf.rs.circ.client.CheckoutItem;
import org.olf.rs.circ.client.LookupUser;
import org.olf.rs.circ.client.NCIP2Client;
import org.olf.rs.circ.client.Constants;
import org.olf.rs.circ.client.TestConstants;

import static org.junit.Assert.*;
Expand Down Expand Up @@ -91,15 +85,31 @@ public void testGenerateNcip1Object() throws Exception {
}

@Test
public void testGenerateNcip2Object() throws Exception {
AcceptItem acceptItem = new AcceptItem();
acceptItem.setToAgency("ABC");
acceptItem.setItemId("ABC-2387402374");
public void testGenerateNcip2Object() {
AcceptItem acceptItem = new AcceptItem()
.setToAgency("ABC")
.setItemId("ABC-2387402374")
.setChargeDefaultPatronFee(true);
AcceptItemInitiationData initData = (AcceptItemInitiationData) acceptItem.generateNCIP2Object();
String toAgencyId = initData.getInitiationHeader().getToAgencyId().getAgencyId().getValue();
String itemId = initData.getItemId().getItemIdentifierValue();
assertEquals(toAgencyId,"ABC");
assertEquals(itemId,"ABC-2387402374");
assertEquals(Constants.CHARGE_DEFAULT_PATRON_FEE, initData.getFiscalTransactionInformation().getFiscalActionType().getValue());
}

@Test
public void testGenerateNcip2ObjectNoFee() {
AcceptItem acceptItem = new AcceptItem()
.setToAgency("ABC")
.setItemId("ABC-2387402374")
.setChargeDefaultPatronFee(false);
AcceptItemInitiationData initData = (AcceptItemInitiationData) acceptItem.generateNCIP2Object();
String toAgencyId = initData.getInitiationHeader().getToAgencyId().getAgencyId().getValue();
String itemId = initData.getItemId().getItemIdentifierValue();
assertEquals(toAgencyId,"ABC");
assertEquals(itemId,"ABC-2387402374");
assertNull(initData.getFiscalTransactionInformation());
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.olf.rs</groupId>
<version>0.23.16</version>
<version>0.23.17</version>
<artifactId>lib-ncip-client-proj</artifactId>
<packaging>pom</packaging>
<name>lib-ncip-client-proj</name>
Expand Down

0 comments on commit a86ec62

Please sign in to comment.