Class BaseSynchroComponent
- java.lang.Object
-
- org.ametys.plugins.contentio.synchronize.BaseSynchroComponent
-
- All Implemented Interfaces:
Component,Serviceable
public class BaseSynchroComponent extends Object implements Serviceable, Component
Class for basics operations on SCC.
-
-
Field Summary
Fields Modifier and Type Field Description protected CurrentUserProvider_currentUserProviderThe current user providerprotected ObservationManager_observationManagerThe observation managerprotected AmetysObjectResolver_resolverThe ametys object resolverprotected ContentWorkflowHelper_workflowHelperThe content workflow helperstatic StringROLEAvalon Role
-
Constructor Summary
Constructors Constructor Description BaseSynchroComponent()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private byte[]_getBytesFromValue(Object valueToSet)Get the bytes array from the value to setprivate String_getContentName(String title, String lang, String prefix)Gets the content nameprivate String[]_getLinesFromValue(Object valueToSet)Get the lines array from valueToSet for the richTextprivate String_getSHA1Hash(ByteArrayInputStream stream, org.slf4j.Logger logger)protected boolean_setBinaryMetadata(ModifiableCompositeMetadata metadataHolder, String metadataName, Object valueToSet, boolean synchronize, String title, org.slf4j.Logger logger)Set the binary metadataprivate Map<String,Boolean>_setMetadata(ModifiableCompositeMetadata metadataHolder, String metadataName, Object valueToSet, boolean synchronize, boolean forceExternalStatus, String contentTitle, String contentType, org.slf4j.Logger logger)private boolean_setRichTextMetadata(ModifiableCompositeMetadata metadataHolder, String metadataName, Object valueToSet, boolean synchronize, String title, org.slf4j.Logger logger)Set the richtext metadataprivate static <T> T[]_toTypedArray(Class<?> classToCastTo, List<Object> list)This method have been build to go through the CONTENTIO-95 problem.Map<String,Boolean>applyChanges(ModifiableDefaultContent content, Integer actionId, String event, boolean ignoreRights, org.slf4j.Logger logger)Does workflow actionMap<String,Boolean>applyChanges(ModifiableDefaultContent content, Integer actionId, String event, org.slf4j.Logger logger)Does workflow actionMap<String,Object>createContentAction(String contentType, String workflowName, int initialActionId, String lang, String contentTitle, String contentPrefix, org.slf4j.Logger logger)Creates content action with result from requestModifiableCompositeMetadatagetMetadataHolder(ModifiableCompositeMetadata parentMetadata, String metadataPath)Get the metadata holder for the requested metadata path.booleanremoveMetadataIfExists(ModifiableCompositeMetadata metadataHolder, String metadataName, boolean synchronize)Remove the metadata if existsvoidservice(ServiceManager manager)Map<String,Boolean>synchronizeMetadata(ModifiableDefaultContent content, ContentType contentType, String logicalMetadataPath, String completeMetadataPath, List<Object> remoteValue, boolean synchronize, boolean create, org.slf4j.Logger logger)Fill the metadata with remove value.Map<String,Boolean>synchronizeMetadata(ModifiableDefaultContent content, ContentType contentType, String logicalMetadataPath, ModifiableCompositeMetadata metadataHolder, String metadataName, List<Object> remoteValue, boolean synchronize, boolean create, org.slf4j.Logger logger)Fill the metadata with remote value.booleanupdateRelation(ModifiableCompositeMetadata metadataToEdit, String metadataName, String contentId, boolean remove)Update the invert relation by adding/removing the content to/from the old values.booleanupdateRelation(ModifiableCompositeMetadata metadataToEdit, String metadataName, Content content, boolean remove)Update the invert relation by adding/removing the content to/from the old values.voidupdateSCCProperty(DefaultContent content, String collectionId)Add the current synchronizable collection as propertyvoidvalidateContent(WorkflowAwareContent content, int validationActionId, boolean ignoreRights, org.slf4j.Logger logger)Validates a content after importvoidvalidateContent(WorkflowAwareContent content, int validationActionId, org.slf4j.Logger logger)Validates a content after import
-
-
-
Field Detail
-
_workflowHelper
protected ContentWorkflowHelper _workflowHelper
The content workflow helper
-
_observationManager
protected ObservationManager _observationManager
The observation manager
-
_currentUserProvider
protected CurrentUserProvider _currentUserProvider
The current user provider
-
_resolver
protected AmetysObjectResolver _resolver
The ametys object resolver
-
-
Constructor Detail
-
BaseSynchroComponent
public BaseSynchroComponent()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
servicein interfaceServiceable- Throws:
ServiceException
-
removeMetadataIfExists
public boolean removeMetadataIfExists(ModifiableCompositeMetadata metadataHolder, String metadataName, boolean synchronize)
Remove the metadata if exists- Parameters:
metadataHolder- The metadata holdermetadataName- The name of the metadatasynchronize-trueif the data is synchronize- Returns:
trueif the metadata have been removed
-
validateContent
public void validateContent(WorkflowAwareContent content, int validationActionId, org.slf4j.Logger logger)
Validates a content after import- Parameters:
content- The content to validatevalidationActionId- Validation action ID to use for this contentlogger- The logger
-
validateContent
public void validateContent(WorkflowAwareContent content, int validationActionId, boolean ignoreRights, org.slf4j.Logger logger)
Validates a content after import- Parameters:
content- The content to validatevalidationActionId- Validation action ID to use for this contentignoreRights- true if checking rights needs to be ignoredlogger- The logger
-
applyChanges
public Map<String,Boolean> applyChanges(ModifiableDefaultContent content, Integer actionId, String event, org.slf4j.Logger logger) throws RepositoryException
Does workflow action- Parameters:
content- The synchronized contentactionId- Workflow actionevent- Type of eventlogger- The logger- Returns:
- A
Mapwith one or twoBoolean, "success" tells if the operation have been done successfully, "error" tells if an error occurs during the content saving. The save can be successful but an error can occurs during the workflow update. - Throws:
RepositoryException- if an error occurs when trying to rollback pending changes in the repository.
-
applyChanges
public Map<String,Boolean> applyChanges(ModifiableDefaultContent content, Integer actionId, String event, boolean ignoreRights, org.slf4j.Logger logger) throws RepositoryException
Does workflow action- Parameters:
content- The synchronized contentactionId- Workflow actionevent- Type of eventignoreRights- true if checking rights needs to be ignoredlogger- The logger- Returns:
- A
Mapwith one or twoBoolean, "success" tells if the operation have been done successfully, "error" tells if an error occurs during the content saving. The save can be successful but an error can occurs during the workflow update. - Throws:
RepositoryException- if an error occurs when trying to rollback pending changes in the repository.
-
updateRelation
public boolean updateRelation(ModifiableCompositeMetadata metadataToEdit, String metadataName, Content content, boolean remove)
Update the invert relation by adding/removing the content to/from the old values.- Parameters:
metadataToEdit- Metadata holder to editmetadataName- Metadata name to setcontent- The content to add or removeremove-trueif we wan't to remove the content from the relation- Returns:
trueif there are changes
-
updateRelation
public boolean updateRelation(ModifiableCompositeMetadata metadataToEdit, String metadataName, String contentId, boolean remove)
Update the invert relation by adding/removing the content to/from the old values.- Parameters:
metadataToEdit- Metadata holder to editmetadataName- Metadata name to setcontentId- The content to add or removeremove-trueif we wan't to remove the content from the relation- Returns:
trueif there are changes
-
updateSCCProperty
public void updateSCCProperty(DefaultContent content, String collectionId) throws RepositoryException
Add the current synchronizable collection as property- Parameters:
content- The synchronized contentcollectionId- The ID of the collection- Throws:
RepositoryException- if an error occurred
-
createContentAction
public Map<String,Object> createContentAction(String contentType, String workflowName, int initialActionId, String lang, String contentTitle, String contentPrefix, org.slf4j.Logger logger)
Creates content action with result from request- Parameters:
contentType- Type of the content to createworkflowName- Workflow to use for this contentinitialActionId- Action ID for initializationlang- The languagecontentTitle- The content titlecontentPrefix- The content prefix for the node creationlogger- The logger- Returns:
- A
Mapwith the created content in "content", and aBooleanin "error" if an error occurs.
-
_getContentName
private String _getContentName(String title, String lang, String prefix)
Gets the content name- Parameters:
title- The namelang- The lang of the contentprefix- The prefix to put before the title- Returns:
- The content name
-
synchronizeMetadata
public Map<String,Boolean> synchronizeMetadata(ModifiableDefaultContent content, ContentType contentType, String logicalMetadataPath, String completeMetadataPath, List<Object> remoteValue, boolean synchronize, boolean create, org.slf4j.Logger logger)
Fill the metadata with remove value.- Parameters:
content- The content to synchronizecontentType- The content typelogicalMetadataPath- The logical metadata path without the entriescompleteMetadataPath- The complete metadata path from the root of the contentremoteValue- The remote valuesynchronize-trueif synchronizablecreate-trueif content is creating, false if it is updatedlogger- The logger- Returns:
- A
Mapwith aBooleanin "hasChanges" value if changes has been made, and aBooleanin "error" value if an error occurs.
-
synchronizeMetadata
public Map<String,Boolean> synchronizeMetadata(ModifiableDefaultContent content, ContentType contentType, String logicalMetadataPath, ModifiableCompositeMetadata metadataHolder, String metadataName, List<Object> remoteValue, boolean synchronize, boolean create, org.slf4j.Logger logger)
Fill the metadata with remote value.- Parameters:
content- The content to synchronizecontentType- The content typelogicalMetadataPath- The logical metadata path without the entriesmetadataHolder- the metadata holder of the content to synchronizemetadataName- the name of the metadataremoteValue- The remote valuesynchronize-trueif synchronizablecreate-trueif content is creating, false if it is updatedlogger- The logger- Returns:
- A
Mapwith aBooleanin "hasChanges" value if changes has been made, and aBooleanin "error" value if an error occurs.
-
_setRichTextMetadata
private boolean _setRichTextMetadata(ModifiableCompositeMetadata metadataHolder, String metadataName, Object valueToSet, boolean synchronize, String title, org.slf4j.Logger logger)
Set the richtext metadata- Parameters:
metadataHolder- the metadata holdermetadataName- the metadata namevalueToSet- the value to setsynchronize- true if the metadata is synchronizetitle- the content titlelogger- the logger- Returns:
trueif changes were made
-
_setBinaryMetadata
protected boolean _setBinaryMetadata(ModifiableCompositeMetadata metadataHolder, String metadataName, Object valueToSet, boolean synchronize, String title, org.slf4j.Logger logger)
Set the binary metadata- Parameters:
metadataHolder- the metadata holdermetadataName- the metadata namevalueToSet- the value to setsynchronize- true if the metadata is synchronizetitle- the content titlelogger- the logger- Returns:
trueif changes were made
-
_getBytesFromValue
private byte[] _getBytesFromValue(Object valueToSet) throws IOException
Get the bytes array from the value to set- Parameters:
valueToSet- the value to set- Returns:
- the bytes array
- Throws:
IOException- if an error occurred
-
_getLinesFromValue
private String[] _getLinesFromValue(Object valueToSet) throws IOException
Get the lines array from valueToSet for the richText- Parameters:
valueToSet- the value to set- Returns:
- the lines array
- Throws:
IOException- if an error occurred
-
_setMetadata
private Map<String,Boolean> _setMetadata(ModifiableCompositeMetadata metadataHolder, String metadataName, Object valueToSet, boolean synchronize, boolean forceExternalStatus, String contentTitle, String contentType, org.slf4j.Logger logger)
-
getMetadataHolder
public ModifiableCompositeMetadata getMetadataHolder(ModifiableCompositeMetadata parentMetadata, String metadataPath)
Get the metadata holder for the requested metadata path.- Parameters:
parentMetadata- Initial metadatametadataPath- Metadata path from the parent- Returns:
- A metadata holder
-
_getSHA1Hash
private String _getSHA1Hash(ByteArrayInputStream stream, org.slf4j.Logger logger)
-
_toTypedArray
private static <T> T[] _toTypedArray(Class<?> classToCastTo, List<Object> list)
This method have been build to go through the CONTENTIO-95 problem. The toArray() method returns an Object[] and it's not supported byExternalizableMetadataHelpermethods.- Type Parameters:
T- The type of the array- Parameters:
classToCastTo- The class to cast tolist- The list to transform to an array- Returns:
- A typed array.
-
-