LWM2M: del log warn

This commit is contained in:
nickAS21 2021-05-28 15:42:01 +03:00 committed by Andrew Shvayka
parent 6cace79b3c
commit 1f00ae833d
7 changed files with 92 additions and 75 deletions

View File

@ -114,6 +114,7 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.c
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertPathFromIdVerToObjectId; import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertPathFromIdVerToObjectId;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertPathFromObjectIdToIdVer; import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertPathFromObjectIdToIdVer;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.getAckCallback; import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.getAckCallback;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.isFwSwWords;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.setValidTypeOper; import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.setValidTypeOper;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.validateObjectVerFromKey; import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.validateObjectVerFromKey;
@ -356,7 +357,6 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
String pathName = tsKvProto.getKv().getKey(); String pathName = tsKvProto.getKv().getKey();
String pathIdVer = this.getPresentPathIntoProfile(sessionInfo, pathName); String pathIdVer = this.getPresentPathIntoProfile(sessionInfo, pathName);
Object valueNew = getValueFromKvProto(tsKvProto.getKv()); Object valueNew = getValueFromKvProto(tsKvProto.getKv());
log.warn("12) Shared AttributeUpdate start pathName [{}], pathIdVer [{}], valueNew [{}]", pathName, pathIdVer, valueNew);
if ((FirmwareUtil.getAttributeKey(FirmwareType.FIRMWARE, FirmwareKey.VERSION).equals(pathName) if ((FirmwareUtil.getAttributeKey(FirmwareType.FIRMWARE, FirmwareKey.VERSION).equals(pathName)
&& (!valueNew.equals(lwM2MClient.getFwUpdate().getCurrentVersion()))) && (!valueNew.equals(lwM2MClient.getFwUpdate().getCurrentVersion())))
|| (FirmwareUtil.getAttributeKey(FirmwareType.FIRMWARE, FirmwareKey.TITLE).equals(pathName) || (FirmwareUtil.getAttributeKey(FirmwareType.FIRMWARE, FirmwareKey.TITLE).equals(pathName)
@ -379,7 +379,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
LOG_LW2M_ERROR, pathIdVer, valueNew); LOG_LW2M_ERROR, pathIdVer, valueNew);
this.sendLogsToThingsboard(logMsg, lwM2MClient.getRegistration().getId()); this.sendLogsToThingsboard(logMsg, lwM2MClient.getRegistration().getId());
} }
} else { } else if (!isFwSwWords(pathName)) {
log.error("Resource name name - [{}] value - [{}] is not present as attribute/telemetry in profile and cannot be updated", pathName, valueNew); log.error("Resource name name - [{}] value - [{}] is not present as attribute/telemetry in profile and cannot be updated", pathName, valueNew);
String logMsg = String.format("%s: attributeUpdate: attribute name - %s value - %s is not present as attribute in profile and cannot be updated", String logMsg = String.format("%s: attributeUpdate: attribute name - %s value - %s is not present as attribute in profile and cannot be updated",
LOG_LW2M_ERROR, pathName, valueNew); LOG_LW2M_ERROR, pathName, valueNew);
@ -446,7 +446,6 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
String bodyParams = StringUtils.trimToNull(toDeviceRpcRequestMsg.getParams()) != null ? toDeviceRpcRequestMsg.getParams() : "null"; String bodyParams = StringUtils.trimToNull(toDeviceRpcRequestMsg.getParams()) != null ? toDeviceRpcRequestMsg.getParams() : "null";
LwM2mTypeOper lwM2mTypeOper = setValidTypeOper(toDeviceRpcRequestMsg.getMethodName()); LwM2mTypeOper lwM2mTypeOper = setValidTypeOper(toDeviceRpcRequestMsg.getMethodName());
UUID requestUUID = new UUID(toDeviceRpcRequestMsg.getRequestIdMSB(), toDeviceRpcRequestMsg.getRequestIdLSB()); UUID requestUUID = new UUID(toDeviceRpcRequestMsg.getRequestIdMSB(), toDeviceRpcRequestMsg.getRequestIdLSB());
log.warn("4) RPC-OK finish to [{}], keys: [{}]", requestUUID, this.rpcSubscriptions.keySet());
if (!this.rpcSubscriptions.containsKey(requestUUID)) { if (!this.rpcSubscriptions.containsKey(requestUUID)) {
this.rpcSubscriptions.put(requestUUID, toDeviceRpcRequestMsg.getExpirationTime()); this.rpcSubscriptions.put(requestUUID, toDeviceRpcRequestMsg.getExpirationTime());
Lwm2mClientRpcRequest lwm2mClientRpcRequest = null; Lwm2mClientRpcRequest lwm2mClientRpcRequest = null;
@ -647,7 +646,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
* set setClient_fw_info... = value * set setClient_fw_info... = value
**/ **/
if (lwM2MClient.getFwUpdate().isInfoFwSwUpdate()) { if (lwM2MClient.getFwUpdate().isInfoFwSwUpdate()) {
lwM2MClient.getFwUpdate().initReadValue(this, this.lwM2mTransportRequest, path); lwM2MClient.getFwUpdate().initReadValue(this, this.lwM2mTransportRequest, path);
} }
if (lwM2MClient.getSwUpdate().isInfoFwSwUpdate()) { if (lwM2MClient.getSwUpdate().isInfoFwSwUpdate()) {
lwM2MClient.getSwUpdate().initReadValue(this, this.lwM2mTransportRequest, path); lwM2MClient.getSwUpdate().initReadValue(this, this.lwM2mTransportRequest, path);
@ -1229,7 +1228,6 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
public void onGetAttributesResponse(TransportProtos.GetAttributeResponseMsg attributesResponse, TransportProtos.SessionInfoProto sessionInfo) { public void onGetAttributesResponse(TransportProtos.GetAttributeResponseMsg attributesResponse, TransportProtos.SessionInfoProto sessionInfo) {
try { try {
List<TransportProtos.TsKvProto> tsKvProtos = attributesResponse.getSharedAttributeListList(); List<TransportProtos.TsKvProto> tsKvProtos = attributesResponse.getSharedAttributeListList();
this.updateAttributeFromThingsboard(tsKvProtos, sessionInfo); this.updateAttributeFromThingsboard(tsKvProtos, sessionInfo);
} catch (Exception e) { } catch (Exception e) {
log.error("", e); log.error("", e);
@ -1346,7 +1344,6 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
if (lwM2MClient.getRegistration().getSupportedVersion(FW_ID) != null) { if (lwM2MClient.getRegistration().getSupportedVersion(FW_ID) != null) {
SessionInfoProto sessionInfo = this.getSessionInfoOrCloseSession(lwM2MClient); SessionInfoProto sessionInfo = this.getSessionInfoOrCloseSession(lwM2MClient);
if (sessionInfo != null) { if (sessionInfo != null) {
DefaultLwM2MTransportMsgHandler serviceImpl = this;
transportService.process(sessionInfo, createFirmwareRequestMsg(sessionInfo, FirmwareType.FIRMWARE.name()), transportService.process(sessionInfo, createFirmwareRequestMsg(sessionInfo, FirmwareType.FIRMWARE.name()),
new TransportServiceCallback<>() { new TransportServiceCallback<>() {
@Override @Override

View File

@ -23,26 +23,26 @@ public class LwM2mNetworkConfig {
NetworkConfig coapConfig = new NetworkConfig(); NetworkConfig coapConfig = new NetworkConfig();
coapConfig.setInt(NetworkConfig.Keys.COAP_PORT,serverPortNoSec); coapConfig.setInt(NetworkConfig.Keys.COAP_PORT,serverPortNoSec);
coapConfig.setInt(NetworkConfig.Keys.COAP_SECURE_PORT,serverSecurePort); coapConfig.setInt(NetworkConfig.Keys.COAP_SECURE_PORT,serverSecurePort);
/* /**
Example:Property for large packet: Example:Property for large packet:
#NetworkConfig config = new NetworkConfig(); #NetworkConfig config = new NetworkConfig();
#config.setInt(NetworkConfig.Keys.MAX_MESSAGE_SIZE,32); #config.setInt(NetworkConfig.Keys.MAX_MESSAGE_SIZE,32);
#config.setInt(NetworkConfig.Keys.PREFERRED_BLOCK_SIZE,32); #config.setInt(NetworkConfig.Keys.PREFERRED_BLOCK_SIZE,32);
#config.setInt(NetworkConfig.Keys.MAX_RESOURCE_BODY_SIZE,2048); #config.setInt(NetworkConfig.Keys.MAX_RESOURCE_BODY_SIZE,2048);
#config.setInt(NetworkConfig.Keys.MAX_RETRANSMIT,3); #config.setInt(NetworkConfig.Keys.MAX_RETRANSMIT,3);
#config.setInt(NetworkConfig.Keys.MAX_TRANSMIT_WAIT,120000); #config.setInt(NetworkConfig.Keys.MAX_TRANSMIT_WAIT,120000);
*/ */
/* /**
Property to indicate if the response should always include the Block2 option \ Property to indicate if the response should always include the Block2 option \
when client request early blockwise negociation but the response can be sent on one packet. when client request early blockwise negociation but the response can be sent on one packet.
- value of false indicate that the server will respond without block2 option if no further blocks are required. - value of false indicate that the server will respond without block2 option if no further blocks are required.
- value of true indicate that the server will response with block2 option event if no further blocks are required. - value of true indicate that the server will response with block2 option event if no further blocks are required.
CoAP client will try to use block mode CoAP client will try to use block mode
or adapt the block size when receiving a 4.13 Entity too large response code or adapt the block size when receiving a 4.13 Entity too large response code
*/ */
coapConfig.setBoolean(NetworkConfig.Keys.BLOCKWISE_STRICT_BLOCK2_OPTION, true); coapConfig.setBoolean(NetworkConfig.Keys.BLOCKWISE_STRICT_BLOCK2_OPTION, true);
/* /**
Property to indicate if the response should always include the Block2 option \ Property to indicate if the response should always include the Block2 option \
when client request early blockwise negociation but the response can be sent on one packet. when client request early blockwise negociation but the response can be sent on one packet.
- value of false indicate that the server will respond without block2 option if no further blocks are required. - value of false indicate that the server will respond without block2 option if no further blocks are required.
@ -51,44 +51,44 @@ public class LwM2mNetworkConfig {
coapConfig.setBoolean(NetworkConfig.Keys.BLOCKWISE_ENTITY_TOO_LARGE_AUTO_FAILOVER, true); coapConfig.setBoolean(NetworkConfig.Keys.BLOCKWISE_ENTITY_TOO_LARGE_AUTO_FAILOVER, true);
coapConfig.setInt(NetworkConfig.Keys.BLOCKWISE_STATUS_LIFETIME, 300000); coapConfig.setInt(NetworkConfig.Keys.BLOCKWISE_STATUS_LIFETIME, 300000);
/* /**
!!! REQUEST_ENTITY_TOO_LARGE CODE=4.13 !!! REQUEST_ENTITY_TOO_LARGE CODE=4.13
The maximum size of a resource body (in bytes) that will be accepted The maximum size of a resource body (in bytes) that will be accepted
as the payload of a POST/PUT or the response to a GET request in a as the payload of a POST/PUT or the response to a GET request in a
transparent> blockwise transfer. transparent> blockwise transfer.
This option serves as a safeguard against excessive memory This option serves as a safeguard against excessive memory
consumption when many resources contain large bodies that cannot be consumption when many resources contain large bodies that cannot be
transferred in a single CoAP message. This option has no impact on transferred in a single CoAP message. This option has no impact on
*manually* managed blockwise transfers in which the blocks are handled individually. *manually* managed blockwise transfers in which the blocks are handled individually.
Note that this option does not prevent local clients or resource Note that this option does not prevent local clients or resource
implementations from sending large bodies as part of a request or response to a peer. implementations from sending large bodies as part of a request or response to a peer.
The default value of this property is DEFAULT_MAX_RESOURCE_BODY_SIZE = 8192 The default value of this property is DEFAULT_MAX_RESOURCE_BODY_SIZE = 8192
A value of {@code 0} turns off transparent handling of blockwise transfers altogether. A value of {@code 0} turns off transparent handling of blockwise transfers altogether.
*/ */
coapConfig.setInt(NetworkConfig.Keys.MAX_RESOURCE_BODY_SIZE, 256 * 1024 * 1024); coapConfig.setInt(NetworkConfig.Keys.MAX_RESOURCE_BODY_SIZE, 256 * 1024 * 1024);
/* /**
The default DTLS response matcher. The default DTLS response matcher.
Supported values are STRICT, RELAXED, or PRINCIPAL. Supported values are STRICT, RELAXED, or PRINCIPAL.
The default value is STRICT. The default value is STRICT.
Create new instance of udp endpoint context matcher. Create new instance of udp endpoint context matcher.
Params: Params:
checkAddress checkAddress
true with address check, (STRICT, UDP) true with address check, (STRICT, UDP)
- false, without - false, without
*/ */
coapConfig.setString(NetworkConfig.Keys.RESPONSE_MATCHING, "STRICT"); coapConfig.setString(NetworkConfig.Keys.RESPONSE_MATCHING, "STRICT");
/* /**
https://tools.ietf.org/html/rfc7959#section-2.9.3 https://tools.ietf.org/html/rfc7959#section-2.9.3
The block size (number of bytes) to use when doing a blockwise transfer. \ The block size (number of bytes) to use when doing a blockwise transfer. \
This value serves as the upper limit for block size in blockwise transfers This value serves as the upper limit for block size in blockwise transfers
*/ */
coapConfig.setInt(NetworkConfig.Keys.PREFERRED_BLOCK_SIZE, 1024); coapConfig.setInt(NetworkConfig.Keys.PREFERRED_BLOCK_SIZE, 1024);
/* /**
The maximum payload size (in bytes) that can be transferred in a The maximum payload size (in bytes) that can be transferred in a
single message, i.e. without requiring a blockwise transfer. single message, i.e. without requiring a blockwise transfer.
NB: this value MUST be adapted to the maximum message size supported by the transport layer. NB: this value MUST be adapted to the maximum message size supported by the transport layer.
In particular, this value cannot exceed the network's MTU if UDP is used as the transport protocol In particular, this value cannot exceed the network's MTU if UDP is used as the transport protocol
DEFAULT_VALUE = 1024 DEFAULT_VALUE = 1024
*/ */
coapConfig.setInt(NetworkConfig.Keys.MAX_MESSAGE_SIZE, 1024); coapConfig.setInt(NetworkConfig.Keys.MAX_MESSAGE_SIZE, 1024);

View File

@ -43,7 +43,10 @@ import org.eclipse.leshan.server.registration.Registration;
import org.nustaq.serialization.FSTConfiguration; import org.nustaq.serialization.FSTConfiguration;
import org.thingsboard.server.common.data.DeviceProfile; import org.thingsboard.server.common.data.DeviceProfile;
import org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration; import org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration;
import org.thingsboard.server.common.data.firmware.FirmwareKey;
import org.thingsboard.server.common.data.firmware.FirmwareType;
import org.thingsboard.server.common.data.firmware.FirmwareUpdateStatus; import org.thingsboard.server.common.data.firmware.FirmwareUpdateStatus;
import org.thingsboard.server.common.data.firmware.FirmwareUtil;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.transport.TransportServiceCallback; import org.thingsboard.server.common.transport.TransportServiceCallback;
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient; import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient;
@ -927,4 +930,17 @@ public class LwM2mTransportUtil {
return null; return null;
} }
} }
public static boolean isFwSwWords (String pathName) {
return FirmwareUtil.getAttributeKey(FirmwareType.FIRMWARE, FirmwareKey.VERSION).equals(pathName)
|| FirmwareUtil.getAttributeKey(FirmwareType.FIRMWARE, FirmwareKey.TITLE).equals(pathName)
|| FirmwareUtil.getAttributeKey(FirmwareType.FIRMWARE, FirmwareKey.CHECKSUM).equals(pathName)
|| FirmwareUtil.getAttributeKey(FirmwareType.FIRMWARE, FirmwareKey.CHECKSUM_ALGORITHM).equals(pathName)
|| FirmwareUtil.getAttributeKey(FirmwareType.FIRMWARE, FirmwareKey.SIZE).equals(pathName)
|| FirmwareUtil.getAttributeKey(FirmwareType.SOFTWARE, FirmwareKey.VERSION).equals(pathName)
|| FirmwareUtil.getAttributeKey(FirmwareType.SOFTWARE, FirmwareKey.TITLE).equals(pathName)
|| FirmwareUtil.getAttributeKey(FirmwareType.SOFTWARE, FirmwareKey.CHECKSUM).equals(pathName)
|| FirmwareUtil.getAttributeKey(FirmwareType.SOFTWARE, FirmwareKey.CHECKSUM_ALGORITHM).equals(pathName)
|| FirmwareUtil.getAttributeKey(FirmwareType.SOFTWARE, FirmwareKey.SIZE).equals(pathName);
}
} }

View File

@ -116,7 +116,7 @@ public class LwM2mClientContextImpl implements LwM2mClientContext {
securityInfo.getDeviceProfile().getUuidId() : null; securityInfo.getDeviceProfile().getUuidId() : null;
// TODO: for tests bug. // TODO: for tests bug.
if (profileUuid== null) { if (profileUuid== null) {
log.warn("input parameters toClientProfile if the result is null: [{}]", securityInfo.getDeviceProfile()); log.trace("input parameters toClientProfile if the result is null: [{}]", securityInfo.getDeviceProfile());
} }
LwM2mClient client; LwM2mClient client;
if (securityInfo.getSecurityInfo() != null) { if (securityInfo.getSecurityInfo() != null) {

View File

@ -188,14 +188,13 @@ public class LwM2mFwSwUpdate {
null, 0, null); null, 0, null);
} }
/** /**
* Firmware start: * Firmware start:
* -- Если Update Result -errors (более 1) - Это означает что пред. апдейт не прошел. * -- If the result of the update - errors (more than 1) - This means that the previous. the update failed.
* - Запускаем апдейт в независимости от состяния прошивки и ее версии. * - We launch the update regardless of the state of the firmware and its version.
* -- Если Update Result - не errors (менее или равно 1) и ver не пустой - Это означает что пред. апдейт прошел. * -- If the result of the update is not errors (equal to 1 or 0) and ver is not empty - This means that before the update has passed.
* -- Если Update Result - не errors и ver пустой - Это означает что апдейта еще не было. * -- If the result of the update is not errors and is empty - This means that there has not been an update yet.
* - Проверяем поменялась ли версия и запускаем новый апдейт. * - Check if the version has changed and launch a new update.
*/ */
private boolean conditionalFwUpdateStart() { private boolean conditionalFwUpdateStart() {
Long updateResultFw = (Long) this.lwM2MClient.getResourceValue(null, this.pathResultId); Long updateResultFw = (Long) this.lwM2MClient.getResourceValue(null, this.pathResultId);
@ -241,12 +240,12 @@ public class LwM2mFwSwUpdate {
/** /**
* Software start * Software start
* -- Если Update Result -errors (равно и более 50) - Это означает что пред. апдейт не прошел. * - If Update Result -errors (equal or more than 50) - This means that the previous. the update failed.
* * - Запускаем апдейт в независимости от состяния прошивки и ее версии. * * - We launch the update regardless of the state of the firmware and its version.
* -- Если Update Result - не errors (менее 50) и ver не пустой - Это означает что пред. апдейт прошел. * - If Update Result is not errors (less than 50) and ver is not empty - This means that before. the update has passed.
* -- Если Update Result - не errors и ver пустой - Это означает что апдейта еще не было или пред. апдейт UnInstall * - If Update Result is not errors and ver is empty - This means that there was no update yet or before. UnInstall update
* -- Если Update Result - не errors и ver не пустой - Это означает что пред. апдейт UnInstall * - If Update Result is not errors and ver is not empty - This means that before unInstall update
* - Проверяем поменялась ли версия и запускаем новый апдейт. * * - Check if the version has changed and launch a new update.
*/ */
private boolean conditionalSwUpdateStart() { private boolean conditionalSwUpdateStart() {
Long updateResultSw = (Long) this.lwM2MClient.getResourceValue(null, this.pathResultId); Long updateResultSw = (Long) this.lwM2MClient.getResourceValue(null, this.pathResultId);

View File

@ -214,9 +214,9 @@ public class TbLwM2mRedisRegistrationStore implements CaliforniumRegistrationSto
// Add or update expiration // Add or update expiration
addOrUpdateExpiration(connection, updatedRegistration); addOrUpdateExpiration(connection, updatedRegistration);
// Update secondary index : /** Update secondary index :
// If registration is already associated to this address we don't care as we only want to keep the most * If registration is already associated to this address we don't care as we only want to keep the most
// recent binding. * recent binding. */
byte[] addr_idx = toRegAddrKey(updatedRegistration.getSocketAddress()); byte[] addr_idx = toRegAddrKey(updatedRegistration.getSocketAddress());
connection.set(addr_idx, updatedRegistration.getEndpoint().getBytes(UTF_8)); connection.set(addr_idx, updatedRegistration.getEndpoint().getBytes(UTF_8));
if (!r.getSocketAddress().equals(updatedRegistration.getSocketAddress())) { if (!r.getSocketAddress().equals(updatedRegistration.getSocketAddress())) {

View File

@ -32,6 +32,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.server.common.data.Customer; import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.DeviceInfo; import org.thingsboard.server.common.data.DeviceInfo;
@ -80,7 +81,6 @@ import org.thingsboard.server.dao.service.DataValidator;
import org.thingsboard.server.dao.service.PaginatedRemover; import org.thingsboard.server.dao.service.PaginatedRemover;
import org.thingsboard.server.dao.tenant.TbTenantProfileCache; import org.thingsboard.server.dao.tenant.TbTenantProfileCache;
import org.thingsboard.server.dao.tenant.TenantDao; import org.thingsboard.server.dao.tenant.TenantDao;
import org.thingsboard.common.util.JacksonUtil;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
@ -200,11 +200,16 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
Device savedDevice = this.saveDeviceWithoutCredentials(device); Device savedDevice = this.saveDeviceWithoutCredentials(device);
deviceCredentials.setDeviceId(savedDevice.getId()); deviceCredentials.setDeviceId(savedDevice.getId());
if (device.getId() == null) { if (device.getId() == null) {
deviceCredentials = deviceCredentialsService.createDeviceCredentials(savedDevice.getTenantId(), deviceCredentials); deviceCredentialsService.createDeviceCredentials(savedDevice.getTenantId(), deviceCredentials);
} }
else { else {
deviceCredentials.setId(deviceCredentialsService.findDeviceCredentialsByDeviceId(device.getTenantId(), savedDevice.getId()).getId()); DeviceCredentials foundDeviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(device.getTenantId(), savedDevice.getId());
deviceCredentials = deviceCredentialsService.updateDeviceCredentials(device.getTenantId(), deviceCredentials); if (foundDeviceCredentials == null) {
deviceCredentialsService.createDeviceCredentials(savedDevice.getTenantId(), deviceCredentials);
}
else {
deviceCredentialsService.updateDeviceCredentials(device.getTenantId(), deviceCredentials);
}
} }
return savedDevice; return savedDevice;
} }