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
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, _i18nUtils, _scriptBindingEP, RIGHT_EXECUTE_SCRIPTS, ROLE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected 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 ScriptExecArguments
buildExecArguments
(Map<String, Object> arguments) Builds theScriptExecArguments
object from the untyped JS object (seen as a Map in Java)content2Json
(Content content, ViewItemContainer resultItems, ContentValuesExtractorFactory.SearchModelContentValuesExtractor extractor) Convert content to jsongetOrCreateModel
(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.ResultProcessor
Returns theScriptHandler.ResultProcessor
used to process script result.protected Object
processScriptResult
(Map<String, Object> results, Object scriptResult, ScriptExecArguments execArgs) Process the result of the scriptvoid
service
(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 Details
-
CmsScriptHandler
public CmsScriptHandler()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Overrides:
service
in classScriptHandler
- Throws:
ServiceException
-
buildExecArguments
Description copied from class:ScriptHandler
Builds theScriptExecArguments
object from the untyped JS object (seen as a Map in Java)- Overrides:
buildExecArguments
in 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:ScriptHandler
Process the result of the script- Overrides:
processScriptResult
in classScriptHandler
- Parameters:
results
- The results map, available to fillscriptResult
- The result of the scriptexecArgs
- The script execution arguments- Returns:
- The processed result
-
getProcessor
Description copied from class:ScriptHandler
Returns theScriptHandler.ResultProcessor
used to process script result.- Overrides:
getProcessor
in 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
-
content2Json
public Map<String,Object> content2Json(Content content, ViewItemContainer resultItems, ContentValuesExtractorFactory.SearchModelContentValuesExtractor extractor) Convert content to json- Parameters:
content
- The contentresultItems
- The result items, to know which value to fillextractor
- The properties extractor- Returns:
- The json data
-