Skip to content

Commit

Permalink
Merge branch 'master' into CIRC-1933
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/test/java/api/requests/StaffSlipsTests.java
  • Loading branch information
OleksandrVidinieiev committed Dec 15, 2023
2 parents 07f5e32 + d7bd9a6 commit 13ee6fb
Show file tree
Hide file tree
Showing 29 changed files with 1,129 additions and 378 deletions.
12 changes: 6 additions & 6 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,8 @@
"accounts.collection.get",
"accounts.item.post",
"feefineactions.item.post",
"circulation-storage.loans-history.collection.get"
"circulation-storage.loans-history.collection.get",
"calendar.endpoint.dates.get"
],
"schedule": {
"cron": "1 0 * * *",
Expand Down Expand Up @@ -1693,7 +1694,7 @@
"circulation.rules.loan-policy.get",
"circulation.rules.request-policy.get",
"inventory-storage.items.item.put",
"circulation-item-storage.items.item.put",
"circulation-item.item.put",
"circulation.internal.fetch-items",
"users.item.get",
"users.collection.get",
Expand Down Expand Up @@ -1741,7 +1742,7 @@
"circulation.rules.loan-policy.get",
"circulation.rules.request-policy.get",
"inventory-storage.items.item.put",
"circulation-item-storage.items.item.put",
"circulation-item.item.put",
"circulation.internal.fetch-items",
"users.item.get",
"users.collection.get",
Expand Down Expand Up @@ -2343,9 +2344,8 @@
"description" : "Internal permission set for fetching item(s)",
"subPermissions": [
"inventory-storage.items.item.get",
"circulation-item-storage.item.collection.get",
"circulation-item-storage.items.collection.get",
"circulation-item-storage.items.item.get",
"circulation-item.collection.get",
"circulation-item.item.get",
"inventory-storage.items.collection.get",
"inventory-storage.holdings.item.get",
"inventory-storage.holdings.collection.get",
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/folio/circulation/domain/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import static org.folio.circulation.domain.representations.ItemProperties.STATUS_PROPERTY;
import static org.folio.circulation.support.json.JsonPropertyFetcher.getBooleanProperty;
import static org.folio.circulation.support.json.JsonPropertyFetcher.getNestedStringProperty;
import static org.folio.circulation.support.json.JsonPropertyFetcher.getProperty;
import static org.folio.circulation.support.json.JsonPropertyWriter.write;

import java.util.Collection;
Expand Down Expand Up @@ -399,7 +400,11 @@ public Item withInTransitDestinationServicePoint(ServicePoint servicePoint) {
this.instance, this.materialType, this.loanType, this.description);
}

public boolean isDcbItem(){
public boolean isDcbItem() {
return getBooleanProperty(itemRepresentation, "dcbItem");
}

public String getLendingLibraryCode() {
return getProperty(itemRepresentation, "lendingLibraryCode");
}
}
11 changes: 5 additions & 6 deletions src/main/java/org/folio/circulation/domain/Loan.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
import org.apache.logging.log4j.Logger;
import org.folio.circulation.domain.policy.LoanPolicy;
import org.folio.circulation.domain.policy.OverdueFinePolicy;
import org.folio.circulation.domain.policy.OverdueFinePolicyRemindersPolicy;
import org.folio.circulation.domain.policy.RemindersPolicy;
import org.folio.circulation.domain.policy.lostitem.LostItemPolicy;
import org.folio.circulation.domain.representations.LoanProperties;
import org.folio.circulation.support.results.Result;
Expand Down Expand Up @@ -660,17 +660,16 @@ public Integer getLastReminderFeeBilledNumber() {
return (Integer) getValueByPath(representation, REMINDERS, LAST_FEE_BILLED, BILL_NUMBER);
}

public OverdueFinePolicyRemindersPolicy.ReminderSequenceEntry getNextReminder() {
public RemindersPolicy.ReminderConfig getNextReminder() {
Integer latestReminderNumber = getLastReminderFeeBilledNumber();
if (latestReminderNumber == null) {
latestReminderNumber = 0;
}
if (getOverdueFinePolicy().getRemindersPolicy() == null
|| getOverdueFinePolicy().getRemindersPolicy().getReminderSchedule() == null) {
RemindersPolicy remindersPolicy = getOverdueFinePolicy().getRemindersPolicy();
if (remindersPolicy == null || !remindersPolicy.hasReminderSchedule()) {
return null;
} else {
OverdueFinePolicyRemindersPolicy.ReminderSequence schedule = getOverdueFinePolicy().getRemindersPolicy().getReminderSchedule();
return schedule.getEntryAfter(latestReminderNumber);
return remindersPolicy.getNextReminderAfter(latestReminderNumber);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private static JsonObject createItemContext(Item item) {
.put("effectiveLocationSpecific", location.getName())
.put("effectiveLocationLibrary", location.getLibraryName())
.put("effectiveLocationCampus", location.getCampusName())
.put("effectiveLocationInstitution", location.getInstitutionName())
.put("effectiveLocationInstitution", item.isDcbItem()?item.getLendingLibraryCode():location.getInstitutionName())
.put("effectiveLocationDiscoveryDisplayName", location.getDiscoveryDisplayName());

var primaryServicePoint = location.getPrimaryServicePoint();
Expand Down Expand Up @@ -430,15 +430,11 @@ public UserContext withAddressProperties(JsonObject address) {
}

public String getCountryNameByCodeIgnoreCase(String code) {
if (StringUtils.isEmpty(code)) {
if (StringUtils.isEmpty(code) || !Stream.of(Locale.getISOCountries()).toList().contains(code)) {
log.info("getCountryNameByCodeIgnoreCase:: Invalid country code {}", code);
return null;
}

if (!Stream.of(Locale.getISOCountries()).toList().contains(code)) {
log.error("getCountryNameByCodeIgnoreCase:: Invalid country code {}", code);
throw new IllegalArgumentException("Not a valid country code to determine the country name.");
}

return new Locale("",code).getDisplayName();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
import org.folio.circulation.domain.Loan;
import org.folio.circulation.domain.LoanAndRelatedRecords;
import org.folio.circulation.domain.notice.NoticeTiming;
import org.folio.circulation.domain.policy.OverdueFinePolicyRemindersPolicy;
import org.folio.circulation.domain.policy.RemindersPolicy.ReminderConfig;
import org.folio.circulation.infrastructure.storage.CalendarRepository;
import org.folio.circulation.infrastructure.storage.notices.ScheduledNoticesRepository;
import org.folio.circulation.support.results.Result;
import org.folio.circulation.support.Clients;

import java.lang.invoke.MethodHandles;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

import static org.folio.circulation.support.results.Result.succeeded;

Expand All @@ -19,42 +22,48 @@ public class ReminderFeeScheduledNoticeService {
protected static final Logger log = LogManager.getLogger(MethodHandles.lookup().lookupClass());

private final ScheduledNoticesRepository scheduledNoticesRepository;
private final CalendarRepository calendarRepository;

public ReminderFeeScheduledNoticeService (ScheduledNoticesRepository scheduledNoticesRepository) {
this.scheduledNoticesRepository = scheduledNoticesRepository;

public ReminderFeeScheduledNoticeService (Clients clients) {
this.scheduledNoticesRepository = ScheduledNoticesRepository.using(clients);
this.calendarRepository = new CalendarRepository(clients);
}

public Result<LoanAndRelatedRecords> scheduleFirstReminder(LoanAndRelatedRecords records) {
log.debug("scheduleFirstReminder:: parameters loanAndRelatedRecords: {}",
records);
Loan loan = records.getLoan();
if (loan.getOverdueFinePolicy().isReminderFeesPolicy()) {

OverdueFinePolicyRemindersPolicy.ReminderSequenceEntry firstReminder =
loan.getOverdueFinePolicy().getRemindersPolicy().getReminderSequenceEntry(1);

ScheduledNoticeConfig config =
new ScheduledNoticeConfig(
NoticeTiming.AFTER,
null, // recurrence handled using reminder fee policy
firstReminder.getNoticeTemplateId(),
firstReminder.getNoticeFormat(),
true);

ScheduledNotice scheduledNotice = new ScheduledNotice(
UUID.randomUUID().toString(),
loan.getId(),
null,
loan.getUserId(),
null,
null,
TriggeringEvent.DUE_DATE_WITH_REMINDER_FEE,
firstReminder.getPeriod().plusDate(loan.getDueDate()),
config
);

scheduledNoticesRepository.create(scheduledNotice);
ReminderConfig firstReminder =
loan.getOverdueFinePolicy().getRemindersPolicy().getFirstReminder();
instantiateFirstScheduledNotice(records, firstReminder)
.thenAccept(r -> r.after(scheduledNoticesRepository::create));
} else {
log.debug("The current item, barcode {}, is not subject to a reminder fees policy.", loan.getItem().getBarcode());
}
return succeeded(records);
}

private CompletableFuture<Result<ScheduledNotice>> instantiateFirstScheduledNotice(
LoanAndRelatedRecords loanRecords, ReminderConfig reminderConfig) {

log.debug("instantiateFirstScheduledNotice:: parameters loanAndRelatedRecords: {}, " +
"reminderConfig: {}", loanRecords, reminderConfig);

final Loan loan = loanRecords.getLoan();

return reminderConfig.nextNoticeDueOn(loan.getDueDate(), loanRecords.getTimeZone(),
loan.getCheckoutServicePointId(), calendarRepository)
.thenApply(r -> r.map(nextDueTime -> new ScheduledNotice(UUID.randomUUID().toString(),
loan.getId(), null, loan.getUserId(), null, null,
TriggeringEvent.DUE_DATE_WITH_REMINDER_FEE, nextDueTime,
instantiateNoticeConfig(reminderConfig))));
}

private ScheduledNoticeConfig instantiateNoticeConfig(ReminderConfig reminderConfig) {
return new ScheduledNoticeConfig(NoticeTiming.AFTER, null,
reminderConfig.getNoticeTemplateId(), reminderConfig.getNoticeFormat(), true);
}

}
Loading

0 comments on commit 13ee6fb

Please sign in to comment.