AllCalculationData (AllCalcDataManager mgr, TimeSheetIdentifier id) { try { EmployeePeriodInfo epInfo = mgr.getEmployeePeriodInfo(id.getPpEnd()); if (epInfo == null) { final PolicyID asgnmtPolicyProfile = mgr.getAsgnmtMaster().getPolicy_profile(id.getPpEnd()); final PolicyID policyProfileId = (asgnmtPolicyProfile == null) ? PolicyID.EMPTY_POLICYID : asgnmtPolicyProfile; throw new InvalidPayPeriodException("EmployeePeriodInfo could not be obtained for employee " + id.getEmployee() + " and assignment " + id.getAsgnmt() + " and period end - " + id.getPpEnd() + ". " + "Possibly because the employee is not active on that date or there are not enough initialized policy profile " + "periods for policy profile " + policyProfileId ); } TimeSheetCalculationInfo calcInfo = this.getCalculationInfo(mgr, id); AssignmentPeriodState asgnmtPeriodState = calcInfo.getAssignmentPeriodState(); TimeSheetState timesheetState = calcInfo.getTimeSheetState(); //If requesting EDIT_VERSION, check to see if one exists or that period is amendable by the logged in user if (id.getVersion() == EmployeePeriodVersionInfo.EDIT_VERSION && !epInfo.hasEditVersion() && !isPeriodAmendable(epInfo, mgr, asgnmtPeriodState, timesheetState) ) { throw new InternalApplicationException("An editable timesheet could not be obtained for employee " + id.getEmployee() + " and period end - " + id.getPpEnd()); } //Check to see if an editable ACD is in ACD manager's cache - if one exists, use it //An empty unmodifiable ACD for a prior period might be in cache if an ACD for prior timesheet is requested and //if that's the case, we want to still be able to create an amended ACD final AllCalculationData acd = mgr.getAllCalcData(id.getPpEnd(),id.getVersion(),AllCalculationData.FETCH_CACHED_ONLY); if (acd != null && !acd.isUnmodifiable()) { return acd; } //Create an amended ACD only if the period is amendable and the logged in user can amend it if (isAmendableBySystemForUser(epInfo, mgr, asgnmtPeriodState)) { final AllCalculationData amendedAllCalcData = mgr.createAmendedAllCalcData(epInfo, parms.getApp_user(), WDateTime.now()); // No need to hook this up to approval change logic, since it is an in-memory change so far. //Recalculate the amended ACD so that timesheet exceptions (if any) get created on the amended timesheet amendedAllCalcData.recalc(mgr); } //By this time, the ACD mgr's ACD cache will have the amended ACD if one's created in this method //and we can retrieve the cached amended ACD or the ACD from the database return mgr.getAllCalcData(id.getPpEnd(), id.getVersion()); } catch(InvalidPayPeriodException e) { //Rethrow InvalidPeriodExceptions--don't wrap them. We want them to be typed as InvalidPeriodExceptions. throw e; } catch (Exception e) { throw new InternalApplicationException("Timesheet could not be obtained for employee " + id.getEmployee() + ", assignment " + id.getAsgnmt()+ ", period end " + id.getPpEnd() + " and version " + id.getVersion() + ".", e); } }