Skip to content

Commit

Permalink
Remove old Backward Compatibility code about RedisRegistrationStore
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Jun 14, 2023
1 parent cd22391 commit d3a6f46
Showing 1 changed file with 8 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@
import org.eclipse.leshan.core.node.LwM2mPath;
import org.eclipse.leshan.core.request.BindingMode;
import org.eclipse.leshan.core.request.ContentFormat;
import org.eclipse.leshan.server.registration.DefaultRegistrationDataExtractor;
import org.eclipse.leshan.server.registration.Registration;
import org.eclipse.leshan.server.registration.RegistrationDataExtractor;
import org.eclipse.leshan.server.registration.RegistrationDataExtractor.RegistrationData;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
Expand All @@ -62,8 +59,6 @@
public class RegistrationSerDes {

private final AttributeParser attributeParser;
// only needed for backward compatibility : maybe should be removed.
private final RegistrationDataExtractor dataExtractor;

public RegistrationSerDes() {
// Define all supported Attributes
Expand All @@ -73,16 +68,10 @@ public RegistrationSerDes() {

// Create default link Parser
this.attributeParser = new DefaultAttributeParser(suppportedAttributes);
this.dataExtractor = new DefaultRegistrationDataExtractor();
}

public RegistrationSerDes(AttributeParser attributeParser) {
this(attributeParser, new DefaultRegistrationDataExtractor());
}

public RegistrationSerDes(AttributeParser attributeParser, RegistrationDataExtractor dataExtractor) {
this.attributeParser = attributeParser;
this.dataExtractor = dataExtractor;
}

public JsonNode jSerialize(Registration r) {
Expand Down Expand Up @@ -247,14 +236,12 @@ public Registration deserialize(JsonNode jObj) {
}
b.additionalRegistrationAttributes(addAttr);

// For backward compatibility only ...
boolean extractData = false;

// parse supported content format
JsonNode ct = jObj.get("ct");
if (ct == null) {
// Backward compatibility : if ct doesn't exist we extract supported content format from object link
extractData = true;
throw new IllegalStateException(
String.format("Missing supported content format 'ct' field for registraiton %s/%s",
jObj.get("regId").asText(), jObj.get("ep").asText()));
} else {
Set<ContentFormat> supportedContentFormat = new HashSet<>();
for (JsonNode ctCode : ct) {
Expand All @@ -265,8 +252,8 @@ public Registration deserialize(JsonNode jObj) {
// parse supported object
JsonNode so = jObj.get("suppObjs");
if (so == null) {
// Backward compatibility : if suppObjs doesn't exist we extract supported object from object link
extractData = true;
throw new IllegalStateException(String.format("Missing supported object 'so' field for registraiton %s/%s",
jObj.get("regId").asText(), jObj.get("ep").asText()));
} else {
Map<Integer, Version> supportedObject = new HashMap<>();
for (Iterator<String> it = so.fieldNames(); it.hasNext();) {
Expand All @@ -279,8 +266,9 @@ public Registration deserialize(JsonNode jObj) {
// parse available instances
JsonNode ai = jObj.get("objInstances");
if (ai == null) {
// Backward compatibility : if objInstances doesn't exist we extract available instances from object link
extractData = true;
throw new IllegalStateException(
String.format("Missing available instances 'ai' field for registraiton %s/%s",
jObj.get("regId").asText(), jObj.get("ep").asText()));
} else {
Set<LwM2mPath> availableInstances = new HashSet<>();
for (JsonNode aiPath : ai) {
Expand All @@ -289,14 +277,6 @@ public Registration deserialize(JsonNode jObj) {
b.availableInstances(availableInstances);
}

// extract data if needed
if (extractData) {
RegistrationData dataFromObjectLinks = dataExtractor.extractDataFromObjectLinks(linkObjs, lwm2mVersion);
b.supportedContentFormats(dataFromObjectLinks.getSupportedContentFormats());
b.supportedObjects(dataFromObjectLinks.getSupportedObjects());
b.availableInstances(dataFromObjectLinks.getAvailableInstances());
}

// parse app data
Map<String, String> appData = new HashMap<>();
ObjectNode oap = (ObjectNode) jObj.get("appdata");
Expand Down

0 comments on commit d3a6f46

Please sign in to comment.