Public class ServiceResourceScheduleHandlerImpl implements lxscheduler.ServiceResourceScheduleHandler{
// The main interface method.
public static List<lxscheduler.ServiceResourceSchedule> getUnavailableTimeslots(lxscheduler.ServiceAppointmentRequestInfo requestInfo){
//Request info values.
List<lxscheduler.ServiceResourceInfo> serviceResources=requestInfo.getServiceResources();
DateTime startDate=requestInfo.getStartDate();
DateTime endDate=requestInfo.getEndDate();
List<lxscheduler.ServiceResourceSchedule> resourceUnavailability = new List<lxscheduler.ServiceResourceSchedule>();
Set<lxscheduler.UnavailableTimeslot> unavailabilityIntervals = new Set<lxscheduler.UnavailableTimeslot>();
//This is a dummy response. Implement your own business logic to connect to your internal or external systems.
for (Integer i = 0; i < 5; i++) {
//Set the unavailability intervals of a service resource.
unavailabilityIntervals.add(new lxscheduler.UnavailableTimeslot(startDate.addMinutes(15*i),startDate.addMinutes(15*(i+1))));
}
for (lxscheduler.ServiceResourceInfo ServiceResource:serviceResources) {
//Set the unavailability of Service resource.
resourceUnavailability.add(new lxscheduler.ServiceResourceSchedule(serviceResource.getServiceResourceId(),unavailabilityIntervals));
}
return resourceUnavailability;
}
}
UHVibGljIGNsYXNzIFNlcnZpY2VSZXNvdXJjZVNjaGVkdWxlSGFuZGxlckltcGwgaW1wbGVtZW50cyBseHNjaGVkdWxlci5TZXJ2aWNlUmVzb3VyY2VTY2hlZHVsZUhhbmRsZXJ7CiAgICAKICAgIC8vIFRoZSBtYWluIGludGVyZmFjZSBtZXRob2QuCiAgICBwdWJsaWMgc3RhdGljIExpc3Q8bHhzY2hlZHVsZXIuU2VydmljZVJlc291cmNlU2NoZWR1bGU+IGdldFVuYXZhaWxhYmxlVGltZXNsb3RzKGx4c2NoZWR1bGVyLlNlcnZpY2VBcHBvaW50bWVudFJlcXVlc3RJbmZvIHJlcXVlc3RJbmZvKXsKICAgICAgICAvL1JlcXVlc3QgaW5mbyB2YWx1ZXMuCiAgICAgICAgTGlzdDxseHNjaGVkdWxlci5TZXJ2aWNlUmVzb3VyY2VJb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ZHVsZXIuU2VydmljZVJlc291cmNlSW5mbyBTZXJ2aWNlUmVzb3VyY2U6c2VydmljZVJlc291cmNlcykgewogICAgICAgICAgICAvL1NldCB0aGUgdW5hdmFpbGFiaWxpdHkgb2YgU2VydmljZSByZXNvdXJjZS4KICAgICAgICByZXNvdXJjZVVuYXZhaWxhYmlsaXR5LmFkZChuZXcgbHhzY2hlZHVsZXIuU2VydmljZVJlc291cmNlU2NoZWR1bGUoc2VydmljZVJlc291cmNlLmdldFNlcnZpY2VSZXNvdXJjZUlkKCksdW5hdmFpbGFiaWxpdHlJbnRlcnZhbHMpKTsKCiAgICAgICB9CiAgICAgICAgCiAgICAgICAgcmV0dXJuIHJlc291cmNlVW5hdmFpbGFiaWxpdHk7CiAgICB9Cn0=