protected List<DocumentAttribute> parsePrimaryKeyValuesFromDocument(
      Class<? extends BusinessObject> businessObjectClass, MaintenanceDocument document) {
    List<DocumentAttribute> values = new ArrayList<DocumentAttribute>();

    final List primaryKeyNames =
        KRADServiceLocatorWeb.getLegacyDataAdapter().listPrimaryKeyFieldNames(businessObjectClass);

    for (Object primaryKeyNameAsObj : primaryKeyNames) {
      final String primaryKeyName = (String) primaryKeyNameAsObj;
      final DocumentAttribute searchableValue =
          parseSearchableAttributeValueForPrimaryKey(primaryKeyName, businessObjectClass, document);
      if (searchableValue != null) {
        values.add(searchableValue);
      }
    }
    return values;
  }
  protected DocumentAttribute generateSearchableAttributeFromChange(Object changeToPersist) {
    List<String> primaryKeyNames =
        KRADServiceLocatorWeb.getLegacyDataAdapter()
            .listPrimaryKeyFieldNames(changeToPersist.getClass());

    for (Object primaryKeyNameAsObject : primaryKeyNames) {
      String primaryKeyName = (String) primaryKeyNameAsObject;
      Object value = ObjectUtils.getPropertyValue(changeToPersist, primaryKeyName);

      if (value != null) {
        final WorkflowAttributePropertyResolutionService propertyResolutionService =
            KNSServiceLocator.getWorkflowAttributePropertyResolutionService();
        DocumentAttribute saValue =
            propertyResolutionService.buildSearchableAttribute(
                (Class) changeToPersist.getClass(), primaryKeyName, value);
        return saValue;
      }
    }
    return null;
  }
  /**
   * Creates a list of search fields, one for each primary key of the maintained business object
   *
   * @param businessObjectClass the class of the maintained business object
   * @return a List of KEW search fields
   */
  protected List<Row> createFieldRowsForBusinessObject(
      Class<? extends BusinessObject> businessObjectClass) {
    List<Row> searchFields = new ArrayList<Row>();

    final List primaryKeyNamesAsObjects =
        KRADServiceLocatorWeb.getLegacyDataAdapter().listPrimaryKeyFieldNames(businessObjectClass);
    final BusinessObjectEntry boEntry =
        KRADServiceLocatorWeb.getDataDictionaryService()
            .getDataDictionary()
            .getBusinessObjectEntry(businessObjectClass.getName());
    final WorkflowAttributePropertyResolutionService propertyResolutionService =
        KNSServiceLocator.getWorkflowAttributePropertyResolutionService();
    for (Object primaryKeyNameAsObject : primaryKeyNamesAsObjects) {

      String attributeName = (String) primaryKeyNameAsObject;
      BusinessObject businessObject = null;
      try {
        businessObject = businessObjectClass.newInstance();
      } catch (Exception e) {
        throw new RuntimeException(e);
      }

      Field searchField = FieldUtils.getPropertyField(businessObjectClass, attributeName, false);
      String dataType =
          propertyResolutionService.determineFieldDataType(businessObjectClass, attributeName);
      searchField.setFieldDataType(dataType);
      List<Field> fieldList = new ArrayList<Field>();

      List displayedFieldNames = new ArrayList();
      displayedFieldNames.add(attributeName);
      LookupUtils.setFieldQuickfinder(
          businessObject, attributeName, searchField, displayedFieldNames);

      fieldList.add(searchField);
      searchFields.add(new Row(fieldList));
    }

    return searchFields;
  }