Minor refactoring
This commit is contained in:
parent
ab10dd4494
commit
37891ec6c6
@ -24,7 +24,7 @@ import org.thingsboard.server.common.data.DataConstants;
|
|||||||
import org.thingsboard.server.common.data.Device;
|
import org.thingsboard.server.common.data.Device;
|
||||||
import org.thingsboard.server.common.data.DeviceProfile;
|
import org.thingsboard.server.common.data.DeviceProfile;
|
||||||
import org.thingsboard.server.common.data.FirmwareInfo;
|
import org.thingsboard.server.common.data.FirmwareInfo;
|
||||||
import org.thingsboard.server.common.data.firmware.FirmwareKeyUtil;
|
import org.thingsboard.server.common.data.firmware.FirmwareUtil;
|
||||||
import org.thingsboard.server.common.data.firmware.FirmwareType;
|
import org.thingsboard.server.common.data.firmware.FirmwareType;
|
||||||
import org.thingsboard.server.common.data.id.DeviceId;
|
import org.thingsboard.server.common.data.id.DeviceId;
|
||||||
import org.thingsboard.server.common.data.id.FirmwareId;
|
import org.thingsboard.server.common.data.id.FirmwareId;
|
||||||
@ -66,9 +66,9 @@ import static org.thingsboard.server.common.data.firmware.FirmwareKey.STATE;
|
|||||||
import static org.thingsboard.server.common.data.firmware.FirmwareKey.TITLE;
|
import static org.thingsboard.server.common.data.firmware.FirmwareKey.TITLE;
|
||||||
import static org.thingsboard.server.common.data.firmware.FirmwareKey.TS;
|
import static org.thingsboard.server.common.data.firmware.FirmwareKey.TS;
|
||||||
import static org.thingsboard.server.common.data.firmware.FirmwareKey.VERSION;
|
import static org.thingsboard.server.common.data.firmware.FirmwareKey.VERSION;
|
||||||
import static org.thingsboard.server.common.data.firmware.FirmwareKeyUtil.getAttributeKey;
|
import static org.thingsboard.server.common.data.firmware.FirmwareUtil.getAttributeKey;
|
||||||
import static org.thingsboard.server.common.data.firmware.FirmwareKeyUtil.getTargetTelemetryKey;
|
import static org.thingsboard.server.common.data.firmware.FirmwareUtil.getTargetTelemetryKey;
|
||||||
import static org.thingsboard.server.common.data.firmware.FirmwareKeyUtil.getTelemetryKey;
|
import static org.thingsboard.server.common.data.firmware.FirmwareUtil.getTelemetryKey;
|
||||||
import static org.thingsboard.server.common.data.firmware.FirmwareType.FIRMWARE;
|
import static org.thingsboard.server.common.data.firmware.FirmwareType.FIRMWARE;
|
||||||
import static org.thingsboard.server.common.data.firmware.FirmwareType.SOFTWARE;
|
import static org.thingsboard.server.common.data.firmware.FirmwareType.SOFTWARE;
|
||||||
|
|
||||||
@ -217,30 +217,10 @@ public class DefaultFirmwareStateService implements FirmwareStateService {
|
|||||||
if (device == null) {
|
if (device == null) {
|
||||||
log.warn("[{}] [{}] Device was removed during firmware update msg was queued!", tenantId, deviceId);
|
log.warn("[{}] [{}] Device was removed during firmware update msg was queued!", tenantId, deviceId);
|
||||||
} else {
|
} else {
|
||||||
FirmwareId currentFirmwareId;
|
FirmwareId currentFirmwareId = FirmwareUtil.getFirmwareId(device, firmwareType);
|
||||||
|
|
||||||
switch (firmwareType) {
|
|
||||||
case FIRMWARE:
|
|
||||||
currentFirmwareId = device.getFirmwareId();
|
|
||||||
break;
|
|
||||||
case SOFTWARE:
|
|
||||||
currentFirmwareId = device.getSoftwareId();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
log.warn("Unsupported firmware type: [{}]", firmwareType);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentFirmwareId == null) {
|
if (currentFirmwareId == null) {
|
||||||
DeviceProfile deviceProfile = deviceProfileService.findDeviceProfileById(tenantId, device.getDeviceProfileId());
|
DeviceProfile deviceProfile = deviceProfileService.findDeviceProfileById(tenantId, device.getDeviceProfileId());
|
||||||
switch (firmwareType) {
|
currentFirmwareId = FirmwareUtil.getFirmwareId(deviceProfile, firmwareType);
|
||||||
case FIRMWARE:
|
|
||||||
currentFirmwareId = deviceProfile.getFirmwareId();
|
|
||||||
break;
|
|
||||||
case SOFTWARE:
|
|
||||||
currentFirmwareId = deviceProfile.getSoftwareId();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetFirmwareId.equals(currentFirmwareId)) {
|
if (targetFirmwareId.equals(currentFirmwareId)) {
|
||||||
@ -333,13 +313,13 @@ public class DefaultFirmwareStateService implements FirmwareStateService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void remove(Device device, FirmwareType firmwareType) {
|
private void remove(Device device, FirmwareType firmwareType) {
|
||||||
telemetryService.deleteAndNotify(device.getTenantId(), device.getId(), DataConstants.SHARED_SCOPE, FirmwareKeyUtil.getAttributeKeys(firmwareType),
|
telemetryService.deleteAndNotify(device.getTenantId(), device.getId(), DataConstants.SHARED_SCOPE, FirmwareUtil.getAttributeKeys(firmwareType),
|
||||||
new FutureCallback<>() {
|
new FutureCallback<>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(@Nullable Void tmp) {
|
public void onSuccess(@Nullable Void tmp) {
|
||||||
log.trace("[{}] Success remove target firmware attributes!", device.getId());
|
log.trace("[{}] Success remove target firmware attributes!", device.getId());
|
||||||
Set<AttributeKey> keysToNotify = new HashSet<>();
|
Set<AttributeKey> keysToNotify = new HashSet<>();
|
||||||
FirmwareKeyUtil.ALL_FW_ATTRIBUTE_KEYS.forEach(key -> keysToNotify.add(new AttributeKey(DataConstants.SHARED_SCOPE, key)));
|
FirmwareUtil.ALL_FW_ATTRIBUTE_KEYS.forEach(key -> keysToNotify.add(new AttributeKey(DataConstants.SHARED_SCOPE, key)));
|
||||||
tbClusterService.pushMsgToCore(DeviceAttributesEventNotificationMsg.onDelete(device.getTenantId(), device.getId(), keysToNotify), null);
|
tbClusterService.pushMsgToCore(DeviceAttributesEventNotificationMsg.onDelete(device.getTenantId(), device.getId(), keysToNotify), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -41,6 +41,7 @@ import org.thingsboard.server.common.data.device.credentials.BasicMqttCredential
|
|||||||
import org.thingsboard.server.common.data.device.credentials.ProvisionDeviceCredentialsData;
|
import org.thingsboard.server.common.data.device.credentials.ProvisionDeviceCredentialsData;
|
||||||
import org.thingsboard.server.common.data.device.profile.ProvisionDeviceProfileCredentials;
|
import org.thingsboard.server.common.data.device.profile.ProvisionDeviceProfileCredentials;
|
||||||
import org.thingsboard.server.common.data.firmware.FirmwareType;
|
import org.thingsboard.server.common.data.firmware.FirmwareType;
|
||||||
|
import org.thingsboard.server.common.data.firmware.FirmwareUtil;
|
||||||
import org.thingsboard.server.common.data.id.CustomerId;
|
import org.thingsboard.server.common.data.id.CustomerId;
|
||||||
import org.thingsboard.server.common.data.id.DeviceId;
|
import org.thingsboard.server.common.data.id.DeviceId;
|
||||||
import org.thingsboard.server.common.data.id.DeviceProfileId;
|
import org.thingsboard.server.common.data.id.DeviceProfileId;
|
||||||
@ -463,26 +464,10 @@ public class DefaultTransportApiService implements TransportApiService {
|
|||||||
return getEmptyTransportApiResponseFuture();
|
return getEmptyTransportApiResponseFuture();
|
||||||
}
|
}
|
||||||
|
|
||||||
FirmwareId firmwareId = null;
|
FirmwareId firmwareId = FirmwareUtil.getFirmwareId(device, firmwareType);
|
||||||
switch (firmwareType) {
|
|
||||||
case FIRMWARE:
|
|
||||||
firmwareId = device.getFirmwareId();
|
|
||||||
break;
|
|
||||||
case SOFTWARE:
|
|
||||||
firmwareId = device.getSoftwareId();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (firmwareId == null) {
|
if (firmwareId == null) {
|
||||||
DeviceProfile deviceProfile = deviceProfileCache.find(device.getDeviceProfileId());
|
DeviceProfile deviceProfile = deviceProfileCache.find(device.getDeviceProfileId());
|
||||||
switch (firmwareType) {
|
firmwareId = FirmwareUtil.getFirmwareId(deviceProfile, firmwareType);
|
||||||
case FIRMWARE:
|
|
||||||
firmwareId = deviceProfile.getFirmwareId();
|
|
||||||
break;
|
|
||||||
case SOFTWARE:
|
|
||||||
firmwareId = deviceProfile.getSoftwareId();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TransportProtos.GetFirmwareResponseMsg.Builder builder = TransportProtos.GetFirmwareResponseMsg.newBuilder();
|
TransportProtos.GetFirmwareResponseMsg.Builder builder = TransportProtos.GetFirmwareResponseMsg.newBuilder();
|
||||||
|
|||||||
@ -32,7 +32,7 @@ import java.io.IOException;
|
|||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implements HasName, HasTenantId, HasCustomerId {
|
public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implements HasName, HasTenantId, HasCustomerId, HasFirmware {
|
||||||
|
|
||||||
private static final long serialVersionUID = 2807343040519543363L;
|
private static final long serialVersionUID = 2807343040519543363L;
|
||||||
|
|
||||||
|
|||||||
@ -36,7 +36,7 @@ import static org.thingsboard.server.common.data.SearchTextBasedWithAdditionalIn
|
|||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class DeviceProfile extends SearchTextBased<DeviceProfileId> implements HasName, HasTenantId {
|
public class DeviceProfile extends SearchTextBased<DeviceProfileId> implements HasName, HasTenantId, HasFirmware {
|
||||||
|
|
||||||
private TenantId tenantId;
|
private TenantId tenantId;
|
||||||
@NoXss
|
@NoXss
|
||||||
|
|||||||
@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* Copyright © 2016-2021 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;
|
||||||
|
|
||||||
|
import org.thingsboard.server.common.data.id.FirmwareId;
|
||||||
|
|
||||||
|
public interface HasFirmware {
|
||||||
|
|
||||||
|
FirmwareId getFirmwareId();
|
||||||
|
|
||||||
|
FirmwareId getSoftwareId();
|
||||||
|
}
|
||||||
@ -15,6 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.thingsboard.server.common.data.firmware;
|
package org.thingsboard.server.common.data.firmware;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.thingsboard.server.common.data.HasFirmware;
|
||||||
|
import org.thingsboard.server.common.data.id.FirmwareId;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -22,7 +26,8 @@ import java.util.List;
|
|||||||
import static org.thingsboard.server.common.data.firmware.FirmwareType.FIRMWARE;
|
import static org.thingsboard.server.common.data.firmware.FirmwareType.FIRMWARE;
|
||||||
import static org.thingsboard.server.common.data.firmware.FirmwareType.SOFTWARE;
|
import static org.thingsboard.server.common.data.firmware.FirmwareType.SOFTWARE;
|
||||||
|
|
||||||
public class FirmwareKeyUtil {
|
@Slf4j
|
||||||
|
public class FirmwareUtil {
|
||||||
|
|
||||||
public static final List<String> ALL_FW_ATTRIBUTE_KEYS;
|
public static final List<String> ALL_FW_ATTRIBUTE_KEYS;
|
||||||
|
|
||||||
@ -71,4 +76,16 @@ public class FirmwareKeyUtil {
|
|||||||
public static String getTelemetryKey(FirmwareType type, FirmwareKey key) {
|
public static String getTelemetryKey(FirmwareType type, FirmwareKey key) {
|
||||||
return type.getKeyPrefix() + "_" + key.getValue();
|
return type.getKeyPrefix() + "_" + key.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static FirmwareId getFirmwareId(HasFirmware entity, FirmwareType firmwareType) {
|
||||||
|
switch (firmwareType) {
|
||||||
|
case FIRMWARE:
|
||||||
|
return entity.getFirmwareId();
|
||||||
|
case SOFTWARE:
|
||||||
|
return entity.getSoftwareId();
|
||||||
|
default:
|
||||||
|
log.warn("Unsupported firmware type: [{}]", firmwareType);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user