Skip to content

Commit

Permalink
MODTLR-75: Search Slips API (#85)
Browse files Browse the repository at this point in the history
* MODTLR-75 Search slips implementation and tests

* MODTLR-75 Unit test for search slips

* MODTLR-75 Remove redundant methods
  • Loading branch information
OleksandrVidinieiev authored Dec 6, 2024
1 parent fd1dfb9 commit dc1e787
Show file tree
Hide file tree
Showing 22 changed files with 1,685 additions and 1,002 deletions.
34 changes: 30 additions & 4 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
"users.collection.get",
"users.item.post",
"inventory-storage.service-points.item.get",
"inventory-storage.service-points.collection.get",
"inventory-storage.service-points.item.post"
"inventory-storage.service-points.collection.get"
]
},
{
Expand Down Expand Up @@ -123,7 +122,6 @@
"permissionsRequired": ["tlr.pick-slips.collection.get"],
"modulePermissions": [
"user-tenants.collection.get",
"search.instances.collection.get",
"circulation-storage.requests.item.get",
"circulation-storage.requests.collection.get",
"users.item.get",
Expand All @@ -135,7 +133,31 @@
"addresstypes.item.get",
"addresstypes.collection.get",
"inventory-storage.service-points.item.get",
"inventory-storage.service-points.collection.get"
"inventory-storage.service-points.collection.get",
"inventory-storage.instances.item.get",
"inventory-storage.instances.collection.get"
]
},
{
"methods": ["GET"],
"pathPattern": "/tlr/staff-slips/search-slips/{servicePointId}",
"permissionsRequired": ["tlr.search-slips.collection.get"],
"modulePermissions": [
"user-tenants.collection.get",
"circulation-storage.requests.item.get",
"circulation-storage.requests.collection.get",
"users.item.get",
"users.collection.get",
"usergroups.item.get",
"usergroups.collection.get",
"departments.item.get",
"departments.collection.get",
"addresstypes.item.get",
"addresstypes.collection.get",
"inventory-storage.service-points.item.get",
"inventory-storage.service-points.collection.get",
"inventory-storage.instances.item.get",
"inventory-storage.instances.collection.get"
]
}
]
Expand Down Expand Up @@ -244,6 +266,10 @@
"permissionName": "tlr.pick-slips.collection.get",
"displayName": "ecs-tlr - pick slips",
"description": "Get pick slips"
}, {
"permissionName": "tlr.search-slips.collection.get",
"displayName": "ecs-tlr - search slips",
"description": "Get search slips"
},
{
"permissionName": "tlr.ecs-request-external.post",
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/folio/client/feign/HoldingClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.folio.client.feign;

import org.folio.domain.dto.HoldingsRecord;
import org.folio.domain.dto.HoldingsRecords;
import org.folio.spring.config.FeignClientConfiguration;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@FeignClient(name = "holdings", url = "holdings-storage/holdings", configuration = FeignClientConfiguration.class)
public interface HoldingClient extends GetByQueryClient<HoldingsRecords> {

@GetMapping("/{id}")
HoldingsRecord get(@PathVariable String id);

}
3 changes: 2 additions & 1 deletion src/main/java/org/folio/client/feign/InstanceClient.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.folio.client.feign;

import org.folio.domain.dto.Instances;
import org.folio.domain.dto.InventoryInstance;
import org.folio.spring.config.FeignClientConfiguration;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@FeignClient(name = "instances", url = "instance-storage/instances", configuration = FeignClientConfiguration.class)
public interface InstanceClient {
public interface InstanceClient extends GetByQueryClient<Instances> {

@GetMapping("/{id}")
InventoryInstance get(@PathVariable String id);
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/org/folio/controller/StaffSlipsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import java.util.UUID;

import org.folio.domain.dto.PickSlipsResponse;
import org.folio.domain.dto.SearchSlipsResponse;
import org.folio.domain.dto.StaffSlip;
import org.folio.rest.resource.PickSlipsApi;
import org.folio.rest.resource.StaffSlipsApi;
import org.folio.service.impl.PickSlipsService;
import org.folio.service.impl.SearchSlipsService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import lombok.AllArgsConstructor;
Expand All @@ -17,9 +20,11 @@
@RestController
@Log4j2
@AllArgsConstructor
public class StaffSlipsController implements PickSlipsApi {
@RequestMapping("/tlr/staff-slips")
public class StaffSlipsController implements StaffSlipsApi {

private final PickSlipsService pickSlipsService;
private final SearchSlipsService searchSlipsService;

@Override
public ResponseEntity<PickSlipsResponse> getPickSlips(UUID servicePointId) {
Expand All @@ -30,4 +35,14 @@ public ResponseEntity<PickSlipsResponse> getPickSlips(UUID servicePointId) {
.pickSlips(new ArrayList<>(pickSlips))
.totalRecords(pickSlips.size()));
}

@Override
public ResponseEntity<SearchSlipsResponse> getSearchSlips(UUID servicePointId) {
log.info("getSearchSlips:: servicePointId={}", servicePointId);
Collection<StaffSlip> searchSlips = searchSlipsService.getStaffSlips(servicePointId.toString());

return ResponseEntity.ok(new SearchSlipsResponse()
.searchSlips(new ArrayList<>(searchSlips))
.totalRecords(searchSlips.size()));
}
}
6 changes: 5 additions & 1 deletion src/main/java/org/folio/service/InventoryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.Collection;

import org.folio.domain.dto.Campus;
import org.folio.domain.dto.HoldingsRecord;
import org.folio.domain.dto.Instance;
import org.folio.domain.dto.Institution;
import org.folio.domain.dto.Item;
import org.folio.domain.dto.Library;
Expand All @@ -12,7 +14,9 @@

public interface InventoryService {
Collection<Item> findItems(CqlQuery query, String idIndex, Collection<String> ids);
Collection<Item> findItems(Collection<String> ids);
Collection<HoldingsRecord> findHoldings(CqlQuery query, String idIndex, Collection<String> ids);
Collection<HoldingsRecord> findHoldings(Collection<String> ids);
Collection<Instance> findInstances(Collection<String> ids);
Collection<MaterialType> findMaterialTypes(Collection<String> ids);
Collection<LoanType> findLoanTypes(Collection<String> ids);
Collection<Library> findLibraries(Collection<String> ids);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/folio/service/RequestService.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ CirculationItem updateCirculationItemOnRequestCreation(CirculationItem circulati
Request getRequestFromStorage(String requestId, String tenantId);
Request getRequestFromStorage(String requestId);
Collection<Request> getRequestsFromStorage(CqlQuery query, String idIndex, Collection<String> ids);
Collection<Request> getRequestsFromStorage(CqlQuery query);
Request updateRequestInStorage(Request request, String tenantId);
List<Request> getRequestsQueueByInstanceId(String instanceId, String tenantId);
List<Request> getRequestsQueueByInstanceId(String instanceId);
Expand Down
59 changes: 33 additions & 26 deletions src/main/java/org/folio/service/impl/InventoryServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.Collection;

import org.folio.client.feign.HoldingClient;
import org.folio.client.feign.InstanceClient;
import org.folio.client.feign.ItemClient;
import org.folio.client.feign.LoanTypeClient;
import org.folio.client.feign.LocationCampusClient;
Expand All @@ -10,6 +12,10 @@
import org.folio.client.feign.MaterialTypeClient;
import org.folio.domain.dto.Campus;
import org.folio.domain.dto.Campuses;
import org.folio.domain.dto.HoldingsRecord;
import org.folio.domain.dto.HoldingsRecords;
import org.folio.domain.dto.Instance;
import org.folio.domain.dto.Instances;
import org.folio.domain.dto.Institution;
import org.folio.domain.dto.Institutions;
import org.folio.domain.dto.Item;
Expand All @@ -34,6 +40,8 @@
public class InventoryServiceImpl implements InventoryService {

private final ItemClient itemClient;
private final InstanceClient instanceClient;
private final HoldingClient holdingClient;
private final MaterialTypeClient materialTypeClient;
private final LoanTypeClient loanTypeClient;
private final LocationLibraryClient libraryClient;
Expand All @@ -45,65 +53,64 @@ public Collection<Item> findItems(CqlQuery query, String idIndex, Collection<Str
log.info("findItems:: searching items by query and index: query={}, index={}, ids={}",
query, idIndex, ids.size());
log.debug("findItems:: ids={}", ids);
Collection<Item> items = BulkFetcher.fetch(itemClient, query, idIndex, ids, Items::getItems);
log.info("findItems:: found {} items", items::size);
return items;
return BulkFetcher.fetch(itemClient, query, idIndex, ids, Items::getItems);
}

@Override
public Collection<Item> findItems(Collection<String> ids) {
log.info("findItems:: searching items by {} IDs", ids::size);
log.debug("findItems:: ids={}", ids);
Collection<Item> items = BulkFetcher.fetch(itemClient, ids, Items::getItems);
log.info("findItems:: found {} items", items::size);
return items;
public Collection<HoldingsRecord> findHoldings(CqlQuery query, String idIndex, Collection<String> ids) {
log.info("findHoldings:: searching holdings by query and index: query={}, index={}, ids={}",
query, idIndex, ids.size());
log.debug("findHoldings:: ids={}", ids);
return BulkFetcher.fetch(holdingClient, query, idIndex, ids, HoldingsRecords::getHoldingsRecords);
}

@Override
public Collection<HoldingsRecord> findHoldings(Collection<String> ids) {
log.info("findHoldings:: searching holdings by {} IDs", ids::size);
return BulkFetcher.fetch(holdingClient, ids, HoldingsRecords::getHoldingsRecords);
}


@Override
public Collection<Instance> findInstances(Collection<String> ids) {
log.info("findInstances:: searching instances by {} IDs", ids::size);
log.debug("findInstances:: ids={}", ids);
return BulkFetcher.fetch(instanceClient, ids, Instances::getInstances);
}

@Override
public Collection<MaterialType> findMaterialTypes(Collection<String> ids) {
log.info("findMaterialTypes:: searching material types by {} IDs", ids::size);
log.debug("findMaterialTypes:: ids={}", ids);
Collection<MaterialType> materialTypes = BulkFetcher.fetch(materialTypeClient, ids,
MaterialTypes::getMtypes);
log.info("findMaterialTypes:: found {} material types", materialTypes::size);
return materialTypes;
return BulkFetcher.fetch(materialTypeClient, ids, MaterialTypes::getMtypes);
}

@Override
public Collection<LoanType> findLoanTypes(Collection<String> ids) {
log.info("findLoanTypes:: searching loan types by {} IDs", ids::size);
log.debug("findLoanTypes:: ids={}", ids);
Collection<LoanType> loanTypes = BulkFetcher.fetch(loanTypeClient, ids, LoanTypes::getLoantypes);
log.info("findLoanTypes:: found {} loan types", loanTypes::size);
return loanTypes;
return BulkFetcher.fetch(loanTypeClient, ids, LoanTypes::getLoantypes);
}

@Override
public Collection<Library> findLibraries(Collection<String> ids) {
log.info("findLibraries:: searching libraries by {} IDs", ids::size);
log.debug("findLibraries:: ids={}", ids);
Collection<Library> libraries = BulkFetcher.fetch(libraryClient, ids, Libraries::getLoclibs);
log.info("findLibraries:: found {} libraries", libraries::size);
return libraries;
return BulkFetcher.fetch(libraryClient, ids, Libraries::getLoclibs);
}

@Override
public Collection<Campus> findCampuses(Collection<String> ids) {
log.info("findCampuses:: searching campuses by {} IDs", ids::size);
log.debug("findCampuses:: ids={}", ids);
Collection<Campus> campuses = BulkFetcher.fetch(campusClient, ids, Campuses::getLoccamps);
log.info("findCampuses:: found {} campuses", campuses::size);
return campuses;
return BulkFetcher.fetch(campusClient, ids, Campuses::getLoccamps);
}

@Override
public Collection<Institution> findInstitutions(Collection<String> ids) {
log.info("findInstitutions:: searching institutions by {} IDs", ids::size);
log.debug("findInstitutions:: ids={}", ids);
Collection<Institution> institutions = BulkFetcher.fetch(institutionClient, ids,
Institutions::getLocinsts);
log.info("findInstitutions:: found {} institutions", institutions::size);
return institutions;
return BulkFetcher.fetch(institutionClient, ids, Institutions::getLocinsts);
}

}
6 changes: 2 additions & 4 deletions src/main/java/org/folio/service/impl/PickSlipsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.folio.service.InventoryService;
import org.folio.service.LocationService;
import org.folio.service.RequestService;
import org.folio.service.SearchService;
import org.folio.service.ServicePointService;
import org.folio.service.UserGroupService;
import org.folio.service.UserService;
Expand All @@ -31,11 +30,10 @@ public PickSlipsService(LocationService locationService, InventoryService invent
RequestService requestService, ConsortiaService consortiaService,
SystemUserScopedExecutionService executionService, UserService userService,
UserGroupService userGroupService, DepartmentService departmentService,
AddressTypeService addressTypeService, SearchService searchService,
ServicePointService servicePointService) {
AddressTypeService addressTypeService, ServicePointService servicePointService) {

super(EnumSet.of(PAGED), EnumSet.of(OPEN_NOT_YET_FILLED), EnumSet.of(PAGE), locationService,
inventoryService, requestService, consortiaService, executionService, userService,
userGroupService, departmentService, addressTypeService, searchService, servicePointService);
userGroupService, departmentService, addressTypeService, servicePointService);
}
}
9 changes: 6 additions & 3 deletions src/main/java/org/folio/service/impl/RequestServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,13 @@ public Collection<Request> getRequestsFromStorage(CqlQuery query, String idIndex
log.info("getRequestsFromStorage:: searching requests by query and index: query={}, index={}, ids={}",
query, idIndex, ids.size());
log.debug("getRequestsFromStorage:: ids={}", ids);
return BulkFetcher.fetch(requestStorageClient, query, idIndex, ids, Requests::getRequests);
}

Collection<Request> requests = BulkFetcher.fetch(requestStorageClient, query, idIndex, ids,
Requests::getRequests);

@Override
public Collection<Request> getRequestsFromStorage(CqlQuery query) {
log.info("getRequestsFromStorage:: searching requests by query: {}", query);
Collection<Request> requests = requestStorageClient.getByQuery(query).getRequests();
log.info("getRequestsFromStorage:: found {} requests", requests::size);
return requests;
}
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/org/folio/service/impl/SearchSlipsService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.folio.service.impl;

import static org.folio.domain.dto.ItemStatus.NameEnum.AWAITING_DELIVERY;
import static org.folio.domain.dto.ItemStatus.NameEnum.CHECKED_OUT;
import static org.folio.domain.dto.ItemStatus.NameEnum.IN_PROCESS;
import static org.folio.domain.dto.ItemStatus.NameEnum.IN_TRANSIT;
import static org.folio.domain.dto.ItemStatus.NameEnum.MISSING;
import static org.folio.domain.dto.ItemStatus.NameEnum.ON_ORDER;
import static org.folio.domain.dto.ItemStatus.NameEnum.PAGED;
import static org.folio.domain.dto.ItemStatus.NameEnum.RESTRICTED;
import static org.folio.domain.dto.Request.RequestTypeEnum.HOLD;
import static org.folio.domain.dto.Request.StatusEnum.OPEN_NOT_YET_FILLED;

import java.util.EnumSet;

import org.folio.domain.dto.ItemStatus;
import org.folio.service.AddressTypeService;
import org.folio.service.ConsortiaService;
import org.folio.service.DepartmentService;
import org.folio.service.InventoryService;
import org.folio.service.LocationService;
import org.folio.service.RequestService;
import org.folio.service.ServicePointService;
import org.folio.service.UserGroupService;
import org.folio.service.UserService;
import org.folio.spring.service.SystemUserScopedExecutionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import lombok.extern.log4j.Log4j2;

@Service
@Log4j2
public class SearchSlipsService extends StaffSlipsServiceImpl {

private static final EnumSet<ItemStatus.NameEnum> ITEM_STATUSES = EnumSet.of(
CHECKED_OUT, AWAITING_DELIVERY, IN_TRANSIT, MISSING, PAGED, ON_ORDER, IN_PROCESS, RESTRICTED);

@Autowired
public SearchSlipsService(LocationService locationService, InventoryService inventoryService,
RequestService requestService, ConsortiaService consortiaService,
SystemUserScopedExecutionService executionService, UserService userService,
UserGroupService userGroupService, DepartmentService departmentService,
AddressTypeService addressTypeService, ServicePointService servicePointService) {

super(ITEM_STATUSES, EnumSet.of(OPEN_NOT_YET_FILLED), EnumSet.of(HOLD), locationService,
inventoryService, requestService, consortiaService, executionService, userService,
userGroupService, departmentService, addressTypeService, servicePointService);
}
}
Loading

0 comments on commit dc1e787

Please sign in to comment.