-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCompany.java
More file actions
1314 lines (1099 loc) · 51.8 KB
/
Company.java
File metadata and controls
1314 lines (1099 loc) · 51.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package bookingbugAPI.models;
import bookingbugAPI.api.AdminURLS;
import bookingbugAPI.api.PublicURLS;
import bookingbugAPI.models.params.*;
import com.damnhandy.uri.template.UriTemplate;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.module.jsonSchema.JsonSchema;
import com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper;
import com.theoryinpractise.halbuilder.api.ContentRepresentation;
import bookingbugAPI.services.HttpService;
import com.theoryinpractise.halbuilder.api.ReadableRepresentation;
import com.theoryinpractise.halbuilder.json.JsonRepresentationFactory;
import helpers.HttpServiceResponse;
import helpers.Utils;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.Map;
import static com.theoryinpractise.halbuilder.api.RepresentationFactory.HAL_JSON;
public class Company extends BBRoot{
private Service servicesList;
private Administrator administratorList;
private BBRoot administratorSchema;
public Company(HttpServiceResponse httpServiceResponse){
super(httpServiceResponse);
}
public Company(HttpServiceResponse httpServiceResponse, String auth_token){
super(httpServiceResponse);
this.auth_token = auth_token;
}
public Company() {}
/*
//TODO temp. until get the purchase from the content representation
public Purchase getPurchase () {
return new Purchase(this.getRep(), this.auth_token);
}
//TODO temp. until get the session from the content representation
public Purchase getSession () {
return new Purchase(this.getRep(), this.auth_token);
}
*/
/*
//TODO: kept for compatibility with ADMIN API until changed there
public Service getServicesList() throws IOException {
if(servicesList == null){
String link = response.getRep().getLinkByRel("services").getHref();
URL url = new URL(UriTemplate.fromTemplate(link).expand());
servicesList = new Service(HttpService.api_GET(url, auth_token), auth_token);
}
return servicesList;
}
*/
/**
* Load All of the Links and Properties of a Company
* @return CompanyConfig
* @throws IOException
*/
public CompanyConfig companyRead_Admin() throws IOException {
URL url = new URL (AdminURLS.Company.companyConfigRead().set("companyId", this.id).expand());
BBCollection<CompanyConfig> config = new BBCollection<CompanyConfig>(HttpService.api_GET(url, auth_token), auth_token, "config", CompanyConfig.class);
return config.getObjectAtIndex(0);
}
/**
* Get the Bookable Items Based on Another Item
* @param bilParams
* @return BBCollection<BookableItem>
* @throws IOException
*/
public BBCollection<BookableItem> bookableItemsList_Admin(BookableItemListParams bilParams) throws IOException {
String urlStr = AdminURLS.BookableItem.bookableItemList().set("companyId", this.id).expand();
URL url = new URL(Utils.inflateLink(urlStr, bilParams.getParams()));
BBCollection<BookableItem> bookableItems = new BBCollection<BookableItem>(HttpService.api_GET(url, auth_token), auth_token, "bookable_items", BookableItem.class);
return bookableItems;
}
/**
* Get All Bookable Services
* @return BBCollection<Service>
* @throws IOException
*/
public BBCollection<Service> serviceList() throws IOException {
URL url = new URL(PublicURLS.Service.serviceList().set("companyId", this.id).expand());
BBCollection<Service> services = new BBCollection<Service>(HttpService.api_GET(url, auth_token), auth_token, "services", Service.class);
return services;
}
public Service serviceNew_Admin() throws IOException {
URL url = new URL(AdminURLS.Service.serviceNew().set("companyId", this.id).expand());
BBCollection<Service> services = new BBCollection<Service>(HttpService.api_GET(url, auth_token), auth_token, "service", Service.class);
return services.getObjectAtIndex(0);
}
public Service serviceEdit_Admin(String serviceId) throws IOException {
URL url = new URL(AdminURLS.Service.serviceEdit().set("companyId", this.id).set("serviceId", serviceId).expand());
BBCollection<Service> services = new BBCollection<Service>(HttpService.api_GET(url, auth_token), auth_token, "service", Service.class);
return services.getObjectAtIndex(0);
}
/**
* List of Services for a Company.
* @return BBCollection<Service>
* @throws IOException
*/
public BBCollection<Service> serviceList_Admin(ServiceListParams slParams) throws IOException {
String urlStr = AdminURLS.Service.serviceList().set("companyId", this.id).expand();
URL url = new URL(Utils.inflateLink(urlStr, slParams.getParams()));
BBCollection<Service> services = new BBCollection<Service>(HttpService.api_GET(url, auth_token), auth_token, "services", Service.class);
return services;
}
/**
* Get a Specific Service.
* @param serviceId Service Id
* @return Service
* @throws IOException
*/
public Service serviceRead(String serviceId) throws IOException {
URL url = new URL(PublicURLS.Service.serviceRead().set("companyId", this.id).set("serviceId", serviceId).expand());
BBCollection<Service> services = new BBCollection<Service>(HttpService.api_GET(url, auth_token), auth_token, "service", Service.class);
return services.getObjectAtIndex(0);
}
/**
* Load a Specific Service Details
* @param serviceId
* @return Service
* @throws IOException
*/
public Service serviceRead_Admin(String serviceId) throws IOException {
URL url = new URL(AdminURLS.Service.serviceRead().set("companyId", this.id).set("serviceId", serviceId).expand());
BBCollection<Service> service = new BBCollection<Service>(HttpService.api_GET(url, auth_token), auth_token, "service", Service.class);
return service.getObjectAtIndex(0);
}
//TODO: kept for compatibility with AdminController until checked there
public People getPeopleList() throws IOException {
String link = response.getRep().getLinkByRel("people").getHref();
URL url = new URL(UriTemplate.fromTemplate(link).expand());
return new People(HttpService.api_GET(url, auth_token), auth_token);
}
/**
* Get All Bookable People for a Company.
* @return BBCollection<People>
* @throws IOException
*/
public BBCollection<People> personList() throws IOException {
URL url = new URL(PublicURLS.Person.personList().set("companyId", this.id).expand());
BBCollection<People> people = new BBCollection<People>(HttpService.api_GET(url, auth_token), auth_token, "people", People.class);
return people;
}
public BBCollection<People> personList_Admin(PeopleListParams plParams) throws IOException {
String urlStr = AdminURLS.Person.personList().set("companyId", this.id).expand();
URL url = new URL(Utils.inflateLink(urlStr, plParams.getParams()));
BBCollection<People> people = new BBCollection<People>(HttpService.api_GET(url, auth_token), auth_token, "people", People.class);
return people;
}
/**
* Get a Specific Bookable Person’s Details.
* @param personId Person Id
* @return People
* @throws IOException
*/
public People personRead(String personId) throws IOException {
URL url = new URL(PublicURLS.Person.personRead().set("companyId", this.id).set("personId", personId).expand());
BBCollection<People> people = new BBCollection<People>(HttpService.api_GET(url, auth_token), auth_token, "person", People.class);
return people.getObjectAtIndex(0);
}
/**
* Get a Specific Person Details using a Reference ID
* @return People
* @throws IOException
*/
public People personReadUsingReferenceId(String ref) throws IOException {
URL url = new URL(PublicURLS.Person.personReadUsingReferenceId().set("companyId", this.id).set("ref", ref).expand());
BBCollection<People> people = new BBCollection<People>(HttpService.api_GET(url, auth_token), auth_token, "person", People.class);
return people.getObjectAtIndex(0);
}
/**
* Get All Bookable Resources
* Results are returned as a paginated list.
* @return BBCollection<Resource>
* @throws IOException
*/
public BBCollection<Resource> resourceList() throws IOException {
URL url = new URL(PublicURLS.Resource.resourceList().set("companyId", this.id).expand());
BBCollection<Resource> resources = new BBCollection<Resource>(HttpService.api_GET(url, auth_token), auth_token, "resources", Resource.class);
return resources;
}
/**
* Get All Questions for a Company
* @param qlParams
* @return BBCollection<Resource>
* @throws IOException
*/
public BBCollection<Question> questionList_Admin(QuestionListParams qlParams) throws IOException {
String urlStr = AdminURLS.Question.questionList().set("companyId", this.id).expand();
URL url = new URL(Utils.inflateLink(urlStr, qlParams.getParams()));
BBCollection<Question> questions = new BBCollection<Question>(HttpService.api_GET(url, auth_token), auth_token, "questions", Question.class);
return questions;
}
/**
* resourceList_Admin
* @param rlParams
* @return BBCollection<Resource>
* @throws IOException
*/
public BBCollection<Resource> resourceList_Admin(ResourceListParams rlParams) throws IOException {
String urlStr = AdminURLS.Resource.resourceList().set("companyId", this.id).expand();
URL url = new URL(Utils.inflateLink(urlStr, rlParams.getParams()));
BBCollection<Resource> resources = new BBCollection<Resource>(HttpService.api_GET(url, auth_token), auth_token, "resources", Resource.class);
return resources;
}
/**
* Get a Specific Bookable Resource
* @param resourceId Resource Id
* @return Resource
* @throws IOException
*/
public Resource resourceRead(String resourceId) throws IOException {
URL url = new URL(PublicURLS.Resource.resourceRead().set("companyId", this.id).set("resourceId", resourceId).expand());
BBCollection<Resource> resource = new BBCollection<Resource>(HttpService.api_GET(url, auth_token), auth_token, "resources", Resource.class);
return resource.getObjectAtIndex(0);
}
/**
* Load a Specific Resource Details
* @param resourceId
* @return Resource
* @throws IOException
*/
public Resource resourceRead_Admin(String resourceId) throws IOException {
URL url = new URL(AdminURLS.Resource.resourceRead().set("companyId", this.id).set("resourceId", resourceId).expand());
BBCollection<Resource> resource = new BBCollection<Resource>(HttpService.api_GET(url, auth_token), auth_token, "resources", Resource.class);
return resource.getObjectAtIndex(0);
}
/**
* Search for a Range of Calendar Bookings for a Business.
* @param slParams SlotListParams
* @return BBCollection<Slot>
* @throws IOException
*/
public BBCollection<Slot> slotList_Admin(SlotListParams slParams) throws IOException {
String urlStr = AdminURLS.Slot.slotList().set("companyId", this.id).expand();
URL url = new URL(Utils.inflateLink(urlStr, slParams.getParams()));
BBCollection<Slot> slots = new BBCollection<Slot>(HttpService.api_GET(url, auth_token), auth_token, "slots", Slot.class);
return slots;
}
/**
* Get the Details and Links of a Specific Booked Slot
* @param slotId
* @return Slot
* @throws IOException
*/
public Slot slotRead_Admin(String slotId) throws IOException {
URL url = new URL(AdminURLS.Slot.slotRead().set("companyId", this.id).set("slotId", slotId).expand());
BBCollection<Slot> slots = new BBCollection<Slot>(HttpService.api_GET(url, auth_token), auth_token, "slots", Slot.class);
return slots.getObjectAtIndex(0);
}
/**
* Load All of the Links and Properties of a Company
* @param companyId Company Id
* @return Resource
* @throws IOException
*/
public Resource companyDetails(String companyId) throws IOException {
URL url = new URL(PublicURLS.Details.companyDetails().set("companyId", companyId).expand());
return new Resource(HttpService.api_GET(url, auth_token), auth_token);
}
/**
* Get a List of Bookable Events.
* @return BBCollection<Event>
* @throws IOException
*/
public BBCollection<Event> eventList() throws IOException {
return eventList(new Params());
}
/**
* Get a List of Bookable Events.
* @param params Parameters for pagination
* @return BBCollection<Event>
* @throws IOException
*/
public BBCollection<Event> eventList(Params params) throws IOException {
UriTemplate template = Utils.TemplateWithPagination(
PublicURLS.Event.eventList().set("companyId", this.id),
params);
URL url = new URL(template.expand());
return new BBCollection<Event>(HttpService.api_GET(url, auth_token), auth_token, "events", Event.class);
}
/**
* Get a Specific Event.
* @return Event
* @throws IOException
*/
public Event eventRead(String eventId) throws IOException {
URL url = new URL(PublicURLS.Event.eventRead().set("companyId", this.id).set("eventId", eventId).expand());
BBCollection<Event> events = new BBCollection<Event>(HttpService.api_GET(url), auth_token, "events", Event.class);
return events.getObjectAtIndex(0);
}
/**
* Get the Bookable Items Based on Another Item
* @return BBCollection<BookableItem>
* @throws IOException
*/
public BBCollection<BookableItem> bookableItemsList() throws IOException {
URL url = new URL(PublicURLS.Bookable.bookableItemsList().set("companyId", this.id).expand());
BBCollection<BookableItem> bookableItems = new BBCollection<BookableItem>(HttpService.api_GET(url, auth_token), auth_token, "items", BookableItem.class);
return bookableItems;
}
/**
* This loads a list of bookable items for a particular date
* @return BBCollection<BookableItem>
* @throws IOException
*/
public BBCollection<BookableItem> bookableItemsByDate(String date) throws IOException {
URL url = new URL(PublicURLS.Bookable.bookableItemsByDate().set("companyId", this.id).set("date", date).expand());
BBCollection<BookableItem> bookableItems = new BBCollection<BookableItem>(HttpService.api_GET(url, auth_token), auth_token, "bookable_items_by_date", BookableItem.class);
return bookableItems;
}
/**
* Get Data for a range of Days
* @return Resource
* @throws IOException
*/
public BBRoot availabilityDaysForBookableItem(TimeDataParams params) throws IOException {
URL url = new URL(
PublicURLS.Bookable.availabilityDaysForBookableItem()
.set("companyId", this.id)
.set((Map)params.getParams())
.expand());
return new BBRoot(HttpService.api_GET(url, auth_token), auth_token);
}
/**
* Get Data for availabile times for a day
* @return Resource
* @throws IOException
*/
public BBCollection<BookableAvailability> availabilityTimesForBookableItem(TimeDataParams params) throws IOException {
URL url = new URL(
PublicURLS.Bookable.availabilityTimesForBookableItem()
.set("companyId", this.id)
.set((Map)params.getParams())
.expand());
return new BBCollection<BookableAvailability>(HttpService.api_GET(url, auth_token), auth_token, "events", BookableAvailability.class);
}
/**
* Check if available
* @return Resource
* @throws IOException
*/
public Resource availabilityCheck(String dateTime) throws IOException {
URL url = new URL(PublicURLS.Bookable.availabilityCheck().set("companyId", this.id).set("dateTime", dateTime).expand());
return new Resource(HttpService.api_GET(url, auth_token), auth_token);
}
/**
* Details about how a client should book
* @return Resource
* @throws IOException
*/
public Resource memberBookingDetails() throws IOException {
URL url = new URL(PublicURLS.Bookable.memberBookingDetails().set("companyId", this.id).expand());
return new Resource(HttpService.api_GET(url, auth_token), auth_token);
}
/**
* Get All Event Groups.
* @return BBCollection<EventGroup>
* @throws IOException
*/
public BBCollection<EventGroup> eventGroupList() throws IOException {
URL url = new URL(PublicURLS.EventGroup.eventGroupList().set("companyId", this.id).expand());
BBCollection<EventGroup> eventGroups = new BBCollection<EventGroup>(HttpService.api_GET(url, auth_token), auth_token, "event_groups", EventGroup.class);
eventGroups.setCollectionNameSpace("");
return eventGroups;
}
/**
* Get a Specific Event Group.
* @return EventGroup
* @throws IOException
*/
public EventGroup eventGroupRead(String eventGroupId) throws IOException {
URL url = new URL (PublicURLS.EventGroup.eventGroupRead().set("companyId", this.id).set("serviceId", eventGroupId).expand());
BBCollection<EventGroup> eventGroups = new BBCollection<EventGroup>(HttpService.api_GET(url, auth_token), auth_token, "event_group", EventGroup.class);
return eventGroups.getObjectAtIndex(0);
}
/**
* Get a List of Courses or Repeating Events for a Company.
* @return BBCollection<EventChain>
* @throws IOException
*/
public BBCollection<EventChain> eventChainList() throws IOException {
return eventChainList(new Params());
}
/**
* Get a List of Courses or Repeating Events for a Company.
* @param params Parameters for pagination
* @return BBCollection<EventChain>
* @throws IOException
*/
public BBCollection<EventChain> eventChainList(Params params) throws IOException {
UriTemplate template = Utils.TemplateWithPagination(
PublicURLS.EventChain.eventChainList().set("companyId", this.id),
params);
URL url = new URL(template.expand());
BBCollection<EventChain> eventChains = new BBCollection<EventChain>(HttpService.api_GET(url, auth_token), auth_token, "event_chains", EventChain.class);
return eventChains;
}
/**
* Get a Specific Event Chain.
* @return EventChain
* @throws IOException
*/
public EventChain eventChainRead(String eventChainId) throws IOException {
URL url = new URL (PublicURLS.EventChain.eventChainRead().set("companyId", this.id).set("eventChainId", eventChainId).expand());
BBCollection<EventChain> eventChains = new BBCollection<EventChain>(HttpService.api_GET(url, auth_token), auth_token, "event_chain", EventChain.class);
return eventChains.getObjectAtIndex(0);
}
/**
* Get All Questions for a Company.
* <BR>Results are returned as a group of question for a specific question group.
* @return BBCollection<BookingQuestion>
* @throws IOException
*/
public BBCollection<BookingQuestion> bookingQuestionList(String detailGroupId) throws IOException {
URL url = new URL(PublicURLS.BookingQuestion.bookingQuestionList().set("companyId", this.id).set("detailGroupId", detailGroupId).expand());
BBCollection<BookingQuestion> bokingQuestions = new BBCollection<BookingQuestion>(HttpService.api_GET(url, auth_token), auth_token, "booking_questions", BookingQuestion.class);
return bokingQuestions;
}
/**
* Question Read
* @param questionId Question Id
* @return BookingQuestion
* @throws IOException
*/
public BookingQuestion bookingQuestionRead(String questionId) throws IOException {
URL url = new URL(PublicURLS.BookingQuestion.bookingQuestionRead().set("companyId", this.id).set("questionId", questionId).expand());
BBCollection<BookingQuestion> bokingQuestions = new BBCollection<BookingQuestion>(HttpService.api_GET(url, auth_token), auth_token, "booking_question", BookingQuestion.class);
return bokingQuestions.getObjectAtIndex(0);
}
/**
* Get all Survey Questions for a Service
* @param detail_group_id Question Group Id
* @return BBCollection<SurveyQuestion>
* @throws IOException
*/
public BBCollection<SurveyQuestion> surveyQuestionList(String detail_group_id) throws IOException {
URL url = new URL(PublicURLS.SurveyQuestion.surveyQuestionList().set("companyId", this.id).set("detail_group_id", detail_group_id).expand());
BBCollection<SurveyQuestion> surveyQuestions = new BBCollection<SurveyQuestion>(HttpService.api_GET(url, auth_token), auth_token, "survey_questions", SurveyQuestion.class);
return surveyQuestions;
}
/**
* List of Categories for a Company.
* @return BBCollection<Category>
* @throws IOException
*/
public BBCollection<Category> categoryList() throws IOException {
URL url = new URL(PublicURLS.Category.categoryList().set("companyId", this.id).expand());
BBCollection<Category> categories = new BBCollection<Category>(HttpService.api_GET(url, auth_token), auth_token, "survey_question", Category.class);
categories.setCollectionNameSpace("categories");
return categories;
}
/**
* Load a Specific Category Details
* @param categoryId Category Id
* @return Category
* @throws IOException
*/
public Category categoryRead(String categoryId) throws IOException {
URL url = new URL(PublicURLS.Category.categoryRead().set("companyId", this.id).set("categoryId", categoryId).expand());
BBCollection<Category> categories = new BBCollection<Category>(HttpService.api_GET(url, auth_token), auth_token, "categories", Category.class);
return (Category)categories.getObjectAtIndex(0);
}
/**
* List of Categories for a Company
* @return Resource
* @throws IOException
*/
public Resource categoryNamedList() throws IOException {
URL url = new URL(PublicURLS.Category.categoryNamedList().set("companyId", this.id).expand());
return new Resource(HttpService.api_GET(url, auth_token), auth_token);
}
/**
* Create a new client for a business
* @return Resource
* @throws IOException
*/
public Resource createClient() throws IOException {
URL url = new URL(PublicURLS.Client.createClient().set("companyId", this.id).expand());
return new Resource(HttpService.api_GET(url, auth_token), auth_token);
}
/**
* Update a client.
* @param clientId
* @return Resource
* @throws IOException
*/
public Resource updateClient(String clientId) throws IOException {
URL url = new URL(PublicURLS.Client.updateClient().set("companyId", this.id).set("clientId", clientId).expand());
return new Resource(HttpService.api_GET(url, auth_token), auth_token);
}
/**
* Search for a client by email against the company that you are currently logged in as
* @param email Email
* @return Resource
* @throws IOException
*/
public Client findByEmail(String email) throws IOException {
URL url = new URL(PublicURLS.Client.findByEmail().set("companyId", this.id).set("email", email).expand());
BBCollection<Client> clients = new BBCollection<Client>(HttpService.api_GET(url, auth_token), auth_token, "clients", Client.class);
return clients.getObjectAtIndex(0);
}
/**
* Get all the child clients of a particular client
* @param clientId Client Id
* @return Resource
* @throws IOException
*/
public BBCollection<Client> childClientsRead(String clientId) throws IOException {
URL url = new URL(PublicURLS.Client.readChildClients().set("companyId", this.id).set("clientId", clientId).expand());
BBCollection<Client> childClients = new BBCollection<Client>(HttpService.api_GET(url, auth_token), auth_token, "clients", Client.class);
childClients.setCollectionNameSpace("child_clients");
return childClients;
}
/**
* Get All Custom Booking Text for a Company
* @return
* @throws IOException
*/
public Resource bookingTextList() throws IOException {
URL url = new URL(PublicURLS.BookingText.getBookingText().set("companyId", this.id).expand());
return new Resource(HttpService.api_GET(url, auth_token), auth_token);
}
/**
* Get all possible Space Statuses for a Company
* @return Resource
* @throws IOException
*/
public Resource spaceStatusList() throws IOException {
URL url = new URL(PublicURLS.Company.spaceStatusList().set("companyId", this.id).expand());
return new Resource(HttpService.api_GET(url));
}
/**
* Loads all of the public settings for a company, this allows you to configure a booking widget,
* and shows all of the details need to book and show an appropriate widget.
* @return CompanySettings
* @throws IOException
*/
public CompanySettings getSettings() throws IOException {
if(getRep().getResourcesByRel("settings").size() > 0) {
//Return settings from embedded
return new CompanySettings(new HttpServiceResponse((ContentRepresentation) getRep().getResourcesByRel("settings").get(0)));
} else {
//Call API
URL url = new URL(PublicURLS.Company.settingsDetails().set("companyId", this.id).expand());
return new CompanySettings(HttpService.api_GET(url));
}
}
/**
* You can either get all the company questions or pass a param to specifiy that you only want company questions
* that apply to either a service, resource, person, company:
* <BR>Service = 1, Resource = 2, Person = 3, Company = 4.
* @return Resource
* @throws IOException
*/
public Resource businessQuestions() throws IOException {
URL url = new URL(PublicURLS.Company.businessQuestions().set("companyId", this.id).expand());
return new Resource(HttpService.api_GET(url));
}
/**
* Get All Addresses for a Company.
* <BR>Provide a company id to retrieve a list of addresses associated with that company.
* This is a list of company branch/store/resource addresses, not client addresses.
* Results are returned as a paginated list.
* @return Resource
* @throws IOException
*/
public BBCollection<Address> addressList() throws IOException {
URL url = new URL(PublicURLS.Address.addressList().set("companyId", this.id).expand());
BBCollection<Address> addresses = new BBCollection<Address>(HttpService.api_GET(url), auth_token, "addresses", Address.class);
return addresses;
}
/**
* Get All Addresses for a Company.
* @param alParams AddressListParams
* @return BBCollection<Address>
* @throws IOException
*/
public BBCollection<Address> addressList_Admin(AddressListParams alParams) throws IOException {
String urlStr = AdminURLS.Address.addressList().set("companyId", this.id).expand();
URL url = new URL(Utils.inflateLink(urlStr, alParams.getParams()));
BBCollection<Address> addresses = new BBCollection<Address>(HttpService.api_GET(url, auth_token), auth_token, "addresses", Address.class);
return addresses;
}
/**
* Get a Specific Address.
* <BR>Provide a company id and address id to retrieve the details and links of that branch/store/resource address.
* @param addressId Address Id
* @return Resource
* @throws IOException
*/
public Address addressRead(String addressId) throws IOException {
URL url = new URL (AdminURLS.Address.addressRead().set("companyId", this.id).set("addressId", addressId).expand());
BBCollection<Address> addresses = new BBCollection<Address>(HttpService.api_GET(url, auth_token), auth_token, "address", Address.class);
return addresses.getObjectAtIndex(0);
}
public Address addressRead_Admin(String addressId) throws IOException {
URL url = new URL (AdminURLS.Address.addressRead().set("companyId", this.id).set("id", addressId).expand());
BBCollection<Address> addresses = new BBCollection<Address>(HttpService.api_GET(url, auth_token), auth_token, "address", Address.class);
return addresses.getObjectAtIndex(0);
}
/**
* Sessions. Results are returned as a paginated list.
* @param slParams
* @return BBCollection<Session>
* @throws IOException
*/
public BBCollection<Session> sessionList_Admin(SessionListParams slParams) throws IOException {
String urlStr = AdminURLS.Session.sessionList().set("companyId", this.id).expand();
URL url = new URL(Utils.inflateLink(urlStr, slParams.getParams()));
BBCollection<Session> sessions = new BBCollection<Session>(HttpService.api_GET(url, auth_token), auth_token, "sessions", Session.class);
return sessions;
}
public Session sessionRead_Admin(String sessionId) throws IOException {
URL url = new URL (AdminURLS.Session.sessionRead().set("companyId", this.id).set("sessionId", sessionId).expand());
BBCollection<Session> session = new BBCollection<Session>(HttpService.api_GET(url, auth_token), auth_token, "session", Session.class);
return session.getObjectAtIndex(0);
}
/**
* Get the address result for a particular customer
* @param customerId Customer Id
* @return Resource
* @throws IOException
*/
public Address customerAddress(String customerId) throws IOException {
URL url = new URL(PublicURLS.Address.customerAddress().set("companyId", this.id).set("customerId", customerId).expand());
BBCollection<Address> addresses = new BBCollection<Address>(HttpService.api_GET(url, auth_token), auth_token, "addresses", Address.class);
return addresses.getObjectAtIndex(0);
}
/**
* Get a list of possible addresses from a postcode
* @param postcode Postcode
* @return Resource
* @throws IOException
*/
public BBCollection<Address> postCodeAddress(String postcode) throws IOException {
URL url = new URL(PublicURLS.Address.postCodeAddress().set("companyId", this.id).set("postcode", postcode).expand());
BBCollection<Address> addresses = new BBCollection<Address>(HttpService.api_GET(url, auth_token), auth_token, "addresses", Address.class);
addresses.setCollectionNameSpace("address");
return addresses;
}
/**
* Get all Products for a Company
* @return Resource
* @throws IOException
*/
public BBCollection<Product> productsList() throws IOException {
URL url = new URL(PublicURLS.Products.productsList().set("companyId", this.id).expand());
BBCollection<Product> products = new BBCollection<Product>(HttpService.api_GET(url), auth_token, "products", Product.class);
return products;
}
/**
* Get a specific Product
* @param productId Product Id
* @return Resource
* @throws IOException
*/
public Product productsRead(String productId) throws IOException {
URL url = new URL (PublicURLS.Products.productRead().set("companyId", this.id).set("productId", productId).expand());
BBCollection<Product> products = new BBCollection<Product>(HttpService.api_GET(url, auth_token), auth_token, "product", Product.class);
return products.getObjectAtIndex(0);
}
/**
* Slot List
* @return Resource
* @throws IOException
*/
public BBCollection<Slot> slotList() throws IOException {
URL url = new URL(PublicURLS.Slot.slotList().set("companyId", this.id).expand());
BBCollection<Slot> slots = new BBCollection<Slot>(HttpService.api_GET(url), auth_token, "slots", Slot.class);
return slots;
}
/**
* Slot Read
* @param slotId Slot Id
* @return Resource
* @throws IOException
*/
public Slot slotRead(String slotId) throws IOException {
URL url = new URL(PublicURLS.Slot.slotRead().set("companyId", this.id).set("slotId", slotId).expand());
BBCollection<Slot> slots = new BBCollection<Slot>(HttpService.api_GET(url), auth_token, "slot", Slot.class);
return slots.getObjectAtIndex(0);
}
/**
* Get a list of images attached to an event group.
* @param eventGroupId Event Group Id
* @return Resource
* @throws IOException
*/
public Resource eventGroupImagesList(String eventGroupId) throws IOException {
URL url = new URL(PublicURLS.EventGroupImages.eventGroupImagesList().set("companyId", this.id).set("eventGroupId", eventGroupId).expand());
return new Resource(HttpService.api_GET(url), auth_token);
}
/**
* TODO: ???
* @param eventGroupId Event Group Id
* @param id Id
* @return
* @throws IOException
*/
public Resource eventGroupImages_f(String eventGroupId, String id) throws IOException {
URL url = new URL(PublicURLS.EventGroupImages.eventGroupImages_f().set("companyId", this.id).set("eventGroupId", eventGroupId).set("id", id).expand());
return new Resource(HttpService.api_GET(url), auth_token);
}
/**
* Get all the deals for a Company
* @return Resource
* @throws IOException
*/
public Resource dealList() throws IOException {
URL url = new URL(PublicURLS.Deal.dealList().set("companyId", this.id).expand());
return new Resource(HttpService.api_GET(url), auth_token);
}
/**
* Get all the deals for a Company.
* @return BBCollection<Deal>
* @throws IOException
*/
public BBCollection<Deal> dealList_Admin() throws IOException {
URL url = new URL (AdminURLS.Deal.dealList().set("companyId", this.id).expand());
BBCollection<Deal> deals = new BBCollection<Deal>(HttpService.api_GET(url, auth_token), auth_token, "deals", Deal.class);
return deals;
}
/**
* Get the deal from a company using the reference id.
* @param referenceId
* @return Deal
* @throws IOException
*/
public Deal dealReadByRef_Admin(String referenceId) throws IOException {
URL url = new URL (AdminURLS.Deal.dealReadByRef().set("companyId", this.id).set("referenceId", referenceId).expand());
BBCollection<Deal> deals = new BBCollection<Deal>(HttpService.api_GET(url, auth_token), auth_token, "deal", Deal.class);
return deals.getObjectAtIndex(0);
}
/**
* List all the deals codes for a deal
* @param dealId
* @return BBCollection<DealCodes>
* @throws IOException
*/
public BBCollection<DealCodes> dealCodesList_Admin(String dealId) throws IOException {
URL url = new URL (AdminURLS.Deal.dealCodes().set("companyId", this.id).set("dealId", dealId).expand());
BBCollection<DealCodes> dealCodes = new BBCollection<DealCodes>(HttpService.api_GET(url, auth_token), auth_token, "dealCodes", DealCodes.class);
return dealCodes;
}
/**
* Get A Deal
* @param dealId Deal Id
* @return Resource
* @throws IOException
*/
public Resource dealRead(String dealId) throws IOException {
URL url = new URL(PublicURLS.Deal.dealRead().set("companyId", this.id).set("dealId", dealId).expand());
return new Resource(HttpService.api_GET(url), auth_token);
}
/**
* Get all the service groups for a Company
* @return Resource
* @throws IOException
*/
public Resource serviceGroupList() throws IOException {
URL url = new URL(PublicURLS.ServiceGroup.serviceGroupList().set("companyId", this.id).expand());
return new Resource(HttpService.api_GET(url), auth_token);
}
/**
* Get a Service Group
* @param groupId Group Id
* @return Resource
* @throws IOException
*/
public Resource serviceGroupRead(String groupId) throws IOException {
URL url = new URL(PublicURLS.ServiceGroup.serviceGroupRead().set("companyId", this.id).set("groupId", groupId).expand());
return new Resource(HttpService.api_GET(url), auth_token);
}
/**
* Get Contents and Details of the Current Cached Basket
* @return Resource
* @throws IOException
*/
public Resource readBasket() throws IOException {
URL url = new URL(PublicURLS.Basket.readBasket().set("companyId", this.id).expand());
return new Resource(HttpService.api_GET(url), auth_token);
}
/**
* Add Shopping Item To Basket
* @return Resource
* @throws IOException
*/
public Resource createBasketItem() throws IOException {
URL url = new URL(PublicURLS.Basket.createBasketItem().set("companyId", this.id).expand());
return new Resource(HttpService.api_POST(url, auth_token), auth_token);
}
/**
* Confirm and Pay for the Items in the Shopping Basket
* @return Resource
* @throws IOException
*/
public Resource checkoutBasket() throws IOException {
URL url = new URL(PublicURLS.Basket.checkoutBasket().set("companyId", this.id).expand());
return new Resource(HttpService.api_POST(url, auth_token), auth_token);
}
/**
* Empty the Shopping Basket
* @return Resource
* @throws IOException
*/
public Resource deleteBasket() throws IOException {
URL url = new URL(PublicURLS.Basket.deleteBasket().set("companyId", this.id).expand());
this.id = "";
return new Resource(HttpService.api_DELETE(url), auth_token);
}
/**
* Get the Details of a Specific Item in the Shopping Basket
* @param basketItemId Basket Item Id
* @return Resource
* @throws IOException
*/
public Resource readBasketItem(String basketItemId) throws IOException {
URL url = new URL(PublicURLS.Basket.readBasketItem().set("companyId", this.id).set("basketItemId", basketItemId).expand());
return new Resource(HttpService.api_GET(url), auth_token);
}
/**
* Remove an Item for the Shopping Basket
* @param basketItemId Basket Item Id
* @return Resource
* @throws IOException
*/
public Resource deleteBasketItem(String basketItemId) throws IOException {
URL url = new URL(PublicURLS.Basket.deleteBasketItem().set("companyId", this.id).set("basketItemId", basketItemId).expand());
return new Resource(HttpService.api_DELETE(url), auth_token);
}
/**