forked from folio-org/mod-ncip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from indexdata/PR-1861
PR-1861 Implement CreateUserFiscalTransaction for charging fees
- Loading branch information
Showing
12 changed files
with
195 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/org/folio/ncip/services/CreateUserFiscalTransactionService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.folio.ncip.services; | ||
|
||
import org.extensiblecatalog.ncip.v2.service.CreateUserFiscalTransactionInitiationData; | ||
import org.extensiblecatalog.ncip.v2.service.CreateUserFiscalTransactionResponseData; | ||
import org.extensiblecatalog.ncip.v2.service.NCIPService; | ||
import org.extensiblecatalog.ncip.v2.service.RemoteServiceManager; | ||
import org.extensiblecatalog.ncip.v2.service.ServiceContext; | ||
import org.extensiblecatalog.ncip.v2.service.ServiceException; | ||
import org.extensiblecatalog.ncip.v2.service.ValidationException; | ||
|
||
public interface CreateUserFiscalTransactionService extends NCIPService<CreateUserFiscalTransactionInitiationData, CreateUserFiscalTransactionResponseData> { | ||
CreateUserFiscalTransactionResponseData performService(CreateUserFiscalTransactionInitiationData initData, ServiceContext serviceContext, RemoteServiceManager remoteServiceManager) throws ServiceException, ValidationException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/org/folio/ncip/services/FolioCreateUserFiscalTransactionService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.folio.ncip.services; | ||
|
||
import org.apache.log4j.Logger; | ||
import org.extensiblecatalog.ncip.v2.service.CreateUserFiscalTransactionInitiationData; | ||
import org.extensiblecatalog.ncip.v2.service.CreateUserFiscalTransactionResponseData; | ||
import org.extensiblecatalog.ncip.v2.service.Problem; | ||
import org.extensiblecatalog.ncip.v2.service.ProblemType; | ||
import org.extensiblecatalog.ncip.v2.service.RemoteServiceManager; | ||
import org.extensiblecatalog.ncip.v2.service.ServiceContext; | ||
import org.extensiblecatalog.ncip.v2.service.ServiceException; | ||
import org.extensiblecatalog.ncip.v2.service.UserId; | ||
import org.extensiblecatalog.ncip.v2.service.ValidationException; | ||
import org.folio.ncip.Constants; | ||
import org.folio.ncip.FolioRemoteServiceManager; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class FolioCreateUserFiscalTransactionService extends FolioNcipService implements CreateUserFiscalTransactionService { | ||
private static final Logger LOGGER = Logger.getLogger(FolioCreateUserFiscalTransactionService.class); | ||
|
||
@Override | ||
public CreateUserFiscalTransactionResponseData performService(CreateUserFiscalTransactionInitiationData initData, ServiceContext serviceContext, RemoteServiceManager remoteServiceManager) throws ServiceException, ValidationException { | ||
CreateUserFiscalTransactionResponseData responseData = new CreateUserFiscalTransactionResponseData(); | ||
UserId userId = initData.getUserId(); | ||
try { | ||
validateUserId(userId); | ||
initData.getFiscalTransactionInformation().getFiscalActionType(); | ||
} catch (Exception exception) { | ||
Problem problem = new Problem(new ProblemType(Constants.CREATE_USER_FISCAL_TRANSACTION_PROBLEM), Constants.CREATE_USER_FISCAL_TRANSACTION_PROBLEM, | ||
exception.getMessage()); | ||
LOGGER.error("Request validation failed"); | ||
return addProblem(responseData, problem); | ||
} | ||
|
||
try { | ||
((FolioRemoteServiceManager)remoteServiceManager).createUserFiscalTransaction(userId, initData.getFiscalTransactionInformation()); | ||
} catch(Exception e) { | ||
Problem problem = new Problem(new ProblemType(Constants.CREATE_USER_FISCAL_TRANSACTION_PROBLEM), Constants.UNKNOWN_DATA_ELEMENT, | ||
Constants.CREATE_USER_FISCAL_TRANSACTION_PROBLEM, e.getMessage()); | ||
return addProblem(responseData, problem); | ||
} | ||
responseData.setUserId(userId); | ||
return responseData; | ||
} | ||
|
||
private CreateUserFiscalTransactionResponseData addProblem(CreateUserFiscalTransactionResponseData responseData, Problem problem){ | ||
if (responseData.getProblems() == null) { | ||
responseData.setProblems(new ArrayList<>()); | ||
} | ||
responseData.getProblems().add(problem); | ||
return responseData; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/test/java/org/folio/ncip/CreateUserFiscalTransaction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.folio.ncip; | ||
|
||
import io.restassured.response.Response; | ||
import org.junit.Test; | ||
|
||
import java.net.MalformedURLException; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class CreateUserFiscalTransaction extends TestBase { | ||
|
||
private static final String USER_ID = "8377631"; | ||
private static final String PROBLEM = "Problem"; | ||
|
||
@Test | ||
public void callCreateUserFiscalTransaction() throws MalformedURLException { | ||
Response response = postData("src/test/resources/mockdata/ncip-createUserFiscalTransaction.xml"); | ||
String body = response.getBody().prettyPrint(); | ||
assertEquals(200, response.getStatusCode()); | ||
assertTrue(body.contains(USER_ID)); | ||
} | ||
|
||
@Test | ||
public void callCreateUserFiscalTransactionNoTransaction() throws MalformedURLException { | ||
Response response = postData("src/test/resources/mockdata/ncip-createUserFiscalTransactionNoTrans.xml"); | ||
String body = response.getBody().prettyPrint(); | ||
assertEquals(200, response.getStatusCode()); | ||
assertTrue(body.contains(PROBLEM)); | ||
} | ||
|
||
@Test | ||
public void callCreateUserFiscalTransactionBlocked() throws MalformedURLException { | ||
Response response = postData("src/test/resources/mockdata/ncip-createUserFiscalTransactionBlocked.xml"); | ||
String body = response.getBody().prettyPrint(); | ||
assertEquals(200, response.getStatusCode()); | ||
assertTrue(body.contains(PROBLEM)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/test/resources/mockdata/ncip-createUserFiscalTransaction.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<ns1:NCIPMessage xmlns:ns1="http://www.niso.org/2008/ncip" ns1:version="http://www.niso.org/schemas/ncip/v2_0/imp1/xsd/ncip_v2_0.xsd"> | ||
<ns1:CreateUserFiscalTransaction> | ||
<ns1:InitiationHeader> | ||
<ns1:FromAgencyId> | ||
<ns1:AgencyId>Relais</ns1:AgencyId> | ||
</ns1:FromAgencyId> | ||
<ns1:ToAgencyId> | ||
<ns1:AgencyId>Lehigh University</ns1:AgencyId> | ||
</ns1:ToAgencyId> | ||
</ns1:InitiationHeader> | ||
<ns1:UserId> | ||
<ns1:AgencyId>LEH</ns1:AgencyId> | ||
<ns1:UserIdentifierValue>8377631</ns1:UserIdentifierValue> | ||
</ns1:UserId> | ||
<ns1:FiscalTransactionInformation> | ||
<ns1:FiscalActionType>charge-default-patron-fee</ns1:FiscalActionType> | ||
<ns1:FiscalTransactionType>ILL-fee</ns1:FiscalTransactionType> | ||
<ns1:Amount> | ||
<ns1:MonetaryValue>0</ns1:MonetaryValue> | ||
</ns1:Amount> | ||
</ns1:FiscalTransactionInformation> | ||
</ns1:CreateUserFiscalTransaction> | ||
</ns1:NCIPMessage> |
24 changes: 24 additions & 0 deletions
24
src/test/resources/mockdata/ncip-createUserFiscalTransactionBlocked.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<ns1:NCIPMessage xmlns:ns1="http://www.niso.org/2008/ncip" ns1:version="http://www.niso.org/schemas/ncip/v2_0/imp1/xsd/ncip_v2_0.xsd"> | ||
<ns1:CreateUserFiscalTransaction> | ||
<ns1:InitiationHeader> | ||
<ns1:FromAgencyId> | ||
<ns1:AgencyId>Relais</ns1:AgencyId> | ||
</ns1:FromAgencyId> | ||
<ns1:ToAgencyId> | ||
<ns1:AgencyId>Lehigh University</ns1:AgencyId> | ||
</ns1:ToAgencyId> | ||
</ns1:InitiationHeader> | ||
<ns1:UserId> | ||
<ns1:AgencyId>LEH</ns1:AgencyId> | ||
<ns1:UserIdentifierValue>5551213</ns1:UserIdentifierValue> | ||
</ns1:UserId> | ||
<ns1:FiscalTransactionInformation> | ||
<ns1:FiscalActionType>charge-default-patron-fee</ns1:FiscalActionType> | ||
<ns1:FiscalTransactionType>ILL-fee</ns1:FiscalTransactionType> | ||
<ns1:Amount> | ||
<ns1:MonetaryValue>0</ns1:MonetaryValue> | ||
</ns1:Amount> | ||
</ns1:FiscalTransactionInformation> | ||
</ns1:CreateUserFiscalTransaction> | ||
</ns1:NCIPMessage> |
17 changes: 17 additions & 0 deletions
17
src/test/resources/mockdata/ncip-createUserFiscalTransactionNoTrans.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<ns1:NCIPMessage xmlns:ns1="http://www.niso.org/2008/ncip" ns1:version="http://www.niso.org/schemas/ncip/v2_0/imp1/xsd/ncip_v2_0.xsd"> | ||
<ns1:CreateUserFiscalTransaction> | ||
<ns1:InitiationHeader> | ||
<ns1:FromAgencyId> | ||
<ns1:AgencyId>Relais</ns1:AgencyId> | ||
</ns1:FromAgencyId> | ||
<ns1:ToAgencyId> | ||
<ns1:AgencyId>Lehigh University</ns1:AgencyId> | ||
</ns1:ToAgencyId> | ||
</ns1:InitiationHeader> | ||
<ns1:UserId> | ||
<ns1:AgencyId>LEH</ns1:AgencyId> | ||
<ns1:UserIdentifierValue>8377631</ns1:UserIdentifierValue> | ||
</ns1:UserId> | ||
</ns1:CreateUserFiscalTransaction> | ||
</ns1:NCIPMessage> |