Class EditContentFunction

All Implemented Interfaces:
com.opensymphony.workflow.FunctionProvider, Initializable, LogEnabled, Serviceable
Direct Known Subclasses:
EditSynchronizedContentFunction

public class EditContentFunction extends AbstractContentWorkflowComponent implements com.opensymphony.workflow.FunctionProvider, Initializable
OSWorkflow function to edit a content.

Values are set either programmatically, or parsed from form submission by their ElementTypes according to the Content model.

The required transient variables:
- AbstractContentWorkflowComponent.RESULT_MAP_KEY - Map<String, Object> The map containing the results of the function.
- AbstractContentWorkflowComponent.RESULT_MAP_KEY.result - String "true" when everything goes fine. Missing in other case.
- AbstractContentWorkflowComponent.RESULT_MAP_KEY.<MetadataPath> - Errors Each error during edition will be set here. Key will be the metadata path (with '.' separator). Value will be the error message.
- AbstractContentWorkflowComponent.CONTENT_KEY - WorkflowAwareContent The content that will be edited. Should have the lock token.
- AbstractWorkflowComponent.CONTEXT_PARAMETERS_KEY - Map<String, Object> Contains the following parameters:
- AbstractWorkflowComponent.CONTEXT_PARAMETERS_KEY.QUIT - boolean True to specify edition mode will be quit, this imply to unlock the content.
- AbstractWorkflowComponent.CONTEXT_PARAMETERS_KEY.VIEW_PARAM The name of the view to use and to check attributes. If missing a view will be created from values.
- AbstractWorkflowComponent.CONTEXT_PARAMETERS_KEY.FALLBACK_VIEW_PARAM The name of the view to use if the initial view does not exist on the Content's model.
- AbstractWorkflowComponent.CONTEXT_PARAMETERS_KEY.VALUES_KEY - Map<String, Object> The typed values. If present, raw values must not be present.
- AbstractWorkflowComponent.CONTEXT_PARAMETERS_KEY.FORM_RAW_VALUES - Map<String, Object> The values of the submitted form. If present, types values must not be present.
- AbstractWorkflowComponent.CONTEXT_PARAMETERS_KEY.FORM_RAW_VALUES.<MetadataPath> Object Key is the path of the metadata ('.' separated) prefixed by FORM_ELEMENTS_PREFIX. Value is a depending on the type of metadata. Sometimes types require additional information. In that case : Key is a metadata path ('.' separated) prefixed by INTERNAL_FORM_ELEMENTS_PREFIX and suffixed by '.' + an additional information name.
- AbstractWorkflowComponent.CONTEXT_PARAMETERS_KEY.FORM_RAW_COMMENTS - Map<String, List<Map<String, String>>> The comments of the metadata of the submitted form :
- AbstractContentWorkflowComponent.RESULT_MAP_KEY.<MetadataPath> - List<Map<String, String>> Key is the path of the metadata ('.' separated) prefixed by FORM_ELEMENTS_PREFIX. Value is the list of comments.
- AbstractContentWorkflowComponent.RESULT_MAP_KEY.<MetadataPath>.<X> - <Map<String, String> A comment with the following parameters
- AbstractContentWorkflowComponent.RESULT_MAP_KEY.<MetadataPath>.<X>.author String The login of the author of the comment
- AbstractContentWorkflowComponent.RESULT_MAP_KEY.<MetadataPath>.<X>.text String The text of the comment
- AbstractContentWorkflowComponent.RESULT_MAP_KEY.<MetadataPath>.<X>.date String The date of the comment using the ISODateTimeFormat (See DateUtils.parse)
Where <MetadataPath> is the path of a metadata (using a '.' separator). In some cases it is prefixed by FORM_ELEMENTS_PREFIX. A metadata path with in a repeater include the number of the repeated instance (1 based).
Where <X> Is an element of the parent list.
  • Field Details

  • Constructor Details

  • Method Details

    • initialize

      public void initialize() throws Exception
      Specified by:
      initialize in interface Initializable
      Throws:
      Exception
    • execute

      public void execute(Map transientVars, Map args, com.opensymphony.module.propertyset.PropertySet ps) throws com.opensymphony.workflow.WorkflowException
      Specified by:
      execute in interface com.opensymphony.workflow.FunctionProvider
      Throws:
      com.opensymphony.workflow.WorkflowException
    • getInvertEditActionId

      protected int getInvertEditActionId(Map transientVars, Content referencedContent)
      Get the identifier of the invert edit action
      Parameters:
      transientVars - The workflow vars
      referencedContent - the content concerned by the invert relation
      Returns:
      the identifier of the invert edit action
    • notifyContentModifying

      protected void notifyContentModifying(Content content, Map<String,Object> values, Map transientVars) throws com.opensymphony.workflow.WorkflowException
      Notify observers that the content is being modified
      Parameters:
      content - The content being modified
      values - the new values being set to the content
      transientVars - The workflow vars
      Throws:
      com.opensymphony.workflow.WorkflowException - If an error occurred
    • notifyContentModified

      protected void notifyContentModified(Content content, Map transientVars, SynchronizationResult synchronizationResult) throws com.opensymphony.workflow.WorkflowException
      Notify observers that the content has been modified
      Parameters:
      content - The content modified
      transientVars - The workflow vars
      synchronizationResult - The result of the content values synchronization
      Throws:
      com.opensymphony.workflow.WorkflowException - If an error occurred
    • getView

      protected View getView(Map<String,Object> parameters, Map<String,Object> values, Map<String,Object> rawValues, Content content, Map transientVars) throws com.opensymphony.workflow.WorkflowException
      Get the view for the content
      Parameters:
      parameters - The parameters
      values - Typed values from inputs
      rawValues - The raw values of the form
      content - The content
      transientVars - the parameters from the call
      Returns:
      The view asked in the request or a built-in view
      Throws:
      com.opensymphony.workflow.WorkflowException - If an error occurred while getting the view
    • getValues

      protected Map<String,Object> getValues(View view, ModifiableContent content, Map<String,Object> typedValues, Map<String,Object> rawValues, Map<String,List<Map<String,String>>> rawComments, boolean localOnly, Map transientVars) throws com.opensymphony.workflow.WorkflowException
      Computes the actual typed values from the input.
      Parameters:
      view - the current View
      content - the current Content
      typedValues - typed values, if any
      rawValues - raw values from form, if any
      rawComments - the form comments, if any
      localOnly - if the form values are local only or may include external values
      transientVars - the parameters from the call.
      Returns:
      the actual values to be set
      Throws:
      com.opensymphony.workflow.WorkflowException - If an error occurred
    • _convertValue

      protected Object _convertValue(ElementDefinition definition, Object value, Map transientVars)
      Converts the given value according to the given definition If the value is multiple, an array is retrieved with each value converted to the right type
      Parameters:
      definition - the definition
      value - the value to convert
      transientVars - the parameters from the call.
      Returns:
      the converted value
    • getValueExternalizableDataStatus

      Get the status of the value to modify
      Parameters:
      content - the content
      definition - the definition of the value
      transientVars - the parameters from the call
      Returns:
      the status of the value
    • validateValues

      protected void validateValues(View view, ModifiableContent content, Map<String,Object> values, AllErrors allErrors, Map transientVars) throws com.opensymphony.workflow.WorkflowException
      Validates all input values.
      Parameters:
      view - the model's view corresponding to the values
      content - the current content
      values - the actual input values
      allErrors - object to be populated with validation errors
      transientVars - the parameters from the call
      Throws:
      com.opensymphony.workflow.WorkflowException - If an error occurred
    • validateValue

      protected void validateValue(ElementDefinition definition, String dataPath, Optional<String> oldDataPath, ModifiableContent content, Object value, AllErrors allErrors, Map transientVars)
      Validate an attribute value.
      Parameters:
      definition - the attribute definition.
      dataPath - the attribute path.
      oldDataPath - the old data path, i.e. with the repeater entries previous positions. Used to know the current status for externalizable data
      content - the Content being edited.
      value - the value.
      allErrors - the errors.
      transientVars - the parameters from the call.
    • validateRepeaterValue

      protected void validateRepeaterValue(ModelViewItemGroup viewItem, RepeaterDefinition definition, String dataPath, Optional<String> oldDataPath, ModifiableContent content, Object value, AllErrors allErrors, Map transientVars)
      Validate repeater values.
      Parameters:
      viewItem - the view item referencing the repeater
      definition - the repeater definition.
      dataPath - the repeater path.
      oldDataPath - the old repeater data path, i.e. with the repeater entries previous positions. Used to know the current status for externalizable data
      content - the Content being edited.
      value - the value.
      allErrors - the errors.
      transientVars - the parameters from the call.
    • globalValidate

      protected void globalValidate(View view, Content content, Map<String,Object> values, AllErrors allErrors)
      Performs a global validation of the Content, based on declared ContentValidators.
      Parameters:
      view - the current View
      content - the current Content.
      values - the values being set
      allErrors - object to be populated with validation errors
    • prepareSynchronize

      protected Collection<ReferencedContents> prepareSynchronize(ModifiableContent content, View view, Map<String,Object> values, UserIdentity user, AllErrors allErrors, Map transientVars)
      Prepares the write process by checking remote contents concerned by invert relations.
      Parameters:
      content - the current content.
      view - the current View.
      values - the new values.
      user - the current user
      allErrors - the collected errors
      transientVars - the parameters from the call.
      Returns:
      the ReferencedContents
    • synchronize

      protected SynchronizationResult synchronize(ModifiableContent content, View view, Map<String,Object> values, Collection<ReferencedContents> referencedContents, Map transientVars) throws com.opensymphony.workflow.WorkflowException
      Synchronize the values of the given content
      Parameters:
      content - the content to synchronize
      view - the content's view to use for synchronization
      values - the values to synchronize
      referencedContents - the contents referenced by invert relations
      transientVars - the parameters from the call.
      Returns:
      The result of the synchronization
      Throws:
      com.opensymphony.workflow.WorkflowException - if an error occurs while triggering the edition workflow action for related contents
    • getSynchronizationContext

      Retrieves the synchronization context
      Parameters:
      transientVars - the parameters from the call
      Returns:
      the synchronization context
    • additionalOperations

      protected ContentSynchronizationResult additionalOperations(ModifiableContent content, Map transientVars) throws com.opensymphony.workflow.WorkflowException
      Allow to do some other modifications on the given content before saving changes
      Parameters:
      content - the content
      transientVars - the parameters from the call
      Returns:
      The synchronization result od additional operations
      Throws:
      com.opensymphony.workflow.WorkflowException - If an error occurred
    • updateCommonMetadata

      protected void updateCommonMetadata(ModifiableContent content, UserIdentity user, SynchronizationResult synchronizationResult) throws com.opensymphony.workflow.WorkflowException
      Updates common metadata (last contributor, last modification date, ...).
      Parameters:
      content - the content.
      user - the user.
      synchronizationResult - The result of the content values synchronization
      Throws:
      com.opensymphony.workflow.WorkflowException - if an error occurs.
    • extractOutgoingReferences

      protected void extractOutgoingReferences(ModifiableContent content, SynchronizationResult synchronizationResult)
      Analyze the content to extract outgoing references and store them
      Parameters:
      content - The content to analyze
      synchronizationResult - The result of the content values synchronization
    • invertRelationEnabled

      protected boolean invertRelationEnabled()
      Template method to indicates if invert relation should be taken into account during the whole edition. Override and return false to disabled invert relation management.
      Returns:
      true if invert relation are enabled
    • triggerInvertWorkflowAction

      protected void triggerInvertWorkflowAction(Content content, int actionId) throws com.opensymphony.workflow.WorkflowException
      Trigger a 'edit content' workflow action (if the content is workflow-aware).
      Parameters:
      content - The content.
      actionId - The current 'edit content' action ID.
      Throws:
      com.opensymphony.workflow.WorkflowException - if an error occurs.
    • _canWriteModelItem

      protected boolean _canWriteModelItem(ModelItem modelItem, Content content, Map transientVars)
      Returns true if the current model item is writable for this content in the current context.
      Parameters:
      modelItem - The model item to check
      content - The content
      transientVars - The parameters from the call
      Returns:
      true if the current model item is writable