Package org.ametys.cms.scripts
Class CmsScriptHandler
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.plugins.core.ui.script.ScriptHandler
-
- org.ametys.cms.scripts.CmsScriptHandler
-
- All Implemented Interfaces:
LogEnabled,Component,Contextualizable,Serviceable
public class CmsScriptHandler extends ScriptHandler
Content aware script handler using search model
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.ametys.plugins.core.ui.script.ScriptHandler
ScriptHandler.ResultProcessor
-
-
Field Summary
-
Fields inherited from class org.ametys.plugins.core.ui.script.ScriptHandler
_context, _currentUserProvider, _i18nUtils, _rightManager, _scriptBindingEP, RIGHT_EXECUTE_SCRIPTS, ROLE
-
-
Constructor Summary
Constructors Constructor Description CmsScriptHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected SearchUIModel_createModel(ThreadSafeComponentManager<SearchUIModel> localSearchModelManager, String defaultModelId, Collection<String> columns, Collection<Content> contents)Create and return a dynamic model based on desired columns or return a default model.protected void_handleColumnConfiguration(MutableConfiguration columnConf, String column)Add/modify column configurationprotected ScriptExecArgumentsbuildExecArguments(Map<String,Object> arguments)Builds theScriptExecArgumentsobject from the untyped JS object (seen as a Map in Java)Map<String,Object>content2Json(Content content, Collection<SearchUIColumn> searchColumns, ContentValuesExtractorFactory.SearchModelContentValuesExtractor extractor)Convert content to jsonSearchUIModelgetOrCreateModel(Collection<String> columns, List<Content> contents, String defaultModelId)Computes the model associated with the given contents and result columns.
Used by scripts functions creating reports or search results.protected ScriptHandler.ResultProcessorgetProcessor()Returns theScriptHandler.ResultProcessorused to process script result.protected ObjectprocessScriptResult(Map<String,Object> results, Object scriptResult, ScriptExecArguments execArgs)Process the result of the scriptvoidservice(ServiceManager serviceManager)-
Methods inherited from class org.ametys.plugins.core.ui.script.ScriptHandler
_executeScript, contextualize, executeScript, executeScript, executeScript, getScriptBindingDescription, getWorkspaceName
-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Constructor Detail
-
CmsScriptHandler
public CmsScriptHandler()
-
-
Method Detail
-
service
public void service(ServiceManager serviceManager) throws ServiceException
- Specified by:
servicein interfaceServiceable- Overrides:
servicein classScriptHandler- Throws:
ServiceException
-
buildExecArguments
protected ScriptExecArguments buildExecArguments(Map<String,Object> arguments)
Description copied from class:ScriptHandlerBuilds theScriptExecArgumentsobject from the untyped JS object (seen as a Map in Java)- Overrides:
buildExecArgumentsin classScriptHandler- Parameters:
arguments- The untyped JS object- Returns:
- the
ScriptExecArguments
-
processScriptResult
protected Object processScriptResult(Map<String,Object> results, Object scriptResult, ScriptExecArguments execArgs)
Description copied from class:ScriptHandlerProcess the result of the script- Overrides:
processScriptResultin classScriptHandler- Parameters:
results- The results map, available to fillscriptResult- The result of the scriptexecArgs- The script execution arguments- Returns:
- The processed result
-
getProcessor
protected ScriptHandler.ResultProcessor getProcessor()
Description copied from class:ScriptHandlerReturns theScriptHandler.ResultProcessorused to process script result.- Overrides:
getProcessorin classScriptHandler- Returns:
- the
ScriptHandler.ResultProcessor.
-
getOrCreateModel
public SearchUIModel getOrCreateModel(Collection<String> columns, List<Content> contents, String defaultModelId) throws Exception
Computes the model associated with the given contents and result columns.
Used by scripts functions creating reports or search results.- Parameters:
columns- the columns of the resultscontents- the contents for the results (one content per line)defaultModelId- the fallback model- Returns:
- the computed search model
- Throws:
Exception- if something went wrong.
-
_createModel
protected SearchUIModel _createModel(ThreadSafeComponentManager<SearchUIModel> localSearchModelManager, String defaultModelId, Collection<String> columns, Collection<Content> contents) throws Exception
Create and return a dynamic model based on desired columns or return a default model.- Parameters:
localSearchModelManager- The local search managerdefaultModelId- The default model idcolumns- The columnscontents- The contents- Returns:
- The search model
- Throws:
Exception- If an error occurred
-
_handleColumnConfiguration
protected void _handleColumnConfiguration(MutableConfiguration columnConf, String column)
Add/modify column configuration- Parameters:
columnConf- The mutable configuration object that will be used to create the column.column- The column identifier
-
content2Json
public Map<String,Object> content2Json(Content content, Collection<SearchUIColumn> searchColumns, ContentValuesExtractorFactory.SearchModelContentValuesExtractor extractor)
Convert content to json- Parameters:
content- The contentsearchColumns- The columns, to know which value to fillextractor- The properties extractor- Returns:
- The json data
-
-