/**
   * Sets the Milestone in the passed in section to be readonly if it has been copied to a CG
   * Invoice doc.
   *
   * @param section Milestone section to review and possibly set readonly
   * @param proposalNumber used to look for CG Invoice docs
   */
  private void prepareMilestonesTab(Section section, Long proposalNumber) {
    ContractsGrantsInvoiceDocumentService cgInvDocService =
        SpringContext.getBean(ContractsGrantsInvoiceDocumentService.class);

    for (Row row : section.getRows()) {
      for (Field field : row.getFields()) {
        if (field.getCONTAINER().equalsIgnoreCase(field.getFieldType())) {
          for (Row containerRow : field.getContainerRows()) {
            for (Field containerRowfield : containerRow.getFields()) {
              // a record is no longer editable if the bill has been copied to a CINV doc
              if (ObjectUtils.getNestedAttributePrimitive(containerRowfield.getPropertyName())
                  .matches(ArPropertyConstants.MilestoneFields.MILESTONE_IDENTIFIER)) {
                String milestoneId = containerRowfield.getPropertyValue();
                if (StringUtils.isNotEmpty(milestoneId)) {
                  if (cgInvDocService.hasMilestoneBeenCopiedToInvoice(
                      proposalNumber, milestoneId)) {
                    for (Field rowfield : row.getFields()) {
                      if (rowfield.getCONTAINER().equalsIgnoreCase(rowfield.getFieldType())) {
                        for (Row fieldContainerRow : rowfield.getContainerRows()) {
                          for (Field fieldContainerRowField : fieldContainerRow.getFields()) {
                            fieldContainerRowField.setReadOnly(true);
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
 /**
  * This method recurses through all the fields of the list of rows and adds each field's property
  * name to the set if it starts with Constants.MAINTENANCE_NEW_MAINTAINABLE
  *
  * @param listOfRows
  * @param errorKeys
  * @see KRADConstants#MAINTENANCE_NEW_MAINTAINABLE
  */
 protected static void addRowsToErrorKeySet(List<Row> listOfRows, Set<String> errorKeys) {
   if (listOfRows == null) {
     return;
   }
   for (Row row : listOfRows) {
     List<Field> fields = row.getFields();
     if (fields == null) {
       continue;
     }
     for (Field field : fields) {
       String fieldPropertyName = field.getPropertyName();
       if (fieldPropertyName != null
           && fieldPropertyName.startsWith(KRADConstants.MAINTENANCE_NEW_MAINTAINABLE)) {
         errorKeys.add(field.getPropertyName());
       }
       addRowsToErrorKeySet(field.getContainerRows(), errorKeys);
     }
   }
 }