Improved:  Fix some bugs Spotbugs reports
Removes generateRandomFinNumber and checkIsNumberInDatabase methods
There is no OOTB usage and they were put in almost 15 years ago with
@@ -273,51 +273,6 @@ public final class FinAccountHelper {
return false;
}
- /**
- * Generate a random financial number
- * @param delegator the delegator
- * @param length length of the number to generate (up to 19 digits)
- * @param isId to be used as an ID (will check the DB to make sure it doesn't already exist)
- * @return Generated number
- * @throws GenericEntityException
- */
- public static String generateRandomFinNumber(Delegator delegator, int length, boolean isId) throws GenericEntityException {
- if (length > 19) {
- length = 19;
- }
-
- Random rand = new Random();
- boolean isValid = false;
- String number = null;
- StringBuilder numberBuilder = new StringBuilder();
- while (!isValid) {
- for (int i = 0; i < length; i++) {
- int randInt = rand.nextInt(9);
- numberBuilder.append(randInt);
- }
-
- if (isId) {
- // FIXME number is null!
- int check = UtilValidate.getLuhnCheckDigit(number);
- numberBuilder.append(check);
- number = numberBuilder.toString();
- // validate the number
- if (checkFinAccountNumber(number)) {
- // make sure this number doens't already exist
- isValid = checkIsNumberInDatabase(delegator, number);
- }
- } else {
- isValid = true;
- }
- }
- return number;
- }
-
- private static boolean checkIsNumberInDatabase(Delegator delegator, String number) throws GenericEntityException {
- GenericValue finAccount = EntityQuery.use(delegator).from("FinAccount").where("finAccountId", number).queryOne();
- return finAccount == null;
- }
-
public static boolean checkFinAccountNumber(String number) {
number = number.replaceAll("\\D", "");
return UtilValidate.sumIsMod10(UtilValidate.getLuhnSum(number));
