Skip to content

Commit

Permalink
MODDCB-128 Release fix for Q Csp5 (#100)
Browse files Browse the repository at this point in the history
* MODDCB-114 Changing service point creation logic (#94)

* MODDCB-114 Changing servicePoint creation logic

* MODDCB-114 Adding missing permissions (#95)

* MODDCB-114 Adding missing permissions

* MODDCB-119 Create default DCB calendar and link DCB specific service Points with it (#98)

* MODDCB-119 Creating default calendar and add virtualServicePointId to calendar

* MODDCB-119 Adding dependency and permission of calendar in ModuleDescriptor-template.json

* MODDCB-119 Fix servicePoints null issue

* MODDCB-119 Fix assignments null issue

* MODDCB-119 Updating servicePoint with calendar if it is not assigned

* MODDCB-119 Adding test cases

* MODDCB-119 Adding test cases

* MODDCB-119 Changing loggers

* MODDCB-119 Associate the DCB servicePoint with the default calendar

* MODDCB-119 Change the datatype of calendar startDate and endDate (#99)

* MODDCB-119 Change the datatype of calendar startDate and endDate

* MODDCB-128 Update NEWS

* [maven-release-plugin] prepare release v1.1.3

* [maven-release-plugin] prepare for next development iteration
  • Loading branch information
Vignesh-kalyanasundaram authored Oct 2, 2024
1 parent 61dd568 commit faa56e7
Show file tree
Hide file tree
Showing 22 changed files with 651 additions and 59 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v1.1.3 2024-10-02

* MODDCB-114: Supplier side: Unable to produce service point pickup location in pick lists
* MODDCB-119: Add DCB calendar and assignment of SPs to it

## v1.1.2 2024-08-07

* MODDCB-112: Kafka TLS configuration is not present
Expand Down
13 changes: 11 additions & 2 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
{
"id": "instance-types",
"version": "2.0"
},
{
"id": "calendar",
"version": "5.0"
}
],
"provides": [
Expand All @@ -82,6 +86,7 @@
],
"modulePermissions": [
"inventory-storage.service-points.item.post",
"inventory-storage.service-points.collection.get",
"users.collection.get",
"users.item.post",
"usergroups.collection.get",
Expand All @@ -97,7 +102,9 @@
"inventory-storage.loan-types.collection.get",
"circulation-storage.requests.item.get",
"circulation-storage.cancellation-reasons.item.get",
"circulation-storage.cancellation-reasons.item.post"
"circulation-storage.cancellation-reasons.item.post",
"calendar.endpoint.calendars.get",
"calendar.endpoint.calendars.calendarId.put"
]
},
{
Expand Down Expand Up @@ -165,7 +172,9 @@
"inventory-storage.loan-types.collection.post",
"inventory-storage.loan-types.item.post",
"circulation-storage.cancellation-reasons.item.get",
"circulation-storage.cancellation-reasons.item.post"
"circulation-storage.cancellation-reasons.item.post",
"calendar.endpoint.calendars.get",
"calendar.endpoint.calendars.post"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<groupId>org.folio</groupId>
<artifactId>mod-dcb</artifactId>
<name>mod-dcb</name>
<version>1.1.3-SNAPSHOT</version>
<version>1.1.4-SNAPSHOT</version>
<description>Manage DCB related transactions in folio</description>
<packaging>jar</packaging>

Expand Down
27 changes: 27 additions & 0 deletions src/main/java/org/folio/dcb/client/feign/CalendarClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.folio.dcb.client.feign;

import org.folio.dcb.domain.dto.Calendar;
import org.folio.dcb.domain.dto.CalendarCollection;
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;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.UUID;

@FeignClient(name = "calendar", configuration = FeignClientConfiguration.class)
public interface CalendarClient {
@PostMapping("/calendars")
Calendar createCalendar(@RequestBody Calendar calendar);

@PutMapping("/calendars/{calendarId}")
Calendar updateCalendar(@PathVariable("calendarId") UUID calendarId, @RequestBody Calendar calendar);

@GetMapping("/calendars")
CalendarCollection getAllCalendars(@RequestParam("limit") Integer limit);

}
44 changes: 44 additions & 0 deletions src/main/java/org/folio/dcb/service/CalendarService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.folio.dcb.service;

import org.folio.dcb.domain.dto.Calendar;

import java.util.UUID;

public interface CalendarService {
/**
* Finds a calendar by its name.
*
* @param name the name of the calendar to find.
* @return the {@link Calendar} object with the specified name,
* or {@code null} if no such calendar is found.
*/
Calendar findCalendarByName(String name);

/**
* Creates a new calendar.
*
* @param calendar the {@link Calendar} object to be created.
* @return the created {@link Calendar} object.
*/
Calendar createCalendar(Calendar calendar);

/**
* Adds a service point ID with a default calendar.
* If the calendar is found, the service point ID is added to the calendar's assignments.
*
* @param servicePointId the unique identifier of the service point to add.
* @throws IllegalArgumentException if the default calendar name is not found.
*/
void addServicePointIdToDefaultCalendar(UUID servicePointId);

/**
* Associates a service point ID with a default calendar if it is not already associated
* with any calendar. Checks existing calendars and adds the service point ID to the
* default calendar if absent.
*
* @param servicePointId the unique identifier of the service point to associate.
* @throws IllegalArgumentException if the default calendar name is not found.
*/
void associateServicePointIdWithDefaultCalendarIfAbsent(UUID servicePointId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
import org.folio.dcb.domain.dto.ServicePointRequest;

public interface ServicePointService {
ServicePointRequest createServicePoint(DcbPickup pickupServicePoint);
ServicePointRequest createServicePointIfNotExists(DcbPickup pickupServicePoint);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public class BorrowingLibraryServiceImpl implements LibraryService {
private final ServicePointService servicePointService;
@Override
public TransactionStatusResponse createCirculation(String dcbTransactionId, DcbTransaction dcbTransaction) {
ServicePointRequest pickupServicePoint = servicePointService.createServicePoint(dcbTransaction.getPickup());
ServicePointRequest pickupServicePoint = servicePointService.createServicePointIfNotExists(dcbTransaction.getPickup());
dcbTransaction.getPickup().setServicePointId(pickupServicePoint.getId());
return libraryService.createBorrowingLibraryTransaction(dcbTransactionId, dcbTransaction, pickupServicePoint.getId());
}

Expand Down
88 changes: 88 additions & 0 deletions src/main/java/org/folio/dcb/service/impl/CalendarServiceImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package org.folio.dcb.service.impl;

import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.folio.dcb.client.feign.CalendarClient;
import org.folio.dcb.domain.dto.Calendar;
import org.folio.dcb.service.CalendarService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

import static org.folio.dcb.utils.DCBConstants.DCB_CALENDAR_NAME;

@Service
@RequiredArgsConstructor
@Log4j2
public class CalendarServiceImpl implements CalendarService {
private final CalendarClient calendarClient;

@Override
public Calendar findCalendarByName(String calendarName) {
log.debug("findCalendarByName:: Trying to find the calendar with name {}", calendarName);
var calendars = getAllCalendars();
return findCalendarByName(calendars, calendarName);
}

@Override
public Calendar createCalendar(Calendar calendar) {
log.debug("createCalendar:: Creating new calendar with details {}", calendar);
return calendarClient.createCalendar(calendar);
}

@Override
public void addServicePointIdToDefaultCalendar(UUID servicePointId) {
log.info("addServicePointIdToDefaultCalendar:: find calendar by name {} to update servicePointId {}",
DCB_CALENDAR_NAME, servicePointId);
var calendar = findCalendarByName(DCB_CALENDAR_NAME);
updateCalendarIfExists(DCB_CALENDAR_NAME, servicePointId, calendar);
}

private void updateCalendarIfExists(String calendarName, UUID servicePointId, Calendar calendar) {
if (calendar != null) {
calendar.getAssignments().add(servicePointId);
calendarClient.updateCalendar(calendar.getId(), calendar);
} else {
log.warn("updateCalendarIfExists:: Calendar with name {} is not found", calendarName);
throw new IllegalArgumentException("Calendar with name " + calendarName + " is not found");
}
}

@Override
public void associateServicePointIdWithDefaultCalendarIfAbsent(UUID servicePointId) {
var calendars = getAllCalendars();
if (checkServicePointIdAssociatedWithAnyCalendar(calendars, servicePointId)) {
log.info("associateServicePointIdWithDefaultCalendarIfAbsent:: servicePointId {} is already " +
"associated with calendar", servicePointId);
} else {
log.info("associateServicePointIdWithDefaultCalendarIfAbsent:: servicePointId {} is not " +
"associated with any calendar. so associating with default calendar", servicePointId);
var defaultDcbCalendar = findCalendarByName(calendars, DCB_CALENDAR_NAME);
updateCalendarIfExists(DCB_CALENDAR_NAME, servicePointId, defaultDcbCalendar);
}
}

private List<Calendar> getAllCalendars() {
log.debug("getAllCalendars:: Fetching all calendars");
return calendarClient.getAllCalendars(Integer.MAX_VALUE)
.getCalendars();
}

private Calendar findCalendarByName(List<Calendar> calendars, String calendarName) {
log.debug("findCalendarByName:: Finding calendar with name {} from calendarList {}", calendarName, calendars);
return calendars
.stream()
.filter(calendar -> calendar.getName().equals(calendarName))
.findFirst()
.orElse(null);
}

private boolean checkServicePointIdAssociatedWithAnyCalendar(List<Calendar> calendars, UUID servicePointId) {
log.debug("checkServicePointIdAssociatedWithAnyCalendar:: checking servicePointId {} associated with " +
"any calendar {}", servicePointId, calendars);
return calendars.stream()
.anyMatch(calendar -> calendar.getAssignments().contains(servicePointId));
}

}
43 changes: 41 additions & 2 deletions src/main/java/org/folio/dcb/service/impl/CustomTenantService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
import org.folio.dcb.client.feign.LoanTypeClient;
import org.folio.dcb.client.feign.LocationUnitClient;
import org.folio.dcb.client.feign.LocationsClient;
import org.folio.dcb.domain.dto.Calendar;
import org.folio.dcb.domain.dto.HoldShelfExpiryPeriod;
import org.folio.dcb.domain.dto.NormalHours;
import org.folio.dcb.domain.dto.ServicePointRequest;
import org.folio.dcb.listener.kafka.service.KafkaService;
import org.folio.dcb.service.CalendarService;
import org.folio.spring.FolioExecutionContext;
import org.folio.spring.liquibase.FolioSpringLiquibase;
import org.folio.spring.service.PrepareSystemUserService;
Expand All @@ -24,12 +27,18 @@
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.Collections;
import java.util.List;
import java.util.UUID;

import static org.folio.dcb.service.impl.ServicePointServiceImpl.HOLD_SHELF_CLOSED_LIBRARY_DATE_MANAGEMENT;
import static org.folio.dcb.utils.DCBConstants.CAMPUS_ID;
import static org.folio.dcb.utils.DCBConstants.CANCELLATION_REASON_ID;
import static org.folio.dcb.utils.DCBConstants.CODE;
import static org.folio.dcb.utils.DCBConstants.DCB_CALENDAR_NAME;
import static org.folio.dcb.utils.DCBConstants.DCB_CANCELLATION_REASON_NAME;
import static org.folio.dcb.utils.DCBConstants.HOLDING_ID;
import static org.folio.dcb.utils.DCBConstants.INSTANCE_ID;
Expand Down Expand Up @@ -61,10 +70,15 @@ public class CustomTenantService extends TenantService {
private final LocationUnitClient locationUnitClient;
private final CancellationReasonClient cancellationReasonClient;
private final LoanTypeClient loanTypeClient;
private final CalendarService calendarService;


public CustomTenantService(JdbcTemplate jdbcTemplate, FolioExecutionContext context,
FolioSpringLiquibase folioSpringLiquibase, PrepareSystemUserService systemUserService, KafkaService kafkaService, InstanceClient inventoryClient, InstanceTypeClient instanceTypeClient, HoldingsStorageClient holdingsStorageClient, LocationsClient locationsClient, HoldingSourcesClient holdingSourcesClient, InventoryServicePointClient servicePointClient, LocationUnitClient locationUnitClient, LoanTypeClient loanTypeClient, CancellationReasonClient cancellationReasonClient) {
public CustomTenantService(JdbcTemplate jdbcTemplate, FolioExecutionContext context, FolioSpringLiquibase folioSpringLiquibase,
PrepareSystemUserService systemUserService, KafkaService kafkaService, InstanceClient inventoryClient,
InstanceTypeClient instanceTypeClient, HoldingsStorageClient holdingsStorageClient,
LocationsClient locationsClient, HoldingSourcesClient holdingSourcesClient,
InventoryServicePointClient servicePointClient, LocationUnitClient locationUnitClient,
LoanTypeClient loanTypeClient, CancellationReasonClient cancellationReasonClient, CalendarService calendarService) {
super(jdbcTemplate, context, folioSpringLiquibase);

this.systemUserService = systemUserService;
Expand All @@ -78,6 +92,7 @@ public CustomTenantService(JdbcTemplate jdbcTemplate, FolioExecutionContext cont
this.locationUnitClient = locationUnitClient;
this.loanTypeClient = loanTypeClient;
this.cancellationReasonClient = cancellationReasonClient;
this.calendarService = calendarService;
}

@Override
Expand All @@ -95,6 +110,7 @@ protected void afterTenantUpdate(TenantAttributes tenantAttributes) {
createHolding();
createCancellationReason();
createLoanType();
createCalendarIfNotExists();
}

private void createLoanType() {
Expand Down Expand Up @@ -254,4 +270,27 @@ private void createCancellationReason(){
log.info("createCancellationReason:: cancellation reason created");
}
}

private void createCalendarIfNotExists() {
Calendar calendar = calendarService.findCalendarByName(DCB_CALENDAR_NAME);
if (calendar == null) {
log.info("createCalendarIfNotExists:: calendar with name {} doesn't exists, so creating new calendar", DCB_CALENDAR_NAME);
Calendar newCalendar = Calendar.builder()
.name(DCB_CALENDAR_NAME)
.startDate(LocalDate.now().toString())
.endDate(LocalDate.now().plusYears(10).toString())
.normalHours(List.of(NormalHours.builder()
.startDay(DayOfWeek.SUNDAY.name())
.startTime(LocalTime.of(0, 0).toString())
.endDay(DayOfWeek.SATURDAY.toString())
.endTime(LocalTime.of(23, 59).toString())
.build()))
.assignments(List.of(UUID.fromString(SERVICE_POINT_ID)))
.exceptions(List.of())
.build();
calendarService.createCalendar(newCalendar);
} else {
log.info("createCalendarIfNotExists:: calendar with name {} already exists", DCB_CALENDAR_NAME);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public TransactionStatusResponse createCirculation(String dcbTransactionId, DcbT

var user = userService.fetchOrCreateUser(patron);
baseLibraryService.checkUserTypeAndThrowIfMismatch(user.getType());
ServicePointRequest pickupServicePoint = servicePointService.createServicePoint(dcbTransaction.getPickup());
ServicePointRequest pickupServicePoint = servicePointService.createServicePointIfNotExists(dcbTransaction.getPickup());
dcbTransaction.getPickup().setServicePointId(pickupServicePoint.getId());
CirculationRequest pageRequest = requestService.createPageItemRequest(user, item, pickupServicePoint.getId());
baseLibraryService.saveDcbTransaction(dcbTransactionId, dcbTransaction, pageRequest.getId());

Expand Down
Loading

0 comments on commit faa56e7

Please sign in to comment.