fixed mobile app settings default value for store links
This commit is contained in:
parent
44f4cd3ad1
commit
be5220a9e9
@ -16,7 +16,6 @@
|
||||
package org.thingsboard.server.controller;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -31,11 +30,9 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.server.common.data.StringUtils;
|
||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.mobile.AndroidConfig;
|
||||
import org.thingsboard.server.common.data.mobile.HasStoreLink;
|
||||
import org.thingsboard.server.common.data.mobile.IosConfig;
|
||||
import org.thingsboard.server.common.data.mobile.MobileAppSettings;
|
||||
import org.thingsboard.server.common.data.security.model.JwtPair;
|
||||
@ -84,8 +81,6 @@ public class MobileApplicationController extends BaseController {
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
public static final String DEFAULT_GOOGLE_APP_STORE_LINK = "https://play.google.com/store/apps/details?id=org.thingsboard.demo.app";
|
||||
public static final String DEFAULT_APPLE_APP_STORE_LINK = "https://apps.apple.com/us/app/thingsboard-live/id1594355695";
|
||||
public static final String SECRET = "secret";
|
||||
public static final String SECRET_PARAM_DESCRIPTION = "A string value representing short-lived secret key";
|
||||
public static final String DEFAULT_APP_DOMAIN = "demo.thingsboard.io";
|
||||
@ -175,14 +170,13 @@ public class MobileApplicationController extends BaseController {
|
||||
@GetMapping(value = "/api/noauth/qr")
|
||||
public ResponseEntity<?> getApplicationRedirect(@RequestHeader(value = "User-Agent") String userAgent) {
|
||||
MobileAppSettings mobileAppSettings = mobileAppSettingsService.getMobileAppSettings(TenantId.SYS_TENANT_ID);
|
||||
boolean useDefaultApp = mobileAppSettings.isUseDefaultApp();
|
||||
if (userAgent.contains("Android")) {
|
||||
return ResponseEntity.status(HttpStatus.FOUND)
|
||||
.header("Location", getAppStoreLink(useDefaultApp, mobileAppSettings.getAndroidConfig(), DEFAULT_GOOGLE_APP_STORE_LINK))
|
||||
.header("Location", mobileAppSettings.getAndroidConfig().getStoreLink())
|
||||
.build();
|
||||
} else if (userAgent.contains("iPhone") || userAgent.contains("iPad")) {
|
||||
return ResponseEntity.status(HttpStatus.FOUND)
|
||||
.header("Location", getAppStoreLink(useDefaultApp, mobileAppSettings.getIosConfig(), DEFAULT_APPLE_APP_STORE_LINK))
|
||||
.header("Location", mobileAppSettings.getIosConfig().getStoreLink())
|
||||
.build();
|
||||
} else {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND)
|
||||
@ -190,12 +184,4 @@ public class MobileApplicationController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
private String getAppStoreLink(boolean useDefaultApp, HasStoreLink storeLink, String defaultAppStoreLink) {
|
||||
if (useDefaultApp || StringUtils.isEmpty(storeLink.getStoreLink())) {
|
||||
return defaultAppStoreLink;
|
||||
} else {
|
||||
return storeLink.getStoreLink();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ import org.thingsboard.server.common.data.validation.NoXss;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class AndroidConfig implements HasStoreLink {
|
||||
public class AndroidConfig {
|
||||
|
||||
private boolean enabled;
|
||||
@NoXss
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2024 The Thingsboard Authors
|
||||
*
|
||||
* 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.thingsboard.server.common.data.mobile;
|
||||
|
||||
public interface HasStoreLink {
|
||||
|
||||
String getStoreLink();
|
||||
}
|
||||
@ -27,7 +27,7 @@ import org.thingsboard.server.common.data.validation.NoXss;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class IosConfig implements HasStoreLink {
|
||||
public class IosConfig {
|
||||
|
||||
private boolean enabled;
|
||||
@NoXss
|
||||
|
||||
@ -19,6 +19,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.event.TransactionalEventListener;
|
||||
import org.thingsboard.server.common.data.StringUtils;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.mobile.AndroidConfig;
|
||||
import org.thingsboard.server.common.data.mobile.BadgePosition;
|
||||
@ -39,6 +40,8 @@ public class BaseMobileAppSettingsService extends AbstractCachedEntityService<Te
|
||||
|
||||
public static final String INCORRECT_TENANT_ID = "Incorrect tenantId ";
|
||||
private static final String DEFAULT_QR_CODE_LABEL = "Scan to connect or download mobile app";
|
||||
public static final String DEFAULT_GOOGLE_APP_STORE_LINK = "https://play.google.com/store/apps/details?id=org.thingsboard.demo.app";
|
||||
public static final String DEFAULT_APPLE_APP_STORE_LINK = "https://apps.apple.com/us/app/thingsboard-live/id1594355695";
|
||||
|
||||
private final MobileAppSettingsDao mobileAppSettingsDao;
|
||||
private final DataValidator<MobileAppSettings> mobileAppSettingsDataValidator;
|
||||
@ -87,9 +90,11 @@ public class BaseMobileAppSettingsService extends AbstractCachedEntityService<Te
|
||||
|
||||
AndroidConfig androidConfig = AndroidConfig.builder()
|
||||
.enabled(true)
|
||||
.storeLink(DEFAULT_GOOGLE_APP_STORE_LINK)
|
||||
.build();
|
||||
IosConfig iosConfig = IosConfig.builder()
|
||||
.enabled(true)
|
||||
.storeLink(DEFAULT_APPLE_APP_STORE_LINK)
|
||||
.build();
|
||||
QRCodeConfig qrCodeConfig = QRCodeConfig.builder()
|
||||
.showOnHomePage(true)
|
||||
@ -103,6 +108,13 @@ public class BaseMobileAppSettingsService extends AbstractCachedEntityService<Te
|
||||
mobileAppSettings.setQrCodeConfig(qrCodeConfig);
|
||||
mobileAppSettings.setAndroidConfig(androidConfig);
|
||||
mobileAppSettings.setIosConfig(iosConfig);
|
||||
} else {
|
||||
if (StringUtils.isEmpty(mobileAppSettings.getAndroidConfig().getStoreLink())) {
|
||||
mobileAppSettings.getAndroidConfig().setStoreLink(DEFAULT_GOOGLE_APP_STORE_LINK);
|
||||
}
|
||||
if (StringUtils.isEmpty(mobileAppSettings.getIosConfig().getStoreLink())) {
|
||||
mobileAppSettings.getIosConfig().setStoreLink(DEFAULT_APPLE_APP_STORE_LINK);
|
||||
}
|
||||
}
|
||||
return mobileAppSettings;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user