Skip to content

Commit

Permalink
server-demo: change attribute name for kind of lwm2m node (type => kind)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Oct 28, 2021
1 parent 30fe937 commit abf081c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
Expand Up @@ -57,12 +57,12 @@ public LwM2mNode deserialize(JsonParser p, DeserializationContext ctxt) throws I
id = object.get("id").asInt();
}

String type = null;
if (object.has("type")) {
type = object.get("type").asText();
String kind = null;
if (object.has("kind")) {
kind = object.get("kind").asText();
}

if ("obj".equals(type) || object.has("instances")) {
if ("obj".equals(kind) || object.has("instances")) {
if (id == null) {
throw new JsonParseException(p, "Missing id");
}
Expand All @@ -75,7 +75,7 @@ public LwM2mNode deserialize(JsonParser p, DeserializationContext ctxt) throws I
}
node = new LwM2mObject(id, instances);

} else if ("instance".equals(type) || object.has("resources")) {
} else if ("instance".equals(kind) || object.has("resources")) {
JsonNode array = object.get("resources");
LwM2mResource[] resources = new LwM2mResource[array.size()];

Expand All @@ -87,7 +87,7 @@ public LwM2mNode deserialize(JsonParser p, DeserializationContext ctxt) throws I
} else {
node = new LwM2mObjectInstance(id, resources);
}
} else if ("multiResource".equals(type) || object.has("values")) {
} else if ("multiResource".equals(kind) || object.has("values")) {
if (id == null) {
throw new JsonParseException(p, "Missing id");
}
Expand Down Expand Up @@ -117,7 +117,7 @@ public LwM2mNode deserialize(JsonParser p, DeserializationContext ctxt) throws I
throw new JsonParseException(p, "Missing id");
}

if ("resourceInstance".equals(type)) {
if ("resourceInstance".equals(kind)) {
// resource instance
JsonNode val = object.get("value");
org.eclipse.leshan.core.model.ResourceModel.Type expectedType = getTypeFor(val);
Expand Down
Expand Up @@ -51,10 +51,10 @@ public void serialize(LwM2mNode src, JsonGenerator gen, SerializerProvider provi
element.put("id", src.getId());

if (src instanceof LwM2mObject) {
element.put("type", "obj");
element.put("kind", "obj");
element.put("instances", ((LwM2mObject) src).getInstances().values());
} else if (src instanceof LwM2mObjectInstance) {
element.put("type", "instance");
element.put("kind", "instance");
element.put("resources", ((LwM2mObjectInstance) src).getResources().values());
} else if (src instanceof LwM2mResource) {
LwM2mResource rsc = (LwM2mResource) src;
Expand All @@ -68,18 +68,18 @@ public void serialize(LwM2mNode src, JsonGenerator gen, SerializerProvider provi
values.put(entry.getKey().toString(), entry.getValue().getValue());
}
}
element.put("type", "multiResource");
element.put("kind", "multiResource");
element.put("values", values);
} else {
element.put("type", "singleResource");
element.put("kind", "singleResource");
if (rsc.getType() == org.eclipse.leshan.core.model.ResourceModel.Type.OPAQUE) {
element.put("value", new String(Hex.encodeHex((byte[]) rsc.getValue())));
} else {
element.put("value", rsc.getValue());
}
}
} else if (src instanceof LwM2mResourceInstance) {
element.put("type", "resourceInstance");
element.put("kind", "resourceInstance");
LwM2mResourceInstance rsc = (LwM2mResourceInstance) src;
if (rsc.getType() == org.eclipse.leshan.core.model.ResourceModel.Type.OPAQUE) {
element.put("value", new String(Hex.encodeHex((byte[]) rsc.getValue())));
Expand Down
Expand Up @@ -158,7 +158,7 @@ export default {
.put(this.requestPath() + this.requestOption(), {
id: this.instanceId,
value: value,
type: "resourceInstance",
kind: "resourceInstance",
})
.then((response) => {
this.updateState(response.data, requestButton);
Expand Down
6 changes: 3 additions & 3 deletions leshan-server-demo/webapp/src/js/restutils.js
Expand Up @@ -27,7 +27,7 @@
* @returns a LWM2M object instance usable for REST API.
*/
function instanceToREST(model, id, value) {
let data = { type: "instance", resources: [] };
let data = { kind: "instance", resources: [] };

// set ID
if (id != null) {
Expand Down Expand Up @@ -66,7 +66,7 @@ function resourceToREST(model, value) {
function singleInstanceResourceToREST(model, value) {
let res = {};
res.id = model.id;
res.type = "singleResource";
res.kind = "singleResource";
res.value = value;
return res;
}
Expand All @@ -79,7 +79,7 @@ function singleInstanceResourceToREST(model, value) {
function multiInstanceResourceToREST(model, value) {
let res = {};
res.id = model.id;
res.type = "multiResource";
res.kind = "multiResource";
res.values = value.reduce(function(resource, instance) {
resource[instance.id] = instance.val;
return resource;
Expand Down
6 changes: 3 additions & 3 deletions leshan-server-demo/webapp/src/plugins/store.js
Expand Up @@ -178,12 +178,12 @@ class Store {
* @param {Boolean} supposed true means the value is supposed (not really send by the client)
*/
newNode(endpoint, path, node, supposed = false) {
if (node.type === "singleResource") {
if (node.kind === "singleResource") {
this.newResourceValue(endpoint, path, node, supposed);
} else if (node.type === "resourceInstance") {
} else if (node.kind === "resourceInstance") {
this.newResourceInstanceValueFromPath(endpoint, path, node, supposed);
} else {
console.log(node.type, " not yet supported");
console.log(node.kind, " not yet supported");
}
}

Expand Down
8 changes: 4 additions & 4 deletions leshan-server-demo/webapp/src/views/Client.vue
Expand Up @@ -159,28 +159,28 @@ export default {
}
})
.on("NOTIFICATION", (msg) => {
if (msg.val.type === "instance") {
if (msg.val.kind === "instance") {
this.$store.newInstanceValue(
this.$route.params.endpoint,
msg.res,
msg.val.resources,
false
);
} else if (msg.val.type === "singleResource") {
} else if (msg.val.kind === "singleResource") {
this.$store.newSingleResourceValue(
this.$route.params.endpoint,
msg.res,
msg.val.value,
false
);
} else if (msg.val.type === "multiResource") {
} else if (msg.val.kind === "multiResource") {
this.$store.newMultiResourceValue(
this.$route.params.endpoint,
msg.res,
msg.val.values,
false
);
} else if (msg.val.type === "resourceInstance") {
} else if (msg.val.kind === "resourceInstance") {
this.$store.newResourceInstanceValueFromPath(
this.$route.params.endpoint,
msg.res,
Expand Down

0 comments on commit abf081c

Please sign in to comment.