Class CopyContentComponent

All Implemented Interfaces:
LogEnabled, Component, Serviceable
Direct Known Subclasses:
CopyContentComponent, CopyContentComponent

This component is used to copy a content (either totally or partially).

In this whole file a Map named copyMap is regularly used. This map provide the name of the attribute to copy as well as some optional parameters. It has the following form (JSON) :

 {
   "$param1": value,
   "attributeA": null,
   "attributeB": {
     "subattributeB1": null,
     "subattributeB2": {
       "$param1": value,
       "$param2": value,
       "subSubattributeB21": {...}
     },
     ...
   }
 }
 

Each attribute that should be copied must be present as a key in the map. Composite attribute can contains child attributes but as seen on the example the map must be well structured, it is not a flat map. Parameters in the map must always start with the reserved character '$', in order to be differentiated from attribute name.

The entry points are the copyContent and editContent methods, which run a dedicated workflow function (createByCopy or edit).
Actual write of values is made through the EditContentFunction, with the values computed by this component.

  • Field Details

  • Constructor Details

  • Method Details

    • service

      public void service(ServiceManager manager) throws ServiceException
      Specified by:
      service in interface Serviceable
      Throws:
      ServiceException
    • copyContent

      public CopyReport copyContent(String contentId, String title, Map<String,Object> copyMap, String viewName, String fallbackViewName, String targetContentType, int initActionId)
      Copy a content by creating a new content and copying the attributes value a source content into the new one.
      Parameters:
      contentId - The source content id
      title - Desired title for the new content or null if computed from the source's title
      copyMap - The map of properties as described in CopyContentComponent. Can be null in which case the map will be constructed from the provided view.
      viewName - The name of the view to be used to construct to copyMap if not provided. This will also be the default name for possible inner copies (if not provided as a copyMap parameter).
      fallbackViewName - The fallback view name if 'viewName' is not found
      targetContentType - The type of content to create. If null the type(s) of created content will be those of base content.
      initActionId - The init workflow action id for main content only
      Returns:
      The copy report containing valuable information about the copy and the possible encountered errors.
    • getInputsForCopy

      protected Map<String,Object> getInputsForCopy(Content baseContent, String title, Map<String,Object> copyMap, String targetContentType, CopyReport copyReport)
      Retrieve the inputs for the copy workflow function.
      Parameters:
      baseContent - The content to copy
      title - The title to set
      copyMap - The map with properties to copy
      targetContentType - The type of content to create. If null the type(s) of created content will be those of base content.
      copyReport - The report of the copy
      Returns:
      The map of inputs.
    • getWorkflowName

      protected String getWorkflowName(Content content, Map<String,Object> inputs) throws IllegalArgumentException
      Retrieve the workflow name of a content.
      Parameters:
      content - The content to consider
      inputs - The inputs that will be provided to the workflow function
      Returns:
      The name of the workflow.
      Throws:
      IllegalArgumentException - if the content is not workflow aware.
    • editContent

      public CopyReport editContent(String contentId, String targetContentId, Map<String,Object> copyMap, String viewName, String fallbackViewName)
      Edit a content by copying attribute values a source content into a target content.
      Parameters:
      contentId - The identifier of the source content
      targetContentId - The identifier of the target content
      copyMap - The map of properties as described in CopyContentComponent. Can be null in which case the map will be constructed from the provided view.
      viewName - The name of the view to be used to construct to copyMap if not provided. This will also be the default name for possible inner copies (if not provided as a copyMap parameter).
      fallbackViewName - The fallback view name if 'viewName' is not found
      Returns:
      The copy report containing valuable information about the copy and the possible encountered errors.
    • editContent

      public CopyReport editContent(String contentId, String targetContentId, Map<String,Object> copyMap, String viewName, String fallbackViewName, int actionId)
      Edit a content by copying attribute values a source content into a target content.
      Parameters:
      contentId - The identifier of the source content
      targetContentId - The identifier of the target content
      copyMap - The map of properties as described in CopyContentComponent. Can be null in which case the map will be constructed from the provided view.
      viewName - The name of the view to be used to construct to copyMap if not provided. This will also be the default name for possible inner copies (if not provided as a copyMap parameter).
      fallbackViewName - The fallback view name if 'viewName' is not found
      actionId - the edit workflow action id
      Returns:
      The copy report containing valuable information about the copy and the possible encountered errors.
    • computeValues

      public Map<String,Object> computeValues(Content content, ModifiableContent targetContent, Map<String,Object> copyMap, Map<String,Object> additionalCopyMap, String viewName, String fallbackViewName, CopyReport copyReport)
      Extract values to copy from the given parameters.
      Parameters:
      content - the source content
      targetContent - the target content
      copyMap - the map of properties as described in CopyContentComponent.
      additionalCopyMap - an additional map of properties if needed. Can be null. Often used in case of recursive copies.
      viewName - The name of the view to be used to construct to copyMap if not provided. This will also be the default name for possible inner copies (if not provided as a copyMap parameter).
      fallbackViewName - The fallback view name if 'viewName' is not found
      copyReport - The copy report containing valuable information about the copy and the possible encountered errors.
      Returns:
      the computed values, ready to be synchronized to the target content.
    • handleLinkedContent

      protected ContentValue handleLinkedContent(ElementDefinition definition, ModifiableContent value, boolean referenceMode, Map<String,Object> copyMap, CopyReport copyReport)
      Handle a single value of a content attribute
      Parameters:
      definition - the attribute definition
      value - the linked value on the source content
      referenceMode - true if a reference was initially requested, false if it was a copy
      copyMap - the current copy map
      copyReport - the copy report
      Returns:
      the ContentValue (copied or not) to insert in the current Content.
    • copyLinkedContent

      protected String copyLinkedContent(Content content, Map<String,Object> copyMap, CopyReport copyReport)
      Copy a value of a content attribute.
      Parameters:
      content - the initial content value.
      copyMap - the current copy map
      copyReport - the current copy report
      Returns:
      the id of the copied Content.
    • getDefaultInitActionId

      public int getDefaultInitActionId()
      Get the default workflow action id for initialization of main content
      Returns:
      the default action id
    • getDefaultActionIdForContentEdition

      Get the default workflow action id for editing content by copy
      Returns:
      the default action id