Skip to content

Commit

Permalink
GH-1666: Correctly handle object id in test Category.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Jan 13, 2025
1 parent 9eec2be commit 70fb56e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,6 @@ public void validate(ResourceModel resource, String modelName, String lwm2mVersi
}

protected void validateURN(String urn, ObjectModel object, String modelName) throws InvalidModelException {
String urnCategory = URN.getUrnKind(object.id);
if (urnCategory == URN.TEST_LABEL) {
// skip validation for Test category.
// See : https://github.com/OpenMobileAlliance/lwm2m-registry/issues/737
return;
}

// Validate URN for other category
if (!urn.startsWith("urn:oma:lwm2m:")) {
throw new InvalidModelException(
Expand All @@ -167,7 +160,7 @@ protected void validateURN(String urn, ObjectModel object, String modelName) thr
object.name, object.id, modelName, urn);
}
String kind = urnParts[3];
String expectedKind = urnCategory;
String expectedKind = URN.getUrnKind(object.id);
if (!expectedKind.equals(kind)) {
throw new InvalidModelException(
"Model for Object %s(%d) in %s is invalid : URN (%s) kind MUST be %s instead of %s", object.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class URN {
public static final String OMA_LABEL = "oma";
public static final String EXT_LABEL = "ext";
public static final String X_LABEL = "x";
public static final String TEST_LABEL = "test";
public static final String INVALID_LABEL = "invalid";
public static final String RESERVED_LABEL = "reserved";

Expand All @@ -43,10 +42,10 @@ public static String generateURN(int objectId, String objectVersion) {
/**
* Return URN "kind" from object id.
*
* @return {@link #OMA_LABEL}, {@link #EXT_LABEL} or {@link #X_LABEL} or {@link #TEST_LABEL} for valid object id.
* {@link #INVALID_LABEL} is returned for invalid id and {@link #RESERVED_LABEL} for reserved range.
* @return {@link #OMA_LABEL}, {@link #EXT_LABEL} or {@link #X_LABEL} for valid object id. {@link #INVALID_LABEL} is
* returned for invalid id and {@link #RESERVED_LABEL} for reserved range.
*
* @see <a href="http://www.openmobilealliance.org/wp/OMNA/LwM2M/LwM2MRegistry.html">OMA LightweightM2M (LwM2M)
* @see <a href="https://www.openmobilealliance.org/lwm2m/resources/registry/objects">OMA LightweightM2M (LwM2M)
* Object and Resource Registry </a>
*/
public static String getUrnKind(int objectId) {
Expand All @@ -56,10 +55,8 @@ public static String getUrnKind(int objectId) {
return RESERVED_LABEL;
if (2048 <= objectId && objectId <= 10240)
return EXT_LABEL;
if (10241 <= objectId && objectId <= 42768)
if (10241 <= objectId && objectId <= 42800)
return X_LABEL;
if (42769 <= objectId && objectId <= 42800)
return TEST_LABEL;
if (42801 <= objectId && objectId <= 65534)
return RESERVED_LABEL;
return INVALID_LABEL;
Expand Down

0 comments on commit 70fb56e

Please sign in to comment.