11import 'dart:convert' ;
22import 'dart:math' ;
33
4+ import 'package:collection/collection.dart' ;
45import 'package:dio/dio.dart' ;
56import 'package:thingsboard_client/thingsboard_client.dart' ;
67
@@ -53,8 +54,12 @@ Future<void> onUserLoaded() async {
5354 print ('currentUser: $currentUser ' );
5455 if (tbClient.isSystemAdmin ()) {
5556 await fetchSettingsExample ();
57+ await fetchPlatformTwoFactorAuthSettingsExample ();
5658 await fetchTenantsExample ();
59+ await fetchQueuesExample ();
5760 } else if (tbClient.isTenantAdmin ()) {
61+ await fetchAccountTwoFactorAuthSettingsExample ();
62+ await fetchTenantSettingsExample ();
5863 await fetchUsersExample ();
5964 await fetchDeviceProfilesExample ();
6065 await fetchDeviceProfileInfosExample ();
@@ -69,7 +74,10 @@ Future<void> onUserLoaded() async {
6974 await fetchAuditLogsExample ();
7075 await fetchResourcesExample ();
7176 await fetchOtaPackagesExample ();
77+ await fetchQueuesExample ();
78+ await vcExample ();
7279 } else if (tbClient.isCustomerUser ()) {
80+ await fetchAccountTwoFactorAuthSettingsExample ();
7381 await fetchUsersExample ();
7482 await fetchDeviceProfileInfosExample ();
7583 await fetchCustomerAssetsExample ();
@@ -133,6 +141,54 @@ Future<void> fetchSettingsExample() async {
133141 '**********************************************************************' );
134142}
135143
144+ Future <void > fetchPlatformTwoFactorAuthSettingsExample () async {
145+ print (
146+ '**********************************************************************' );
147+ print (
148+ '* FETCH PLATFORM TWO FACTOR AUTH SETTINGS EXAMPLE *' );
149+ print (
150+ '**********************************************************************' );
151+
152+ var settings =
153+ await tbClient.getTwoFactorAuthService ().getPlatformTwoFaSettings ();
154+
155+ print ('Platform Two Factor Authentication settings: $settings ' );
156+ }
157+
158+ Future <void > fetchAccountTwoFactorAuthSettingsExample () async {
159+ print (
160+ '**********************************************************************' );
161+ print (
162+ '* FETCH ACCOUNT TWO FACTOR AUTH SETTINGS EXAMPLE *' );
163+ print (
164+ '**********************************************************************' );
165+
166+ var settings =
167+ await tbClient.getTwoFactorAuthService ().getAccountTwoFaSettings ();
168+
169+ print ('Account Two Factor Authentication settings: $settings ' );
170+ }
171+
172+ Future <void > fetchTenantSettingsExample () async {
173+ print (
174+ '**********************************************************************' );
175+ print (
176+ '* FETCH TENANT SETTINGS EXAMPLE *' );
177+ print (
178+ '**********************************************************************' );
179+
180+ var repositorySettings =
181+ await tbClient.getAdminService ().getRepositorySettings ();
182+ print ('Repository settings: $repositorySettings ' );
183+
184+ var autoCommitSettings =
185+ await tbClient.getAdminService ().getAutoCommitSettings ();
186+ print ('Auto-commit settings: $autoCommitSettings ' );
187+
188+ print (
189+ '**********************************************************************' );
190+ }
191+
136192Future <void > fetchTenantsExample () async {
137193 print (
138194 '**********************************************************************' );
@@ -543,7 +599,7 @@ Future<void> fetchCustomerAssetsExample() async {
543599 do {
544600 assets = await tbClient
545601 .getAssetService ()
546- .getCustomerAssetInfos (tbClient.getAuthUser ()! .customerId, pageLink);
602+ .getCustomerAssetInfos (tbClient.getAuthUser ()! .customerId! , pageLink);
547603 print ('assets: $assets ' );
548604 pageLink = pageLink.nextPageLink ();
549605 } while (assets.hasNext);
@@ -564,7 +620,7 @@ Future<void> fetchCustomerDevicesExample() async {
564620 do {
565621 devices = await tbClient
566622 .getDeviceService ()
567- .getCustomerDeviceInfos (tbClient.getAuthUser ()! .customerId, pageLink);
623+ .getCustomerDeviceInfos (tbClient.getAuthUser ()! .customerId! , pageLink);
568624 print ('devices: $devices ' );
569625 pageLink = pageLink.nextPageLink ();
570626 } while (devices.hasNext);
@@ -584,10 +640,70 @@ Future<void> fetchCustomerDashboardsExample() async {
584640 do {
585641 dashboards = await tbClient
586642 .getDashboardService ()
587- .getCustomerDashboards (tbClient.getAuthUser ()! .customerId, pageLink);
643+ .getCustomerDashboards (tbClient.getAuthUser ()! .customerId! , pageLink);
588644 print ('dashboards: $dashboards ' );
589645 pageLink = pageLink.nextPageLink ();
590646 } while (dashboards.hasNext);
591647 print (
592648 '**********************************************************************' );
593649}
650+
651+ Future <void > fetchQueuesExample () async {
652+ print (
653+ '**********************************************************************' );
654+ print (
655+ '* FETCH QUEUES EXAMPLE *' );
656+ print (
657+ '**********************************************************************' );
658+
659+ for (ServiceType serviceType in ServiceType .values) {
660+ print ('Fetching queues for ${serviceType .toShortString ()} service type:' );
661+ var pageLink = PageLink (10 );
662+ PageData <Queue > queues;
663+ do {
664+ queues = await tbClient
665+ .getQueueService ()
666+ .getTenantQueuesByServiceType (pageLink, serviceType);
667+ print ('queues: $queues ' );
668+ pageLink = pageLink.nextPageLink ();
669+ } while (queues.hasNext);
670+ }
671+ print (
672+ '**********************************************************************' );
673+ }
674+
675+ Future <void > vcExample () async {
676+ print (
677+ '**********************************************************************' );
678+ print (
679+ '* VERSION CONTROL EXAMPLE *' );
680+ print (
681+ '**********************************************************************' );
682+
683+ var repositorySettingsExists =
684+ await tbClient.getAdminService ().repositorySettingsExists ();
685+ print ('Repository settings exists: $repositorySettingsExists ' );
686+
687+ if (repositorySettingsExists) {
688+ var branches =
689+ await tbClient.getEntitiesVersionControlService ().listBranches ();
690+ print ('branches: $branches ' );
691+
692+ var defaultBranch = branches.firstWhereOrNull ((branch) => branch.isDefault);
693+ print ('defaultBranch: $defaultBranch ' );
694+ if (defaultBranch != null ) {
695+ var pageLink = PageLink (10 );
696+ PageData <EntityVersion > versions;
697+ do {
698+ versions = await tbClient
699+ .getEntitiesVersionControlService ()
700+ .listVersions (pageLink, defaultBranch.name);
701+ print ('versions: $versions ' );
702+ pageLink = pageLink.nextPageLink ();
703+ } while (versions.hasNext);
704+ }
705+ }
706+
707+ print (
708+ '**********************************************************************' );
709+ }
0 commit comments