Lwm2m Fix bug review edit formatting

This commit is contained in:
nickAS21 2021-09-21 17:35:19 +03:00
parent 7f681a993f
commit 157e2361f6
5 changed files with 7 additions and 45 deletions

View File

@ -348,16 +348,13 @@ public class LwM2MClient implements Serializable {
} else if (resourceModel.operations.isWritable() && resourceModel.mandatory) {
throw new IllegalArgumentException("Resource id=" + resourceId + " is mandatory. The value of this resource must not be null.");
}
}
else if (resourceModel.operations.isWritable() && resourceModel.mandatory) {
} else if (resourceModel.operations.isWritable() && resourceModel.mandatory) {
throw new IllegalArgumentException("Resource id=" + resourceId + " is mandatory. The value of this resource must not be null.");
}
});
}
else if (params == null) {
} else if (params == null) {
throw new IllegalArgumentException("The value of this resource must not be null.");
}
else {
} else {
throw new IllegalArgumentException("The value of this resource must be in Map format and size > 0");
}
return resources;

View File

@ -37,12 +37,12 @@ import org.thingsboard.server.queue.util.TbLwM2mTransportComponent;
import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig;
import org.thingsboard.server.transport.lwm2m.secure.TbLwM2MSecurityInfo;
import org.thingsboard.server.transport.lwm2m.server.LwM2MTransportContext;
import org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil;
import org.thingsboard.server.transport.lwm2m.server.ota.LwM2MOtaUpdateService;
import org.thingsboard.server.transport.lwm2m.server.session.LwM2MSessionManager;
import org.thingsboard.server.transport.lwm2m.server.store.TbLwM2MClientStore;
import org.thingsboard.server.transport.lwm2m.server.store.TbMainSecurityStore;
import org.thingsboard.server.transport.lwm2m.server.uplink.DefaultLwM2MUplinkMsgHandler;
import org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil;
import java.util.Arrays;
import java.util.Collection;
@ -293,7 +293,7 @@ public class LwM2MClientContextImpl implements LwM2MClientContext {
String k = entry.getKey();
String v = entry.getValue();
if (v.equals(keyName) && client.isValidObjectVersion(k).isEmpty()) {
return k;
return k;
}
}
throw new IllegalArgumentException(keyName + " is not configured in the device profile!");

View File

@ -352,7 +352,7 @@ public class LwM2MTransportUtil {
}
public static Map convertMultiResourceValuesFromRpcBody(Object value, ResourceModel.Type type, String versionedId) throws Exception {
String valueJsonStr = JsonUtils.riteValueAsString(value);
String valueJsonStr = JsonUtils.writeValueAsString(value);
JsonElement element = JsonUtils.parse(valueJsonStr);
return convertMultiResourceValuesFromJson(element, type, versionedId);
}

View File

@ -57,7 +57,7 @@ public class JsonUtils {
return jsonParser.parse(params);
}
public static String riteValueAsString (Object value) throws JsonProcessingException {
public static String writeValueAsString(Object value) throws JsonProcessingException {
return json.writeValueAsString(value);
}

View File

@ -124,39 +124,4 @@ public class JacksonUtil {
public static <T> T treeToValue(JsonNode tree, Class<T> type) throws JsonProcessingException {
return OBJECT_MAPPER.treeToValue(tree, type);
}
/**
*
* @param {bootstrap:client:host, client, client:port, client:endpoint}
* @param ":"
* @return
* - "bootstrap:client:host"
* -- if in nodeCredentialsValue is absent:
* --- "bootstrap" or "bootstrap:client" or "bootstrap:client:host" -> return "host"
* -- if in nodeCredentialsValue is absent:
* --- "client:port" -> return "port"
* -- if the nodeCredentialsValue contains:
* --- "client" and "client:port" -> "port" not add to Set
*/
public static String validateFieldsToTree(JsonNode nodeCredentialsValue, String[] fields, String delimiter) {
try {
StringBuilder msgSet = new StringBuilder();
for (String field : fields) {
String[] keys = field.split(delimiter);
JsonNode nodeVal = nodeCredentialsValue;
for (String key : keys) {
if (!nodeVal.hasNonNull(key)) {
msgSet.append(" " + keys[keys.length - 1]);
break;
} else {
nodeVal = nodeVal.get(key);
}
}
}
return msgSet.toString().trim();
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
}
}