-
Notifications
You must be signed in to change notification settings - Fork 477
/
KaaAdminController.java
2181 lines (2046 loc) · 87.1 KB
/
KaaAdminController.java
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
/*
* Copyright 2014-2016 CyberVision, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kaaproject.kaa.server.admin.controller;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.util.StringUtils.isEmpty;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.kaaproject.kaa.common.dto.ApplicationDto;
import org.kaaproject.kaa.common.dto.ConfigurationDto;
import org.kaaproject.kaa.common.dto.ConfigurationRecordDto;
import org.kaaproject.kaa.common.dto.ConfigurationSchemaDto;
import org.kaaproject.kaa.common.dto.EndpointGroupDto;
import org.kaaproject.kaa.common.dto.EndpointNotificationDto;
import org.kaaproject.kaa.common.dto.EndpointProfileBodyDto;
import org.kaaproject.kaa.common.dto.EndpointProfileDto;
import org.kaaproject.kaa.common.dto.EndpointProfileSchemaDto;
import org.kaaproject.kaa.common.dto.EndpointProfilesBodyDto;
import org.kaaproject.kaa.common.dto.EndpointProfilesPageDto;
import org.kaaproject.kaa.common.dto.EndpointUserConfigurationDto;
import org.kaaproject.kaa.common.dto.KaaAuthorityDto;
import org.kaaproject.kaa.common.dto.NotificationDto;
import org.kaaproject.kaa.common.dto.NotificationSchemaDto;
import org.kaaproject.kaa.common.dto.PageLinkDto;
import org.kaaproject.kaa.common.dto.ProfileFilterDto;
import org.kaaproject.kaa.common.dto.ProfileFilterRecordDto;
import org.kaaproject.kaa.common.dto.ProfileVersionPairDto;
import org.kaaproject.kaa.common.dto.ServerProfileSchemaDto;
import org.kaaproject.kaa.common.dto.TopicDto;
import org.kaaproject.kaa.common.dto.VersionDto;
import org.kaaproject.kaa.common.dto.admin.AuthResultDto;
import org.kaaproject.kaa.common.dto.admin.RecordKey;
import org.kaaproject.kaa.common.dto.admin.ResultCode;
import org.kaaproject.kaa.common.dto.admin.SchemaVersions;
import org.kaaproject.kaa.common.dto.admin.SdkPlatform;
import org.kaaproject.kaa.common.dto.admin.SdkProfileDto;
import org.kaaproject.kaa.common.dto.admin.TenantUserDto;
import org.kaaproject.kaa.common.dto.admin.UserDto;
import org.kaaproject.kaa.common.dto.credentials.CredentialsDto;
import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto;
import org.kaaproject.kaa.common.dto.ctl.CTLSchemaExportMethod;
import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto;
import org.kaaproject.kaa.common.dto.event.AefMapInfoDto;
import org.kaaproject.kaa.common.dto.event.ApplicationEventFamilyMapDto;
import org.kaaproject.kaa.common.dto.event.EcfInfoDto;
import org.kaaproject.kaa.common.dto.event.EventClassDto;
import org.kaaproject.kaa.common.dto.event.EventClassFamilyDto;
import org.kaaproject.kaa.common.dto.event.EventClassType;
import org.kaaproject.kaa.common.dto.file.FileData;
import org.kaaproject.kaa.common.dto.logs.LogAppenderDto;
import org.kaaproject.kaa.common.dto.logs.LogSchemaDto;
import org.kaaproject.kaa.common.dto.user.UserVerifierDto;
import org.kaaproject.kaa.server.admin.services.cache.CacheService;
import org.kaaproject.kaa.server.admin.services.dao.UserFacade;
import org.kaaproject.kaa.server.admin.services.entity.CreateUserResult;
import org.kaaproject.kaa.server.admin.services.util.Utils;
import org.kaaproject.kaa.server.admin.servlet.ServletUtils;
import org.kaaproject.kaa.server.admin.shared.services.KaaAdminService;
import org.kaaproject.kaa.server.admin.shared.services.KaaAdminServiceException;
import org.kaaproject.kaa.server.admin.shared.services.KaaAuthService;
import org.kaaproject.kaa.server.admin.shared.services.ServiceErrorCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spring4gwt.server.SpringGwtRemoteServiceServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpStatus;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.multipart.MultipartFile;
/**
* The Class KaaAdminController.
*/
@Controller
@RequestMapping("api")
public class KaaAdminController {
/** The Constant LOG. */
private static final Logger LOG = LoggerFactory.getLogger(KaaAdminController.class);
/** The Constant BUFFER. */
private static final int BUFFER = 1024 * 100;
/** The Constant DEFAULT_LIMIT. */
private static final String DEFAULT_LIMIT = "20";
/** The Constant DEFAULT_OFFSET. */
private static final String DEFAULT_OFFSET = "0";
/** The Constant HTTPS_PORT. */
public static final int HTTPS_PORT = 443;
/** The Constant HTTP_PORT. */
public static final int HTTP_PORT = 80;
private static final Charset DECODING_CHARSET = Charset.forName("ISO-8859-1");
/** The kaa admin service. */
@Autowired
KaaAdminService kaaAdminService;
/** The kaa auth service. */
@Autowired
KaaAuthService kaaAuthService;
/** The user facade. */
@Autowired
UserFacade userFacade;
/** The password encoder. */
@Autowired
@Qualifier("encoder")
PasswordEncoder passwordEncoder;
/** The cache service. */
@Autowired
private CacheService cacheService;
@ExceptionHandler(KaaAdminServiceException.class)
public void handleKaaAdminServiceException(KaaAdminServiceException ex, HttpServletResponse response) {
try {
ServiceErrorCode errorCode = ex.getErrorCode();
switch (errorCode) {
case NOT_AUTHORIZED:
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, ex.getMessage());
break;
case PERMISSION_DENIED:
response.sendError(HttpServletResponse.SC_FORBIDDEN, ex.getMessage());
break;
case INVALID_ARGUMENTS:
response.sendError(HttpServletResponse.SC_BAD_REQUEST, ex.getMessage());
break;
case INVALID_SCHEMA:
response.sendError(HttpServletResponse.SC_BAD_REQUEST, ex.getMessage());
break;
case FILE_NOT_FOUND:
response.sendError(HttpServletResponse.SC_NOT_FOUND, ex.getMessage());
break;
case ITEM_NOT_FOUND:
response.sendError(HttpServletResponse.SC_NOT_FOUND, ex.getMessage());
break;
case BAD_REQUEST_PARAMS:
response.sendError(HttpServletResponse.SC_BAD_REQUEST, ex.getMessage());
break;
case GENERAL_ERROR:
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getMessage());
break;
case CONFLICT:
response.sendError(HttpServletResponse.SC_CONFLICT, ex.getMessage());
default:
break;
}
} catch (IOException e) {
LOG.error("Can't handle exception", e);
}
}
/**
* Gets the endpoint profile by endpoint group id.
*
* @param endpointGroupId
* the endpoint group id
* @param limit
* the limit
* @param offset
* the offset
* @param request
* the request
* @return the endpoint profiles page dto
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "endpointProfileByGroupId", method = RequestMethod.GET, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public EndpointProfilesPageDto getEndpointProfileByEndpointGroupId(@RequestParam(value = "endpointGroupId") String endpointGroupId,
@RequestParam(value = "limit", defaultValue = DEFAULT_LIMIT) String limit,
@RequestParam(value = "offset", defaultValue = DEFAULT_OFFSET) String offset, HttpServletRequest request)
throws KaaAdminServiceException {
EndpointProfilesPageDto endpointProfilesPageDto = kaaAdminService.getEndpointProfileByEndpointGroupId(endpointGroupId, limit,
offset);
if (endpointProfilesPageDto.hasEndpointProfiles()) {
PageLinkDto pageLinkDto = createNext(endpointProfilesPageDto.getPageLinkDto(), request);
endpointProfilesPageDto.setNext(pageLinkDto.getNext());
}
return endpointProfilesPageDto;
}
/**
* Gets the endpoint profile body by endpoint group id.
*
* @param endpointGroupId
* the endpoint group id
* @param limit
* the limit
* @param offset
* the offset
* @param request
* the request
* @return the endpoint profiles body dto
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "endpointProfileBodyByGroupId", method = RequestMethod.GET, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public EndpointProfilesBodyDto getEndpointProfileBodyByEndpointGroupId(@RequestParam(value = "endpointGroupId") String endpointGroupId,
@RequestParam(value = "limit", defaultValue = DEFAULT_LIMIT) String limit,
@RequestParam(value = "offset", defaultValue = DEFAULT_OFFSET) String offset, HttpServletRequest request)
throws KaaAdminServiceException {
EndpointProfilesBodyDto endpointProfilesBodyDto = kaaAdminService.getEndpointProfileBodyByEndpointGroupId(endpointGroupId, limit,
offset);
if (endpointProfilesBodyDto.hasEndpointBodies()) {
PageLinkDto pageLinkDto = createNext(endpointProfilesBodyDto.getPageLinkDto(), request);
endpointProfilesBodyDto.setNext(pageLinkDto.getNext());
}
return endpointProfilesBodyDto;
}
private PageLinkDto createNext(PageLinkDto pageLink, HttpServletRequest request) {
if (pageLink != null && pageLink.getNext() == null) {
StringBuilder nextUrl = new StringBuilder();
nextUrl.append(request.getScheme()).append("://").append(request.getServerName());
int port = request.getServerPort();
if (HTTP_PORT != port && HTTPS_PORT != port) {
nextUrl.append(":").append(port);
}
String next = nextUrl.append(request.getRequestURI()).append("?").append(pageLink.getNextUrlPart()).toString();
pageLink.setNext(next);
LOG.debug("Generated next url {}", next);
}
return pageLink;
}
/**
* Gets the endpoint profile by endpoint key.
*
* @param endpointProfileKey
* the endpoint profile key
* @return the endpoint profile dto
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "endpointProfile/{endpointProfileKey}", method = RequestMethod.GET)
@ResponseBody
public EndpointProfileDto getEndpointProfileByKeyHash(@PathVariable String endpointProfileKey) throws KaaAdminServiceException {
return kaaAdminService.getEndpointProfileByKeyHash(endpointProfileKey);
}
/**
* Gets the endpoint profile body by endpoint key.
*
* @param endpointProfileKey
* the endpoint profile key
* @return the endpoint profile body dto
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "endpointProfileBody/{endpointProfileKey}", method = RequestMethod.GET)
@ResponseBody
public EndpointProfileBodyDto getEndpointProfileBodyByKeyHash(@PathVariable String endpointProfileKey) throws KaaAdminServiceException {
return kaaAdminService.getEndpointProfileBodyByKeyHash(endpointProfileKey);
}
/**
* Remove the endpoint with specific profile key.
*
* @param endpointProfileKeyHash
*
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "removeEndpointProfileByKeyHash", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void removeEndpointProfileByKeyHash(@RequestParam(value = "endpointProfileKeyHash") String endpointProfileKeyHash) throws KaaAdminServiceException {
kaaAdminService.removeEndpointProfileByKeyHash(endpointProfileKeyHash);
}
/**
* Update server profile of endpoint.
*
* @param endpointProfileKey
* the endpoint profile key
* @param version
* the version
* @param serverProfileBody
* the server profile body
* @return the endpoint profile dto
* @throws Exception
* the exception
*/
@RequestMapping(value = "updateServerProfile", method = RequestMethod.POST)
@ResponseBody
public EndpointProfileDto updateServerProfile(@RequestParam(value = "endpointProfileKey") String endpointProfileKey,
@RequestParam(value = "version") int version, @RequestParam(value = "serverProfileBody") String serverProfileBody)
throws Exception {
return kaaAdminService.updateServerProfile(endpointProfileKey, version, serverProfileBody);
}
/**
* Check auth of kaa admin.
*
* @param request
* the request
* @return the auth result dto
* @throws Exception
* the exception
*/
@RequestMapping(value = "auth/checkAuth", method = RequestMethod.GET)
@ResponseBody
public AuthResultDto checkAuth(HttpServletRequest request) throws Exception {
SpringGwtRemoteServiceServlet.setRequest(request);
try {
return kaaAuthService.checkAuth();
} finally {
SpringGwtRemoteServiceServlet.setRequest(null);
}
}
/**
* Creates the kaa admin with specific name and password.
*
* @param username
* the username
* @param password
* the password
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "auth/createKaaAdmin", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void createKaaAdmin(@RequestParam(value = "username") String username, @RequestParam(value = "password") String password)
throws KaaAdminServiceException {
if (!userFacade.isAuthorityExists(KaaAuthorityDto.KAA_ADMIN.name())) {
kaaAuthService.createKaaAdmin(username, password);
} else {
throw new KaaAdminServiceException("Kaa admin already exists. Can't create more than one kaa admin users.",
ServiceErrorCode.PERMISSION_DENIED);
}
}
/**
* Change password of user with specific name if old password valid.
*
* @param username
* the username
* @param oldPassword
* the old password
* @param newPassword
* the new password
* @return the result code
* @throws Exception
* the exception
*/
@RequestMapping(value = "auth/changePassword", method = RequestMethod.POST)
@ResponseBody
public ResultCode changePassword(@RequestParam(value = "username") String username,
@RequestParam(value = "oldPassword") String oldPassword, @RequestParam(value = "newPassword") String newPassword)
throws Exception {
ResultCode resultCode = kaaAuthService.changePassword(username, oldPassword, newPassword);
if (resultCode == ResultCode.USER_NOT_FOUND) {
throw Utils.handleException(new IllegalArgumentException("User with specified username was not found."));
} else if (resultCode == ResultCode.OLD_PASSWORD_MISMATCH) {
throw Utils.handleException(new IllegalArgumentException("Current password is invalid."));
} else if (resultCode == ResultCode.BAD_PASSWORD_STRENGTH) {
throw Utils.handleException(new IllegalArgumentException("Password strength is insufficient."));
}
return resultCode;
}
/**
* Gets all tenants.
*
* @return the list of tenant user dto
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "tenants", method = RequestMethod.GET)
@ResponseBody
public List<TenantUserDto> getTenants() throws KaaAdminServiceException {
return kaaAdminService.getTenants();
}
/**
* Gets the tenant by user id.
*
* @param userId
* the user id
* @return the tenant user dto
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "tenant/{userId}", method = RequestMethod.GET)
@ResponseBody
public TenantUserDto getTenant(@PathVariable("userId") String userId) throws KaaAdminServiceException {
return kaaAdminService.getTenant(userId);
}
/**
* Edits tenant to the list of all tenants.
*
* @param tenantUser
* the tenant user
* @return the tenant user dto
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "tenant", method = RequestMethod.POST)
@ResponseBody
public TenantUserDto editTenant(@RequestBody TenantUserDto tenantUser) throws KaaAdminServiceException {
try {
if (isEmpty(tenantUser.getAuthority())) {
tenantUser.setAuthority(KaaAuthorityDto.TENANT_ADMIN);
} else if (!KaaAuthorityDto.TENANT_ADMIN.equals(tenantUser.getAuthority())) {
throw new KaaAdminServiceException("Incorrect authority for tenant. Authority must be TENANT_ADMIN.", ServiceErrorCode.INVALID_ARGUMENTS);
}
CreateUserResult result = userFacade.saveUserDto(tenantUser, passwordEncoder);
tenantUser.setExternalUid(result.getUserId().toString());
TenantUserDto tenant = kaaAdminService.editTenant(tenantUser);
if (StringUtils.isNotBlank(result.getPassword())) {
tenant.setTempPassword(result.getPassword());
}
return tenant;
} catch (Exception e) {
throw Utils.handleException(e);
}
}
/**
* Gets all applications.
*
* @return the list application dto
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "applications", method = RequestMethod.GET)
@ResponseBody
public List<ApplicationDto> getApplications() throws KaaAdminServiceException {
return kaaAdminService.getApplications();
}
/**
* Gets the application by its application token.
*
* @param applicationToken
* the application token
* @return the application dto
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "application/{applicationToken}", method = RequestMethod.GET)
@ResponseBody
public ApplicationDto getApplicationByApplicationToken(@PathVariable String applicationToken) throws KaaAdminServiceException {
return kaaAdminService.getApplicationByApplicationToken(applicationToken);
}
/**
* Edits application to the list of all applications.
*
* @param application
* the application
* @return the application dto
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "application", method = RequestMethod.POST)
@ResponseBody
public ApplicationDto editApplication(@RequestBody ApplicationDto application) throws KaaAdminServiceException {
return kaaAdminService.editApplication(application);
}
/**
* Delete application by application id.
*
* @param applicationId
* the application id
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "delApplication", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void deleteApplication(@RequestParam(value = "applicationId") String applicationId) throws KaaAdminServiceException {
kaaAdminService.deleteApplication(applicationId);
}
/**
* Gets the user profile of current user.
*
* @return the user dto
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "userProfile", method = RequestMethod.GET)
@ResponseBody
public UserDto getUserProfile() throws KaaAdminServiceException {
return kaaAdminService.getUserProfile();
}
/**
* Edits user profile to all user profiles.
*
* @param userDto
* the user dto
* @return the user dto
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "userProfile", method = RequestMethod.POST)
@ResponseBody
public UserDto editUserProfile(@RequestBody UserDto userDto) throws KaaAdminServiceException {
return kaaAdminService.editUserProfile(userDto);
}
/**
* Gets all users.
*
* @return the list user dto
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "users", method = RequestMethod.GET)
@ResponseBody
public List<UserDto> getUsers() throws KaaAdminServiceException {
return kaaAdminService.getUsers();
}
/**
* Gets the user by his id.
*
* @param userId
* the user id
* @return the user dto
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "user/{userId}", method = RequestMethod.GET)
@ResponseBody
public UserDto getUser(@PathVariable String userId) throws KaaAdminServiceException {
return kaaAdminService.getUser(userId);
}
/**
* Edits user to the list of all users.
*
* @param user
* the user
* @return the user dto
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "user", method = RequestMethod.POST)
@ResponseBody
public UserDto editUser(@RequestBody UserDto user) throws KaaAdminServiceException {
try {
CreateUserResult result = userFacade.saveUserDto(user, passwordEncoder);
user.setExternalUid(result.getUserId().toString());
UserDto userDto = kaaAdminService.editUser(user);
if (StringUtils.isNotBlank(result.getPassword())) {
userDto.setTempPassword(result.getPassword());
}
return userDto;
} catch (Exception e) {
throw Utils.handleException(e);
}
}
/**
* Delete user by user id.
*
* @param userId
* the user id
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "delUser", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void deleteUser(@RequestParam(value = "userId") String userId) throws KaaAdminServiceException {
kaaAdminService.deleteUser(userId);
}
/**
* Gets the schema versions by application token.
*
* @param applicationToken
* the application token
* @return the schema versions
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "schemaVersions/{applicationToken}", method = RequestMethod.GET)
@ResponseBody
public SchemaVersions getSchemaVersionsByApplicationToken(@PathVariable String applicationToken) throws KaaAdminServiceException {
return kaaAdminService.getSchemaVersionsByApplicationToken(applicationToken);
}
/**
* Generates an SDK for the specified target platform from an SDK profile .
*
* @param sdkProfileId
* the sdk profile id
* @param targetPlatform
* the target platform
* @param request
* the request
* @param response
* the response
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "sdk", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void getSdk(@RequestParam(value = "sdkProfileId") String sdkProfileId,
@RequestParam(value = "targetPlatform") String targetPlatform, HttpServletRequest request, HttpServletResponse response)
throws KaaAdminServiceException {
try {
SdkProfileDto sdkProfile = kaaAdminService.getSdkProfile(sdkProfileId);
FileData sdkData = kaaAdminService.getSdk(sdkProfile, SdkPlatform.valueOf(targetPlatform.toUpperCase()));
response.setContentType(sdkData.getContentType());
ServletUtils.prepareDisposition(request, response, sdkData.getFileName());
response.setContentLength(sdkData.getFileData().length);
response.setBufferSize(BUFFER);
response.getOutputStream().write(sdkData.getFileData());
response.flushBuffer();
} catch (Exception e) {
throw Utils.handleException(e);
}
}
/**
* Stores a new SDK profile into the database.
*
* @param sdkProfile
* the sdk profile
* @return the sdk profile dto
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "createSdkProfile", method = RequestMethod.POST)
@ResponseBody
public SdkProfileDto createSdkProfile(@RequestBody SdkProfileDto sdkProfile) throws KaaAdminServiceException {
return kaaAdminService.createSdkProfile(sdkProfile);
}
/**
* Deletes an SDK profile by its identifier.
*
* @param sdkProfileId
* the sdk profile id
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "deleteSdkProfile", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void deleteSdkProfile(@RequestParam(value = "sdkProfileId") String sdkProfileId) throws KaaAdminServiceException {
kaaAdminService.deleteSdkProfile(sdkProfileId);
}
/**
* Returns an SDK profile by its identifier.
*
* @param sdkProfileId
* the sdk profile id
* @return the sdk profile dto
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "sdkProfile/{sdkProfileId}")
@ResponseBody
public SdkProfileDto getSdkProfile(@PathVariable String sdkProfileId) throws KaaAdminServiceException {
return kaaAdminService.getSdkProfile(sdkProfileId);
}
/**
* Returns a list of SDK profiles for the given application.
*
* @param applicationToken
* the application token
* @return the list sdk profile dto
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "sdkProfiles/{applicationToken}")
@ResponseBody
public List<SdkProfileDto> getSdkProfilesByApplicationToken(@PathVariable String applicationToken) throws KaaAdminServiceException {
return kaaAdminService.getSdkProfilesByApplicationToken(applicationToken);
}
/**
* Flushes all cached Sdks within tenant.
*
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "flushSdkCache", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void flushSdkCache() throws KaaAdminServiceException {
try {
kaaAdminService.flushSdkCache();
} catch (Exception e) {
throw Utils.handleException(e);
}
}
/**
* Saves a CTL schema.
*
* @param body
* the ctl body
* @param applicationToken
* the application token
* @param tenantId
* id of the tenant
*
* @throws KaaAdminServiceException
* the kaa admin service exception
*
* @return CTL schema info
*/
@RequestMapping(value = "CTL/saveSchema", params = { "body" }, method = RequestMethod.POST)
@ResponseBody
public CTLSchemaDto saveCTLSchemaWithAppToken(@RequestParam String body, @RequestParam(required = false) String tenantId,
@RequestParam(required = false) String applicationToken) throws KaaAdminServiceException {
return kaaAdminService.saveCTLSchemaWithAppToken(body, tenantId, applicationToken);
}
/**
* Removes a CTL schema by its fully qualified name and version number.
*
* @param fqn
* the fqn
* @param version
* the version
* @param tenantId
* id of the tenant
* @param applicationToken
* the application token
*
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "CTL/deleteSchema", params = { "fqn", "version" }, method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void deleteCTLSchemaByFqnVersionTenantIdAndApplicationToken(@RequestParam String fqn, @RequestParam int version,
@RequestParam(required = false) String tenantId,
@RequestParam(required = false) String applicationToken)
throws KaaAdminServiceException {
kaaAdminService.deleteCTLSchemaByFqnVersionTenantIdAndApplicationToken(fqn, version, tenantId, applicationToken);
}
/**
* Retrieves a CTL schema by its fully qualified name and version number.
*
* @param fqn
* the fqn
* @param version
* the version
* @param tenantId
* id of the tenant
* @param applicationToken
* the application token
*
* @throws KaaAdminServiceException
* the kaa admin service exception
*
* @return CTL schema info
*/
@RequestMapping(value = "CTL/getSchema", params = { "fqn", "version" }, method = RequestMethod.GET)
@ResponseBody
public CTLSchemaDto getCTLSchemaByFqnVersionTenantIdAndApplicationToken(@RequestParam String fqn,
@RequestParam int version,
@RequestParam(required = false) String tenantId,
@RequestParam(required = false) String applicationToken)
throws KaaAdminServiceException {
return kaaAdminService.getCTLSchemaByFqnVersionTenantIdAndApplicationToken(fqn, version, tenantId, applicationToken);
}
/**
* Retrieves a CTL schema by its id.
*
* @param id
* the CTL schema id
*
* @throws KaaAdminServiceException
* the kaa admin service exception
*
* @return CTL schema info
*/
@RequestMapping(value = "CTL/getSchemaById", params = { "id" }, method = RequestMethod.GET)
@ResponseBody
public CTLSchemaDto getCTLSchemaById(@RequestParam String id) throws KaaAdminServiceException {
return kaaAdminService.getCTLSchemaById(id);
}
/**
* Checks if CTL schema with same fqn is already exists in the sibling application.
*
* @param fqn
* the fqn
* @param tenantId
* id of the tenant
* @param applicationToken
* the application token
*
* @throws KaaAdminServiceException
* the kaa admin service exception
*
* @return true if CTL schema with same fqn is already exists in other scope
*/
@RequestMapping(value = "CTL/checkFqn", params = { "fqn" }, method = RequestMethod.GET)
@ResponseBody
public boolean checkFqnExistsWithAppToken(@RequestParam String fqn,
@RequestParam(required = false) String tenantId,
@RequestParam(required = false) String applicationToken)
throws KaaAdminServiceException {
return kaaAdminService.checkFqnExistsWithAppToken(fqn, tenantId, applicationToken);
}
/**
* Promote existing CTL schema meta info from application to tenant scope
*
* @param applicationId the id of application where schema was created
* @param fqn the fqn of promoting CTL schema
* @throws KaaAdminServiceException the kaa admin service exception
*
* @return CTLSchemaMetaInfoDto the promoted CTL schema meta info object.
*/
@RequestMapping(value = "CTL/promoteScopeToTenant", method = RequestMethod.POST)
@ResponseBody
public CTLSchemaMetaInfoDto promoteScopeToTenant(@RequestParam String applicationId, @RequestParam String fqn)
throws KaaAdminServiceException {
return kaaAdminService.promoteScopeToTenant(applicationId, fqn);
}
/**
* Retrieves a list of available system CTL schemas.
*
* @throws KaaAdminServiceException
* the kaa admin service exception
* @return CTL schema metadata list
*/
@RequestMapping(value = "CTL/getSystemSchemas", method = RequestMethod.GET)
@ResponseBody
public List<CTLSchemaMetaInfoDto> getSystemLevelCTLSchemas() throws KaaAdminServiceException {
return kaaAdminService.getSystemLevelCTLSchemas();
}
/**
* Retrieves a list of available CTL schemas for tenant.
*
* @throws KaaAdminServiceException
* the kaa admin service exception
* @return CTL schema metadata list
*/
@RequestMapping(value = "CTL/getTenantSchemas", method = RequestMethod.GET)
@ResponseBody
public List<CTLSchemaMetaInfoDto> getTenantLevelCTLSchemas() throws KaaAdminServiceException {
return kaaAdminService.getTenantLevelCTLSchemas();
}
/**
* Retrieves a list of available CTL schemas for application.
*
* @param applicationToken
* the application token
*
* @throws KaaAdminServiceException
* the kaa admin service exception
* @return CTL schema metadata list
*/
@RequestMapping(value = "CTL/getApplicationSchemas/{applicationToken}", method = RequestMethod.GET)
@ResponseBody
public List<CTLSchemaMetaInfoDto> getApplicationLevelCTLSchemasByAppToken(@PathVariable String applicationToken) throws KaaAdminServiceException {
return kaaAdminService.getApplicationLevelCTLSchemasByAppToken(applicationToken);
}
/**
* Exports a CTL schema and, depending on the export method specified, all
* of its dependencies.
*
* @param fqn
* - the schema fqn
* @param version
* - the schema version
* @param method
* - the schema export method
* @param applicationToken
* the application token
* @param request
* - the http request
* @param response
* - the http response
*
* @see CTLSchemaExportMethod
*
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "CTL/exportSchema", params = { "fqn", "version", "method" }, method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void exportCTLSchemaByAppToken(@RequestParam String fqn, @RequestParam int version, @RequestParam String method,
@RequestParam(required = false) String applicationToken,
HttpServletRequest request, HttpServletResponse response) throws KaaAdminServiceException {
try {
FileData output = kaaAdminService.exportCTLSchemaByAppToken(fqn, version, applicationToken, CTLSchemaExportMethod.valueOf(method.toUpperCase()));
ServletUtils.prepareDisposition(request, response, output.getFileName());
response.setContentType(output.getContentType());
response.setContentLength(output.getFileData().length);
response.setBufferSize(BUFFER);
response.getOutputStream().write(output.getFileData());
response.flushBuffer();
} catch (Exception cause) {
throw Utils.handleException(cause);
}
}
/**
* Gets the server profile schemas by application token.
*
* @param applicationToken
* the application token
* @return the list profile schema dto
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "serverProfileSchemas/{applicationToken}", method = RequestMethod.GET)
@ResponseBody
public List<ServerProfileSchemaDto> getServerProfileSchemasByApplicationToken(@PathVariable String applicationToken)
throws KaaAdminServiceException {
return kaaAdminService.getServerProfileSchemasByApplicationToken(applicationToken);
}
/**
* Gets the server profile schema by its id.
*
* @param serverProfileSchemaId
* the profile schema id
* @return the profile schema dto
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "serverProfileSchema/{serverProfileSchemaId}", method = RequestMethod.GET)
@ResponseBody
public ServerProfileSchemaDto getServerProfileSchema(@PathVariable String serverProfileSchemaId) throws KaaAdminServiceException {
return kaaAdminService.getServerProfileSchema(serverProfileSchemaId);
}
/**
* Saves server profile schema.
*
* @param serverProfileSchema
* the profile schema
* @return the server profile schema dto
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "saveServerProfileSchema", method = RequestMethod.POST)
@ResponseBody
public ServerProfileSchemaDto saveServerProfileSchema(@RequestBody ServerProfileSchemaDto serverProfileSchema)
throws KaaAdminServiceException {
return kaaAdminService.saveServerProfileSchema(serverProfileSchema);
}
/**
* Gets the profile schemas by application token.
*
* @param applicationToken
* the application token
* @return the list of endpoint profile schema dto objects
* @throws KaaAdminServiceException
* the kaa admin service exception
*/