Class AbstractImportCDMFrComponent
- java.lang.Object
-
- org.ametys.plugins.odfsync.cdmfr.components.AbstractImportCDMFrComponent
-
- All Implemented Interfaces:
ImportCDMFrComponent
,Initializable
,Component
,Configurable
,Contextualizable
,Serviceable
- Direct Known Subclasses:
RemoteImportCDMFrComponent
,SCCImportCDMFrComponent
public abstract class AbstractImportCDMFrComponent extends Object implements ImportCDMFrComponent, Serviceable, Initializable, Contextualizable, Configurable, Component
Abstract class of a component to import a CDM-fr input stream.
-
-
Field Summary
Fields Modifier and Type Field Description protected CatalogsManager
_catalogsManager
The catalog managerprotected CDMFrSyncExtensionPoint
_cdmFrSyncExtensionPoint
Extension point to transform CDM-frprotected Context
_cocoonContext
The Cocoon contextprotected String
_contentPrefix
The prefix of the contentsprotected ContentTypeExtensionPoint
_contentTypeEP
The content type extension pointprotected ContentWorkflowHelper
_contentWorkflowHelper
The content workflow helperprotected CurrentUserProvider
_currentUserProvider
The current user providerprotected DOMParser
_domParser
The DOM parserprotected Map<String,Integer>
_importedContents
List of imported contentsprotected int
_nbError
Number of errors encounteredprotected ObservationManager
_observationManager
The observation managerprotected ODFHelper
_odfHelper
The ODF Helperprotected String
_odfLang
Default language configured for ODFprotected OdfReferenceTableHelper
_odfRefTableHelper
The ODF TableRef Helperprotected AmetysObjectResolver
_resolver
The ametys object resolverprotected RootOrgUnitProvider
_rootOUProvider
The root orgunit providerprotected SynchronizableContentsCollectionHelper
_sccHelper
The SCC helperprotected ShareableCourseHelper
_shareableCourseHelper
The shareable course helperprotected Map<String,Set<String>>
_syncFieldsByContentType
Synchronized fields by content typeprotected static int
_SYNCHRONIZE_WORKFLOW_ACTION_ID
The synchronize workflow action idprotected Set<String>
_synchronizedContents
List of synchronized contentsprotected static String
_TAG_CONTAINER
Tag to identify a containerprotected static String
_TAG_COURSELIST
Tag to identify a courseListprotected static String
_TAG_COURSEPART
Tag to identify a coursePartprotected static String
_TAG_PROGRAM
Tag to identify a programprotected static String
_TAG_SUBPROGRAM
Tag to identify a subprogramprotected ImportCDMFrValuesExtractorFactory
_valuesExtractorFactory
theImportCDMFrValuesExtractor
factoryprotected XPathProcessor
_xPathProcessor
The XPath processor-
Fields inherited from interface org.ametys.plugins.odfsync.cdmfr.components.ImportCDMFrComponent
ROLE
-
-
Constructor Summary
Constructors Constructor Description AbstractImportCDMFrComponent()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected ModifiableContent
_createContent(ContentWorkflowDescription wfDescription, String title, ImportCDMFrContext context)
Create the content from the workflow description and the import context.protected void
_editContent(WorkflowAwareContent content, Optional<View> view, Map<String,Object> values, boolean create, Set<String> notSynchronizedContentIds, ImportCDMFrContext context)
Synchronize the content with given values.protected Map<String,Object>
_getAdditionalValuesToSynchronize(ModifiableContent content, String syncCode, ImportCDMFrContext context)
Retrieves additional values to synchronize for the contentprotected List<Expression>
_getExpressionsList(String contentTypeId, String syncCode, ImportCDMFrContext context)
Construct the query to retrieve the content.protected Map<String,Object>
_getInputsForContentCreation(ContentWorkflowDescription wfDescription, ImportCDMFrContext context)
Retrieves the inputs to give for content creationprotected Set<String>
_getNotSynchronizedRelatedContentIds(ModifiableContent content, String syncCode, ImportCDMFrContext context)
Retrieves the ids of the contents related to the given content but that are not part of the synchronizationprotected ModifiableContent
_getOrCreateContent(ContentWorkflowDescription wfDescription, String title, String syncCode, ImportCDMFrContext context)
Get or create the content from the workflow description, the synchronization code and the import context.protected List<ModifiableContent>
_initializeShareableCoursesFields(ProgramItem programItem)
Initialize shareable fields for the courses under the givenProgramItem
protected void
_linkTranslationsIfExist(ModifiableContent importedContent, String contentType, ImportCDMFrContext context)
Search for translated contentsprotected void
_setOrgUnitParent(WorkflowAwareContent orgUnit, ImportCDMFrContext context)
Set the orgUnit parent to rootOrgUnit.protected void
_synchronizeContent(Element contentElement, ModifiableContent content, String contentTypeId, String syncCode, ImportCDMFrContext context)
Synchronize contentContentSynchronizationResult
additionalOperations(ModifiableContent content, Map<String,Object> additionalParameters, org.slf4j.Logger logger)
Add specific fields to the content during import or synchronization.protected abstract void
additionalParameters(Map<String,Object> parameters)
Additional parameters for specific treatments.void
configure(Configuration configuration)
void
contextualize(Context context)
String
getCatalogName(Element contentElement)
Get the name of catalog to use for importModifiableContent
getContent(String contentType, String syncCode, ImportCDMFrContext context)
Get the content from the synchronization code, the content type and the context.String
getIdField()
Return the attribute identifier for CDM-fr synchronization.String
getIdFromCDMThenCode(String tableRefId, String cdmCode)
Get the content ID from the CDM code, if there is no match with the CDM code, then we search with the code.Set<String>
getLocalAndExternalFields(Map<String,Object> additionalParameters)
Get the path of tri-state fields (with local and external values)Map<String,Object>
handleInputStream(InputStream input, Map<String,Object> parameters, SynchronizableContentsCollection scc, org.slf4j.Logger logger)
Handle the CDM-fr input stream to import all the programs and its dependencies containing into it.protected boolean
ignoreRights()
If true, bypass the rights check during the import processModifiableContent
importOrSynchronizeContent(Element contentElement, ContentWorkflowDescription wfDescription, String title, String syncCode, ImportCDMFrContext context)
Import or synchronize the content.void
initialize()
protected abstract boolean
removalSync()
When returns true, a content created by a previous synchro will be removed if it does not exist anymore during the current synchro.void
service(ServiceManager manager)
protected Document
transformDocument(Document document, Map<String,Object> parameters, org.slf4j.Logger logger)
Transform the document depending of it structure.protected abstract boolean
validateAfterImport()
True to validate the contents after importprotected void
validateContent(WorkflowAwareContent content, int validationActionId, org.slf4j.Logger logger)
Validates a content after import
-
-
-
Field Detail
-
_TAG_PROGRAM
protected static final String _TAG_PROGRAM
Tag to identify a program- See Also:
- Constant Field Values
-
_TAG_SUBPROGRAM
protected static final String _TAG_SUBPROGRAM
Tag to identify a subprogram- See Also:
- Constant Field Values
-
_TAG_CONTAINER
protected static final String _TAG_CONTAINER
Tag to identify a container- See Also:
- Constant Field Values
-
_TAG_COURSELIST
protected static final String _TAG_COURSELIST
Tag to identify a courseList- See Also:
- Constant Field Values
-
_TAG_COURSEPART
protected static final String _TAG_COURSEPART
Tag to identify a coursePart- See Also:
- Constant Field Values
-
_SYNCHRONIZE_WORKFLOW_ACTION_ID
protected static final int _SYNCHRONIZE_WORKFLOW_ACTION_ID
The synchronize workflow action id- See Also:
- Constant Field Values
-
_cocoonContext
protected Context _cocoonContext
The Cocoon context
-
_domParser
protected DOMParser _domParser
The DOM parser
-
_xPathProcessor
protected XPathProcessor _xPathProcessor
The XPath processor
-
_cdmFrSyncExtensionPoint
protected CDMFrSyncExtensionPoint _cdmFrSyncExtensionPoint
Extension point to transform CDM-fr
-
_catalogsManager
protected CatalogsManager _catalogsManager
The catalog manager
-
_resolver
protected AmetysObjectResolver _resolver
The ametys object resolver
-
_odfRefTableHelper
protected OdfReferenceTableHelper _odfRefTableHelper
The ODF TableRef Helper
-
_contentTypeEP
protected ContentTypeExtensionPoint _contentTypeEP
The content type extension point
-
_currentUserProvider
protected CurrentUserProvider _currentUserProvider
The current user provider
-
_observationManager
protected ObservationManager _observationManager
The observation manager
-
_rootOUProvider
protected RootOrgUnitProvider _rootOUProvider
The root orgunit provider
-
_odfHelper
protected ODFHelper _odfHelper
The ODF Helper
-
_sccHelper
protected SynchronizableContentsCollectionHelper _sccHelper
The SCC helper
-
_contentWorkflowHelper
protected ContentWorkflowHelper _contentWorkflowHelper
The content workflow helper
-
_shareableCourseHelper
protected ShareableCourseHelper _shareableCourseHelper
The shareable course helper
-
_valuesExtractorFactory
protected ImportCDMFrValuesExtractorFactory _valuesExtractorFactory
theImportCDMFrValuesExtractor
factory
-
_importedContents
protected Map<String,Integer> _importedContents
List of imported contents
-
_synchronizedContents
protected Set<String> _synchronizedContents
List of synchronized contents
-
_nbError
protected int _nbError
Number of errors encountered
-
_contentPrefix
protected String _contentPrefix
The prefix of the contents
-
_syncFieldsByContentType
protected Map<String,Set<String>> _syncFieldsByContentType
Synchronized fields by content type
-
-
Constructor Detail
-
AbstractImportCDMFrComponent
public AbstractImportCDMFrComponent()
-
-
Method Detail
-
initialize
public void initialize() throws Exception
- Specified by:
initialize
in interfaceInitializable
- Throws:
Exception
-
contextualize
public void contextualize(Context context) throws ContextException
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
configure
public void configure(Configuration configuration) throws ConfigurationException
- Specified by:
configure
in interfaceConfigurable
- Throws:
ConfigurationException
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
getIdField
public String getIdField()
Description copied from interface:ImportCDMFrComponent
Return the attribute identifier for CDM-fr synchronization.- Specified by:
getIdField
in interfaceImportCDMFrComponent
- Returns:
- The attribute name (cdmfrSyncCode)
-
handleInputStream
public Map<String,Object> handleInputStream(InputStream input, Map<String,Object> parameters, SynchronizableContentsCollection scc, org.slf4j.Logger logger) throws ProcessingException
Description copied from interface:ImportCDMFrComponent
Handle the CDM-fr input stream to import all the programs and its dependencies containing into it.- Specified by:
handleInputStream
in interfaceImportCDMFrComponent
- Parameters:
input
- The CDM-fr input streamparameters
- The parameters useful for the operationscc
- TheSynchronizableContentsCollection
calling this componentlogger
- The logger- Returns:
- The list of imported/synchronized programs
- Throws:
ProcessingException
- If an error occurs
-
validateAfterImport
protected abstract boolean validateAfterImport()
True to validate the contents after import- Returns:
- True to validate the contents after import
-
removalSync
protected abstract boolean removalSync()
When returns true, a content created by a previous synchro will be removed if it does not exist anymore during the current synchro.- Returns:
- true if a content created by a previous synchro has to be removed if it does not exist anymore during the current synchro.
-
additionalParameters
protected abstract void additionalParameters(Map<String,Object> parameters)
Additional parameters for specific treatments.- Parameters:
parameters
- The parameters map to get
-
transformDocument
protected Document transformDocument(Document document, Map<String,Object> parameters, org.slf4j.Logger logger) throws IOException, SAXException, ProcessingException
Transform the document depending of it structure.- Parameters:
document
- Document to transform.parameters
- Optional parameters for transformationlogger
- The logger- Returns:
- The transformed document.
- Throws:
IOException
- if an error occurs.SAXException
- if an error occurs.ProcessingException
- if an error occurs.
-
getCatalogName
public String getCatalogName(Element contentElement)
Description copied from interface:ImportCDMFrComponent
Get the name of catalog to use for import- Specified by:
getCatalogName
in interfaceImportCDMFrComponent
- Parameters:
contentElement
- Element of the content- Returns:
- The catalog to used
-
importOrSynchronizeContent
public ModifiableContent importOrSynchronizeContent(Element contentElement, ContentWorkflowDescription wfDescription, String title, String syncCode, ImportCDMFrContext context)
Description copied from interface:ImportCDMFrComponent
Import or synchronize the content.- Specified by:
importOrSynchronizeContent
in interfaceImportCDMFrComponent
- Parameters:
contentElement
- Element of the contentwfDescription
- The workflow descriptiontitle
- The titlesyncCode
- The synchronization codecontext
- the import context- Returns:
- The imported or synchronized content
-
_getOrCreateContent
protected ModifiableContent _getOrCreateContent(ContentWorkflowDescription wfDescription, String title, String syncCode, ImportCDMFrContext context)
Get or create the content from the workflow description, the synchronization code and the import context.- Parameters:
wfDescription
- The workflow descriptiontitle
- The titlesyncCode
- The synchronization codecontext
- The import context- Returns:
- the retrieved or created content
-
getContent
public ModifiableContent getContent(String contentType, String syncCode, ImportCDMFrContext context)
Description copied from interface:ImportCDMFrComponent
Get the content from the synchronization code, the content type and the context.- Specified by:
getContent
in interfaceImportCDMFrComponent
- Parameters:
contentType
- The content typesyncCode
- The synchronization codecontext
- the import context- Returns:
- the retrieved content
-
_createContent
protected ModifiableContent _createContent(ContentWorkflowDescription wfDescription, String title, ImportCDMFrContext context) throws com.opensymphony.workflow.WorkflowException
Create the content from the workflow description and the import context.- Parameters:
wfDescription
- The workflow descriptiontitle
- The titlecontext
- The import context- Returns:
- the created content
- Throws:
com.opensymphony.workflow.WorkflowException
- if an error occurs while creating the content
-
_getInputsForContentCreation
protected Map<String,Object> _getInputsForContentCreation(ContentWorkflowDescription wfDescription, ImportCDMFrContext context)
Retrieves the inputs to give for content creation- Parameters:
wfDescription
- The workflow descriptioncontext
- The import context- Returns:
- the inputs to give for content creation
-
_synchronizeContent
protected void _synchronizeContent(Element contentElement, ModifiableContent content, String contentTypeId, String syncCode, ImportCDMFrContext context) throws Exception
Synchronize content- Parameters:
contentElement
- the DOM content elementcontent
- The content to synchronizecontentTypeId
- The content type IDsyncCode
- The synchronization codecontext
- the import context- Throws:
Exception
- if an error occurs while synchronizing the content values
-
_getAdditionalValuesToSynchronize
protected Map<String,Object> _getAdditionalValuesToSynchronize(ModifiableContent content, String syncCode, ImportCDMFrContext context)
Retrieves additional values to synchronize for the content- Parameters:
content
- the contentsyncCode
- the content synchronization codecontext
- the import context- Returns:
- the additional values
-
_getNotSynchronizedRelatedContentIds
protected Set<String> _getNotSynchronizedRelatedContentIds(ModifiableContent content, String syncCode, ImportCDMFrContext context)
Retrieves the ids of the contents related to the given content but that are not part of the synchronization- Parameters:
content
- the contentsyncCode
- the content synchronization codecontext
- the import context- Returns:
- the not synchronized content ids
-
_editContent
protected void _editContent(WorkflowAwareContent content, Optional<View> view, Map<String,Object> values, boolean create, Set<String> notSynchronizedContentIds, ImportCDMFrContext context) throws com.opensymphony.workflow.WorkflowException
Synchronize the content with given values.- Parameters:
content
- The content to synchronizeview
- the view containing the item to editvalues
- the valuescreate
-true
if content is creating, false if it is updatednotSynchronizedContentIds
- the ids of the contents related to the given content but that are not part of the synchronizationcontext
- the import context- Throws:
com.opensymphony.workflow.WorkflowException
- if an error occurs
-
additionalOperations
public ContentSynchronizationResult additionalOperations(ModifiableContent content, Map<String,Object> additionalParameters, org.slf4j.Logger logger)
Description copied from interface:ImportCDMFrComponent
Add specific fields to the content during import or synchronization.- Specified by:
additionalOperations
in interfaceImportCDMFrComponent
- Parameters:
content
- Content to updateadditionalParameters
- Additional parameterslogger
- The logger- Returns:
- The synchronization result of the additional operations
-
_initializeShareableCoursesFields
protected List<ModifiableContent> _initializeShareableCoursesFields(ProgramItem programItem)
Initialize shareable fields for the courses under the givenProgramItem
- Parameters:
programItem
- the program item- Returns:
- the list of contents that have been modified during the initialization
-
_linkTranslationsIfExist
protected void _linkTranslationsIfExist(ModifiableContent importedContent, String contentType, ImportCDMFrContext context)
Search for translated contents- Parameters:
importedContent
- The imported contentcontentType
- The content typecontext
- the import context
-
_setOrgUnitParent
protected void _setOrgUnitParent(WorkflowAwareContent orgUnit, ImportCDMFrContext context) throws Exception
Set the orgUnit parent to rootOrgUnit.- Parameters:
orgUnit
- The orgunit to linkcontext
- the import context- Throws:
Exception
- if an error occurs while synchronizing the content values
-
validateContent
protected 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
-
getIdFromCDMThenCode
public String getIdFromCDMThenCode(String tableRefId, String cdmCode)
Description copied from interface:ImportCDMFrComponent
Get the content ID from the CDM code, if there is no match with the CDM code, then we search with the code. If nothing is found we return null.- Specified by:
getIdFromCDMThenCode
in interfaceImportCDMFrComponent
- Parameters:
tableRefId
- The reference table IDcdmCode
- The CDM code- Returns:
- A content ID or
null
-
ignoreRights
protected boolean ignoreRights()
If true, bypass the rights check during the import process- Returns:
- True if the rights check are bypassed during the import process
-
_getExpressionsList
protected List<Expression> _getExpressionsList(String contentTypeId, String syncCode, ImportCDMFrContext context)
Construct the query to retrieve the content.- Parameters:
contentTypeId
- The content typesyncCode
- The synchronization codecontext
- the import context- Returns:
- The
List
ofExpression
-
getLocalAndExternalFields
public Set<String> getLocalAndExternalFields(Map<String,Object> additionalParameters)
Description copied from interface:ImportCDMFrComponent
Get the path of tri-state fields (with local and external values)- Specified by:
getLocalAndExternalFields
in interfaceImportCDMFrComponent
- Parameters:
additionalParameters
- Additional parameters- Returns:
- the synchronized fields
-
-