Browse Source

Merge pull request #4959 from YevhenBondarenko/feature/ota-tag

[3.3.0] OtaPackage Tag
pull/4966/head
Andrew Shvayka 5 years ago
committed by GitHub
parent
commit
1f6210197c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      application/src/main/data/upgrade/3.2.2/schema_update.sql
  2. 1
      application/src/main/java/org/thingsboard/server/controller/OtaPackageController.java
  3. 9
      application/src/main/java/org/thingsboard/server/service/ota/DefaultOtaPackageStateService.java
  4. 2
      common/data/src/main/java/org/thingsboard/server/common/data/OtaPackageInfo.java
  5. 2
      common/data/src/main/java/org/thingsboard/server/common/data/ota/OtaPackageKey.java
  6. 10
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/attributes/DefaultLwM2MAttributesService.java
  7. 20
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/ota/DefaultLwM2MOtaUpdateService.java
  8. 13
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/ota/LwM2MClientOtaInfo.java
  9. 4
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/ota/LwM2MOtaUpdateService.java
  10. 1
      dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java
  11. 74
      dao/src/main/java/org/thingsboard/server/dao/model/sql/OtaPackageEntity.java
  12. 73
      dao/src/main/java/org/thingsboard/server/dao/model/sql/OtaPackageInfoEntity.java
  13. 5
      dao/src/main/java/org/thingsboard/server/dao/ota/BaseOtaPackageService.java
  14. 6
      dao/src/main/java/org/thingsboard/server/dao/sql/ota/OtaPackageInfoRepository.java
  15. 1
      dao/src/main/resources/sql/schema-entities-hsql.sql
  16. 1
      dao/src/main/resources/sql/schema-entities.sql
  17. 7
      ui-ngx/src/app/modules/home/pages/ota-update/ota-update-table-config.resolve.ts
  18. 9
      ui-ngx/src/app/modules/home/pages/ota-update/ota-update.component.html
  19. 49
      ui-ngx/src/app/modules/home/pages/ota-update/ota-update.component.ts
  20. 1
      ui-ngx/src/app/shared/models/ota-package.models.ts
  21. 4
      ui-ngx/src/assets/locale/locale.constant-en_US.json

1
application/src/main/data/upgrade/3.2.2/schema_update.sql

@ -67,6 +67,7 @@ CREATE TABLE IF NOT EXISTS ota_package (
type varchar(32) NOT NULL, type varchar(32) NOT NULL,
title varchar(255) NOT NULL, title varchar(255) NOT NULL,
version varchar(255) NOT NULL, version varchar(255) NOT NULL,
tag varchar(255),
url varchar(255), url varchar(255),
file_name varchar(255), file_name varchar(255),
content_type varchar(255), content_type varchar(255),

1
application/src/main/java/org/thingsboard/server/controller/OtaPackageController.java

@ -146,6 +146,7 @@ public class OtaPackageController extends BaseController {
otaPackage.setType(info.getType()); otaPackage.setType(info.getType());
otaPackage.setTitle(info.getTitle()); otaPackage.setTitle(info.getTitle());
otaPackage.setVersion(info.getVersion()); otaPackage.setVersion(info.getVersion());
otaPackage.setTag(info.getTag());
otaPackage.setAdditionalInfo(info.getAdditionalInfo()); otaPackage.setAdditionalInfo(info.getAdditionalInfo());
ChecksumAlgorithm checksumAlgorithm = ChecksumAlgorithm.valueOf(checksumAlgorithmStr.toUpperCase()); ChecksumAlgorithm checksumAlgorithm = ChecksumAlgorithm.valueOf(checksumAlgorithmStr.toUpperCase());

9
application/src/main/java/org/thingsboard/server/service/ota/DefaultOtaPackageStateService.java

@ -64,6 +64,7 @@ import static org.thingsboard.server.common.data.ota.OtaPackageKey.CHECKSUM;
import static org.thingsboard.server.common.data.ota.OtaPackageKey.CHECKSUM_ALGORITHM; import static org.thingsboard.server.common.data.ota.OtaPackageKey.CHECKSUM_ALGORITHM;
import static org.thingsboard.server.common.data.ota.OtaPackageKey.SIZE; import static org.thingsboard.server.common.data.ota.OtaPackageKey.SIZE;
import static org.thingsboard.server.common.data.ota.OtaPackageKey.STATE; import static org.thingsboard.server.common.data.ota.OtaPackageKey.STATE;
import static org.thingsboard.server.common.data.ota.OtaPackageKey.TAG;
import static org.thingsboard.server.common.data.ota.OtaPackageKey.TITLE; import static org.thingsboard.server.common.data.ota.OtaPackageKey.TITLE;
import static org.thingsboard.server.common.data.ota.OtaPackageKey.TS; import static org.thingsboard.server.common.data.ota.OtaPackageKey.TS;
import static org.thingsboard.server.common.data.ota.OtaPackageKey.URL; import static org.thingsboard.server.common.data.ota.OtaPackageKey.URL;
@ -246,6 +247,11 @@ public class DefaultOtaPackageStateService implements OtaPackageStateService {
List<TsKvEntry> telemetry = new ArrayList<>(); List<TsKvEntry> telemetry = new ArrayList<>();
telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(getTargetTelemetryKey(firmware.getType(), TITLE), firmware.getTitle()))); telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(getTargetTelemetryKey(firmware.getType(), TITLE), firmware.getTitle())));
telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(getTargetTelemetryKey(firmware.getType(), VERSION), firmware.getVersion()))); telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(getTargetTelemetryKey(firmware.getType(), VERSION), firmware.getVersion())));
if (StringUtils.isNotEmpty(firmware.getTag())) {
telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(getTargetTelemetryKey(firmware.getType(), TAG), firmware.getTag())));
}
telemetry.add(new BasicTsKvEntry(ts, new LongDataEntry(getTargetTelemetryKey(firmware.getType(), TS), ts))); telemetry.add(new BasicTsKvEntry(ts, new LongDataEntry(getTargetTelemetryKey(firmware.getType(), TS), ts)));
telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(getTelemetryKey(firmware.getType(), STATE), OtaPackageUpdateStatus.QUEUED.name()))); telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(getTelemetryKey(firmware.getType(), STATE), OtaPackageUpdateStatus.QUEUED.name())));
@ -289,6 +295,9 @@ public class DefaultOtaPackageStateService implements OtaPackageStateService {
List<AttributeKvEntry> attributes = new ArrayList<>(); List<AttributeKvEntry> attributes = new ArrayList<>();
attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(getAttributeKey(otaPackageType, TITLE), otaPackage.getTitle()))); attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(getAttributeKey(otaPackageType, TITLE), otaPackage.getTitle())));
attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(getAttributeKey(otaPackageType, VERSION), otaPackage.getVersion()))); attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(getAttributeKey(otaPackageType, VERSION), otaPackage.getVersion())));
if (StringUtils.isNotEmpty(otaPackage.getTag())) {
attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(getAttributeKey(otaPackageType, TAG), otaPackage.getTag())));
}
if (otaPackage.hasUrl()) { if (otaPackage.hasUrl()) {
attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(getAttributeKey(otaPackageType, URL), otaPackage.getUrl()))); attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(getAttributeKey(otaPackageType, URL), otaPackage.getUrl())));
List<String> attrToRemove = new ArrayList<>(); List<String> attrToRemove = new ArrayList<>();

2
common/data/src/main/java/org/thingsboard/server/common/data/OtaPackageInfo.java

@ -37,6 +37,7 @@ public class OtaPackageInfo extends SearchTextBasedWithAdditionalInfo<OtaPackage
private OtaPackageType type; private OtaPackageType type;
private String title; private String title;
private String version; private String version;
private String tag;
private String url; private String url;
private boolean hasData; private boolean hasData;
private String fileName; private String fileName;
@ -61,6 +62,7 @@ public class OtaPackageInfo extends SearchTextBasedWithAdditionalInfo<OtaPackage
this.type = otaPackageInfo.getType(); this.type = otaPackageInfo.getType();
this.title = otaPackageInfo.getTitle(); this.title = otaPackageInfo.getTitle();
this.version = otaPackageInfo.getVersion(); this.version = otaPackageInfo.getVersion();
this.tag = otaPackageInfo.getTag();
this.url = otaPackageInfo.getUrl(); this.url = otaPackageInfo.getUrl();
this.hasData = otaPackageInfo.isHasData(); this.hasData = otaPackageInfo.isHasData();
this.fileName = otaPackageInfo.getFileName(); this.fileName = otaPackageInfo.getFileName();

2
common/data/src/main/java/org/thingsboard/server/common/data/ota/OtaPackageKey.java

@ -19,7 +19,7 @@ import lombok.Getter;
public enum OtaPackageKey { public enum OtaPackageKey {
TITLE("title"), VERSION("version"), TS("ts"), STATE("state"), SIZE("size"), CHECKSUM("checksum"), CHECKSUM_ALGORITHM("checksum_algorithm"), URL("url"); TITLE("title"), VERSION("version"), TS("ts"), STATE("state"), SIZE("size"), CHECKSUM("checksum"), CHECKSUM_ALGORITHM("checksum_algorithm"), URL("url"), TAG("tag");
@Getter @Getter
private final String value; private final String value;

10
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/attributes/DefaultLwM2MAttributesService.java

@ -120,9 +120,11 @@ public class DefaultLwM2MAttributesService implements LwM2MAttributesService {
if (msg.getSharedUpdatedCount() > 0 && lwM2MClient != null) { if (msg.getSharedUpdatedCount() > 0 && lwM2MClient != null) {
String newFirmwareTitle = null; String newFirmwareTitle = null;
String newFirmwareVersion = null; String newFirmwareVersion = null;
String newFirmwareTag = null;
String newFirmwareUrl = null; String newFirmwareUrl = null;
String newSoftwareTitle = null; String newSoftwareTitle = null;
String newSoftwareVersion = null; String newSoftwareVersion = null;
String newSoftwareTag = null;
String newSoftwareUrl = null; String newSoftwareUrl = null;
List<TransportProtos.TsKvProto> otherAttributes = new ArrayList<>(); List<TransportProtos.TsKvProto> otherAttributes = new ArrayList<>();
for (TransportProtos.TsKvProto tsKvProto : msg.getSharedUpdatedList()) { for (TransportProtos.TsKvProto tsKvProto : msg.getSharedUpdatedList()) {
@ -131,12 +133,16 @@ public class DefaultLwM2MAttributesService implements LwM2MAttributesService {
newFirmwareTitle = getStrValue(tsKvProto); newFirmwareTitle = getStrValue(tsKvProto);
} else if (DefaultLwM2MOtaUpdateService.FIRMWARE_VERSION.equals(attrName)) { } else if (DefaultLwM2MOtaUpdateService.FIRMWARE_VERSION.equals(attrName)) {
newFirmwareVersion = getStrValue(tsKvProto); newFirmwareVersion = getStrValue(tsKvProto);
} else if (DefaultLwM2MOtaUpdateService.FIRMWARE_TAG.equals(attrName)) {
newFirmwareTag = getStrValue(tsKvProto);
} else if (DefaultLwM2MOtaUpdateService.FIRMWARE_URL.equals(attrName)) { } else if (DefaultLwM2MOtaUpdateService.FIRMWARE_URL.equals(attrName)) {
newFirmwareUrl = getStrValue(tsKvProto); newFirmwareUrl = getStrValue(tsKvProto);
} else if (DefaultLwM2MOtaUpdateService.SOFTWARE_TITLE.equals(attrName)) { } else if (DefaultLwM2MOtaUpdateService.SOFTWARE_TITLE.equals(attrName)) {
newSoftwareTitle = getStrValue(tsKvProto); newSoftwareTitle = getStrValue(tsKvProto);
} else if (DefaultLwM2MOtaUpdateService.SOFTWARE_VERSION.equals(attrName)) { } else if (DefaultLwM2MOtaUpdateService.SOFTWARE_VERSION.equals(attrName)) {
newSoftwareVersion = getStrValue(tsKvProto); newSoftwareVersion = getStrValue(tsKvProto);
} else if (DefaultLwM2MOtaUpdateService.SOFTWARE_TAG.equals(attrName)) {
newSoftwareTag = getStrValue(tsKvProto);
} else if (DefaultLwM2MOtaUpdateService.SOFTWARE_URL.equals(attrName)) { } else if (DefaultLwM2MOtaUpdateService.SOFTWARE_URL.equals(attrName)) {
newSoftwareUrl = getStrValue(tsKvProto); newSoftwareUrl = getStrValue(tsKvProto);
}else { }else {
@ -144,10 +150,10 @@ public class DefaultLwM2MAttributesService implements LwM2MAttributesService {
} }
} }
if (newFirmwareTitle != null || newFirmwareVersion != null) { if (newFirmwareTitle != null || newFirmwareVersion != null) {
otaUpdateService.onTargetFirmwareUpdate(lwM2MClient, newFirmwareTitle, newFirmwareVersion, Optional.ofNullable(newFirmwareUrl)); otaUpdateService.onTargetFirmwareUpdate(lwM2MClient, newFirmwareTitle, newFirmwareVersion, Optional.ofNullable(newFirmwareUrl), Optional.ofNullable(newFirmwareTag));
} }
if (newSoftwareTitle != null || newSoftwareVersion != null) { if (newSoftwareTitle != null || newSoftwareVersion != null) {
otaUpdateService.onTargetSoftwareUpdate(lwM2MClient, newSoftwareTitle, newSoftwareVersion, Optional.ofNullable(newSoftwareUrl)); otaUpdateService.onTargetSoftwareUpdate(lwM2MClient, newSoftwareTitle, newSoftwareVersion, Optional.ofNullable(newSoftwareUrl), Optional.ofNullable(newSoftwareTag));
} }
if (!otherAttributes.isEmpty()) { if (!otherAttributes.isEmpty()) {
onAttributesUpdate(lwM2MClient, otherAttributes); onAttributesUpdate(lwM2MClient, otherAttributes);

20
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/ota/DefaultLwM2MOtaUpdateService.java

@ -85,9 +85,11 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
public static final String FIRMWARE_VERSION = getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.VERSION); public static final String FIRMWARE_VERSION = getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.VERSION);
public static final String FIRMWARE_TITLE = getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.TITLE); public static final String FIRMWARE_TITLE = getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.TITLE);
public static final String FIRMWARE_TAG = getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.TAG);
public static final String FIRMWARE_URL = getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.URL); public static final String FIRMWARE_URL = getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.URL);
public static final String SOFTWARE_VERSION = getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.VERSION); public static final String SOFTWARE_VERSION = getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.VERSION);
public static final String SOFTWARE_TITLE = getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.TITLE); public static final String SOFTWARE_TITLE = getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.TITLE);
public static final String SOFTWARE_TAG = getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.TAG);
public static final String SOFTWARE_URL = getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.URL); public static final String SOFTWARE_URL = getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.URL);
public static final String FIRMWARE_UPDATE_COAP_RESOURCE = "tbfw"; public static final String FIRMWARE_UPDATE_COAP_RESOURCE = "tbfw";
@ -165,6 +167,7 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
if (fwInfo.isSupported()) { if (fwInfo.isSupported()) {
attributesToFetch.add(FIRMWARE_TITLE); attributesToFetch.add(FIRMWARE_TITLE);
attributesToFetch.add(FIRMWARE_VERSION); attributesToFetch.add(FIRMWARE_VERSION);
attributesToFetch.add(FIRMWARE_TAG);
attributesToFetch.add(FIRMWARE_URL); attributesToFetch.add(FIRMWARE_URL);
} }
@ -172,6 +175,7 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
if (swInfo.isSupported()) { if (swInfo.isSupported()) {
attributesToFetch.add(SOFTWARE_TITLE); attributesToFetch.add(SOFTWARE_TITLE);
attributesToFetch.add(SOFTWARE_VERSION); attributesToFetch.add(SOFTWARE_VERSION);
attributesToFetch.add(SOFTWARE_TAG);
attributesToFetch.add(SOFTWARE_URL); attributesToFetch.add(SOFTWARE_URL);
} }
@ -186,17 +190,19 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
if (fwInfo.isSupported()) { if (fwInfo.isSupported()) {
Optional<String> newFwTitle = getAttributeValue(attrs, FIRMWARE_TITLE); Optional<String> newFwTitle = getAttributeValue(attrs, FIRMWARE_TITLE);
Optional<String> newFwVersion = getAttributeValue(attrs, FIRMWARE_VERSION); Optional<String> newFwVersion = getAttributeValue(attrs, FIRMWARE_VERSION);
Optional<String> newFwTag = getAttributeValue(attrs, FIRMWARE_TAG);
Optional<String> newFwUrl = getAttributeValue(attrs, FIRMWARE_URL); Optional<String> newFwUrl = getAttributeValue(attrs, FIRMWARE_URL);
if (newFwTitle.isPresent() && newFwVersion.isPresent()) { if (newFwTitle.isPresent() && newFwVersion.isPresent()) {
onTargetFirmwareUpdate(client, newFwTitle.get(), newFwVersion.get(), newFwUrl); onTargetFirmwareUpdate(client, newFwTitle.get(), newFwVersion.get(), newFwUrl, newFwTag);
} }
} }
if (swInfo.isSupported()) { if (swInfo.isSupported()) {
Optional<String> newSwTitle = getAttributeValue(attrs, SOFTWARE_TITLE); Optional<String> newSwTitle = getAttributeValue(attrs, SOFTWARE_TITLE);
Optional<String> newSwVersion = getAttributeValue(attrs, SOFTWARE_VERSION); Optional<String> newSwVersion = getAttributeValue(attrs, SOFTWARE_VERSION);
Optional<String> newSwTag = getAttributeValue(attrs, SOFTWARE_TAG);
Optional<String> newSwUrl = getAttributeValue(attrs, SOFTWARE_URL); Optional<String> newSwUrl = getAttributeValue(attrs, SOFTWARE_URL);
if (newSwTitle.isPresent() && newSwVersion.isPresent()) { if (newSwTitle.isPresent() && newSwVersion.isPresent()) {
onTargetSoftwareUpdate(client, newSwTitle.get(), newSwVersion.get(), newSwUrl); onTargetSoftwareUpdate(client, newSwTitle.get(), newSwVersion.get(), newSwUrl, newSwTag);
} }
} }
}, throwable -> { }, throwable -> {
@ -216,9 +222,9 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
} }
@Override @Override
public void onTargetFirmwareUpdate(LwM2mClient client, String newFirmwareTitle, String newFirmwareVersion, Optional<String> newFirmwareUrl) { public void onTargetFirmwareUpdate(LwM2mClient client, String newFirmwareTitle, String newFirmwareVersion, Optional<String> newFirmwareUrl, Optional<String> newFirmwareTag) {
LwM2MClientFwOtaInfo fwInfo = getOrInitFwInfo(client); LwM2MClientFwOtaInfo fwInfo = getOrInitFwInfo(client);
fwInfo.updateTarget(newFirmwareTitle, newFirmwareVersion, newFirmwareUrl); fwInfo.updateTarget(newFirmwareTitle, newFirmwareVersion, newFirmwareUrl, newFirmwareTag);
update(fwInfo); update(fwInfo);
startFirmwareUpdateIfNeeded(client, fwInfo); startFirmwareUpdateIfNeeded(client, fwInfo);
} }
@ -354,9 +360,9 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
} }
@Override @Override
public void onTargetSoftwareUpdate(LwM2mClient client, String newSoftwareTitle, String newSoftwareVersion, Optional<String> newFirmwareUrl) { public void onTargetSoftwareUpdate(LwM2mClient client, String newSoftwareTitle, String newSoftwareVersion, Optional<String> newSoftwareUrl, Optional<String> newSoftwareTag) {
LwM2MClientSwOtaInfo fwInfo = getOrInitSwInfo(client); LwM2MClientSwOtaInfo fwInfo = getOrInitSwInfo(client);
fwInfo.updateTarget(newSoftwareTitle, newSoftwareVersion, newFirmwareUrl); fwInfo.updateTarget(newSoftwareTitle, newSoftwareVersion, newSoftwareUrl, newSoftwareTag);
update(fwInfo); update(fwInfo);
startSoftwareUpdateIfNeeded(client, fwInfo); startSoftwareUpdateIfNeeded(client, fwInfo);
} }
@ -368,7 +374,7 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
sendStateUpdateToTelemetry(client, fwInfo, OtaPackageUpdateStatus.FAILED, "Client does not support firmware update or profile misconfiguration!"); sendStateUpdateToTelemetry(client, fwInfo, OtaPackageUpdateStatus.FAILED, "Client does not support firmware update or profile misconfiguration!");
} else if (fwInfo.isUpdateRequired()) { } else if (fwInfo.isUpdateRequired()) {
if (StringUtils.isNotEmpty(fwInfo.getTargetUrl())) { if (StringUtils.isNotEmpty(fwInfo.getTargetUrl())) {
log.debug("[{}] Starting update to [{}{}] using URL: {}", client.getEndpoint(), fwInfo.getTargetName(), fwInfo.getTargetVersion(), fwInfo.getTargetUrl()); log.debug("[{}] Starting update to [{}{}][] using URL: {}", client.getEndpoint(), fwInfo.getTargetName(), fwInfo.getTargetVersion(), fwInfo.getTargetUrl());
startUpdateUsingUrl(client, FW_URL_ID, fwInfo.getTargetUrl()); startUpdateUsingUrl(client, FW_URL_ID, fwInfo.getTargetUrl());
} else { } else {
log.debug("[{}] Starting update to [{}{}] using binary", client.getEndpoint(), fwInfo.getTargetName(), fwInfo.getTargetVersion()); log.debug("[{}] Starting update to [{}{}] using binary", client.getEndpoint(), fwInfo.getTargetName(), fwInfo.getTargetVersion());

13
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/ota/LwM2MClientOtaInfo.java

@ -32,6 +32,7 @@ public abstract class LwM2MClientOtaInfo<Strategy, State, Result> {
protected String targetName; protected String targetName;
protected String targetVersion; protected String targetVersion;
protected String targetTag;
protected String targetUrl; protected String targetUrl;
//TODO: use value from device if applicable; //TODO: use value from device if applicable;
@ -52,10 +53,11 @@ public abstract class LwM2MClientOtaInfo<Strategy, State, Result> {
this.strategy = strategy; this.strategy = strategy;
} }
public void updateTarget(String targetName, String targetVersion, Optional<String> newTargetUrl) { public void updateTarget(String targetName, String targetVersion, Optional<String> newTargetUrl, Optional<String> newTargetTag) {
this.targetName = targetName; this.targetName = targetName;
this.targetVersion = targetVersion; this.targetVersion = targetVersion;
this.targetUrl = newTargetUrl.orElse(null); this.targetUrl = newTargetUrl.orElse(null);
this.targetTag = newTargetTag.orElse(null);
} }
@JsonIgnore @JsonIgnore
@ -64,13 +66,18 @@ public abstract class LwM2MClientOtaInfo<Strategy, State, Result> {
return false; return false;
} else { } else {
String targetPackageId = getPackageId(targetName, targetVersion); String targetPackageId = getPackageId(targetName, targetVersion);
String currentPackageIdUsingObject5 = getPackageId(currentName, currentVersion); String currentPackageId = getPackageId(currentName, currentVersion);
if (StringUtils.isNotEmpty(failedPackageId) && failedPackageId.equals(targetPackageId)) { if (StringUtils.isNotEmpty(failedPackageId) && failedPackageId.equals(targetPackageId)) {
return false; return false;
} else { } else {
if (targetPackageId.equals(currentPackageIdUsingObject5)) { if (targetPackageId.equals(currentPackageId)) {
return false;
} else if (StringUtils.isNotEmpty(targetTag) && targetTag.equals(currentPackageId)) {
return false; return false;
} else if (StringUtils.isNotEmpty(currentVersion3)) { } else if (StringUtils.isNotEmpty(currentVersion3)) {
if (StringUtils.isNotEmpty(targetTag) && currentVersion3.contains(targetTag)) {
return false;
}
return !currentVersion3.contains(targetPackageId); return !currentVersion3.contains(targetPackageId);
} else { } else {
return true; return true;

4
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/ota/LwM2MOtaUpdateService.java

@ -26,9 +26,9 @@ public interface LwM2MOtaUpdateService {
void forceFirmwareUpdate(LwM2mClient client); void forceFirmwareUpdate(LwM2mClient client);
void onTargetFirmwareUpdate(LwM2mClient client, String newFwTitle, String newFwVersion, Optional<String> newFwUrl); void onTargetFirmwareUpdate(LwM2mClient client, String newFwTitle, String newFwVersion, Optional<String> newFwUrl, Optional<String> newFwTag);
void onTargetSoftwareUpdate(LwM2mClient client, String newSwTitle, String newSwVersion, Optional<String> newSwUrl); void onTargetSoftwareUpdate(LwM2mClient client, String newSwTitle, String newSwVersion, Optional<String> newSwUrl, Optional<String> newSwTag);
void onCurrentFirmwareNameUpdate(LwM2mClient client, String name); void onCurrentFirmwareNameUpdate(LwM2mClient client, String name);

1
dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java

@ -499,6 +499,7 @@ public class ModelConstants {
public static final String OTA_PACKAGE_TYPE_COLUMN = "type"; public static final String OTA_PACKAGE_TYPE_COLUMN = "type";
public static final String OTA_PACKAGE_TILE_COLUMN = TITLE_PROPERTY; public static final String OTA_PACKAGE_TILE_COLUMN = TITLE_PROPERTY;
public static final String OTA_PACKAGE_VERSION_COLUMN = "version"; public static final String OTA_PACKAGE_VERSION_COLUMN = "version";
public static final String OTA_PACKAGE_TAG_COLUMN = "tag";
public static final String OTA_PACKAGE_URL_COLUMN = "url"; public static final String OTA_PACKAGE_URL_COLUMN = "url";
public static final String OTA_PACKAGE_FILE_NAME_COLUMN = "file_name"; public static final String OTA_PACKAGE_FILE_NAME_COLUMN = "file_name";
public static final String OTA_PACKAGE_CONTENT_TYPE_COLUMN = "content_type"; public static final String OTA_PACKAGE_CONTENT_TYPE_COLUMN = "content_type";

74
dao/src/main/java/org/thingsboard/server/dao/model/sql/OtaPackageEntity.java

@ -48,6 +48,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_DATA_S
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_DEVICE_PROFILE_ID_COLUMN; import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_DEVICE_PROFILE_ID_COLUMN;
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_FILE_NAME_COLUMN; import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_FILE_NAME_COLUMN;
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TABLE_NAME; import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TABLE_NAME;
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TAG_COLUMN;
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TENANT_ID_COLUMN; import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TENANT_ID_COLUMN;
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TILE_COLUMN; import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TILE_COLUMN;
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TYPE_COLUMN; import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TYPE_COLUMN;
@ -78,6 +79,9 @@ public class OtaPackageEntity extends BaseSqlEntity<OtaPackage> implements Searc
@Column(name = OTA_PACKAGE_VERSION_COLUMN) @Column(name = OTA_PACKAGE_VERSION_COLUMN)
private String version; private String version;
@Column(name = OTA_PACKAGE_TAG_COLUMN)
private String tag;
@Column(name = OTA_PACKAGE_URL_COLUMN) @Column(name = OTA_PACKAGE_URL_COLUMN)
private String url; private String url;
@ -112,24 +116,25 @@ public class OtaPackageEntity extends BaseSqlEntity<OtaPackage> implements Searc
super(); super();
} }
public OtaPackageEntity(OtaPackage firmware) { public OtaPackageEntity(OtaPackage otaPackage) {
this.createdTime = firmware.getCreatedTime(); this.createdTime = otaPackage.getCreatedTime();
this.setUuid(firmware.getUuidId()); this.setUuid(otaPackage.getUuidId());
this.tenantId = firmware.getTenantId().getId(); this.tenantId = otaPackage.getTenantId().getId();
if (firmware.getDeviceProfileId() != null) { if (otaPackage.getDeviceProfileId() != null) {
this.deviceProfileId = firmware.getDeviceProfileId().getId(); this.deviceProfileId = otaPackage.getDeviceProfileId().getId();
} }
this.type = firmware.getType(); this.type = otaPackage.getType();
this.title = firmware.getTitle(); this.title = otaPackage.getTitle();
this.version = firmware.getVersion(); this.version = otaPackage.getVersion();
this.url = firmware.getUrl(); this.tag = otaPackage.getTag();
this.fileName = firmware.getFileName(); this.url = otaPackage.getUrl();
this.contentType = firmware.getContentType(); this.fileName = otaPackage.getFileName();
this.checksumAlgorithm = firmware.getChecksumAlgorithm(); this.contentType = otaPackage.getContentType();
this.checksum = firmware.getChecksum(); this.checksumAlgorithm = otaPackage.getChecksumAlgorithm();
this.data = firmware.getData().array(); this.checksum = otaPackage.getChecksum();
this.dataSize = firmware.getDataSize(); this.data = otaPackage.getData().array();
this.additionalInfo = firmware.getAdditionalInfo(); this.dataSize = otaPackage.getDataSize();
this.additionalInfo = otaPackage.getAdditionalInfo();
} }
@Override @Override
@ -144,26 +149,27 @@ public class OtaPackageEntity extends BaseSqlEntity<OtaPackage> implements Searc
@Override @Override
public OtaPackage toData() { public OtaPackage toData() {
OtaPackage firmware = new OtaPackage(new OtaPackageId(id)); OtaPackage otaPackage = new OtaPackage(new OtaPackageId(id));
firmware.setCreatedTime(createdTime); otaPackage.setCreatedTime(createdTime);
firmware.setTenantId(new TenantId(tenantId)); otaPackage.setTenantId(new TenantId(tenantId));
if (deviceProfileId != null) { if (deviceProfileId != null) {
firmware.setDeviceProfileId(new DeviceProfileId(deviceProfileId)); otaPackage.setDeviceProfileId(new DeviceProfileId(deviceProfileId));
} }
firmware.setType(type); otaPackage.setType(type);
firmware.setTitle(title); otaPackage.setTitle(title);
firmware.setVersion(version); otaPackage.setVersion(version);
firmware.setUrl(url); otaPackage.setTag(tag);
firmware.setFileName(fileName); otaPackage.setUrl(url);
firmware.setContentType(contentType); otaPackage.setFileName(fileName);
firmware.setChecksumAlgorithm(checksumAlgorithm); otaPackage.setContentType(contentType);
firmware.setChecksum(checksum); otaPackage.setChecksumAlgorithm(checksumAlgorithm);
firmware.setDataSize(dataSize); otaPackage.setChecksum(checksum);
otaPackage.setDataSize(dataSize);
if (data != null) { if (data != null) {
firmware.setData(ByteBuffer.wrap(data)); otaPackage.setData(ByteBuffer.wrap(data));
firmware.setHasData(true); otaPackage.setHasData(true);
} }
firmware.setAdditionalInfo(additionalInfo); otaPackage.setAdditionalInfo(additionalInfo);
return firmware; return otaPackage;
} }
} }

73
dao/src/main/java/org/thingsboard/server/dao/model/sql/OtaPackageInfoEntity.java

@ -48,6 +48,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_DATA_S
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_DEVICE_PROFILE_ID_COLUMN; import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_DEVICE_PROFILE_ID_COLUMN;
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_FILE_NAME_COLUMN; import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_FILE_NAME_COLUMN;
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TABLE_NAME; import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TABLE_NAME;
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TAG_COLUMN;
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TENANT_ID_COLUMN; import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TENANT_ID_COLUMN;
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TILE_COLUMN; import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TILE_COLUMN;
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TYPE_COLUMN; import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TYPE_COLUMN;
@ -78,6 +79,9 @@ public class OtaPackageInfoEntity extends BaseSqlEntity<OtaPackageInfo> implemen
@Column(name = OTA_PACKAGE_VERSION_COLUMN) @Column(name = OTA_PACKAGE_VERSION_COLUMN)
private String version; private String version;
@Column(name = OTA_PACKAGE_TAG_COLUMN)
private String tag;
@Column(name = OTA_PACKAGE_URL_COLUMN) @Column(name = OTA_PACKAGE_URL_COLUMN)
private String url; private String url;
@ -111,26 +115,27 @@ public class OtaPackageInfoEntity extends BaseSqlEntity<OtaPackageInfo> implemen
super(); super();
} }
public OtaPackageInfoEntity(OtaPackageInfo firmware) { public OtaPackageInfoEntity(OtaPackageInfo otaPackageInfo) {
this.createdTime = firmware.getCreatedTime(); this.createdTime = otaPackageInfo.getCreatedTime();
this.setUuid(firmware.getUuidId()); this.setUuid(otaPackageInfo.getUuidId());
this.tenantId = firmware.getTenantId().getId(); this.tenantId = otaPackageInfo.getTenantId().getId();
this.type = firmware.getType(); this.type = otaPackageInfo.getType();
if (firmware.getDeviceProfileId() != null) { if (otaPackageInfo.getDeviceProfileId() != null) {
this.deviceProfileId = firmware.getDeviceProfileId().getId(); this.deviceProfileId = otaPackageInfo.getDeviceProfileId().getId();
} }
this.title = firmware.getTitle(); this.title = otaPackageInfo.getTitle();
this.version = firmware.getVersion(); this.version = otaPackageInfo.getVersion();
this.url = firmware.getUrl(); this.tag = otaPackageInfo.getTag();
this.fileName = firmware.getFileName(); this.url = otaPackageInfo.getUrl();
this.contentType = firmware.getContentType(); this.fileName = otaPackageInfo.getFileName();
this.checksumAlgorithm = firmware.getChecksumAlgorithm(); this.contentType = otaPackageInfo.getContentType();
this.checksum = firmware.getChecksum(); this.checksumAlgorithm = otaPackageInfo.getChecksumAlgorithm();
this.dataSize = firmware.getDataSize(); this.checksum = otaPackageInfo.getChecksum();
this.additionalInfo = firmware.getAdditionalInfo(); this.dataSize = otaPackageInfo.getDataSize();
this.additionalInfo = otaPackageInfo.getAdditionalInfo();
} }
public OtaPackageInfoEntity(UUID id, long createdTime, UUID tenantId, UUID deviceProfileId, OtaPackageType type, String title, String version, public OtaPackageInfoEntity(UUID id, long createdTime, UUID tenantId, UUID deviceProfileId, OtaPackageType type, String title, String version, String tag,
String url, String fileName, String contentType, ChecksumAlgorithm checksumAlgorithm, String checksum, Long dataSize, String url, String fileName, String contentType, ChecksumAlgorithm checksumAlgorithm, String checksum, Long dataSize,
Object additionalInfo, boolean hasData) { Object additionalInfo, boolean hasData) {
this.id = id; this.id = id;
@ -140,6 +145,7 @@ public class OtaPackageInfoEntity extends BaseSqlEntity<OtaPackageInfo> implemen
this.type = type; this.type = type;
this.title = title; this.title = title;
this.version = version; this.version = version;
this.tag = tag;
this.url = url; this.url = url;
this.fileName = fileName; this.fileName = fileName;
this.contentType = contentType; this.contentType = contentType;
@ -162,23 +168,24 @@ public class OtaPackageInfoEntity extends BaseSqlEntity<OtaPackageInfo> implemen
@Override @Override
public OtaPackageInfo toData() { public OtaPackageInfo toData() {
OtaPackageInfo firmware = new OtaPackageInfo(new OtaPackageId(id)); OtaPackageInfo otaPackageInfo = new OtaPackageInfo(new OtaPackageId(id));
firmware.setCreatedTime(createdTime); otaPackageInfo.setCreatedTime(createdTime);
firmware.setTenantId(new TenantId(tenantId)); otaPackageInfo.setTenantId(new TenantId(tenantId));
if (deviceProfileId != null) { if (deviceProfileId != null) {
firmware.setDeviceProfileId(new DeviceProfileId(deviceProfileId)); otaPackageInfo.setDeviceProfileId(new DeviceProfileId(deviceProfileId));
} }
firmware.setType(type); otaPackageInfo.setType(type);
firmware.setTitle(title); otaPackageInfo.setTitle(title);
firmware.setVersion(version); otaPackageInfo.setVersion(version);
firmware.setUrl(url); otaPackageInfo.setTag(tag);
firmware.setFileName(fileName); otaPackageInfo.setUrl(url);
firmware.setContentType(contentType); otaPackageInfo.setFileName(fileName);
firmware.setChecksumAlgorithm(checksumAlgorithm); otaPackageInfo.setContentType(contentType);
firmware.setChecksum(checksum); otaPackageInfo.setChecksumAlgorithm(checksumAlgorithm);
firmware.setDataSize(dataSize); otaPackageInfo.setChecksum(checksum);
firmware.setAdditionalInfo(additionalInfo); otaPackageInfo.setDataSize(dataSize);
firmware.setHasData(hasData); otaPackageInfo.setAdditionalInfo(additionalInfo);
return firmware; otaPackageInfo.setHasData(hasData);
return otaPackageInfo;
} }
} }

5
dao/src/main/java/org/thingsboard/server/dao/ota/BaseOtaPackageService.java

@ -51,6 +51,7 @@ import org.thingsboard.server.dao.tenant.TenantDao;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import static org.thingsboard.server.common.data.CacheConstants.OTA_PACKAGE_CACHE; import static org.thingsboard.server.common.data.CacheConstants.OTA_PACKAGE_CACHE;
@ -318,6 +319,10 @@ public class BaseOtaPackageService implements OtaPackageService {
throw new DataValidationException("Updating otaPackage version is prohibited!"); throw new DataValidationException("Updating otaPackage version is prohibited!");
} }
if (!Objects.equals(otaPackage.getTag(), otaPackageOld.getTag())) {
throw new DataValidationException("Updating otaPackage tag is prohibited!");
}
if (!otaPackageOld.getDeviceProfileId().equals(otaPackage.getDeviceProfileId())) { if (!otaPackageOld.getDeviceProfileId().equals(otaPackage.getDeviceProfileId())) {
throw new DataValidationException("Updating otaPackage deviceProfile is prohibited!"); throw new DataValidationException("Updating otaPackage deviceProfile is prohibited!");
} }

6
dao/src/main/java/org/thingsboard/server/dao/sql/ota/OtaPackageInfoRepository.java

@ -26,14 +26,14 @@ import org.thingsboard.server.dao.model.sql.OtaPackageInfoEntity;
import java.util.UUID; import java.util.UUID;
public interface OtaPackageInfoRepository extends CrudRepository<OtaPackageInfoEntity, UUID> { public interface OtaPackageInfoRepository extends CrudRepository<OtaPackageInfoEntity, UUID> {
@Query("SELECT new OtaPackageInfoEntity(f.id, f.createdTime, f.tenantId, f.deviceProfileId, f.type, f.title, f.version, f.url, f.fileName, f.contentType, f.checksumAlgorithm, f.checksum, f.dataSize, f.additionalInfo, CASE WHEN (f.data IS NOT NULL OR f.url IS NOT NULL) THEN true ELSE false END) FROM OtaPackageEntity f WHERE " + @Query("SELECT new OtaPackageInfoEntity(f.id, f.createdTime, f.tenantId, f.deviceProfileId, f.type, f.title, f.version, f.tag, f.url, f.fileName, f.contentType, f.checksumAlgorithm, f.checksum, f.dataSize, f.additionalInfo, CASE WHEN (f.data IS NOT NULL OR f.url IS NOT NULL) THEN true ELSE false END) FROM OtaPackageEntity f WHERE " +
"f.tenantId = :tenantId " + "f.tenantId = :tenantId " +
"AND LOWER(f.searchText) LIKE LOWER(CONCAT(:searchText, '%'))") "AND LOWER(f.searchText) LIKE LOWER(CONCAT(:searchText, '%'))")
Page<OtaPackageInfoEntity> findAllByTenantId(@Param("tenantId") UUID tenantId, Page<OtaPackageInfoEntity> findAllByTenantId(@Param("tenantId") UUID tenantId,
@Param("searchText") String searchText, @Param("searchText") String searchText,
Pageable pageable); Pageable pageable);
@Query("SELECT new OtaPackageInfoEntity(f.id, f.createdTime, f.tenantId, f.deviceProfileId, f.type, f.title, f.version, f.url, f.fileName, f.contentType, f.checksumAlgorithm, f.checksum, f.dataSize, f.additionalInfo, true) FROM OtaPackageEntity f WHERE " + @Query("SELECT new OtaPackageInfoEntity(f.id, f.createdTime, f.tenantId, f.deviceProfileId, f.type, f.title, f.version, f.tag, f.url, f.fileName, f.contentType, f.checksumAlgorithm, f.checksum, f.dataSize, f.additionalInfo, true) FROM OtaPackageEntity f WHERE " +
"f.tenantId = :tenantId " + "f.tenantId = :tenantId " +
"AND f.deviceProfileId = :deviceProfileId " + "AND f.deviceProfileId = :deviceProfileId " +
"AND f.type = :type " + "AND f.type = :type " +
@ -45,7 +45,7 @@ public interface OtaPackageInfoRepository extends CrudRepository<OtaPackageInfoE
@Param("searchText") String searchText, @Param("searchText") String searchText,
Pageable pageable); Pageable pageable);
@Query("SELECT new OtaPackageInfoEntity(f.id, f.createdTime, f.tenantId, f.deviceProfileId, f.type, f.title, f.version, f.url, f.fileName, f.contentType, f.checksumAlgorithm, f.checksum, f.dataSize, f.additionalInfo, CASE WHEN (f.data IS NOT NULL OR f.url IS NOT NULL) THEN true ELSE false END) FROM OtaPackageEntity f WHERE f.id = :id") @Query("SELECT new OtaPackageInfoEntity(f.id, f.createdTime, f.tenantId, f.deviceProfileId, f.type, f.title, f.version, f.tag, f.url, f.fileName, f.contentType, f.checksumAlgorithm, f.checksum, f.dataSize, f.additionalInfo, CASE WHEN (f.data IS NOT NULL OR f.url IS NOT NULL) THEN true ELSE false END) FROM OtaPackageEntity f WHERE f.id = :id")
OtaPackageInfoEntity findOtaPackageInfoById(@Param("id") UUID id); OtaPackageInfoEntity findOtaPackageInfoById(@Param("id") UUID id);
@Query(value = "SELECT exists(SELECT * " + @Query(value = "SELECT exists(SELECT * " +

1
dao/src/main/resources/sql/schema-entities-hsql.sql

@ -173,6 +173,7 @@ CREATE TABLE IF NOT EXISTS ota_package (
type varchar(32) NOT NULL, type varchar(32) NOT NULL,
title varchar(255) NOT NULL, title varchar(255) NOT NULL,
version varchar(255) NOT NULL, version varchar(255) NOT NULL,
tag varchar(255),
url varchar(255), url varchar(255),
file_name varchar(255), file_name varchar(255),
content_type varchar(255), content_type varchar(255),

1
dao/src/main/resources/sql/schema-entities.sql

@ -188,6 +188,7 @@ CREATE TABLE IF NOT EXISTS ota_package (
type varchar(32) NOT NULL, type varchar(32) NOT NULL,
title varchar(255) NOT NULL, title varchar(255) NOT NULL,
version varchar(255) NOT NULL, version varchar(255) NOT NULL,
tag varchar(255),
url varchar(255), url varchar(255),
file_name varchar(255), file_name varchar(255),
content_type varchar(255), content_type varchar(255),

7
ui-ngx/src/app/modules/home/pages/ota-update/ota-update-table-config.resolve.ts

@ -59,9 +59,10 @@ export class OtaUpdateTableConfigResolve implements Resolve<EntityTableConfig<Ot
this.config.columns.push( this.config.columns.push(
new DateEntityTableColumn<OtaPackageInfo>('createdTime', 'common.created-time', this.datePipe, '150px'), new DateEntityTableColumn<OtaPackageInfo>('createdTime', 'common.created-time', this.datePipe, '150px'),
new EntityTableColumn<OtaPackageInfo>('title', 'ota-update.title', '20%'), new EntityTableColumn<OtaPackageInfo>('title', 'ota-update.title', '15%'),
new EntityTableColumn<OtaPackageInfo>('version', 'ota-update.version', '20%'), new EntityTableColumn<OtaPackageInfo>('version', 'ota-update.version', '15%'),
new EntityTableColumn<OtaPackageInfo>('type', 'ota-update.package-type', '20%', entity => { new EntityTableColumn<OtaPackageInfo>('tag', 'ota-update.version-tag', '15%'),
new EntityTableColumn<OtaPackageInfo>('type', 'ota-update.package-type', '15%', entity => {
return this.translate.instant(OtaUpdateTypeTranslationMap.get(entity.type)); return this.translate.instant(OtaUpdateTypeTranslationMap.get(entity.type));
}), }),
new EntityTableColumn<OtaPackageInfo>('url', 'ota-update.direct-url', '20%', entity => { new EntityTableColumn<OtaPackageInfo>('url', 'ota-update.direct-url', '20%', entity => {

9
ui-ngx/src/app/modules/home/pages/ota-update/ota-update.component.html

@ -74,6 +74,11 @@
</mat-error> </mat-error>
</mat-form-field> </mat-form-field>
</div> </div>
<mat-form-field class="mat-block" fxFlex style="margin-bottom: 8px">
<mat-label translate>ota-update.version-tag</mat-label>
<input matInput formControlName="tag" type="text" [readonly]="!isAdd">
<mat-hint *ngIf="isAdd" translate>ota-update.version-tag-hint</mat-hint>
</mat-form-field>
<tb-device-profile-autocomplete <tb-device-profile-autocomplete
formControlName="deviceProfileId" formControlName="deviceProfileId"
required required
@ -94,8 +99,8 @@
<section *ngIf="isAdd"> <section *ngIf="isAdd">
<div class="mat-caption" style="margin: -8px 0 8px;" translate>ota-update.warning-after-save-no-edit</div> <div class="mat-caption" style="margin: -8px 0 8px;" translate>ota-update.warning-after-save-no-edit</div>
<mat-radio-group formControlName="isURL" fxLayoutGap="16px"> <mat-radio-group formControlName="isURL" fxLayoutGap="16px">
<mat-radio-button [value]="false">Upload binary file</mat-radio-button> <mat-radio-button [value]="false">{{ "ota-update.upload-binary-file" | translate }}</mat-radio-button>
<mat-radio-button [value]="true">Use external URL</mat-radio-button> <mat-radio-button [value]="true">{{ "ota-update.use-external-url" | translate }}</mat-radio-button>
</mat-radio-group> </mat-radio-group>
</section> </section>
<section *ngIf="!entityForm.get('isURL').value"> <section *ngIf="!entityForm.get('isURL').value">

49
ui-ngx/src/app/modules/home/pages/ota-update/ota-update.component.ts

@ -15,7 +15,7 @@
/// ///
import { Component, Inject, OnDestroy, OnInit } from '@angular/core'; import { Component, Inject, OnDestroy, OnInit } from '@angular/core';
import { Subject } from 'rxjs'; import { combineLatest, Subject } from 'rxjs';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state'; import { AppState } from '@core/core.state';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
@ -30,7 +30,7 @@ import {
OtaUpdateTypeTranslationMap OtaUpdateTypeTranslationMap
} from '@shared/models/ota-package.models'; } from '@shared/models/ota-package.models';
import { ActionNotificationShow } from '@core/notification/notification.actions'; import { ActionNotificationShow } from '@core/notification/notification.actions';
import { filter, takeUntil } from 'rxjs/operators'; import { filter, startWith, takeUntil } from 'rxjs/operators';
import { isNotEmptyStr } from '@core/utils'; import { isNotEmptyStr } from '@core/utils';
@Component({ @Component({
@ -56,22 +56,33 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O
ngOnInit() { ngOnInit() {
super.ngOnInit(); super.ngOnInit();
this.entityForm.get('isURL').valueChanges.pipe( if (this.isAdd) {
filter(() => this.isAdd), this.entityForm.get('isURL').valueChanges.pipe(
takeUntil(this.destroy$) takeUntil(this.destroy$)
).subscribe((isURL) => { ).subscribe((isURL) => {
if (isURL === false) { if (isURL === false) {
this.entityForm.get('url').clearValidators(); this.entityForm.get('url').clearValidators();
this.entityForm.get('file').setValidators(Validators.required); this.entityForm.get('file').setValidators(Validators.required);
this.entityForm.get('url').updateValueAndValidity({emitEvent: false}); this.entityForm.get('url').updateValueAndValidity({emitEvent: false});
this.entityForm.get('file').updateValueAndValidity({emitEvent: false}); this.entityForm.get('file').updateValueAndValidity({emitEvent: false});
} else { } else {
this.entityForm.get('file').clearValidators(); this.entityForm.get('file').clearValidators();
this.entityForm.get('url').setValidators([Validators.required, Validators.pattern('(.|\\s)*\\S(.|\\s)*')]); this.entityForm.get('url').setValidators([Validators.required, Validators.pattern('(.|\\s)*\\S(.|\\s)*')]);
this.entityForm.get('file').updateValueAndValidity({emitEvent: false}); this.entityForm.get('file').updateValueAndValidity({emitEvent: false});
this.entityForm.get('url').updateValueAndValidity({emitEvent: false}); this.entityForm.get('url').updateValueAndValidity({emitEvent: false});
} }
}); });
combineLatest([
this.entityForm.get('title').valueChanges.pipe(startWith('')),
this.entityForm.get('version').valueChanges.pipe(startWith(''))
]).pipe(
filter(() => this.entityForm.get('tag').pristine),
takeUntil(this.destroy$)
).subscribe(([title, version]) => {
const tag = (`${title} ${version}`).trim();
this.entityForm.get('tag').patchValue(tag);
});
}
} }
ngOnDestroy() { ngOnDestroy() {
@ -92,6 +103,7 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O
const form = this.fb.group({ const form = this.fb.group({
title: [entity ? entity.title : '', [Validators.required, Validators.maxLength(255)]], title: [entity ? entity.title : '', [Validators.required, Validators.maxLength(255)]],
version: [entity ? entity.version : '', [Validators.required, Validators.maxLength(255)]], version: [entity ? entity.version : '', [Validators.required, Validators.maxLength(255)]],
tag: [entity ? entity.tag : '', [Validators.maxLength(255)]],
type: [entity?.type ? entity.type : OtaUpdateType.FIRMWARE, Validators.required], type: [entity?.type ? entity.type : OtaUpdateType.FIRMWARE, Validators.required],
deviceProfileId: [entity ? entity.deviceProfileId : null, Validators.required], deviceProfileId: [entity ? entity.deviceProfileId : null, Validators.required],
checksumAlgorithm: [entity && entity.checksumAlgorithm ? entity.checksumAlgorithm : ChecksumAlgorithm.SHA256], checksumAlgorithm: [entity && entity.checksumAlgorithm ? entity.checksumAlgorithm : ChecksumAlgorithm.SHA256],
@ -119,6 +131,7 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O
this.entityForm.patchValue({ this.entityForm.patchValue({
title: entity.title, title: entity.title,
version: entity.version, version: entity.version,
tag: entity.tag,
type: entity.type, type: entity.type,
deviceProfileId: entity.deviceProfileId, deviceProfileId: entity.deviceProfileId,
checksumAlgorithm: entity.checksumAlgorithm, checksumAlgorithm: entity.checksumAlgorithm,

1
ui-ngx/src/app/shared/models/ota-package.models.ts

@ -91,6 +91,7 @@ export interface OtaPackageInfo extends BaseData<OtaPackageId> {
deviceProfileId?: DeviceProfileId; deviceProfileId?: DeviceProfileId;
title?: string; title?: string;
version?: string; version?: string;
tag?: string;
hasData?: boolean; hasData?: boolean;
url?: string; url?: string;
fileName: string; fileName: string;

4
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -2341,8 +2341,12 @@
"firmware": "Firmware", "firmware": "Firmware",
"software": "Software" "software": "Software"
}, },
"upload-binary-file": "Upload binary file",
"use-external-url": "Use external URL",
"version": "Version", "version": "Version",
"version-required": "Version is required.", "version-required": "Version is required.",
"version-tag": "Version Tag",
"version-tag-hint": "Custom tag should match the package version reported by your device.",
"warning-after-save-no-edit": "Once the package is uploaded, you will not be able to modify title, version, device profile and package type." "warning-after-save-no-edit": "Once the package is uploaded, you will not be able to modify title, version, device profile and package type."
}, },
"position": { "position": {

Loading…
Cancel
Save