Package org.openrefine.commands
Class Command
- java.lang.Object
-
- org.openrefine.commands.Command
-
- Direct Known Subclasses:
ApplyOperationsCommand
,CancelImportingJobCommand
,CancelProcessCommand
,CancelProcessesCommand
,ComputeClustersCommand
,ComputeFacetsCommand
,CreateImportingJobCommand
,CreateProjectCommand
,DatabaseCommand
,DeAuthorizeCommand
,DeleteProjectCommand
,ExportProjectCommand
,ExportRowsCommand
,GetAllPreferencesCommand
,GetAllProjectMetadataCommand
,GetAllProjectTagsCommand
,GetClusteringFunctionsAndDistancesCommand
,GetColumnsInfoCommand
,GetCSRFTokenCommand
,GetExpressionHistoryCommand
,GetExpressionLanguageInfoCommand
,GetHistoryCommand
,GetImportingConfigurationCommand
,GetImportingJobStatusCommand
,GetLanguagesCommand
,GetModelsCommand
,GetOperationsCommand
,GetPreferenceCommand
,GetProcessesCommand
,GetProjectMetadataCommand
,GetRowsCommand
,GetScatterplotCommand
,GetStarredExpressionsCommand
,GetVersionCommand
,GuessTypesOfColumnCommand
,ImportingControllerCommand
,ImportProjectCommand
,LoadLanguageCommand
,LogExpressionCommand
,LoginCommand
,OpenWorkspaceDirCommand
,ParseWikibaseSchemaCommand
,PauseProcessCommand
,PreviewExpressionCommand
,PreviewExtendDataCommand
,PreviewWikibaseSchemaCommand
,RenameProjectCommand
,ResumeProcessCommand
,SaveWikibaseSchemaCommand
,SetPreferenceCommand
,SetProjectMetadataCommand
,SetProjectTagsCommand
,ToggleStarredExpressionCommand
,UndoRedoCommand
,UploadCommand
public abstract class Command extends Object
The super class of all calls that the client side can invoke, most of which are AJAX calls.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
Command.HistoryEntryResponse
-
Field Summary
Fields Modifier and Type Field Description static CSRFTokenFactory
csrfFactory
protected static org.slf4j.Logger
logger
protected RefineServlet
servlet
-
Constructor Summary
Constructors Constructor Description Command()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected static void
addHistoryEntryAndRespond(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Project project, Operation operation)
void
doDelete(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
void
doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
void
doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
void
doPut(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
protected static Engine
getEngine(javax.servlet.http.HttpServletRequest request, Project project)
Utility function to reconstruct the browsing engine from the "engine" request parameter, most often in the POST body.protected static EngineConfig
getEngineConfig(javax.servlet.http.HttpServletRequest request)
Utility function to get the browsing engine's configuration as a JSON object from the "engine" request parameter, most often in the POST body.protected static int
getIntegerParameter(javax.servlet.http.HttpServletRequest request, String name, int def)
protected static long
getLongParameter(javax.servlet.http.HttpServletRequest request, String name, long def)
protected Project
getProject(javax.servlet.http.HttpServletRequest request)
Utility method for retrieving the Project object having the ID specified in the "project" URL parameter.protected ProjectMetadata
getProjectMetadata(javax.servlet.http.HttpServletRequest request)
Utility method for retrieving the ProjectMetadata object having the ID specified in the "project" URL parameter.protected SortingConfig
getSortingConfig(javax.servlet.http.HttpServletRequest request)
protected boolean
hasValidCSRFToken(javax.servlet.http.HttpServletRequest request)
Utility method for retrieving the CSRF token stored in the "csrf_token" parameter of the request, and checking that it is valid.protected boolean
hasValidCSRFTokenAsGET(javax.servlet.http.HttpServletRequest request)
Checks the validity of a CSRF token, without reading the whole POST body.void
init(RefineServlet servlet)
boolean
logRequests()
Whether each request to this command should be logged.protected static void
redirect(javax.servlet.http.HttpServletResponse response, String url)
static void
respondCSRFError(javax.servlet.http.HttpServletResponse response)
static void
respondError(javax.servlet.http.HttpServletResponse response, int status, String errorMessage)
Helper introduced to ease returning error messages from a response.static void
respondError(javax.servlet.http.HttpServletResponse response, String errorMessage)
Helper introduced to ease returning error messages from a response, with a default 400 status code.static void
respondJSON(javax.servlet.http.HttpServletResponse response, int status, Object o)
protected static void
respondJSON(javax.servlet.http.HttpServletResponse response, Object o)
Deprecated.userespondJSON(HttpServletResponse, int, Object)
to make sure an HTTP status code is setstatic void
respondOK(javax.servlet.http.HttpServletResponse response)
protected void
respondWithErrorPage(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String message, Throwable e)
-
-
-
Field Detail
-
logger
protected static final org.slf4j.Logger logger
-
csrfFactory
public static final CSRFTokenFactory csrfFactory
-
servlet
protected RefineServlet servlet
-
-
Method Detail
-
init
public void init(RefineServlet servlet)
-
doPost
public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws Exception
- Throws:
Exception
-
doGet
public void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws Exception
- Throws:
Exception
-
doPut
public void doPut(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws Exception
- Throws:
Exception
-
doDelete
public void doDelete(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws Exception
- Throws:
Exception
-
logRequests
public boolean logRequests()
Whether each request to this command should be logged. For some commands that can get called too frequently, such as GetProcessesCommand, logging is very distracting.
-
getEngineConfig
protected static EngineConfig getEngineConfig(javax.servlet.http.HttpServletRequest request)
Utility function to get the browsing engine's configuration as a JSON object from the "engine" request parameter, most often in the POST body.- Parameters:
request
-- Returns:
-
getEngine
protected static Engine getEngine(javax.servlet.http.HttpServletRequest request, Project project) throws Exception
Utility function to reconstruct the browsing engine from the "engine" request parameter, most often in the POST body.- Parameters:
request
-project
-- Returns:
- Throws:
Exception
-
getProject
protected Project getProject(javax.servlet.http.HttpServletRequest request) throws javax.servlet.ServletException
Utility method for retrieving the Project object having the ID specified in the "project" URL parameter.- Throws:
javax.servlet.ServletException
-
getProjectMetadata
protected ProjectMetadata getProjectMetadata(javax.servlet.http.HttpServletRequest request) throws javax.servlet.ServletException
Utility method for retrieving the ProjectMetadata object having the ID specified in the "project" URL parameter.- Parameters:
request
-- Returns:
- Throws:
javax.servlet.ServletException
-
getIntegerParameter
protected static int getIntegerParameter(javax.servlet.http.HttpServletRequest request, String name, int def)
-
getLongParameter
protected static long getLongParameter(javax.servlet.http.HttpServletRequest request, String name, long def)
-
hasValidCSRFToken
protected boolean hasValidCSRFToken(javax.servlet.http.HttpServletRequest request) throws javax.servlet.ServletException
Utility method for retrieving the CSRF token stored in the "csrf_token" parameter of the request, and checking that it is valid.- Parameters:
request
-- Returns:
- Throws:
javax.servlet.ServletException
-
hasValidCSRFTokenAsGET
protected boolean hasValidCSRFTokenAsGET(javax.servlet.http.HttpServletRequest request)
Checks the validity of a CSRF token, without reading the whole POST body. Useful when we need to control how the POST body is read (for instance if it contains files).
-
addHistoryEntryAndRespond
protected static void addHistoryEntryAndRespond(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Project project, Operation operation) throws Exception
- Throws:
Exception
-
respondJSON
@Deprecated protected static void respondJSON(javax.servlet.http.HttpServletResponse response, Object o) throws IOException
Deprecated.userespondJSON(HttpServletResponse, int, Object)
to make sure an HTTP status code is set- Throws:
IOException
-
respondJSON
public static void respondJSON(javax.servlet.http.HttpServletResponse response, int status, Object o) throws IOException
- Throws:
IOException
-
respondCSRFError
public static void respondCSRFError(javax.servlet.http.HttpServletResponse response) throws IOException
- Throws:
IOException
-
respondError
public static void respondError(javax.servlet.http.HttpServletResponse response, String errorMessage) throws IOException
Helper introduced to ease returning error messages from a response, with a default 400 status code.- Throws:
IOException
-
respondError
public static void respondError(javax.servlet.http.HttpServletResponse response, int status, String errorMessage) throws IOException
Helper introduced to ease returning error messages from a response.- Throws:
IOException
-
respondOK
public static void respondOK(javax.servlet.http.HttpServletResponse response) throws IOException
- Throws:
IOException
-
respondWithErrorPage
protected void respondWithErrorPage(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String message, Throwable e)
-
getSortingConfig
protected SortingConfig getSortingConfig(javax.servlet.http.HttpServletRequest request)
-
redirect
protected static void redirect(javax.servlet.http.HttpServletResponse response, String url) throws IOException
- Throws:
IOException
-
-