This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add manufacturerSpecificId to Device model and tests (#29)
* Add manufacturerSpecificId to Device model and tests Updated the Device model to include the 'manufacturerSpecificId' field and modified all the 'DeviceIntegrationService*' and 'DroneDeviceMeasurementIntegrationService' integration tests to include the 'manufacturerSpecificId' in their respective Device builder. This change ensures more detailed device identification and improved traceability in device-related operations in the system. * Modify FiwareIdGenerator to be a utility class FiwareIdGenerator has been updated to a final class with a private constructor that cannot be instantiated. This transformation ensures the class can only contain static methods, making it a utility class which is with respect to Java best practices.
- Loading branch information
1 parent
079f4ee
commit 49d5bed
Showing
6 changed files
with
67 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/de/app/fivegla/fiware/api/FiwareIdGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package de.app.fivegla.fiware.api; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* This class provides methods for generating FIWARE IDs. | ||
* FIWARE IDs are used to uniquely identify entities in the FIWARE ecosystem. | ||
*/ | ||
@Slf4j | ||
public final class FiwareIdGenerator { | ||
|
||
private FiwareIdGenerator() { | ||
// private constructor to prevent instantiation | ||
} | ||
|
||
/** | ||
* Generates a unique identifier with the given prefix. | ||
* The generated identifier is a combination of the prefix and two parts of a randomly generated UUID string. | ||
* If the length of the generated identifier exceeds 62 characters, a FiwareIntegrationLayerException will be thrown. | ||
* | ||
* @param prefix the prefix to be appended to the randomly generated UUID parts | ||
* @return a unique identifier generated by combining the prefix and two parts of a randomly generated UUID string | ||
* @throws FiwareIntegrationLayerException if the length of the generated identifier exceeds 62 characters | ||
*/ | ||
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; | ||
} | ||
} | ||
|
||
/** | ||
* Generates a unique ID. | ||
* | ||
* @return a unique ID string | ||
*/ | ||
public static String id() { | ||
return id(""); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters