/**
   * Generates the field definition for the transient <code>rmCategoryIdentifier</code> property
   *
   * @param form The Form instance to add the property to
   * @param nodeRef The node the form is being generated for
   */
  protected void generateDispositionInstructionsPropertyField(Form form, NodeRef nodeRef) {
    String dataKeyName = FormFieldConstants.PROP_DATA_PREFIX + TRANSIENT_DISPOSITION_INSTRUCTIONS;
    PropertyFieldDefinition dispInstructionsField =
        new PropertyFieldDefinition(
            TRANSIENT_DISPOSITION_INSTRUCTIONS, DataTypeDefinition.TEXT.getLocalName());
    dispInstructionsField.setLabel(TRANSIENT_DISPOSITION_INSTRUCTIONS);
    dispInstructionsField.setDescription(TRANSIENT_DISPOSITION_INSTRUCTIONS);
    dispInstructionsField.setProtectedField(true);
    dispInstructionsField.setDataKeyName(dataKeyName);
    form.addFieldDefinition(dispInstructionsField);

    // use RMService to get disposition instructions
    DispositionSchedule ds = dispositionService.getDispositionSchedule(nodeRef);
    if (ds != null) {
      String instructions = ds.getDispositionInstructions();
      if (instructions != null) {
        form.addData(dataKeyName, instructions);
      }
    }
  }
  /*
   * @see org.alfresco.repo.forms.processor.Filter#afterGenerate(java.lang.Object, java.util.List, java.util.List, org.alfresco.repo.forms.Form, java.util.Map)
   */
  public void afterGenerate(
      NodeRef nodeRef,
      List<String> fields,
      List<String> forcedFields,
      Form form,
      Map<String, Object> context) {
    // TODO this needs a massive refactor inorder to support any custom type or aspect ....

    // if the node has the RM marker aspect look for the custom properties
    // for the type
    if (this.nodeService.hasAspect(nodeRef, ASPECT_FILE_PLAN_COMPONENT)) {
      if (this.nodeService.hasAspect(nodeRef, ASPECT_RECORD)) {
        // determine whether the record has any custom RM properties
        if (this.nodeService.hasAspect(nodeRef, ASPECT_CUSTOM_RECORD_PROPERTIES)) {
          // add the 'rm-custom' field group
          addCustomRMGroup(form);
        } else {
          // add field defintions for all the custom properties
          // addCustomRMProperties(CustomisableRmElement.RECORD, form);
          addCustomRMProperties(ASPECT_RECORD, form);
        }

        // force the "supplementalMarkingList" property to be present
        forceSupplementalMarkingListProperty(form, nodeRef);

        // generate property definitions for the 'transient' properties
        generateDeclaredPropertyField(form, nodeRef);
        generateRecordTypePropertyField(form, nodeRef);
        generateCategoryIdentifierPropertyField(form, nodeRef);
        generateDispositionInstructionsPropertyField(form, nodeRef);

        // if the record is the result of an email we need to 'protect' some fields
        if (this.nodeService.hasAspect(nodeRef, ImapModel.ASPECT_IMAP_CONTENT)) {
          protectEmailExtractedFields(form, nodeRef);
        }
      } else {
        QName type = this.nodeService.getType(nodeRef);
        if (TYPE_RECORD_SERIES.equals(type)) {
          // determine whether the record series has any custom RM
          // properties
          if (this.nodeService.hasAspect(nodeRef, ASPECT_CUSTOM_RECORD_SERIES_PROPERTIES)) {
            // add the 'rm-custom' field group
            addCustomRMGroup(form);
          } else {
            // add field defintions for all the custom properties
            // addCustomRMProperties(CustomisableRmElement.RECORD_SERIES, form);
            addCustomRMProperties(TYPE_RECORD_SERIES, form);
          }
        } else if (TYPE_RECORD_CATEGORY.equals(type)) {
          // determine whether the record category has any custom RM
          // properties
          if (this.nodeService.hasAspect(nodeRef, ASPECT_CUSTOM_RECORD_CATEGORY_PROPERTIES)) {
            // add the 'rm-custom' field group
            addCustomRMGroup(form);
          } else {
            // add field defintions for all the custom properties
            addCustomRMProperties(TYPE_RECORD_CATEGORY, form);
          }
        } else if (TYPE_RECORD_FOLDER.equals(type)) {
          // determine whether the record folder has any custom RM
          // properties
          if (this.nodeService.hasAspect(nodeRef, ASPECT_CUSTOM_RECORD_FOLDER_PROPERTIES)) {
            // add the 'rm-custom' field group
            addCustomRMGroup(form);
          } else {
            // add field defintions for all the custom properties
            addCustomRMProperties(TYPE_RECORD_FOLDER, form);
          }

          // force the "supplementalMarkingList" property to be present
          forceSupplementalMarkingListProperty(form, nodeRef);
        } else if (TYPE_DISPOSITION_SCHEDULE.equals(type)) {
          // use the same mechanism used to determine whether steps can be removed from the
          // schedule to determine whether the disposition level can be changed i.e. record
          // level or folder level.
          DispositionSchedule schedule =
              new DispositionScheduleImpl(this.rmServiceRegistry, this.nodeService, nodeRef);
          if (dispositionService.hasDisposableItems(schedule) == true) {
            protectRecordLevelDispositionPropertyField(form);
          }
        }
      }
    }
  }