Package fr.gouv.vitam.worker.core.impl
Class HandlerIOImpl
java.lang.Object
fr.gouv.vitam.worker.core.impl.HandlerIOImpl
- All Implemented Interfaces:
VitamAutoCloseable
,HandlerIO
,AutoCloseable
Handler input and output parameter
-
Field Summary
-
Constructor Summary
ConstructorDescriptionHandlerIOImpl
(WorkspaceClientFactory workspaceClientFactory, LogbookLifeCyclesClientFactory logbookLifeCyclesClientFactory, String containerName, String workerId, List<String> objectIds) Constructor with workspaceClient, local root path he is used for test purposeHandlerIOImpl
(String containerName, String workerId, List<String> objectIds) Constructor with local root path -
Method Summary
Modifier and TypeMethodDescriptionvoid
addInIOParameters
(List<IOParameter> list) Add Input parametersvoid
addOutIOParameters
(List<IOParameter> list) Add Output parametersaddOutputResult
(int rank, Object object) addOutputResult
(int rank, Object object, boolean asyncIO) Add one output result (no delete)addOutputResult
(int rank, Object object, boolean deleteLocal, boolean asyncIO) Add one output resultboolean
checkHandlerIO
(int outputNumber, List<Class<?>> clasz) Check if input and output have the very same number of elements and for Input the associated typesvoid
close()
void
consumeAnyEntityAndClose
(javax.ws.rs.core.Response response) Consume any entity and close responsevoid
enableAsync
(boolean async) If true then start async manager, if false then waitEndOfTransfer and stop asyncManagergetFile
(int rank) getFileFromWorkspace
(String objectName) Helper to load a file from Workspace (or local cache) and save it into local cache.
To be used when not specified within the Input parametersgetFilesWithParamsFromWorkspace
(String containerName, String folderName) get Map of File With Params From folder in WorkspacegetInput()
getInput
(int rank) Return one Object from input<T> T
Return one Object casted to type from inputgetInputStreamFromWorkspace
(String objectName) Helper to get an InputStream (using local cache if possible) from Workspace
To be used when not specified within the Input parameterscom.fasterxml.jackson.databind.JsonNode
getJsonFromWorkspace
(String jsonFilePath) Retrieve a json file as aJsonNode
from the workspace.getNewLocalFile
(String name) getOutput
(int rank) Return one ProcessingUri from outputgetUriList
(String containerName, String folderName) boolean
isExistingFileInWorkspace
(String workspacePath) void
Close the HandlerIO, including temporary files and directories at the end of the step Workflow execution, but do not close the WorkspaceClientboolean
removeFolder
(String folderName) Remove a specific foldervoid
reset()
Reset after each Actionvoid
setCurrentObjectId
(String currentObjectId) void
transferAtomicFileToWorkspace
(String workspacePath, File sourceFile) void
transferFileToWorkspace
(String workspacePath, File sourceFile, boolean toDelete, boolean asyncIO) Helper to write a file to Workspace
To be used when not specified within the Output Parametersvoid
transferInputStreamToWorkspace
(String workspacePath, InputStream inputStream, Path filePath, boolean asyncIO) Helper to write an InputStream to Workspace
To be used when not specified within the Output Parametersvoid
transferJsonToWorkspace
(String collectionName, String objectName, com.fasterxml.jackson.databind.JsonNode jsonNode, boolean toDelete, boolean asyncIO) Helper to convert and write a file to Workspace
void
unzipInputStreamOnWorkspace
(String container, String folderName, String archiveMimeType, InputStream uploadedInputStream, boolean asyncIO)
-
Field Details
-
NOT_CONFORM_PARAM
Not Conform Param- See Also:
-
-
Constructor Details
-
HandlerIOImpl
Constructor with local root path- Parameters:
containerName
- the container nameworkerId
- the worker idobjectIds
-
-
HandlerIOImpl
public HandlerIOImpl(WorkspaceClientFactory workspaceClientFactory, LogbookLifeCyclesClientFactory logbookLifeCyclesClientFactory, String containerName, String workerId, List<String> objectIds) Constructor with workspaceClient, local root path he is used for test purpose- Parameters:
workspaceClientFactory
-logbookLifeCyclesClientFactory
-containerName
- the container nameworkerId
- the worker idobjectIds
-
-
-
Method Details
-
getLifecyclesClient
- Specified by:
getLifecyclesClient
in interfaceHandlerIO
- Returns:
- the HandlerIO LifecycleClient
-
getHelper
-
addInIOParameters
Description copied from interface:HandlerIO
Add Input parameters- Specified by:
addInIOParameters
in interfaceHandlerIO
-
addOutIOParameters
Description copied from interface:HandlerIO
Add Output parameters- Specified by:
addOutIOParameters
in interfaceHandlerIO
-
reset
public void reset()Description copied from interface:HandlerIO
Reset after each Action -
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceVitamAutoCloseable
-
partialClose
public void partialClose()Close the HandlerIO, including temporary files and directories at the end of the step Workflow execution, but do not close the WorkspaceClient -
getInput
-
getInput
Description copied from interface:HandlerIO
Return one Object from input -
getInput
Description copied from interface:HandlerIO
Return one Object casted to type from input -
getFile
-
getOutput
-
getOutput
Description copied from interface:HandlerIO
Return one ProcessingUri from output -
addOutputResult
- Specified by:
addOutputResult
in interfaceHandlerIO
- Throws:
ProcessingException
-
addOutputResult
public HandlerIO addOutputResult(int rank, Object object, boolean asyncIO) throws ProcessingException Description copied from interface:HandlerIO
Add one output result (no delete)- Specified by:
addOutputResult
in interfaceHandlerIO
- Parameters:
rank
- the position in the outputobject
- the result to store (WORKSPACE to workspace and must be a File, MEMORY to memory whatever it is)asyncIO
- asynchronously send to the workspace- Returns:
- this
- Throws:
ProcessingException
-
addOutputResult
public HandlerIO addOutputResult(int rank, Object object, boolean deleteLocal, boolean asyncIO) throws ProcessingException Description copied from interface:HandlerIO
Add one output result- Specified by:
addOutputResult
in interfaceHandlerIO
- Parameters:
rank
- the position in the outputobject
- the result to store (WORKSPACE to workspace and must be a File, MEMORY to memory whatever it is)deleteLocal
- if true, will delete the local file in case of WORKSPACE onlyasyncIO
- asynchronously send to the workspace- Returns:
- this
- Throws:
ProcessingException
-
getContainerName
- Specified by:
getContainerName
in interfaceHandlerIO
- Returns:
- the container Name
-
getWorkerId
- Specified by:
getWorkerId
in interfaceHandlerIO
- Returns:
- the worker Id
-
getNewLocalFile
- Specified by:
getNewLocalFile
in interfaceHandlerIO
- Returns:
- a File pointing to a local path in Tmp directory under protected Worker instance space
-
checkHandlerIO
Description copied from interface:HandlerIO
Check if input and output have the very same number of elements and for Input the associated types- Specified by:
checkHandlerIO
in interfaceHandlerIO
- Parameters:
outputNumber
- the number of outputArgumentsclasz
- the list of Class that should be in the InputParameters- Returns:
- true if everything ok
-
isExistingFileInWorkspace
- Specified by:
isExistingFileInWorkspace
in interfaceHandlerIO
- Throws:
ProcessingException
-
transferFileToWorkspace
public void transferFileToWorkspace(String workspacePath, File sourceFile, boolean toDelete, boolean asyncIO) throws ProcessingException Description copied from interface:HandlerIO
Helper to write a file to Workspace
To be used when not specified within the Output Parameters- Specified by:
transferFileToWorkspace
in interfaceHandlerIO
- Parameters:
workspacePath
- path within the workspath, without the container (implicit)sourceFile
- the source file to writetoDelete
- if True, will delete the local fileasyncIO
- asynchronously send to the workspace- Throws:
ProcessingException
-
transferAtomicFileToWorkspace
public void transferAtomicFileToWorkspace(String workspacePath, File sourceFile) throws ProcessingException - Specified by:
transferAtomicFileToWorkspace
in interfaceHandlerIO
- Throws:
ProcessingException
-
transferInputStreamToWorkspace
public void transferInputStreamToWorkspace(String workspacePath, InputStream inputStream, Path filePath, boolean asyncIO) throws ProcessingException Description copied from interface:HandlerIO
Helper to write an InputStream to Workspace
To be used when not specified within the Output Parameters- Specified by:
transferInputStreamToWorkspace
in interfaceHandlerIO
- Parameters:
workspacePath
- path within the workspath, without the container (implicit)inputStream
- the source InputStream to writeasyncIO
- asynchronously send to the workspace- Throws:
ProcessingException
-
getFileFromWorkspace
public File getFileFromWorkspace(String objectName) throws IOException, ContentAddressableStorageNotFoundException, ContentAddressableStorageServerException Description copied from interface:HandlerIO
Helper to load a file from Workspace (or local cache) and save it into local cache.
To be used when not specified within the Input parameters- Specified by:
getFileFromWorkspace
in interfaceHandlerIO
- Returns:
- file if found
- Throws:
IOException
ContentAddressableStorageNotFoundException
ContentAddressableStorageServerException
-
getInputStreamFromWorkspace
public InputStream getInputStreamFromWorkspace(String objectName) throws IOException, ContentAddressableStorageNotFoundException, ContentAddressableStorageServerException Description copied from interface:HandlerIO
Helper to get an InputStream (using local cache if possible) from Workspace
To be used when not specified within the Input parameters- Specified by:
getInputStreamFromWorkspace
in interfaceHandlerIO
- Returns:
- the InputStream
- Throws:
IOException
ContentAddressableStorageNotFoundException
ContentAddressableStorageServerException
-
consumeAnyEntityAndClose
public void consumeAnyEntityAndClose(javax.ws.rs.core.Response response) Description copied from interface:HandlerIO
Consume any entity and close response- Specified by:
consumeAnyEntityAndClose
in interfaceHandlerIO
-
getJsonFromWorkspace
public com.fasterxml.jackson.databind.JsonNode getJsonFromWorkspace(String jsonFilePath) throws ProcessingException Description copied from interface:HandlerIO
Retrieve a json file as aJsonNode
from the workspace.- Specified by:
getJsonFromWorkspace
in interfaceHandlerIO
- Parameters:
jsonFilePath
- path in workspace of the json File- Returns:
- JsonNode of the json file
- Throws:
ProcessingException
- throws when error occurs
-
getUriList
- Specified by:
getUriList
in interfaceHandlerIO
- Returns:
- List
a list of uri of object in SIP folder - Throws:
ProcessingException
-
transferJsonToWorkspace
public void transferJsonToWorkspace(String collectionName, String objectName, com.fasterxml.jackson.databind.JsonNode jsonNode, boolean toDelete, boolean asyncIO) throws ProcessingException Description copied from interface:HandlerIO
Helper to convert and write a file to Workspace
- Specified by:
transferJsonToWorkspace
in interfaceHandlerIO
- Parameters:
collectionName
- : collection typeobjectName
- path within the workspacepath, without the container (implicit)jsonNode
- the json file to writetoDelete
- if True, will delete the local fileasyncIO
- asynchronously send to the workspace- Throws:
ProcessingException
-
unzipInputStreamOnWorkspace
public void unzipInputStreamOnWorkspace(String container, String folderName, String archiveMimeType, InputStream uploadedInputStream, boolean asyncIO) throws ContentAddressableStorageException - Specified by:
unzipInputStreamOnWorkspace
in interfaceHandlerIO
asyncIO
- asynchronously send and unzip file to/in the workspace- Throws:
ContentAddressableStorageException
-
enableAsync
Description copied from interface:HandlerIO
If true then start async manager, if false then waitEndOfTransfer and stop asyncManager- Specified by:
enableAsync
in interfaceHandlerIO
- Throws:
WorkerspaceQueueException
-
removeFolder
Description copied from interface:HandlerIO
Remove a specific folder- Specified by:
removeFolder
in interfaceHandlerIO
- Parameters:
folderName
- the folderName to delete- Returns:
- true if the folder was removed, false if it does not exist
- Throws:
ContentAddressableStorageException
- when storage error occurs
-
setCurrentObjectId
- Specified by:
setCurrentObjectId
in interfaceHandlerIO
-
getWorkspaceClientFactory
- Specified by:
getWorkspaceClientFactory
in interfaceHandlerIO
-
getFilesWithParamsFromWorkspace
public Map<String,Long> getFilesWithParamsFromWorkspace(String containerName, String folderName) throws ProcessingException Description copied from interface:HandlerIO
get Map of File With Params From folder in Workspace- Specified by:
getFilesWithParamsFromWorkspace
in interfaceHandlerIO
- Returns:
- Throws:
ProcessingException
-