diff --git a/application/src/main/data/upgrade/3.6.4/schema_update.sql b/application/src/main/data/upgrade/3.6.4/schema_update.sql index b7bbdc761f..5f00b7c2cf 100644 --- a/application/src/main/data/upgrade/3.6.4/schema_update.sql +++ b/application/src/main/data/upgrade/3.6.4/schema_update.sql @@ -135,14 +135,14 @@ DELETE FROM asset_profile WHERE name ='TbServiceQueue'; -- QUEUE STATS UPDATE END --- MOBILE APPS TABLE CREATE START +-- MOBILE APP SETTINGS TABLE CREATE START CREATE TABLE IF NOT EXISTS mobile_app_settings ( tenant_id UUID NOT NULL, - use_default boolean, + use_default_app boolean, android_config VARCHAR(1000), ios_config VARCHAR(1000), qr_code_config VARCHAR(100000) ); --- MOBILE APPS TABLE CREATE END \ No newline at end of file +-- MOBILE APP SETTINGS TABLE CREATE END \ No newline at end of file diff --git a/application/src/main/java/org/thingsboard/server/controller/MobileApplicationController.java b/application/src/main/java/org/thingsboard/server/controller/MobileApplicationController.java index 0cd0884126..e8ac13b077 100644 --- a/application/src/main/java/org/thingsboard/server/controller/MobileApplicationController.java +++ b/application/src/main/java/org/thingsboard/server/controller/MobileApplicationController.java @@ -106,7 +106,6 @@ public class MobileApplicationController extends BaseController { public ResponseEntity getAppleAppSiteAssociation() { MobileAppSettings mobileAppSettings = mobileAppSettingsService.getMobileAppSettings(TenantId.SYS_TENANT_ID); IosConfig iosConfig = mobileAppSettings.getIosConfig(); - if (iosConfig != null && iosConfig.isEnabled() && !iosConfig.getAppId().isBlank()) { return ResponseEntity.ok(JacksonUtil.toJsonNode(String.format(APPLE_APP_SITE_ASSOCIATION_PATTERN, iosConfig.getAppId()))); } else { @@ -115,7 +114,7 @@ public class MobileApplicationController extends BaseController { } @ApiOperation(value = "Create Or Update the Mobile application settings (saveMobileAppSettings)", - notes = "The payload contains associated android and iOS applications and platform qr code widget settings." + SYSTEM_AUTHORITY_PARAGRAPH) + notes = "The request payload contains configuration for android/iOS applications and platform qr code widget settings." + SYSTEM_AUTHORITY_PARAGRAPH) @PreAuthorize("hasAnyAuthority('SYS_ADMIN')") @PostMapping(value = "/api/mobile/app/settings") public MobileAppSettings saveMobileAppSettings(@Parameter(description = "A JSON value representing the mobile apps configuration") @@ -128,7 +127,7 @@ public class MobileApplicationController extends BaseController { } @ApiOperation(value = "Get Mobile application settings (getMobileAppSettings)", - notes = "The payload contains associated android and iOS applications and platform qr code widget settings." + AVAILABLE_FOR_ANY_AUTHORIZED_USER) + notes = "The response payload contains configuration for android/iOS applications and platform qr code widget settings." + AVAILABLE_FOR_ANY_AUTHORIZED_USER) @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") @GetMapping(value = "/api/mobile/app/settings") public MobileAppSettings getMobileAppSettings() throws ThingsboardException { @@ -139,18 +138,16 @@ public class MobileApplicationController extends BaseController { } @ApiOperation(value = "Get the deep link to the associated mobile application (getMobileAppDeepLink)", - notes = "Fetch the url that takes user to associated mobile application " + AVAILABLE_FOR_ANY_AUTHORIZED_USER) + notes = "Fetch the url that takes user to linked mobile application " + AVAILABLE_FOR_ANY_AUTHORIZED_USER) @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") @GetMapping(value = "/api/mobile/deepLink", produces = "text/plain") public String getMobileAppDeepLink(HttpServletRequest request) throws ThingsboardException, URISyntaxException { - SecurityUser currentUser = getCurrentUser(); - String secret = mobileAppSecretService.generateMobileAppSecret(currentUser); - + String secret = mobileAppSecretService.generateMobileAppSecret(getCurrentUser()); String baseUrl = systemSecurityService.getBaseUrl(TenantId.SYS_TENANT_ID, new CustomerId(EntityId.NULL_UUID), request); String platformDomain = new URI(baseUrl).getHost(); MobileAppSettings mobileAppSettings = mobileAppSettingsService.getMobileAppSettings(TenantId.SYS_TENANT_ID); String appDomain; - if (!mobileAppSettings.isUseDefault()) { + if (!mobileAppSettings.isUseDefaultApp()) { appDomain = platformDomain; } else { appDomain = DEFAULT_APP_DOMAIN; diff --git a/application/src/test/java/org/thingsboard/server/controller/MobileApplicationControllerTest.java b/application/src/test/java/org/thingsboard/server/controller/MobileApplicationControllerTest.java index 9e493980b1..b7dd9b5b3b 100644 --- a/application/src/test/java/org/thingsboard/server/controller/MobileApplicationControllerTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/MobileApplicationControllerTest.java @@ -52,7 +52,7 @@ public class MobileApplicationControllerTest extends AbstractControllerTest { qrCodeConfig.setQrCodeLabel(TEST_LABEL); MobileAppSettings mobileAppSettings = new MobileAppSettings(); - mobileAppSettings.setUseDefault(true); + mobileAppSettings.setUseDefaultApp(true); AndroidConfig androidConfig = AndroidConfig.builder() .appPackage(ANDROID_PACKAGE_NAME) .sha256CertFingerprints(ANDROID_APP_SHA256) @@ -75,15 +75,15 @@ public class MobileApplicationControllerTest extends AbstractControllerTest { loginSysAdmin(); MobileAppSettings mobileAppSettings = doGet("/api/mobile/app/settings", MobileAppSettings.class); assertThat(mobileAppSettings.getQrCodeConfig().getQrCodeLabel()).isEqualTo(TEST_LABEL); - assertThat(mobileAppSettings.isUseDefault()).isTrue(); + assertThat(mobileAppSettings.isUseDefaultApp()).isTrue(); - mobileAppSettings.setUseDefault(false); + mobileAppSettings.setUseDefaultApp(false); doPost("/api/mobile/app/settings", mobileAppSettings) .andExpect(status().isOk()); MobileAppSettings updatedMobileAppSettings = doGet("/api/mobile/app/settings", MobileAppSettings.class); - assertThat(updatedMobileAppSettings.isUseDefault()).isFalse(); + assertThat(updatedMobileAppSettings.isUseDefaultApp()).isFalse(); } @Test @@ -134,7 +134,7 @@ public class MobileApplicationControllerTest extends AbstractControllerTest { // update mobile setting to use custom one loginSysAdmin(); MobileAppSettings mobileAppSettings = doGet("/api/mobile/app/settings", MobileAppSettings.class); - mobileAppSettings.setUseDefault(false); + mobileAppSettings.setUseDefaultApp(false); doPost("/api/mobile/app/settings", mobileAppSettings); String customAppDeepLink = doGet("/api/mobile/deepLink", String.class); diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/mobile/MobileAppSettings.java b/common/data/src/main/java/org/thingsboard/server/common/data/mobile/MobileAppSettings.java index 9153265950..217db862f8 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/mobile/MobileAppSettings.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/mobile/MobileAppSettings.java @@ -27,7 +27,7 @@ public class MobileAppSettings implements Serializable { private static final long serialVersionUID = 2628323657987010348L; private TenantId tenantId; - boolean useDefault; + private boolean useDefaultApp; @Valid private AndroidConfig androidConfig; @Valid diff --git a/dao/src/main/java/org/thingsboard/server/dao/mobile/BaseMobileAppSettingsService.java b/dao/src/main/java/org/thingsboard/server/dao/mobile/BaseMobileAppSettingsService.java index d11edafb1b..a72498b3b2 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/mobile/BaseMobileAppSettingsService.java +++ b/dao/src/main/java/org/thingsboard/server/dao/mobile/BaseMobileAppSettingsService.java @@ -28,11 +28,14 @@ import org.thingsboard.server.common.data.mobile.MobileAppSettings; import org.thingsboard.server.common.data.mobile.QRCodeConfig; import org.thingsboard.server.dao.entity.AbstractCachedService; +import static org.thingsboard.server.dao.service.Validator.validateId; + @Service @Slf4j @RequiredArgsConstructor public class BaseMobileAppSettingsService extends AbstractCachedService implements MobileAppSettingsService { + public static final String INCORRECT_TENANT_ID = "Incorrect tenantId "; private static final String DEFAULT_QR_CODE_LABEL = "Scan to connect or download mobile app"; private final MobileAppSettingsDao mobileAppSettingsDao; @@ -51,6 +54,13 @@ public class BaseMobileAppSettingsService extends AbstractCachedService INCORRECT_TENANT_ID + id); + mobileAppSettingsDao.removeByTenantId(tenantId); + } + @TransactionalEventListener(classes = MobileAppSettingsEvictEvent.class) @Override public void handleEvictEvent(MobileAppSettingsEvictEvent event) { @@ -60,7 +70,7 @@ public class BaseMobileAppSettingsService extends AbstractCachedService, Seria @Column(name = ModelConstants.TENANT_ID_COLUMN, columnDefinition = "uuid") protected UUID tenantId; - @Column(name = ModelConstants.MOBILE_APP_SETTINGS_USE_DEFAULT_PROPERTY) - private boolean useDefault; + @Column(name = ModelConstants.MOBILE_APP_SETTINGS_USE_DEFAULT_APP_PROPERTY) + private boolean useDefaultApp; @Convert(converter = JsonConverter.class) @Column(name = ModelConstants.MOBILE_APP_SETTINGS_ANDROID_CONFIG_PROPERTY) @@ -63,7 +63,7 @@ public class MobileAppSettingsEntity implements ToData, Seria public MobileAppSettingsEntity(MobileAppSettings mobileAppSettings) { this.tenantId = mobileAppSettings.getTenantId().getId(); - this.useDefault = mobileAppSettings.isUseDefault(); + this.useDefaultApp = mobileAppSettings.isUseDefaultApp(); if (mobileAppSettings.getAndroidConfig() != null) { this.androidConfig = JacksonUtil.valueToTree(mobileAppSettings.getAndroidConfig()); } @@ -79,7 +79,7 @@ public class MobileAppSettingsEntity implements ToData, Seria public MobileAppSettings toData() { MobileAppSettings mobileAppSettings = new MobileAppSettings(); mobileAppSettings.setTenantId(TenantId.fromUUID(tenantId)); - mobileAppSettings.setUseDefault(useDefault); + mobileAppSettings.setUseDefaultApp(useDefaultApp); if (qrCodeConfig != null) { mobileAppSettings.setAndroidConfig(JacksonUtil.convertValue(androidConfig, AndroidConfig.class)); } diff --git a/dao/src/main/java/org/thingsboard/server/dao/tenant/TenantServiceImpl.java b/dao/src/main/java/org/thingsboard/server/dao/tenant/TenantServiceImpl.java index 8b3e65c927..7d256ceb27 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/tenant/TenantServiceImpl.java +++ b/dao/src/main/java/org/thingsboard/server/dao/tenant/TenantServiceImpl.java @@ -42,6 +42,7 @@ import org.thingsboard.server.dao.device.DeviceService; import org.thingsboard.server.dao.entity.AbstractCachedEntityService; import org.thingsboard.server.dao.eventsourcing.DeleteEntityEvent; import org.thingsboard.server.dao.eventsourcing.SaveEntityEvent; +import org.thingsboard.server.dao.mobile.MobileAppSettingsService; import org.thingsboard.server.dao.notification.NotificationRequestService; import org.thingsboard.server.dao.notification.NotificationRuleService; import org.thingsboard.server.dao.notification.NotificationSettingsService; @@ -137,6 +138,10 @@ public class TenantServiceImpl extends AbstractCachedEntityService