// next I shall validate that the client is present in this group
if (!sourceGroup.hasClientAsMember(client)) { throw new ClientNotInGroupException(client.getId(), sourceGroup.getId()); }
// Is client active?
if (client.isNotActive()) { throw new ClientHasBeenClosedException(client.getId()); }
/**
* TODO: for now we need to ensure that only one collection sheet
* calendar can be linked with a center or group entity <br/>
**/
final CalendarInstance sourceGroupCalendarInstance = this.calendarInstanceRepository
.findByEntityIdAndEntityTypeIdAndCalendarTypeId(sourceGroup.getId(), CalendarEntityType.GROUPS.getValue(),
CalendarType.COLLECTION.getValue());
// get all customer loans synced with this group calendar Instance
final List<CalendarInstance> activeLoanCalendarInstances = this.calendarInstanceRepository
.findCalendarInstancesForActiveLoansByGroupIdAndClientId(sourceGroup.getId(), client.getId());
/**
* if a calendar is present in the source group along with loans synced
* with it, we should ensure that the destination group also has a
* collection calendar
**/
if (sourceGroupCalendarInstance != null && !activeLoanCalendarInstances.isEmpty()) {
// get the destination calendar
final CalendarInstance destinationGroupCalendarInstance = this.calendarInstanceRepository
.findByEntityIdAndEntityTypeIdAndCalendarTypeId(destinationGroup.getId(), CalendarEntityType.GROUPS.getValue(),
CalendarType.COLLECTION.getValue());
if (destinationGroupCalendarInstance == null) { throw new TransferNotSupportedException(
TRANSFER_NOT_SUPPORTED_REASON.DESTINATION_GROUP_HAS_NO_MEETING, destinationGroup.getId());
}
final Calendar sourceGroupCalendar = sourceGroupCalendarInstance.getCalendar();
final Calendar destinationGroupCalendar = destinationGroupCalendarInstance.getCalendar();
/***
* Ensure that the recurrence pattern are same for collection
* meeting in both the source and the destination calendar
***/