Class CopyContentComponent
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.cms.content.CopyContentComponent
-
- All Implemented Interfaces:
LogEnabled
,Component
,Serviceable
- Direct Known Subclasses:
CopyContentComponent
,CopyContentComponent
public class CopyContentComponent extends AbstractLogEnabled implements Serviceable, Component
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
CopyContentComponent.CopyAttachmentsHandler
A copy attachments content handler.
-
Field Summary
Fields Modifier and Type Field Description protected ContentHelper
_contentHelper
The content helperprotected ContentTypesHelper
_contentTypesHelper
Helper for content typesprotected ContentWorkflowHelper
_contentWorkflowHelper
The content workflow helperprotected ServiceManager
_manager
Avalon service managerprotected AmetysObjectResolver
_resolver
Ametys object resolver available to subclasses.protected WorkflowProvider
_workflowProvider
Workflow provider.static String
ROLE
Avalon ROLE.
-
Constructor Summary
Constructors Constructor Description CopyContentComponent()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.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.protected String
copyLinkedContent(Content content, Map<String,Object> copyMap, CopyReport copyReport)
Copy a value of a content attribute.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.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.int
getDefaultActionIdForContentEdition()
Get the default workflow action id for editing content by copyint
getDefaultInitActionId()
Get the default workflow action id for initialization of main contentprotected Map<String,Object>
getInputsForCopy(Content baseContent, String title, Map<String,Object> copyMap, String targetContentType, CopyReport copyReport)
Retrieve the inputs for the copy workflow function.protected String
getWorkflowName(Content content, Map<String,Object> inputs)
Retrieve the workflow name of a content.protected ContentValue
handleLinkedContent(ElementDefinition definition, ModifiableContent value, boolean referenceMode, Map<String,Object> copyMap, CopyReport copyReport)
Handle a single value of a content attributevoid
service(ServiceManager manager)
-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
_workflowProvider
protected WorkflowProvider _workflowProvider
Workflow provider.
-
_resolver
protected AmetysObjectResolver _resolver
Ametys object resolver available to subclasses.
-
_contentTypesHelper
protected ContentTypesHelper _contentTypesHelper
Helper for content types
-
_contentHelper
protected ContentHelper _contentHelper
The content helper
-
_contentWorkflowHelper
protected ContentWorkflowHelper _contentWorkflowHelper
The content workflow helper
-
_manager
protected ServiceManager _manager
Avalon service manager
-
-
Constructor Detail
-
CopyContentComponent
public CopyContentComponent()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- 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 idtitle
- Desired title for the new content or null if computed from the source's titlecopyMap
- The map of properties as described inCopyContentComponent
. 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 foundtargetContentType
- 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 copytitle
- The title to setcopyMap
- The map with properties to copytargetContentType
- 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 considerinputs
- 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 contenttargetContentId
- The identifier of the target contentcopyMap
- The map of properties as described inCopyContentComponent
. 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 contenttargetContentId
- The identifier of the target contentcopyMap
- The map of properties as described inCopyContentComponent
. 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 foundactionId
- 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 contenttargetContent
- the target contentcopyMap
- the map of properties as described inCopyContentComponent
.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 foundcopyReport
- 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 definitionvalue
- the linked value on the source contentreferenceMode
- true if a reference was initially requested, false if it was a copycopyMap
- the current copy mapcopyReport
- 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 mapcopyReport
- 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
public int getDefaultActionIdForContentEdition()
Get the default workflow action id for editing content by copy- Returns:
- the default action id
-
-