Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Bump version and refactor FiwareIdGenerator (#30)
Browse files Browse the repository at this point in the history
Version in pom.xml bumped from 6.3.0 to 6.4.0. FiwareIdGenerator updated to a utility class by making it final and adding a private constructor, reducing chance of misuse. MAX_ID_LENGTH constant introduced to validate generated ID length, ensuring adherence to fiware specifications. This makes the code cleaner, and easier to debug and maintain.
  • Loading branch information
saschadoemer authored Nov 25, 2023
1 parent 49d5bed commit a45c6e3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>de.app.5gla</groupId>
<artifactId>fiware-integration-layer</artifactId>
<version>6.3.0</version>
<version>6.4.0</version>

<name>5gLa FIWARE integration layer</name>
<url>https://github.com/vitrum-connect/5gla-fiware-integration-layer</url>
Expand Down
25 changes: 19 additions & 6 deletions src/main/java/de/app/fivegla/fiware/api/FiwareIdGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
@Slf4j
public final class FiwareIdGenerator {

public static final int MAX_ID_LENGTH = 62;

private FiwareIdGenerator() {
// private constructor to prevent instantiation
}
Expand All @@ -27,12 +29,9 @@ private FiwareIdGenerator() {
public static String id(String prefix) {
var randomUUIDParts = UUID.randomUUID().toString().split("-");
var fiwareId = prefix + randomUUIDParts[0] + randomUUIDParts[1];
if (fiwareId.length() > 62) {
throw new FiwareIntegrationLayerException("The generated id is too long. Please choose a shorter prefix.");
} else {
log.debug("Generated id: " + fiwareId);
return fiwareId;
}
check(fiwareId);
log.debug("Generated id: " + fiwareId);
return fiwareId;
}

/**
Expand All @@ -44,4 +43,18 @@ public static String id() {
return id("");
}

/**
* Checks if the given ID is valid.
*
* @param id the ID to be checked
* @throws FiwareIntegrationLayerException if the ID is too long
*/
public static void check(String id) {
if (id.length() > MAX_ID_LENGTH) {
log.error("The id is too long. Please choose a shorter prefix.");
log.debug("Checked ID: " + id);
throw new FiwareIntegrationLayerException("The generated id is too long. Please choose a shorter prefix.");
}
}

}

0 comments on commit a45c6e3

Please sign in to comment.