From f768ae90e9ea9c0f43ae9db85ed1674b0932033c Mon Sep 17 00:00:00 2001 From: Janis Saldabols Date: Mon, 5 Aug 2024 14:07:35 +0300 Subject: [PATCH] PR-1861 Return user UUID and Fee UUID --- .../folio/ncip/FolioRemoteServiceManager.java | 10 ++++++---- ...olioCreateUserFiscalTransactionService.java | 18 +++++++++++++++--- .../ncip/CreateUserFiscalTransaction.java | 4 +++- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/folio/ncip/FolioRemoteServiceManager.java b/src/main/java/org/folio/ncip/FolioRemoteServiceManager.java index 4ad6ca7..b5b9193 100644 --- a/src/main/java/org/folio/ncip/FolioRemoteServiceManager.java +++ b/src/main/java/org/folio/ncip/FolioRemoteServiceManager.java @@ -576,7 +576,8 @@ public JsonObject acceptItem(AcceptItemInitiationData initData, UserId userId, S return returnValues; } - protected void addDefaultPatronFee(FiscalTransactionInformation fiscalTransactionInformation, String userId, String patronGroupId, String baseUrl) throws Exception { + protected JsonObject addDefaultPatronFee(FiscalTransactionInformation fiscalTransactionInformation, String userId, String patronGroupId, String baseUrl) throws Exception { + JsonObject result = new JsonObject(); if (fiscalTransactionInformation != null && fiscalTransactionInformation.getFiscalActionType() != null && Constants.CHARGE_DEFAULT_PATRON_FEE.equalsIgnoreCase(fiscalTransactionInformation.getFiscalActionType().getValue())) { try { @@ -612,12 +613,13 @@ protected void addDefaultPatronFee(FiscalTransactionInformation fiscalTransactio charge.put("feeFineOwner", ownersArray.getJsonObject(0).getString("owner")); charge.put("userId", userId); charge.put("id", UUID.randomUUID().toString()); - callApiPost(baseUrl + Constants.ACCOUNT_URL, charge); + return new JsonObject(callApiPost(baseUrl + Constants.ACCOUNT_URL, charge)); } catch (Exception e) { logger.error("Failed to add default patron fee", e); throw e; } } + return result; } private void deleteItemAndRelatedRecords(String baseUrl, String instanceUuid, String holdingsUuid, String itemUuid){ @@ -1087,11 +1089,11 @@ public void deleteItem(String itemId, String agencyId) throws Exception { } } - public void createUserFiscalTransaction(UserId userId, FiscalTransactionInformation fiscalTransactionInformation) throws Exception { + public JsonObject createUserFiscalTransaction(UserId userId, FiscalTransactionInformation fiscalTransactionInformation) throws Exception { try { String baseUrl = okapiHeaders.get(Constants.X_OKAPI_URL); JsonObject user = lookupPatronRecord(userId); - addDefaultPatronFee(fiscalTransactionInformation, user.getString("id"), user.getString(Constants.PATRON_GROUP), baseUrl); + return addDefaultPatronFee(fiscalTransactionInformation, user.getString("id"), user.getString(Constants.PATRON_GROUP), baseUrl); } catch (Exception exception) { logger.error("Exception occurred during CreateUserFiscalTransaction"); throw exception; diff --git a/src/main/java/org/folio/ncip/services/FolioCreateUserFiscalTransactionService.java b/src/main/java/org/folio/ncip/services/FolioCreateUserFiscalTransactionService.java index 06416e4..0d8dd94 100644 --- a/src/main/java/org/folio/ncip/services/FolioCreateUserFiscalTransactionService.java +++ b/src/main/java/org/folio/ncip/services/FolioCreateUserFiscalTransactionService.java @@ -1,19 +1,24 @@ package org.folio.ncip.services; +import io.vertx.core.json.JsonObject; 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.FiscalTransactionReferenceId; 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.UserIdentifierType; +import org.extensiblecatalog.ncip.v2.service.UserOptionalFields; import org.extensiblecatalog.ncip.v2.service.ValidationException; import org.folio.ncip.Constants; import org.folio.ncip.FolioRemoteServiceManager; import java.util.ArrayList; +import java.util.List; public class FolioCreateUserFiscalTransactionService extends FolioNcipService implements CreateUserFiscalTransactionService { private static final Logger LOGGER = Logger.getLogger(FolioCreateUserFiscalTransactionService.class); @@ -31,15 +36,22 @@ public CreateUserFiscalTransactionResponseData performService(CreateUserFiscalTr LOGGER.error("Request validation failed"); return addProblem(responseData, problem); } - try { - ((FolioRemoteServiceManager)remoteServiceManager).createUserFiscalTransaction(userId, initData.getFiscalTransactionInformation()); + JsonObject result = ((FolioRemoteServiceManager)remoteServiceManager).createUserFiscalTransaction(userId, initData.getFiscalTransactionInformation()); + + UserId userUuid = new UserId(); + userUuid.setUserIdentifierType(new UserIdentifierType(Constants.SCHEME,"uuid")); + userUuid.setUserIdentifierValue(result.getString("userId")); + responseData.setUserId(userUuid); + + FiscalTransactionReferenceId fiscalTransactionReferenceId = new FiscalTransactionReferenceId(); + fiscalTransactionReferenceId.setFiscalTransactionIdentifierValue(result.getString("id")); + responseData.setFiscalTransactionReferenceId(fiscalTransactionReferenceId); } 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; } diff --git a/src/test/java/org/folio/ncip/CreateUserFiscalTransaction.java b/src/test/java/org/folio/ncip/CreateUserFiscalTransaction.java index 8b356e8..3979749 100644 --- a/src/test/java/org/folio/ncip/CreateUserFiscalTransaction.java +++ b/src/test/java/org/folio/ncip/CreateUserFiscalTransaction.java @@ -10,7 +10,8 @@ public class CreateUserFiscalTransaction extends TestBase { - private static final String USER_ID = "8377631"; + private static final String USER_ID = "d4a845bd-a326-4916-9cb4-6a5ac1a86155"; + private static final String FEE_ID = "628e0831-30b0-415f-8b21-944950624926"; private static final String PROBLEM = "Problem"; @Test @@ -19,6 +20,7 @@ public void callCreateUserFiscalTransaction() throws MalformedURLException { String body = response.getBody().prettyPrint(); assertEquals(200, response.getStatusCode()); assertTrue(body.contains(USER_ID)); + assertTrue(body.contains(FEE_ID)); } @Test