Package org.ametys.cms.workflow
Class EditContentFunction
- java.lang.Object
-
- org.ametys.plugins.workflow.AbstractWorkflowComponent
-
- org.ametys.cms.workflow.AbstractContentWorkflowComponent
-
- org.ametys.cms.workflow.EditContentFunction
-
- All Implemented Interfaces:
com.opensymphony.workflow.FunctionProvider,Initializable,LogEnabled,Serviceable
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 theirElementTypes according to theContentmodel.
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 Summary
Fields Modifier and Type Field Description protected ContentDataHelper_contentDataHelperHelper for collecting content referencesprotected ContentTypeExtensionPoint_contentTypeExtensionPointContent type extension point.protected ContentTypesHelper_contentTypesHelperHelper for content typesprotected ExternalizableDataProviderExtensionPoint_externalizableDataProviderEPProvider for externalizable dataprotected ObservationManager_observationManagerObservation manager available to subclasses.protected OutgoingReferencesExtractor_outgoingReferencesExtractorThe outgoing references extractorprotected UserManager_userManagerThe user managerprotected ContentWorkflowHelper_workflowHelperThe content workflow helper.static StringEDIT_MUTUAL_RELATIONSHIPConstant for storing the action id for editing revert relations.static StringFALLBACK_VIEW_NAMEFallback view name parameter.static StringFORM_ELEMENTS_PREFIXPrefix for HTML form elements.static StringFORM_RAW_COMMENTSRequest parameter key for the field comments.static StringFORM_RAW_VALUESRequest parameter key for the field values.static StringGLOBAL_ERROR_KEYThe key for global errorsstatic StringINTERNAL_FORM_ELEMENTS_PREFIXPrefix for internal HTML form elements.static intINVERT_EDIT_ACTION_IDDefault action id of editing revert relations.static StringINVERT_RELATION_EDIT_WORKFLOW_ACTION_IDConstant for storing the action id for editing revert relations.static StringLOCAL_ONLYLocal only parameter.static StringQUITQuit edition mode parameter.static StringVALUES_KEYInputs key for typed values.static StringVIEWView parameter.static StringVIEW_ITEMSView items parameter.static StringVIEW_NAMEView name parameter.-
Fields inherited from class org.ametys.cms.workflow.AbstractContentWorkflowComponent
_contentHelper, CONTENT_KEY
-
Fields inherited from class org.ametys.plugins.workflow.AbstractWorkflowComponent
_logger, _manager, CONTEXT_PARAMETERS_KEY, FAIL_CONDITIONS_KEY, RESULT_MAP_KEY, WORKFLOW_ERRORS_KEY, WORKFLOW_WARNS_KEY
-
-
Constructor Summary
Constructors Constructor Description EditContentFunction()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private LockableAmetysObject_checkLock(Content content, UserIdentity user)private Object_convertValue(ElementDefinition definition, Object value)private Map<String,Object>_convertValues(ViewItemContainer viewItemContainer, Map<String,Object> values)private void_flattenCollectedReferencedContents(Map<ContentValue,List<String>> references, Map<ContentValue,Pair<Boolean,String>> refContents, boolean forceInvert)private Object_getSynchronizableValue(Object value, ExternalizableDataProvider.ExternalizableDataStatus status, Object externalValue, List<Map<String,String>> rawComments)private void_getViewItems(Map<String,Object> values, Collection<? extends ModelItemContainer> parent, Content content, Set<String> viewItems)private void_handleErrors(Map transientVars, ModifiableContent modifiableContent, AllErrors errors)private boolean_isEditRefContentAvailable(int editActionId, Content refContent, boolean forceInvert, String currentMetadataPath, UserIdentity user, AllErrors allErrors)private Map<String,Object>_parseValues(ViewItemContainer viewItemContainer, String prefix, ModifiableContent content, Map<String,Object> rawValues, Map<String,List<Map<String,String>>> rawComments, boolean localOnly)protected void_triggerEditWorkflowAction(Content content, int actionId)Trigger a 'edit content' workflow action (if the content is workflow-aware).private void_validateValues(ViewItemContainer viewItemContainer, Optional<Map<String,Object>> values, String dataPath, ModifiableContent content, AllErrors allErrors)voidexecute(Map transientVars, Map args, com.opensymphony.module.propertyset.PropertySet ps)protected voidextractOutgoingReferences(ModifiableContent content)Analyze the content to extract outgoing references and store themprotected intgetInvertEditActionId(Map transientVars)Get the identifier of the invert edit actionprotected Map<String,Object>getValues(View view, Map<String,Object> typedValues, ModifiableContent content, Map<String,Object> rawValues, Map<String,List<Map<String,String>>> rawComments, boolean localOnly)Computes the actual typed values from the input.protected ViewgetView(Map<String,Object> parameters, Map<String,Object> values, Map<String,Object> rawValues, Content content)Get the view for the contentprotected voidglobalValidate(Content content, Map<String,Object> values, View view, AllErrors allErrors)Performs a global validation of the Content, based on declaredContentValidators.voidinitialize()protected booleaninvertRelationEnabled()Template method to indicates if invert relation should be taken into account during the whole edition.protected voidnotifyContentModified(Content content, Map transientVars)Notify observers that the content has been modifiedprotected voidnotifyContentModifying(Content content, Map<String,Object> values, Map transientVars)Notify observers that the content is being modifiedprotected Collection<ReferencedContents>prepareSynchronize(ModifiableContent content, View view, Map<String,Object> values, int invertEditActionId, UserIdentity user, AllErrors allErrors)Prepares the write process by checking remote contents concerned by invert relations.protected voidupdateCommonMetadata(ModifiableContent content, UserIdentity user)Updates common metadata (last contributor, last modification date, ...).protected voidvalidateValue(ElementDefinition definition, ModifiableContent content, String dataPath, AllErrors allErrors, Object value)Validate an attribute value.protected voidvalidateValues(View view, Map<String,Object> values, ModifiableContent content, AllErrors allErrors)Validates all input values.-
Methods inherited from class org.ametys.cms.workflow.AbstractContentWorkflowComponent
getContent, service
-
Methods inherited from class org.ametys.plugins.workflow.AbstractWorkflowComponent
addWorkflowError, addWorkflowWarning, enableLogging, getConditionFailures, getContextParameters, getResultsMap, getUser
-
-
-
-
Field Detail
-
INVERT_RELATION_EDIT_WORKFLOW_ACTION_ID
public static final String INVERT_RELATION_EDIT_WORKFLOW_ACTION_ID
Constant for storing the action id for editing revert relations.
-
EDIT_MUTUAL_RELATIONSHIP
public static final String EDIT_MUTUAL_RELATIONSHIP
Constant for storing the action id for editing revert relations.
-
FORM_ELEMENTS_PREFIX
public static final String FORM_ELEMENTS_PREFIX
Prefix for HTML form elements.- See Also:
- Constant Field Values
-
GLOBAL_ERROR_KEY
public static final String GLOBAL_ERROR_KEY
The key for global errors- See Also:
- Constant Field Values
-
INTERNAL_FORM_ELEMENTS_PREFIX
public static final String INTERNAL_FORM_ELEMENTS_PREFIX
Prefix for internal HTML form elements.- See Also:
- Constant Field Values
-
VALUES_KEY
public static final String VALUES_KEY
Inputs key for typed values.- See Also:
- Constant Field Values
-
FORM_RAW_VALUES
public static final String FORM_RAW_VALUES
Request parameter key for the field values.- See Also:
- Constant Field Values
-
FORM_RAW_COMMENTS
public static final String FORM_RAW_COMMENTS
Request parameter key for the field comments.- See Also:
- Constant Field Values
-
VIEW
public static final String VIEW
View parameter.- See Also:
- Constant Field Values
-
VIEW_ITEMS
public static final String VIEW_ITEMS
View items parameter.- See Also:
- Constant Field Values
-
VIEW_NAME
public static final String VIEW_NAME
View name parameter.- See Also:
- Constant Field Values
-
FALLBACK_VIEW_NAME
public static final String FALLBACK_VIEW_NAME
Fallback view name parameter.- See Also:
- Constant Field Values
-
QUIT
public static final String QUIT
Quit edition mode parameter.- See Also:
- Constant Field Values
-
LOCAL_ONLY
public static final String LOCAL_ONLY
Local only parameter.- See Also:
- Constant Field Values
-
INVERT_EDIT_ACTION_ID
public static final int INVERT_EDIT_ACTION_ID
Default action id of editing revert relations.- See Also:
- Constant Field Values
-
_contentTypeExtensionPoint
protected ContentTypeExtensionPoint _contentTypeExtensionPoint
Content type extension point.
-
_contentTypesHelper
protected ContentTypesHelper _contentTypesHelper
Helper for content types
-
_observationManager
protected ObservationManager _observationManager
Observation manager available to subclasses.
-
_workflowHelper
protected ContentWorkflowHelper _workflowHelper
The content workflow helper.
-
_outgoingReferencesExtractor
protected OutgoingReferencesExtractor _outgoingReferencesExtractor
The outgoing references extractor
-
_userManager
protected UserManager _userManager
The user manager
-
_externalizableDataProviderEP
protected ExternalizableDataProviderExtensionPoint _externalizableDataProviderEP
Provider for externalizable data
-
_contentDataHelper
protected ContentDataHelper _contentDataHelper
Helper for collecting content references
-
-
Constructor Detail
-
EditContentFunction
public EditContentFunction()
-
-
Method Detail
-
initialize
public void initialize() throws Exception
- Specified by:
initializein interfaceInitializable- Throws:
Exception
-
execute
public void execute(Map transientVars, Map args, com.opensymphony.module.propertyset.PropertySet ps) throws com.opensymphony.workflow.WorkflowException
- Specified by:
executein interfacecom.opensymphony.workflow.FunctionProvider- Throws:
com.opensymphony.workflow.WorkflowException
-
_checkLock
private LockableAmetysObject _checkLock(Content content, UserIdentity user) throws com.opensymphony.workflow.WorkflowException
- Throws:
com.opensymphony.workflow.WorkflowException
-
_handleErrors
private void _handleErrors(Map transientVars, ModifiableContent modifiableContent, AllErrors errors) throws com.opensymphony.workflow.WorkflowException, InvalidInputWorkflowException
- Throws:
com.opensymphony.workflow.WorkflowExceptionInvalidInputWorkflowException
-
getInvertEditActionId
protected int getInvertEditActionId(Map transientVars)
Get the identifier of the invert edit action- Parameters:
transientVars- The workflow vars- 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 modifiedvalues- the new values being set to the contenttransientVars- The workflow vars- Throws:
com.opensymphony.workflow.WorkflowException- If an error occurred
-
notifyContentModified
protected void notifyContentModified(Content content, Map transientVars) throws com.opensymphony.workflow.WorkflowException
Notify observers that the content has been modified- Parameters:
content- The content modifiedtransientVars- The workflow vars- 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) throws com.opensymphony.workflow.WorkflowException
Get the view for the content- Parameters:
parameters- The parametersvalues- Typed values from inputsrawValues- The raw values of the formcontent- The content- 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
-
_getViewItems
private void _getViewItems(Map<String,Object> values, Collection<? extends ModelItemContainer> parent, Content content, Set<String> viewItems)
-
getValues
protected Map<String,Object> getValues(View view, Map<String,Object> typedValues, ModifiableContent content, Map<String,Object> rawValues, Map<String,List<Map<String,String>>> rawComments, boolean localOnly)
Computes the actual typed values from the input.- Parameters:
view- the currentViewtypedValues- typed values, if anycontent- the current ContentrawValues- raw values from form, if anyrawComments- the form comments, if anylocalOnly- if the form values are local only or may include external values- Returns:
- the actual values to be set
-
_parseValues
private Map<String,Object> _parseValues(ViewItemContainer viewItemContainer, String prefix, ModifiableContent content, Map<String,Object> rawValues, Map<String,List<Map<String,String>>> rawComments, boolean localOnly)
-
_getSynchronizableValue
private Object _getSynchronizableValue(Object value, ExternalizableDataProvider.ExternalizableDataStatus status, Object externalValue, List<Map<String,String>> rawComments)
-
_convertValue
private Object _convertValue(ElementDefinition definition, Object value)
-
_convertValues
private Map<String,Object> _convertValues(ViewItemContainer viewItemContainer, Map<String,Object> values)
-
validateValues
protected void validateValues(View view, Map<String,Object> values, ModifiableContent content, AllErrors allErrors) throws com.opensymphony.workflow.WorkflowException
Validates all input values.- Parameters:
view- the model's view corresponding to the valuesvalues- the actual input valuescontent- the current contentallErrors- object to be populated with validation errors- Throws:
com.opensymphony.workflow.WorkflowException- If an error occurred
-
_validateValues
private void _validateValues(ViewItemContainer viewItemContainer, Optional<Map<String,Object>> values, String dataPath, ModifiableContent content, AllErrors allErrors)
-
validateValue
protected void validateValue(ElementDefinition definition, ModifiableContent content, String dataPath, AllErrors allErrors, Object value)
Validate an attribute value.- Parameters:
definition- the attribute definition.content- the Content being edited.dataPath- the attribute path.allErrors- the errors.value- the value.
-
globalValidate
protected void globalValidate(Content content, Map<String,Object> values, View view, AllErrors allErrors)
Performs a global validation of the Content, based on declaredContentValidators.
-
prepareSynchronize
protected Collection<ReferencedContents> prepareSynchronize(ModifiableContent content, View view, Map<String,Object> values, int invertEditActionId, UserIdentity user, AllErrors allErrors)
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.invertEditActionId- the action id to checkuser- the current userallErrors- the collected errors- Returns:
- the
ReferencedContents
-
_flattenCollectedReferencedContents
private void _flattenCollectedReferencedContents(Map<ContentValue,List<String>> references, Map<ContentValue,Pair<Boolean,String>> refContents, boolean forceInvert)
-
_isEditRefContentAvailable
private boolean _isEditRefContentAvailable(int editActionId, Content refContent, boolean forceInvert, String currentMetadataPath, UserIdentity user, AllErrors allErrors)
-
extractOutgoingReferences
protected void extractOutgoingReferences(ModifiableContent content)
Analyze the content to extract outgoing references and store them- Parameters:
content- The content to analyze
-
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
-
updateCommonMetadata
protected void updateCommonMetadata(ModifiableContent content, UserIdentity user) throws com.opensymphony.workflow.WorkflowException
Updates common metadata (last contributor, last modification date, ...).- Parameters:
content- the content.user- the user.- Throws:
com.opensymphony.workflow.WorkflowException- if an error occurs.
-
_triggerEditWorkflowAction
protected void _triggerEditWorkflowAction(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.
-
-