-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MODDCB-128 Release fix for Q Csp5 (#100)
* 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
1 parent
61dd568
commit faa56e7
Showing
22 changed files
with
651 additions
and
59 deletions.
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
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
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
27 changes: 27 additions & 0 deletions
27
src/main/java/org/folio/dcb/client/feign/CalendarClient.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,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); | ||
|
||
} |
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,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); | ||
|
||
} |
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
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
88 changes: 88 additions & 0 deletions
88
src/main/java/org/folio/dcb/service/impl/CalendarServiceImpl.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,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)); | ||
} | ||
|
||
} |
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
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.