/** * An award report term item is unique if no other matching items are in the collection To know if * this is a new add or an edit of an existing equipment item, we check the identifier for * nullity. If null, this is an add; otherwise, it's an update If an update, then we expect to * find one match in the collection (itself). If an add, we expect to find no matches in the * collection. * * @param awardReportTermItems * @param awardReportTermItem * @return */ protected boolean isUnique( List<? extends GenericAwardReportTerm> awardReportTermItems, GenericAwardReportTerm awardReportTermItem) { boolean duplicateFound = false; for (GenericAwardReportTerm listItem : awardReportTermItems) { duplicateFound = awardReportTermItem != listItem && listItem.equalsInitialFields(awardReportTermItem); if (duplicateFound) { break; } } if (duplicateFound) { if (!GlobalVariables.getMessageMap() .containsMessageKey(KeyConstants.ERROR_AWARD_REPORT_TERM_ITEM_NOT_UNIQUE)) { reportError("awardReportTerm", KeyConstants.ERROR_AWARD_REPORT_TERM_ITEM_NOT_UNIQUE); } } return !duplicateFound; }
/** * This method validates that all the required fields have values. It is protected so that it can * be unit tested easily. * * @param awardReportTermItem * @param fieldPrePend * @return */ protected boolean validateRequiredFields( GenericAwardReportTerm awardReportTermItem, String fieldPrePend) { boolean retVal = true; if (StringUtils.isBlank(awardReportTermItem.getReportCode())) { retVal = false; reportError( fieldPrePend + AWARD_REPORT_TERM_REPORT_CODE_PROPERTY, KeyConstants.ERROR_REQUIRED, REPORT_CODE_ERROR_PARM); } if (StringUtils.isBlank(awardReportTermItem.getFrequencyCode()) && !StringUtils.isBlank(awardReportTermItem.getOspDistributionCode())) { retVal = false; reportError( fieldPrePend + AWARD_REPORT_TERM_FREQUENCY_CODE_PROPERTY, KeyConstants.ERROR_AWARD_REPORT_TERM_ITEM_FREQUENCY_REQUIRED); } if (StringUtils.isBlank(awardReportTermItem.getFrequencyBaseCode())) { FrequencyBaseCodeValuesFinder finder = new FrequencyBaseCodeValuesFinder(awardReportTermItem.getFrequencyCode()); /** * If there are no frequency bases active, then we don't validate the frequency base field. * Note, there is always a 'select' value pair in the keyValues. */ if (finder.getKeyValues().size() > 1) { retVal = false; reportError( fieldPrePend + AWARD_REPORT_TERM_FREQUENCY_BASE_CODE_PROPERTY, KeyConstants.ERROR_REQUIRED, FREQUENCY_BASE_CODE_ERROR_PARM); } } if (StringUtils.isBlank(awardReportTermItem.getOspDistributionCode()) && isFinalReport(awardReportTermItem.getReportCode()) && StringUtils.isNotBlank(awardReportTermItem.getFrequencyCode())) { reportError( fieldPrePend + AWARD_REPORT_TERM_DISTRIBUTION_PROPERTY, KeyConstants.ERROR_AWARD_REPORT_TERM_ITEM_OSP_REQUIRED); retVal = false; } return retVal; }