Package fr.gouv.vitam.worker.core.impl
Class HandlerIOImpl
- java.lang.Object
-
- fr.gouv.vitam.worker.core.impl.HandlerIOImpl
-
- All Implemented Interfaces:
VitamAutoCloseable
,HandlerIO
,java.lang.AutoCloseable
public class HandlerIOImpl extends java.lang.Object implements HandlerIO, VitamAutoCloseable
Handler input and output parameter
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
NOT_CONFORM_PARAM
Not Conform Param
-
Constructor Summary
Constructors Constructor Description HandlerIOImpl(WorkspaceClientFactory workspaceClientFactory, LogbookLifeCyclesClientFactory logbookLifeCyclesClientFactory, java.lang.String containerName, java.lang.String workerId, java.util.List<java.lang.String> objectIds)
Constructor with workspaceClient, local root path he is used for test purposeHandlerIOImpl(java.lang.String containerName, java.lang.String workerId, java.util.List<java.lang.String> objectIds)
Constructor with local root path
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addInIOParameters(java.util.List<IOParameter> list)
Add Input parametersvoid
addOutIOParameters(java.util.List<IOParameter> list)
Add Output parametersHandlerIO
addOutputResult(int rank, java.lang.Object object)
HandlerIO
addOutputResult(int rank, java.lang.Object object, boolean asyncIO)
Add one output result (no delete)HandlerIO
addOutputResult(int rank, java.lang.Object object, boolean deleteLocal, boolean asyncIO)
Add one output resultboolean
checkHandlerIO(int outputNumber, java.util.List<java.lang.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 asyncManagerjava.lang.String
getContainerName()
java.io.File
getFile(int rank)
java.io.File
getFileFromWorkspace(java.lang.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 parametersjava.util.Map<java.lang.String,java.lang.Long>
getFilesWithParamsFromWorkspace(java.lang.String containerName, java.lang.String folderName)
get Map of File With Params From folder in WorkspaceLogbookLifeCyclesClientHelper
getHelper()
java.util.List<java.lang.Object>
getInput()
java.lang.Object
getInput(int rank)
Return one Object from input<T> T
getInput(int rank, java.lang.Class<T> type)
Return one Object casted to type from inputjava.io.InputStream
getInputStreamFromWorkspace(java.lang.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(java.lang.String jsonFilePath)
Retrieve a json file as aJsonNode
from the workspace.LogbookLifeCyclesClient
getLifecyclesClient()
java.io.File
getNewLocalFile(java.lang.String name)
java.util.List<ProcessingUri>
getOutput()
ProcessingUri
getOutput(int rank)
Return one ProcessingUri from outputjava.util.List<java.net.URI>
getUriList(java.lang.String containerName, java.lang.String folderName)
java.lang.String
getWorkerId()
WorkspaceClientFactory
getWorkspaceClientFactory()
boolean
isExistingFileInWorkspace(java.lang.String workspacePath)
void
partialClose()
Close the HandlerIO, including temporary files and directories at the end of the step Workflow execution, but do not close the WorkspaceClientboolean
removeFolder(java.lang.String folderName)
Remove a specific foldervoid
reset()
Reset after each Actionvoid
setCurrentObjectId(java.lang.String currentObjectId)
void
transferAtomicFileToWorkspace(java.lang.String workspacePath, java.io.File sourceFile)
void
transferFileToWorkspace(java.lang.String workspacePath, java.io.File sourceFile, boolean toDelete, boolean asyncIO)
Helper to write a file to Workspace
To be used when not specified within the Output Parametersvoid
transferInputStreamToWorkspace(java.lang.String workspacePath, java.io.InputStream inputStream, java.nio.file.Path filePath, boolean asyncIO)
Helper to write an InputStream to Workspace
To be used when not specified within the Output Parametersvoid
transferJsonToWorkspace(java.lang.String collectionName, java.lang.String objectName, com.fasterxml.jackson.databind.JsonNode jsonNode, boolean toDelete, boolean asyncIO)
Helper to convert and write a file to Workspace
void
unzipInputStreamOnWorkspace(java.lang.String container, java.lang.String folderName, java.lang.String archiveMimeType, java.io.InputStream uploadedInputStream, boolean asyncIO)
-
-
-
Field Detail
-
NOT_CONFORM_PARAM
public static final java.lang.String NOT_CONFORM_PARAM
Not Conform Param- See Also:
- Constant Field Values
-
-
Constructor Detail
-
HandlerIOImpl
public HandlerIOImpl(java.lang.String containerName, java.lang.String workerId, java.util.List<java.lang.String> objectIds)
Constructor with local root path- Parameters:
containerName
- the container nameworkerId
- the worker idobjectIds
-
-
HandlerIOImpl
public HandlerIOImpl(WorkspaceClientFactory workspaceClientFactory, LogbookLifeCyclesClientFactory logbookLifeCyclesClientFactory, java.lang.String containerName, java.lang.String workerId, java.util.List<java.lang.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 Detail
-
getLifecyclesClient
public LogbookLifeCyclesClient getLifecyclesClient()
- Specified by:
getLifecyclesClient
in interfaceHandlerIO
- Returns:
- the HandlerIO LifecycleClient
-
getHelper
public LogbookLifeCyclesClientHelper getHelper()
-
addInIOParameters
public void addInIOParameters(java.util.List<IOParameter> list)
Description copied from interface:HandlerIO
Add Input parameters- Specified by:
addInIOParameters
in interfaceHandlerIO
-
addOutIOParameters
public void addOutIOParameters(java.util.List<IOParameter> list)
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 interfacejava.lang.AutoCloseable
- 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
public java.util.List<java.lang.Object> getInput()
-
getInput
public java.lang.Object getInput(int rank)
Description copied from interface:HandlerIO
Return one Object from input
-
getInput
public <T> T getInput(int rank, java.lang.Class<T> type)
Description copied from interface:HandlerIO
Return one Object casted to type from input
-
getOutput
public java.util.List<ProcessingUri> getOutput()
-
getOutput
public ProcessingUri getOutput(int rank)
Description copied from interface:HandlerIO
Return one ProcessingUri from output
-
addOutputResult
public HandlerIO addOutputResult(int rank, java.lang.Object object) throws ProcessingException
- Specified by:
addOutputResult
in interfaceHandlerIO
- Throws:
ProcessingException
-
addOutputResult
public HandlerIO addOutputResult(int rank, java.lang.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, java.lang.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
public java.lang.String getContainerName()
- Specified by:
getContainerName
in interfaceHandlerIO
- Returns:
- the container Name
-
getWorkerId
public java.lang.String getWorkerId()
- Specified by:
getWorkerId
in interfaceHandlerIO
- Returns:
- the worker Id
-
getNewLocalFile
public java.io.File getNewLocalFile(java.lang.String name)
- Specified by:
getNewLocalFile
in interfaceHandlerIO
- Returns:
- a File pointing to a local path in Tmp directory under protected Worker instance space
-
checkHandlerIO
public boolean checkHandlerIO(int outputNumber, java.util.List<java.lang.Class<?>> clasz)
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
public boolean isExistingFileInWorkspace(java.lang.String workspacePath) throws ProcessingException
- Specified by:
isExistingFileInWorkspace
in interfaceHandlerIO
- Throws:
ProcessingException
-
transferFileToWorkspace
public void transferFileToWorkspace(java.lang.String workspacePath, java.io.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(java.lang.String workspacePath, java.io.File sourceFile) throws ProcessingException
- Specified by:
transferAtomicFileToWorkspace
in interfaceHandlerIO
- Throws:
ProcessingException
-
transferInputStreamToWorkspace
public void transferInputStreamToWorkspace(java.lang.String workspacePath, java.io.InputStream inputStream, java.nio.file.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 java.io.File getFileFromWorkspace(java.lang.String objectName) throws java.io.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:
java.io.IOException
ContentAddressableStorageNotFoundException
ContentAddressableStorageServerException
-
getInputStreamFromWorkspace
public java.io.InputStream getInputStreamFromWorkspace(java.lang.String objectName) throws java.io.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:
java.io.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(java.lang.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
public java.util.List<java.net.URI> getUriList(java.lang.String containerName, java.lang.String folderName) throws ProcessingException
- Specified by:
getUriList
in interfaceHandlerIO
- Returns:
- List
a list of uri of object in SIP folder - Throws:
ProcessingException
-
transferJsonToWorkspace
public void transferJsonToWorkspace(java.lang.String collectionName, java.lang.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(java.lang.String container, java.lang.String folderName, java.lang.String archiveMimeType, java.io.InputStream uploadedInputStream, boolean asyncIO) throws ContentAddressableStorageException
- Specified by:
unzipInputStreamOnWorkspace
in interfaceHandlerIO
asyncIO
- asynchronously send and unzip file to/in the workspace- Throws:
ContentAddressableStorageException
-
enableAsync
public void enableAsync(boolean async) throws WorkerspaceQueueException
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
public boolean removeFolder(java.lang.String folderName) throws ContentAddressableStorageException
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
public void setCurrentObjectId(java.lang.String currentObjectId)
- Specified by:
setCurrentObjectId
in interfaceHandlerIO
-
getWorkspaceClientFactory
public WorkspaceClientFactory getWorkspaceClientFactory()
- Specified by:
getWorkspaceClientFactory
in interfaceHandlerIO
-
getFilesWithParamsFromWorkspace
public java.util.Map<java.lang.String,java.lang.Long> getFilesWithParamsFromWorkspace(java.lang.String containerName, java.lang.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
-
-