/** * This method is used to handle activation code generation on both the school-wide level, * and on the individual family level, depending on the activationIdType. * * @common:operation */ public ArrayList resetActivationCode(ActivationIdType activationIdType, IdNumber idNumber) { ArrayList activations = new ArrayList(4096); if (activationIdType.isSchoolId()) { /** * Parse through each family in the school and generate an actiavtion code for * each family that does not already have one generated. Retrieve all the * families from the school in an array or array-type object, and check against * the array, rather than making 1000 queries (?). * * The only queries that will need to be looped are UPDATE queries, when updating * the table with the new "activationCode" and "lastReset" fields. */ String schoolId = activationIdType.getId().toString(); /** * Retrieve all families in the school based on the current graduation year. */ FamilyId[] families = familyData.getFamiliesBySchoolId(schoolId, globalApp.getSchoolYearString()); for (int index = 0; index < families.length; index++) { /** * Get the current date and time to store as lastReset. */ java.sql.Date lastReset = new java.sql.Date(System.currentTimeMillis()); /** * Initialize an Activation object into the array of Activations, and store * the generated activation code. * * TODO: Add better error-handling. */ try { activations.add(new Activation(families[index], generateActivationCode(), null, lastReset, null, idNumber)); } catch (Exception e) { e.printStackTrace(); } } } else if (activationIdType.isFamilyId()) { /** * This is similar to the logic for the above "schoolId" activation code generation, * but doesn't require the retrieval of an array of families. Only one family's * information is reset. */ FamilyId id = (FamilyId) activationIdType.getId(); /** * Get the current date and time to store as lastReset. * * TODO: Add better error-handling. */ java.sql.Date lastReset = new java.sql.Date(System.currentTimeMillis()); try { activations.add(new Activation(id, generateActivationCode(), null, lastReset, null, new IdNumber())); } catch (Exception e) { e.printStackTrace(); } } System.out.println("ACTIVATIONS ARRAYLIST SIZE IN RESETPASSWORD(): " + activations.size()); activations.trimToSize(); System.out.println("ACTIVATIONS ARRAYLIST SIZE IN RESETPASSWORD() AFTER TRIMTOSIZE(): " + activations.size()); /** * Process the reset for each item in the "activations" ArrayList. */ try { ListIterator lit = activations.listIterator(); int number = 0; while (lit.hasNext()) { Activation activation = (Activation) lit.next(); this.addActivationCode(activation.getActivationCode(), activation.getFamilyId(), idNumber); number++; } System.out.println("ACTIVATIONS LISTITERATOR SIZE IN RESETPASSWORD(): " + number); } catch (Exception e) { e.printStackTrace(); } return activations; }