Package org.trustdeck.service
Class AlgorithmDBService
java.lang.Object
org.trustdeck.service.AlgorithmDBService
This class encapsulates the database access for algorithm objects.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanThe default value for whether or not to add a check digit to the pseudonym.static final StringThe name of the default algorithm.static final longThe default starting point for consecutive numbers as pseudonyms.static final booleanThe default value for whether or not the check digit should be included in the pseudonym length.static final StringThe default character used for padding the pseudonyms to the desired length.static final intThe default length for the pseudonyms.static final intThe default length for the pseudonyms when using a random algorithm.static final StringThe default success probability for creating a new pseudonym when using a randomness-based algorithm.static final longThe default number of pseudonyms that a randomness-based algorithm should be able to produce.static final doubleThe default success probability for creating a new pseudonym when using a randomness-based algorithm.static final intThe default length of a newly generated salt value. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateAlgorithm(Algorithm algorithm) Creates an algorithm object in the database.createOrGetAlgorithm(Algorithm algorithm) Creates an algorithm object in the database if it does not already exist.booleandeleteAlgorithm(int ID) Deletes the algorithm object based on its unique ID.getAlgorithmByID(int ID) Retrieves the algorithm object based on its unique ID.getAlgorithmByValues(String name, String alphabet, Long randomAlgoDesiredSize, Double randomAlgoDesiredSuccessProbability, Integer pseudonymLength, String paddingChar, Boolean addCheckDigit, Boolean lengthIncludesCheckDigit, String salt, Integer saltLength) Method to retrieve an algorithm-object from the database.booleanisAlgorithmInUse(int algorithmID) Helper method that checks if an algorithm is still used anywhere by searching for references to its ID.updateAlgorithm(Algorithm oldAlgorithm, Algorithm updatedAlgorithm) Updates an algorithm object in the database.booleanupdateCounter(Long counter, int algorithmID) Method to update only the counter value of an algorithm.
-
Field Details
-
DEFAULT_ALGORITHM_NAME
The name of the default algorithm.- See Also:
-
DEFAULT_RANDOM_ALGORITHM_DESIRED_SIZE
public static final long DEFAULT_RANDOM_ALGORITHM_DESIRED_SIZEThe default number of pseudonyms that a randomness-based algorithm should be able to produce.- See Also:
-
DEFAULT_RANDOM_ALGORITHM_DESIRED_SUCCESS_PROBABILITY
public static final double DEFAULT_RANDOM_ALGORITHM_DESIRED_SUCCESS_PROBABILITYThe default success probability for creating a new pseudonym when using a randomness-based algorithm.- See Also:
-
DEFAULT_RANDOM_ALGORITHM_ALPHABET
The default success probability for creating a new pseudonym when using a randomness-based algorithm.- See Also:
-
DEFAULT_CONSECUTIVE_VALUE_COUNTER
public static final long DEFAULT_CONSECUTIVE_VALUE_COUNTERThe default starting point for consecutive numbers as pseudonyms.- See Also:
-
DEFAULT_PSEUDONYM_LENGTH
public static final int DEFAULT_PSEUDONYM_LENGTHThe default length for the pseudonyms.- See Also:
-
DEFAULT_PSEUDONYM_LENGTH_RND
public static final int DEFAULT_PSEUDONYM_LENGTH_RNDThe default length for the pseudonyms when using a random algorithm.- See Also:
-
DEFAULT_PADDING_CHARACTER
The default character used for padding the pseudonyms to the desired length.- See Also:
-
DEFAULT_ADD_CHECK_DIGIT
public static final boolean DEFAULT_ADD_CHECK_DIGITThe default value for whether or not to add a check digit to the pseudonym.- See Also:
-
DEFAULT_LENGTH_INCLUDES_CHECK_DIGIT
public static final boolean DEFAULT_LENGTH_INCLUDES_CHECK_DIGITThe default value for whether or not the check digit should be included in the pseudonym length.- See Also:
-
DEFAULT_SALT_LENGTH
public static final int DEFAULT_SALT_LENGTHThe default length of a newly generated salt value.- See Also:
-
-
Constructor Details
-
AlgorithmDBService
public AlgorithmDBService()
-
-
Method Details
-
createAlgorithm
Creates an algorithm object in the database.- Parameters:
algorithm- the algorithm POJO to store- Returns:
- the ID of the newly created algorithm, or
nullif an error occurred.
-
createOrGetAlgorithm
Creates an algorithm object in the database if it does not already exist.- Parameters:
algorithm- the algorithm POJO to store- Returns:
- the ID of the (already) created algorithm, or
nullif an error occurred.
-
deleteAlgorithm
Deletes the algorithm object based on its unique ID.- Parameters:
ID- the ID corresponding to the algorithm object of interest- Returns:
trueif the deletion was successful,falseotherwise- Throws:
UnexpectedResultSizeException- whenever the deletion would not exactly affect one entry
-
getAlgorithmByID
Retrieves the algorithm object based on its unique ID.- Parameters:
ID- the ID corresponding to the algorithm object of interest- Returns:
- the algorithm POJO, or
nullif nothing could be found
-
getAlgorithmByValues
@Transactional public Algorithm getAlgorithmByValues(String name, String alphabet, Long randomAlgoDesiredSize, Double randomAlgoDesiredSuccessProbability, Integer pseudonymLength, String paddingChar, Boolean addCheckDigit, Boolean lengthIncludesCheckDigit, String salt, Integer saltLength) Method to retrieve an algorithm-object from the database. If there is more than one result, this method will return an arbitrary one that fits the search criteria.- Parameters:
name- the name of the algorithmalphabet- the alphabet used in the algorithmrandomAlgoDesiredSize- the desired number of possible pseudonyms in the output space of a randomness-based algorithmrandomAlgoDesiredSuccessProbability- the desired success probability for a randomness-based algorithmpseudonymLength- the length of the pseudonymspaddingChar- the character used to pad short pseudonyms to the desired lengthaddCheckDigit- whether or not to add a check digit to the pseudonymlengthIncludesCheckDigit- whether or not the desired length includes the check digitsalt- the salt used for pseudonymizationsaltLength- the length of the salt value- Returns:
- the algorithm object that was found when searching for the given attributes, or
nullwhen nothing was found
-
isAlgorithmInUse
@Transactional public boolean isAlgorithmInUse(int algorithmID) Helper method that checks if an algorithm is still used anywhere by searching for references to its ID.- Parameters:
algorithmID- the algorithm's ID- Returns:
truewhen the algorithm ID is referenced anywhere,falseotherwise
-
updateAlgorithm
Updates an algorithm object in the database. Null values in the updateAlgorithm object indicate that this specific attribute is to be kept as before.- Parameters:
oldAlgorithm- the old algorithm POJO that should be updatedupdatedAlgorithm- the algorithm POJO that contains all the updated values- Returns:
- the ID of the updated algorithm, or
nullif an error occurred
-
updateCounter
Method to update only the counter value of an algorithm.- Parameters:
counter- the new counter valuealgorithmID- the ID of the algorithm-object for which the counter should be updated- Returns:
true, when the update was successful,falseotherwise.
-