Package org.ametys.plugins.contentio
Class AbstractContentImporter
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.plugins.contentio.AbstractContentImporter
-
- All Implemented Interfaces:
ContentImporter,LogEnabled,Configurable,Serviceable
- Direct Known Subclasses:
AbstractXmlContentImporter,CsvContentImporter
public abstract class AbstractContentImporter extends AbstractLogEnabled implements ContentImporter, Serviceable, Configurable
AbstractContentImporterclass which provides base importer configuration and logic.<br> Configuration options: <ul> <li>Importer priority</li> <li>Allowed extensions, without leading dot and comma-separated</li> <li>Content types and mixins of the created contents</li> <li>Language of the created contents</li> <li>Content workflow name and creation action ID</li> </ul><br> Example configuration handled by the configure method: <pre> <extension point="org.ametys.plugins.contentio.ContentImporterExtensionPoint" id="my.content.importer" class="..."> <priority>500</priority> <extensions>ext,ext2</extensions> <content-creation> <content-types>My.ContentType.1,My.ContentType.2</content-types> <mixins>My.Mixin.1,My.Mixin.2</mixins> <language>en</language> <workflow name="content" createActionId="1" editActionId="2"/> </content-creation> </extension> </pre>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classAbstractContentImporter.ContentReferenceClass representing a reference to a content in an import file.
-
Field Summary
Fields Modifier and Type Field Description protected static String_CONTENT_ID_MAP_KEYMap used to store the mapping from "local" ID to content ID, when actually imported.protected static String_CONTENT_LINK_MAP_KEYMap used to store the content references, indexed by content and metadata path.protected static String_CONTENT_REPEATER_SIZE_MAPMap used to store the content repeater sizes.protected String[]_contentTypesThe imported contents' types.protected ContentWorkflowHelper_contentWorkflowHelperThe content workflow helper.protected int_editActionIdThe importer contents' edition action ID.protected Set<String>_extensionsThe allowed extensions.protected int_initialActionIdThe importer contents' initial action ID.protected String_languageThe importer contents' language.protected String[]_mixinsThe imported contents' mixins.protected int_priorityThe importer priority.protected AmetysObjectResolver_resolverThe AmetysObject resolver.protected String_workflowNameThe importer contents' workflow name.protected static intDEFAULT_PRIORITYThe default importer priority.
-
Constructor Summary
Constructors Constructor Description AbstractContentImporter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddContentReference(Map<Content,Map<String,Object>> contentRefMap, Content content, String metadataPath, AbstractContentImporter.ContentReference reference)Add a content reference to the map.protected voidaddContentReference(Content content, String metadataPath, AbstractContentImporter.ContentReference reference, Map<String,Object> params)Add a content reference to the map.protected voidaddContentReferences(Map<Content,Map<String,Object>> contentRefMap, Content content, String metadataPath, List<AbstractContentImporter.ContentReference> references)Add content references to the map.voidconfigure(Configuration configuration)protected voidconfigureContentCreation(Configuration configuration)Configure the content creation parameters.protected voidconfigureExtensions(Configuration configuration)Configure the allowed extensions.protected voidconfigureWorkflow(Configuration configuration)Configure the content workflow.protected ContentcreateContent(String title, String[] contentTypes, String[] mixins, String language, String workflowName, int initialActionId, String parentContentId, String parentContentMetadataPath, Map<String,Object> params)Create a content.protected ContentcreateContent(String title, String[] contentTypes, String[] mixins, String language, String workflowName, int initialActionId, Map<String,Object> params)Create a content.protected ContentcreateContent(String title, String[] contentTypes, String[] mixins, String language, String parentContentId, String parentContentMetadataPath, Map<String,Object> params)Create a content.protected ContentcreateContent(String title, String[] contentTypes, String[] mixins, String language, Map<String,Object> params)Create a content.protected ContentcreateContent(String title, Map<String,Object> params)Create a content.protected ContentgetContentFromProperties(Map<String,String> propertyValues)Search a content from a map of its metadata values.protected Map<String,String>getContentIdMap(Map<String,Object> params)Get the map used to store the mapping from "local" ID (defined in the import file) to the AmetysObject ID of the contents, when actually imported.protected Map<Content,Map<String,Object>>getContentRefMap(Map<String,Object> params)Get the map used to store the content references.protected Map<Content,Map<String,Integer>>getContentRepeaterSizeMap(Map<String,Object> params)Get the map used to store the repeater sizes.protected String[]getContentTypes(Map<String,Object> params)The content types of a created content.protected Collection<String>getDefaultExtensions()Get the default allowed extensions.protected intgetEditActionId(Map<String,Object> params)The workflow action ID used to edit a content.protected intgetInitialActionId(Map<String,Object> params)The workflow creation action ID of a created content.protected StringgetLanguage(Map<String,Object> params)The language of a created content.protected String[]getMixins(Map<String,Object> params)The mixins of a created content.intgetPriority()Get the importer priority.protected StringgetReferencedContentId(AbstractContentImporter.ContentReference contentRef, Map<String,Object> params)Get the content ID from a content reference.protected StringgetWorkflowName(Map<String,Object> params)The workflow name of a created content.protected booleanisExtensionValid(String name)Test if the given filename has a supported extension.protected DateparseDate(String value)Parse a String value as a Date.
Allowed formats: yyyy-MM-dd yyyy-MM-dd'T'HH:mm:ss.SSSZZprotected DateparseDate(String value, boolean throwException)Parse a String value as a Date.
Allowed formats: yyyy-MM-dd yyyy-MM-dd'T'HH:mm:ss.SSSZZprotected voidrestoreContentReferences(Map<String,Object> params)Restore content references.voidservice(ServiceManager manager)protected voidsetBinaryMetadata(ModifiableCompositeMetadata meta, String name, MetadataDefinition metaDef, String value)Set a file metadata.protected voidsetBooleanMetadata(ModifiableCompositeMetadata meta, String name, MetadataDefinition metaDef, String[] values)Set a boolean metadata.protected voidsetDateMetadata(ModifiableCompositeMetadata meta, String name, MetadataDefinition metaDef, String[] values)Set a date or datetime metadata.protected voidsetDoubleMetadata(ModifiableCompositeMetadata meta, String name, MetadataDefinition metaDef, String[] values)Set a double metadata.protected voidsetGeocodeMetadata(ModifiableCompositeMetadata meta, String name, MetadataDefinition metaDef, double latitude, double longitude)Set a geocode metadata.protected voidsetGeocodeMetadata(ModifiableCompositeMetadata meta, String name, MetadataDefinition metaDef, String latitude, String longitude)Set a geocode metadata.protected voidsetLongMetadata(ModifiableCompositeMetadata meta, String name, MetadataDefinition metaDef, String[] values)Set a long metadata.protected voidsetReferenceMetadatas(Map<String,Object> contentReferences, Map<String,Object> values, Map<String,Integer> repeaters, Map<String,Object> params)Fill the value map with the content references.protected voidsetRepeaterSize(Content content, String metadataPath, int repeaterSize, Map<String,Object> params)Set a repeater size in the map (needed to execute the edit content function).protected voidsetRichText(ModifiableCompositeMetadata meta, String name, InputStream data)Set a RichText metadata.protected voidsetStringMetadata(ModifiableCompositeMetadata meta, String name, MetadataDefinition metaDef, String[] values)Set a string metadata.-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.ametys.plugins.contentio.ContentImporter
importContents, supports
-
-
-
-
Field Detail
-
DEFAULT_PRIORITY
protected static final int DEFAULT_PRIORITY
The default importer priority.- See Also:
- Constant Field Values
-
_CONTENT_ID_MAP_KEY
protected static final String _CONTENT_ID_MAP_KEY
Map used to store the mapping from "local" ID to content ID, when actually imported.
-
_CONTENT_LINK_MAP_KEY
protected static final String _CONTENT_LINK_MAP_KEY
Map used to store the content references, indexed by content and metadata path.
-
_CONTENT_REPEATER_SIZE_MAP
protected static final String _CONTENT_REPEATER_SIZE_MAP
Map used to store the content repeater sizes.
-
_resolver
protected AmetysObjectResolver _resolver
The AmetysObject resolver.
-
_contentWorkflowHelper
protected ContentWorkflowHelper _contentWorkflowHelper
The content workflow helper.
-
_priority
protected int _priority
The importer priority.
-
_extensions
protected Set<String> _extensions
The allowed extensions.
-
_contentTypes
protected String[] _contentTypes
The imported contents' types.
-
_workflowName
protected String _workflowName
The importer contents' workflow name.
-
_initialActionId
protected int _initialActionId
The importer contents' initial action ID.
-
_editActionId
protected int _editActionId
The importer contents' edition action ID.
-
-
Constructor Detail
-
AbstractContentImporter
public AbstractContentImporter()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
servicein interfaceServiceable- Throws:
ServiceException
-
configure
public void configure(Configuration configuration) throws ConfigurationException
- Specified by:
configurein interfaceConfigurable- Throws:
ConfigurationException
-
configureExtensions
protected void configureExtensions(Configuration configuration) throws ConfigurationException
Configure the allowed extensions.- Parameters:
configuration- the extension configuration.- Throws:
ConfigurationException- if an error occurs.
-
configureContentCreation
protected void configureContentCreation(Configuration configuration) throws ConfigurationException
Configure the content creation parameters.- Parameters:
configuration- the content creation configuration.- Throws:
ConfigurationException- if an error occurs.
-
configureWorkflow
protected void configureWorkflow(Configuration configuration) throws ConfigurationException
Configure the content workflow.- Parameters:
configuration- the content creation configuration.- Throws:
ConfigurationException- if an error occurs.
-
getPriority
public int getPriority()
Description copied from interface:ContentImporterGet the importer priority. A lower number means a higher priority.- Specified by:
getPriorityin interfaceContentImporter- Returns:
- the importer priority.
-
getDefaultExtensions
protected Collection<String> getDefaultExtensions()
Get the default allowed extensions.- Returns:
- the default allowed extensions, without leading dots. Cannot be null.
-
isExtensionValid
protected boolean isExtensionValid(String name) throws IOException
Test if the given filename has a supported extension.- Parameters:
name- the name, can't be null.- Returns:
- true if the extension is supported, false otherwise.
- Throws:
IOException- if an error occurs.
-
getContentTypes
protected String[] getContentTypes(Map<String,Object> params)
The content types of a created content.- Parameters:
params- the import parameters.- Returns:
- the content types of a created content.
-
getMixins
protected String[] getMixins(Map<String,Object> params)
The mixins of a created content.- Parameters:
params- the import parameters.- Returns:
- The mixins of a created content.
-
getLanguage
protected String getLanguage(Map<String,Object> params)
The language of a created content.- Parameters:
params- the import parameters.- Returns:
- The language of a created content.
-
getWorkflowName
protected String getWorkflowName(Map<String,Object> params)
The workflow name of a created content.- Parameters:
params- the import parameters.- Returns:
- The workflow name of a created content.
-
getInitialActionId
protected int getInitialActionId(Map<String,Object> params)
The workflow creation action ID of a created content.- Parameters:
params- the import parameters.- Returns:
- The workflow creation action ID of a created content.
-
getEditActionId
protected int getEditActionId(Map<String,Object> params)
The workflow action ID used to edit a content.- Parameters:
params- the import parameters.- Returns:
- The workflow action ID used to edit a content.
-
getContentIdMap
protected Map<String,String> getContentIdMap(Map<String,Object> params)
Get the map used to store the mapping from "local" ID (defined in the import file) to the AmetysObject ID of the contents, when actually imported.- Parameters:
params- the import parameters.- Returns:
- the content "local to repository" ID map.
-
getContentRefMap
protected Map<Content,Map<String,Object>> getContentRefMap(Map<String,Object> params)
Get the map used to store the content references. The Map is shaped like: referencing content -> local metadata path -> content references.- Parameters:
params- the import parameters.- Returns:
- the content reference map.
-
addContentReference
protected void addContentReference(Content content, String metadataPath, AbstractContentImporter.ContentReference reference, Map<String,Object> params)
Add a content reference to the map.- Parameters:
content- The referencing content.metadataPath- The path of the metadata which holds the content references.reference- The content reference.params- The import parameters.
-
addContentReference
protected void addContentReference(Map<Content,Map<String,Object>> contentRefMap, Content content, String metadataPath, AbstractContentImporter.ContentReference reference)
Add a content reference to the map.- Parameters:
contentRefMap- The content reference map.content- The referencing content.metadataPath- The path of the metadata which holds the content references.reference- The content reference.
-
addContentReferences
protected void addContentReferences(Map<Content,Map<String,Object>> contentRefMap, Content content, String metadataPath, List<AbstractContentImporter.ContentReference> references)
Add content references to the map.- Parameters:
contentRefMap- The content reference map.content- The referencing content.metadataPath- The path of the metadata which holds the content references.references- the content reference list.
-
getContentRepeaterSizeMap
protected Map<Content,Map<String,Integer>> getContentRepeaterSizeMap(Map<String,Object> params)
Get the map used to store the repeater sizes. The Map is shaped like: referencing content -> local metadata path -> content references.- Parameters:
params- the import parameters.- Returns:
- the content reference map.
-
setRepeaterSize
protected void setRepeaterSize(Content content, String metadataPath, int repeaterSize, Map<String,Object> params)
Set a repeater size in the map (needed to execute the edit content function).- Parameters:
content- The content containing the repeater.metadataPath- The repeater metadata path.repeaterSize- The repeater size.params- The import parameters.
-
createContent
protected Content createContent(String title, Map<String,Object> params) throws com.opensymphony.workflow.WorkflowException
Create a content.- Parameters:
title- the content title.params- the import parameters.- Returns:
- the created content.
- Throws:
com.opensymphony.workflow.WorkflowException- if an error occurs.
-
createContent
protected Content createContent(String title, String[] contentTypes, String[] mixins, String language, Map<String,Object> params) throws com.opensymphony.workflow.WorkflowException
Create a content.- Parameters:
title- the content title.contentTypes- the content types.mixins- the content mixins.language- the content language.params- the import parameters.- Returns:
- the created content.
- Throws:
com.opensymphony.workflow.WorkflowException- if an error occurs.
-
createContent
protected Content createContent(String title, String[] contentTypes, String[] mixins, String language, String parentContentId, String parentContentMetadataPath, Map<String,Object> params) throws com.opensymphony.workflow.WorkflowException
Create a content.- Parameters:
title- the content title.contentTypes- the content types.mixins- the content mixins.language- the content language.parentContentId- the parent content ID.parentContentMetadataPath- the parent content metadata path.params- the import parameters.- Returns:
- the created content.
- Throws:
com.opensymphony.workflow.WorkflowException- if an error occurs.
-
createContent
protected Content createContent(String title, String[] contentTypes, String[] mixins, String language, String workflowName, int initialActionId, Map<String,Object> params) throws com.opensymphony.workflow.WorkflowException
Create a content.- Parameters:
title- the content title.contentTypes- the content types.mixins- the content mixins.language- the content language.workflowName- the content workflow name.initialActionId- the content create action ID.params- the import parameters.- Returns:
- the created content.
- Throws:
com.opensymphony.workflow.WorkflowException- if an error occurs.
-
createContent
protected Content createContent(String title, String[] contentTypes, String[] mixins, String language, String workflowName, int initialActionId, String parentContentId, String parentContentMetadataPath, Map<String,Object> params) throws com.opensymphony.workflow.WorkflowException
Create a content.- Parameters:
title- the content title.contentTypes- the content types.mixins- the content mixins.language- the content language.workflowName- the content workflow name.initialActionId- the content create action ID.parentContentId- the parent content ID.parentContentMetadataPath- the parent content metadata path.params- the import parameters.- Returns:
- the created content.
- Throws:
com.opensymphony.workflow.WorkflowException- if an error occurs.
-
setStringMetadata
protected void setStringMetadata(ModifiableCompositeMetadata meta, String name, MetadataDefinition metaDef, String[] values)
Set a string metadata.- Parameters:
meta- the metadata holder.name- the metadata name.metaDef- the metadata definition.values- the metadata values.
-
setBooleanMetadata
protected void setBooleanMetadata(ModifiableCompositeMetadata meta, String name, MetadataDefinition metaDef, String[] values)
Set a boolean metadata.- Parameters:
meta- the metadata holder.name- the metadata name.metaDef- the metadata definition.values- the metadata values.
-
setLongMetadata
protected void setLongMetadata(ModifiableCompositeMetadata meta, String name, MetadataDefinition metaDef, String[] values)
Set a long metadata.- Parameters:
meta- the metadata holder.name- the metadata name.metaDef- the metadata definition.values- the metadata values.
-
setDoubleMetadata
protected void setDoubleMetadata(ModifiableCompositeMetadata meta, String name, MetadataDefinition metaDef, String[] values)
Set a double metadata.- Parameters:
meta- the metadata holder.name- the metadata name.metaDef- the metadata definition.values- the metadata values.
-
setDateMetadata
protected void setDateMetadata(ModifiableCompositeMetadata meta, String name, MetadataDefinition metaDef, String[] values)
Set a date or datetime metadata.- Parameters:
meta- the metadata holder.name- the metadata name.metaDef- the metadata definition.values- the metadata values.
-
parseDate
protected Date parseDate(String value)
Parse a String value as a Date.
Allowed formats:- yyyy-MM-dd
- yyyy-MM-dd'T'HH:mm:ss.SSSZZ
- Parameters:
value- the String value.- Returns:
- the parsed Date or
nullif the value can't be parsed.
-
parseDate
protected Date parseDate(String value, boolean throwException)
Parse a String value as a Date.
Allowed formats:- yyyy-MM-dd
- yyyy-MM-dd'T'HH:mm:ss.SSSZZ
- Parameters:
value- the String value.throwException- true to throw an exception if the value can't be parsed, false to return null.- Returns:
- the parsed Date or
nullif the value can't be parsed and throwException is false.
-
setGeocodeMetadata
protected void setGeocodeMetadata(ModifiableCompositeMetadata meta, String name, MetadataDefinition metaDef, String latitude, String longitude)
Set a geocode metadata.- Parameters:
meta- the metadata holder.name- the metadata name.metaDef- the metadata definition.latitude- the geocode latitude as a String.longitude- the geocode longitude as a String.
-
setGeocodeMetadata
protected void setGeocodeMetadata(ModifiableCompositeMetadata meta, String name, MetadataDefinition metaDef, double latitude, double longitude)
Set a geocode metadata.- Parameters:
meta- the metadata holder.name- the metadata name.metaDef- the metadata definition.latitude- the geocode latitude.longitude- the geocode longitude.
-
setBinaryMetadata
protected void setBinaryMetadata(ModifiableCompositeMetadata meta, String name, MetadataDefinition metaDef, String value) throws IOException
Set a file metadata.- Parameters:
meta- the metadata holder.name- the metadata name.metaDef- the metadata definitionvalue- the value- Throws:
IOException- if an exception occurs when manipulating files
-
setRichText
protected void setRichText(ModifiableCompositeMetadata meta, String name, InputStream data)
Set a RichText metadata.- Parameters:
meta- the metadata holder.name- the metadata name.data- an input stream on the rich text content.
-
restoreContentReferences
protected void restoreContentReferences(Map<String,Object> params)
Restore content references.- Parameters:
params- The import parameters.
-
setReferenceMetadatas
protected void setReferenceMetadatas(Map<String,Object> contentReferences, Map<String,Object> values, Map<String,Integer> repeaters, Map<String,Object> params)
Fill the value map with the content references.- Parameters:
contentReferences- The list of content references indexed by metadata path.values- The value map passed to the EditContentFunction class.repeaters- The repeater sizes for this content.params- The import parameters.
-
getReferencedContentId
protected String getReferencedContentId(AbstractContentImporter.ContentReference contentRef, Map<String,Object> params)
Get the content ID from a content reference.- Parameters:
contentRef- The content reference.params- The import parameters.- Returns:
- the content ID if it was found, or null otherwise.
-
getContentFromProperties
protected Content getContentFromProperties(Map<String,String> propertyValues)
Search a content from a map of its metadata values.- Parameters:
propertyValues- The metadata values.- Returns:
- The Content if found, null otherwise.
-
-