-
Notifications
You must be signed in to change notification settings - Fork 1
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
imerabishvili
wants to merge
6
commits into
master
Choose a base branch
from
MCBFF-38
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
131db36
MCBFF-38: Update hardcoded effective location during checkin
imerabishvili ae4a787
MCBFF-38: fix search query
imerabishvili c70dcf4
MCBFF-38: removed empty lines, added permissions, fixed duplicate log…
imerabishvili 0e725cd
MCBFF-38: given-when-then comments removed
imerabishvili a3daf0d
MCBFF-38: try to fix allowed SPs
imerabishvili 0d9bd39
MCBFF-38 Refactor allowed SP logic
alexanderkurash File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 9 additions & 0 deletions
9
src/main/java/org/folio/circulationbff/service/InventoryService.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,9 @@ | ||
package org.folio.circulationbff.service; | ||
|
||
import org.folio.circulationbff.domain.dto.Item; | ||
import org.folio.circulationbff.domain.dto.ServicePoint; | ||
|
||
public interface InventoryService { | ||
Item fetchItem(String id); | ||
ServicePoint fetchServicePoint(String id); | ||
} |
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
1 change: 1 addition & 0 deletions
1
src/main/java/org/folio/circulationbff/service/UserTenantsService.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
58 changes: 54 additions & 4 deletions
58
src/main/java/org/folio/circulationbff/service/impl/CheckInServiceImpl.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 |
---|---|---|
@@ -1,26 +1,76 @@ | ||
package org.folio.circulationbff.service.impl; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.folio.circulationbff.client.feign.CheckInClient; | ||
import org.folio.circulationbff.domain.dto.CheckInRequest; | ||
import org.folio.circulationbff.domain.dto.CheckInResponse; | ||
import org.folio.circulationbff.domain.dto.SearchItem; | ||
import org.folio.circulationbff.service.CheckInService; | ||
import org.folio.circulationbff.service.InventoryService; | ||
import org.folio.circulationbff.service.SearchService; | ||
import org.folio.circulationbff.service.UserTenantsService; | ||
import org.folio.spring.service.SystemUserScopedExecutionService; | ||
import org.springframework.stereotype.Service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.log4j.Log4j2; | ||
import java.util.Objects; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Log4j2 | ||
public class CheckInServiceImpl implements CheckInService { | ||
|
||
private final CheckInClient checkInClient; | ||
private final SearchService searchService; | ||
private final UserTenantsService userTenantsService; | ||
private final InventoryService inventoryService; | ||
private final SystemUserScopedExecutionService executionService; | ||
|
||
@Override | ||
public CheckInResponse checkIn(CheckInRequest request) { | ||
log.info("checkIn: checking in item with barcode {} on service point {}", | ||
request::getItemBarcode, request::getServicePointId); | ||
return checkInClient.checkIn(request); | ||
request.getItemBarcode(), request.getServicePointId()); | ||
var response = checkInClient.checkIn(request); | ||
var item = response.getItem(); | ||
var servicePointName = getEffectiveLocationServicePoint(item.getId()); | ||
if (servicePointName != null) { | ||
var slipContextItem = response.getStaffSlipContext().getItem(); | ||
slipContextItem.setEffectiveLocationPrimaryServicePointName(servicePointName); | ||
slipContextItem.toServicePoint(servicePointName); | ||
} | ||
return response; | ||
} | ||
|
||
private String getEffectiveLocationServicePoint(String itemId) { | ||
log.info("getEffectiveLocationServicePoint: itemId {}", itemId); | ||
var instance = searchService.findInstanceByItemId(itemId); | ||
if (instance == null) { | ||
log.warn("getEffectiveLocationServicePoint: instance not found"); | ||
return null; | ||
} | ||
var itemTenantId = instance.getItems() | ||
.stream() | ||
.filter(item -> item.getId().equals(itemId)) | ||
.findFirst() | ||
.map(SearchItem::getTenantId) | ||
.orElse(null); | ||
if (Objects.equals(itemTenantId, userTenantsService.getCurrentTenant())) { | ||
log.info("getEffectiveLocationServicePoint: same tenant case {}", itemTenantId); | ||
var item = inventoryService.fetchItem(itemId); | ||
var servicePoint = inventoryService.fetchServicePoint(item.getEffectiveLocationId()); | ||
return servicePoint.getName(); | ||
} else { | ||
log.info("getEffectiveLocationServicePoint: cross tenant case {}", itemTenantId); | ||
var item = executionService.executeSystemUserScoped( | ||
itemTenantId, | ||
() -> inventoryService.fetchItem(itemId) | ||
); | ||
var servicePoint = executionService.executeSystemUserScoped( | ||
itemTenantId, | ||
() -> inventoryService.fetchServicePoint(item.getEffectiveLocationId()) | ||
); | ||
return servicePoint.getName(); | ||
} | ||
} | ||
|
||
} |
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
30 changes: 30 additions & 0 deletions
30
src/main/java/org/folio/circulationbff/service/impl/InventoryServiceImpl.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,30 @@ | ||
package org.folio.circulationbff.service.impl; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.folio.circulationbff.client.feign.ItemStorageClient; | ||
import org.folio.circulationbff.client.feign.ServicePointClient; | ||
import org.folio.circulationbff.domain.dto.Item; | ||
import org.folio.circulationbff.domain.dto.ServicePoint; | ||
import org.folio.circulationbff.service.InventoryService; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Log4j2 | ||
public class InventoryServiceImpl implements InventoryService { | ||
private final ItemStorageClient itemClient; | ||
private final ServicePointClient servicePointClient; | ||
|
||
@Override | ||
public Item fetchItem(String id) { | ||
log.info("fetchItem:: fetching item {}", id); | ||
return itemClient.findItem(id); | ||
} | ||
|
||
@Override | ||
public ServicePoint fetchServicePoint(String id) { | ||
log.info("fetchServicePoint:: fetching service point {}", id); | ||
return servicePointClient.findServicePoint(id); | ||
} | ||
} |
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 | ||||
---|---|---|---|---|---|---|
|
@@ -14,6 +14,7 @@ | |||||
import java.util.function.Function; | ||||||
import java.util.stream.Collectors; | ||||||
|
||||||
import org.apache.commons.collections4.CollectionUtils; | ||||||
import org.apache.commons.lang3.StringUtils; | ||||||
import org.folio.circulationbff.client.feign.HoldingsStorageClient; | ||||||
import org.folio.circulationbff.client.feign.InstanceStorageClient; | ||||||
|
@@ -71,6 +72,17 @@ public class SearchServiceImpl implements SearchService { | |||||
private final BulkFetchingService fetchingService; | ||||||
private final SearchInstanceMapper searchInstanceMapper; | ||||||
|
||||||
@Override | ||||||
public SearchInstance findInstanceByItemId(String itemId) { | ||||||
log.info("findInstanceByItemId:: itemId {}", itemId); | ||||||
String query = "items.id==" + itemId; | ||||||
SearchInstances searchResult = searchClient.findInstances(query, true); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||||||
if (CollectionUtils.isEmpty(searchResult.getInstances())) { | ||||||
return null; | ||||||
} | ||||||
return searchResult.getInstances().get(0); | ||||||
} | ||||||
|
||||||
@Override | ||||||
public Collection<BffSearchInstance> findInstances(String query) { | ||||||
log.info("findInstances:: searching instances by query: {}", query); | ||||||
|
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
?There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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