private void persistEntries(ProjectAssignment assignment, List<TimesheetEntry> entries, DateRange weekRange, boolean onlyLessThanExisting, List<Date> lockedDates) throws OverBudgetException { List<TimesheetEntry> previousEntries = Lists.newArrayList(timesheetDAO.getTimesheetEntriesInRange(assignment, weekRange)); for (TimesheetEntry entry : entries) { if (!entry.getEntryId().getProjectAssignment().equals(assignment)) { LOGGER.error("Invalid entry in assignment list, skipping: " + entry); previousEntries.remove(entry); continue; } if (lockedDates.contains(entry.getEntryId().getEntryDate())) { LOGGER.error("Date is locked but still trying to update " + entry); previousEntries.remove(entry); continue; } if (!entry.isEmptyEntry()) { persistEntry(onlyLessThanExisting, entry, getEntry(previousEntries, entry)); previousEntries.remove(entry); } } removeOldEntries(previousEntries); }