Skip to content

Commit

Permalink
MODTLR-58: Pick Slips API (part 1) (#69)
Browse files Browse the repository at this point in the history
* MODTLR-58 Declare new interface in ModuleDescriptor-template.json

* MODTLR-59 Create YAML for new API

* MODTLR-59 Add servicePointId parameter to YAML

* MODTLR-58 Implementation and tests

* MODTLR-58 Remove MockMvc

* MODTLR-58 Refactoring

* MODTLR-58 Extend API test

* MODTLR-58 Remove Stream#peek

* MODTLR-58 Tests for CqlQuery

* MODTLR-58 Tests for CqlQuery

* MODTLR-58 Make BulkFetcher a utility class

* MODTLR-58 Make BulkFetcher a utility class

* MODTLR-58 Fix URL in ModuleDescriptor-template.json

* MODTLR-58 Move permissions from module descriptor to system user

* MODTLR-58 Fix permission names

* MODTLR-58 Add comment for copy number fallback

* MODTLR-58 Improve logging

* MODTLR-58 Improve logging

* MODTLR-58 Remove staff-slips-response.json

---------

Co-authored-by: Alexander Kurash <[email protected]>
  • Loading branch information
OleksandrVidinieiev and alexanderkurash authored Nov 2, 2024
1 parent c01e3c5 commit a1d6fee
Show file tree
Hide file tree
Showing 37 changed files with 1,646 additions and 14 deletions.
19 changes: 19 additions & 0 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@
}
]
},
{
"id": "staff-slips",
"version": "1.0",
"handlers": [
{
"methods": ["GET"],
"pathPattern": "/tlr/staff-slips/pick-slips/{servicePointId}",
"permissionsRequired": ["tlr.staff-slips.pick-slips.get"],
"modulePermissions": [
"user-tenants.collection.get"
]
}
]
},
{
"id": "_tenant",
"version": "2.0",
Expand Down Expand Up @@ -186,6 +200,11 @@
"permissionName": "tlr.ecs-tlr-allowed-service-points.get",
"displayName": "ecs-tlr - allowed service points",
"description": "Get ECS TLR allowed service points"
},
{
"permissionName": "tlr.staff-slips.pick-slips.get",
"displayName": "ecs-tlr - pick slips",
"description": "Get pick slips"
}
],
"requires": [
Expand Down
27 changes: 27 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,33 @@
</configOptions>
</configuration>
</execution>
<execution>
<id>staff-slips</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/swagger.api/staff-slips.yaml</inputSpec>
<output>${project.build.directory}/generated-sources</output>
<generatorName>spring</generatorName>
<modelPackage>${project.groupId}.domain.dto</modelPackage>
<apiPackage>${project.groupId}.rest.resource</apiPackage>
<generateApis>true</generateApis>
<generateApiTests>true</generateApiTests>
<generateApiDocumentation>true</generateApiDocumentation>
<generateModels>true</generateModels>
<generateModelTests>false</generateModelTests>
<generateSupportingFiles>true</generateSupportingFiles>
<supportingFilesToGenerate>ApiUtil.java</supportingFilesToGenerate>
<generateModelDocumentation>true</generateModelDocumentation>
<configOptions>
<dateLibrary>java</dateLibrary>
<interfaceOnly>true</interfaceOnly>
<useSpringBoot3>true</useSpringBoot3>
<useTags>true</useTags>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/folio/client/feign/GetByQueryClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.folio.client.feign;

import org.folio.spring.config.FeignClientConfiguration;
import org.folio.support.CqlQuery;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(name="get-by-query", configuration = FeignClientConfiguration.class)
public interface GetByQueryClient<T> {
int DEFAULT_LIMIT = 1000;

@GetMapping
T getByQuery(@RequestParam CqlQuery query, @RequestParam int limit);

default T getByQuery(CqlQuery query) {
return getByQuery(query, DEFAULT_LIMIT);
}
}
3 changes: 2 additions & 1 deletion src/main/java/org/folio/client/feign/ItemClient.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.InventoryItem;
import org.folio.domain.dto.Items;
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 = "items", url = "item-storage/items", configuration = FeignClientConfiguration.class)
public interface ItemClient {
public interface ItemClient extends GetByQueryClient<Items> {

@GetMapping("/{id}")
InventoryItem get(@PathVariable String id);
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/folio/client/feign/LocationClient.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.Location;
import org.folio.domain.dto.Locations;
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 = "locations", url = "locations", configuration = FeignClientConfiguration.class)
public interface LocationClient extends GetByQueryClient<Locations> {

@GetMapping("/{id}")
Location findLocation(@PathVariable String id);

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.folio.client.feign;

import org.folio.domain.dto.Request;
import org.folio.domain.dto.Requests;
import org.folio.spring.config.FeignClientConfiguration;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -9,7 +10,7 @@
import org.springframework.web.bind.annotation.RequestBody;

@FeignClient(name = "request-storage", url = "request-storage/requests", configuration = FeignClientConfiguration.class)
public interface RequestStorageClient {
public interface RequestStorageClient extends GetByQueryClient<Requests> {

@GetMapping("/{requestId}")
Request getRequest(@PathVariable String requestId);
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/org/folio/controller/StaffSlipsController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.folio.controller;

import java.util.ArrayList;
import java.util.Collection;
import java.util.UUID;

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

import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;

@RestController
@Log4j2
@AllArgsConstructor
public class StaffSlipsController implements PickSlipsApi {

private final PickSlipsService pickSlipsService;

@Override
public ResponseEntity<PickSlipsResponse> getPickSlips(UUID servicePointId) {
log.info("getPickSlips:: servicePointId={}", servicePointId);
Collection<StaffSlip> pickSlips = pickSlipsService.getStaffSlips(servicePointId.toString());

return ResponseEntity.ok(new PickSlipsResponse()
.pickSlips(new ArrayList<>(pickSlips))
.totalRecords(pickSlips.size()));
}
}
6 changes: 5 additions & 1 deletion src/main/java/org/folio/service/ConsortiaService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package org.folio.service;

import java.util.Collection;

import org.folio.domain.dto.Tenant;
import org.folio.domain.dto.TenantCollection;

public interface ConsortiaService {
TenantCollection getAllDataTenants(String consortiumId);
TenantCollection getAllConsortiumTenants(String consortiumId);
Collection<Tenant> getAllConsortiumTenants();
}
10 changes: 10 additions & 0 deletions src/main/java/org/folio/service/ItemService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.folio.service;

import java.util.Collection;

import org.folio.domain.dto.Item;
import org.folio.support.CqlQuery;

public interface ItemService {
Collection<Item> findItems(CqlQuery query, String idIndex, Collection<String> ids);
}
10 changes: 10 additions & 0 deletions src/main/java/org/folio/service/LocationService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.folio.service;

import java.util.Collection;

import org.folio.domain.dto.Location;
import org.folio.support.CqlQuery;

public interface LocationService {
Collection<Location> findLocations(CqlQuery query);
}
2 changes: 2 additions & 0 deletions src/main/java/org/folio/service/RequestService.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.folio.domain.dto.ReorderQueue;
import org.folio.domain.dto.Request;
import org.folio.domain.entity.EcsTlrEntity;
import org.folio.support.CqlQuery;

public interface RequestService {
RequestWrapper createPrimaryRequest(Request request, String borrowingTenantId);
Expand All @@ -29,6 +30,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);
Request updateRequestInStorage(Request request, String tenantId);
List<Request> getRequestsQueueByInstanceId(String instanceId, String tenantId);
List<Request> getRequestsQueueByInstanceId(String instanceId);
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/folio/service/StaffSlipsService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.folio.service;

import java.util.Collection;

import org.folio.domain.dto.StaffSlip;

public interface StaffSlipsService {
Collection<StaffSlip> getStaffSlips(String servicePointId);
}
24 changes: 23 additions & 1 deletion src/main/java/org/folio/service/impl/ConsortiaServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package org.folio.service.impl;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import org.folio.client.feign.ConsortiaClient;
import org.folio.domain.dto.Tenant;
import org.folio.domain.dto.TenantCollection;
import org.folio.domain.dto.UserTenant;
import org.folio.service.ConsortiaService;
import org.folio.service.UserTenantsService;
import org.springframework.stereotype.Service;

import lombok.RequiredArgsConstructor;
Expand All @@ -13,9 +21,23 @@
@RequiredArgsConstructor
public class ConsortiaServiceImpl implements ConsortiaService {
private final ConsortiaClient consortiaClient;
private final UserTenantsService userTenantsService;

@Override
public TenantCollection getAllDataTenants(String consortiumId) {
public TenantCollection getAllConsortiumTenants(String consortiumId) {
return consortiaClient.getConsortiaTenants(consortiumId);
}

@Override
public Collection<Tenant> getAllConsortiumTenants() {
log.info("getAllConsortiumTenants:: fetching consortium tenants");
List<Tenant> tenants = Optional.ofNullable(userTenantsService.findFirstUserTenant())
.map(UserTenant::getConsortiumId)
.map(consortiaClient::getConsortiaTenants)
.map(TenantCollection::getTenants)
.orElseGet(Collections::emptyList);

log.info("getAllConsortiumTenants:: found {} consortium tenants", tenants::size);
return tenants;
}
}
31 changes: 31 additions & 0 deletions src/main/java/org/folio/service/impl/ItemServiceImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.folio.service.impl;

import java.util.Collection;

import org.folio.client.feign.ItemClient;
import org.folio.domain.dto.Item;
import org.folio.domain.dto.Items;
import org.folio.service.ItemService;
import org.folio.support.BulkFetcher;
import org.folio.support.CqlQuery;
import org.springframework.stereotype.Service;

import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;

@Service
@RequiredArgsConstructor
@Log4j2
public class ItemServiceImpl implements ItemService {
private final ItemClient itemClient;

@Override
public Collection<Item> findItems(CqlQuery query, String idIndex, Collection<String> ids) {
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;
}
}
28 changes: 28 additions & 0 deletions src/main/java/org/folio/service/impl/LocationServiceImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.folio.service.impl;

import java.util.Collection;
import java.util.List;

import org.folio.client.feign.LocationClient;
import org.folio.domain.dto.Location;
import org.folio.support.CqlQuery;
import org.springframework.stereotype.Service;

import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;

@Service
@RequiredArgsConstructor
@Log4j2
public class LocationServiceImpl implements org.folio.service.LocationService {

private final LocationClient locationClient;

@Override
public Collection<Location> findLocations(CqlQuery query) {
log.info("findLocations:: searching locations by query: {}", query);
List<Location> locations = locationClient.getByQuery(query).getLocations();
log.info("findLocations:: found {} locations", locations::size);
return locations;
}
}
31 changes: 31 additions & 0 deletions src/main/java/org/folio/service/impl/PickSlipsService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.folio.service.impl;

import static org.folio.domain.dto.ItemStatus.NameEnum.PAGED;
import static org.folio.domain.dto.Request.RequestTypeEnum.PAGE;
import static org.folio.domain.dto.Request.StatusEnum.OPEN_NOT_YET_FILLED;

import java.util.EnumSet;

import org.folio.service.ConsortiaService;
import org.folio.service.ItemService;
import org.folio.service.LocationService;
import org.folio.service.RequestService;
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 PickSlipsService extends StaffSlipsServiceImpl {

public PickSlipsService(@Autowired LocationService locationService,
@Autowired ItemService itemService, @Autowired RequestService requestService,
@Autowired ConsortiaService consortiaService,
@Autowired SystemUserScopedExecutionService executionService) {

super(EnumSet.of(PAGED), EnumSet.of(OPEN_NOT_YET_FILLED), EnumSet.of(PAGE), locationService,
itemService, requestService, consortiaService, executionService);
}
}
Loading

0 comments on commit a1d6fee

Please sign in to comment.