Skip to content

Commit

Permalink
PR-1861 Return user UUID and Fee UUID (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
JanisSaldabols authored Aug 5, 2024
1 parent 56f3914 commit f4e27e4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/main/java/org/folio/ncip/FolioRemoteServiceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f4e27e4

Please sign in to comment.