Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MCBFF-38: Update hardcoded effective location during checkin #47

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

imerabishvili
Copy link
Contributor

Purpose

https://folio-org.atlassian.net/browse/MCBFF-38

Approach

Obtain proper effective location based on item's effectiveLocationId and tenant and update required fields in response.

TODOS and Open Questions

Learning

Comment on lines 85 to 99
var request = new CheckInRequest()
.itemBarcode("test_barcode")
.checkInDate(new Date())
.servicePointId(randomUUID());

givenCirculationCheckinSucceed(request);

var checkinItem = new Item()
.id("itemId")
.copyNumber("copyNumber")
.effectiveLocationId( "effectiveLocationId");

givenSearchInstanceReturnsItem(TENANT_ID_COLLEGE, checkinItem);

givenCurrentTenantIsConsortium();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var request = new CheckInRequest()
.itemBarcode("test_barcode")
.checkInDate(new Date())
.servicePointId(randomUUID());
givenCirculationCheckinSucceed(request);
var checkinItem = new Item()
.id("itemId")
.copyNumber("copyNumber")
.effectiveLocationId( "effectiveLocationId");
givenSearchInstanceReturnsItem(TENANT_ID_COLLEGE, checkinItem);
givenCurrentTenantIsConsortium();
var request = new CheckInRequest()
.itemBarcode("test_barcode")
.checkInDate(new Date())
.servicePointId(randomUUID());
givenCirculationCheckinSucceed(request);
var checkinItem = new Item()
.id("itemId")
.copyNumber("copyNumber")
.effectiveLocationId( "effectiveLocationId");
givenSearchInstanceReturnsItem(TENANT_ID_COLLEGE, checkinItem);
givenCurrentTenantIsConsortium();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't empty lines OK? I see them in other places and in my opinion they are improving readability.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They enhance readability by splitting certain logic blocks of code, but I don't think it’s necessary to place them after every line...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines 127 to 137
var request = new CheckInRequest()
.itemBarcode("test_barcode")
.checkInDate(new Date())
.servicePointId(randomUUID());

givenCirculationCheckinSucceed(request);

var searchResponse = new SearchInstances().instances(List.of());
wireMockServer.stubFor(WireMock.get(urlMatching("/search/instances.*"))
.willReturn(jsonResponse(searchResponse, SC_OK)));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var request = new CheckInRequest()
.itemBarcode("test_barcode")
.checkInDate(new Date())
.servicePointId(randomUUID());
givenCirculationCheckinSucceed(request);
var searchResponse = new SearchInstances().instances(List.of());
wireMockServer.stubFor(WireMock.get(urlMatching("/search/instances.*"))
.willReturn(jsonResponse(searchResponse, SC_OK)));
var request = new CheckInRequest()
.itemBarcode("test_barcode")
.checkInDate(new Date())
.servicePointId(randomUUID());
givenCirculationCheckinSucceed(request);
var searchResponse = new SearchInstances().instances(List.of());
wireMockServer.stubFor(WireMock.get(urlMatching("/search/instances.*"))
.willReturn(jsonResponse(searchResponse, SC_OK)));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

log.info("getEffectiveLocationServicePoint: itemId {}", itemId);
var instance = searchService.findInstanceByItemId(itemId);
if (instance == null) {
log.info("getEffectiveLocationServicePoint: instance not found");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.info("getEffectiveLocationServicePoint: instance not found");
log.warn("getEffectiveLocationServicePoint: instance not found");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

public SearchInstance findInstanceByItemId(String itemId) {
log.info("findInstanceByItemId:: itemId {}", itemId);
String query = String.format("items.id==%s&expandAll=true", itemId);
SearchInstances searchResult = searchClient.findInstances(query, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SearchInstances searchResult = searchClient.findInstances(query, true);
SearchInstances searchInstances = searchClient.findInstances(query, true);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@@ -150,7 +150,11 @@
"circulation-bff.loans.check-in-by-barcode.execute"
],
"modulePermissions": [
"circulation.check-in-by-barcode.post"
"circulation.check-in-by-barcode.post",
"user-tenants.collection.get",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add the same for item

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need user-tenants.item.get?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a rule that if we add a permission for an item, we need to add a similar one for the collection, and vice versa

Copy link
Contributor Author

@imerabishvili imerabishvili Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could not find user-tenants.item.get anywhere in folio-org. Does it exists?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, it exists only for consortia.user-tenants.item.get, so ignore it then

Comment on lines 156 to 157
"inventory-storage.items.item.get",
"inventory-storage.service-points.item.get"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add the same permissions for collections

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

public String getCurrentTenant() {
UserTenant firstUserTenant = getFirstUserTenant();
if (firstUserTenant == null) {
log.info("getCurrentTenant:: failed to fetch user tenants");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.info("getCurrentTenant:: failed to fetch user tenants");
log.warn("getCurrentTenant:: failed to fetch user tenants");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. But then we need to change this for similar lines in this file right?

Copy link
Contributor

@roman-barannyk roman-barannyk Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that the absence of the first user-tenant is unexpected behavior, and should be logged with warning level. This approach should be applied to all similar cases

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed duplicate logging in the class

Comment on lines +56 to +57
when(searchClient.findInstances(query, true))
.thenReturn(mockSearchResponse);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
when(searchClient.findInstances(query, true))
.thenReturn(mockSearchResponse);
when(searchClient.findInstances(query, true)).thenReturn(mockSearchResponse);

Comment on lines +59 to +60
SearchInstance response = searchService.findInstanceByItemId(itemId);
assertEquals(response, instance);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SearchInstance response = searchService.findInstanceByItemId(itemId);
assertEquals(response, instance);
assertEquals(searchService.findInstanceByItemId(itemId), instance);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants