diff --git a/pom.xml b/pom.xml index 77807b3..ecc70b5 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ de.app.5gla fiware-integration-layer - 6.3.0 + 6.4.0 5gLa FIWARE integration layer https://github.com/vitrum-connect/5gla-fiware-integration-layer diff --git a/src/main/java/de/app/fivegla/fiware/api/FiwareIdGenerator.java b/src/main/java/de/app/fivegla/fiware/api/FiwareIdGenerator.java index 606de4f..377c649 100644 --- a/src/main/java/de/app/fivegla/fiware/api/FiwareIdGenerator.java +++ b/src/main/java/de/app/fivegla/fiware/api/FiwareIdGenerator.java @@ -11,6 +11,8 @@ @Slf4j public final class FiwareIdGenerator { + public static final int MAX_ID_LENGTH = 62; + private FiwareIdGenerator() { // private constructor to prevent instantiation } @@ -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; } /** @@ -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."); + } + } + }