Package de.elo.ix.client.imfs
Class ImportFileSystem
java.lang.Object
de.elo.ix.client.imfs.ImportFileSystem
Import files and folders from file system into an ELO archive.
Example:
import java.util.Properties;
import byps.BSyncResult;
import de.elo.ix.client.IXConnFactory;
import de.elo.ix.client.IXConnection;
public class ImportFileSystemExample {
public final static void main(String[] args) {
// How to connect to IX
String ixUrl = "http://srvtdev03:6020/ix-elo90/ix";
String userName = "Administrator";
String pwd = "elo";
IXConnFactory connFact = null;
IXConnection conn = null;
try {
// Initialize connection properties map.
// Allow 100 parallel requests.
Properties connProps = IXConnFactory.createConnProps(ixUrl);
connProps.put(IXConnFactory.PROP_NB_OF_CNNS, "100");
// Reverse connections (server push functionality) are not required.
connProps.put(IXConnFactory.NB_OF_REVERSE_CNNS, "0");
// Initialize session options with application name and version.
Properties sessOpts = IXConnFactory.createSessionOptions("import-fs-example", "0.1");
// Connect
connFact = new IXConnFactory(connProps, sessOpts);
conn = connFact.create(userName, pwd, "import-fs", "");
// Initialize import options.
ImportOptions options = new ImportOptions();
options.setSource("H:/temp/mailablage/PSUPPORT/2008");
options.setDestination("/ImportFS/2008-1");
options.setHandleDuplicate(ImportOptions.CREATE_REFERENCE_FOR_DUPLICATE);
AccessControlOptions accessControlOptions = new AccessControlOptions();
accessControlOptions.setSkip(true);
options.setAccessControlOptions(accessControlOptions);
// Callback function (interface) to print import progress on stdout.
ProgressCallback progress = (ProgressInfo value) -> {
System.out.println(value.toString());
};
// Create the importer object.
ImportFileSystem importFS = new ImportFileSystem(ImportFileSystem.IMPORT, conn, options, progress);
// Do import.
BSyncResult<ImportResult> asyncResult = new BSyncResult<ImportResult>();
importFS.doImport(asyncResult);
// Await finished.
ImportResult importResult = asyncResult.getResult();
System.out.println("importResult=" + importResult);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (conn != null) {
conn.close();
}
if (connFact != null) {
connFact.done();
}
}
}
}
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionImportFileSystem
(boolean importNotAnalyze, IXConnection conn, ImportOptions options, ProgressCallback progress) Import or analyze file system. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
assignCustomMembers
(File srcFile, Sord sord, SordZ sordZ, DocVersion dv) Assign additional Members to Sord object.protected void
assignFileTimeToSord
(File sourceFile, Sord sord, SordZ sordZ, DocVersion dv) Assing file time values of the given file to the Sord and DocVersion object.protected int
checkSordExists
(int parentId, String name) Check whether an object with the given name already exists.protected int
createFolder
(File srcDir, int parentId, String destArcPath) Create a new folder in the ELO archive.void
doImport
(byps.BAsyncResult<ImportResult> importResult) Start import or analyze process.int
Get maximum number of documents that are processed simultaneously.protected boolean
importDocument
(File file, int parentId) Import document.protected void
importFolderOrDocument
(File file, int folderId) Import one folder or one file.protected int
importFolderSync
(File srcDir, int parentId, String destArcPath) Import folder.protected int
importOrAnalyzeFolder
(File srcDir, int parentId, String destArcPath) Import or analyze given folder with all sub-items.protected void
Read the keywording form to be used for folders.boolean
isPause()
Returns true, if the process is paused.protected String
makeSordNameFromFileName
(String fname) Replace whitespace characters in file name withImportOptions.getBlankReplacement()
.protected String[]
makeValidSordNameAndExt
(File file) Split file name and extension.protected boolean
maybeCreateReferenceOnDuplicate
(File file, int parentId, String internalName, String[] refMD5) Create a reference if the given document is a duplicate.void
pause
(boolean pauseNotResume) Pause or resume process.protected Sord
readSordIfExists
(String objId, SordZ sordZ) void
setImportEvents
(ImportEvents importEvents) void
setMaximumThreadPoolSize
(int nbOfThreads) Set maximum number documents that are processed simultaneously.protected void
setOriginalFileName
(Sord sord, String fname) Store the file name in the ObjKey reserved for this purposse.void
stop()
Interrupt and stop the process.protected boolean
testFiltersMatchThisFile
(File file) Test whether file matches any include filter and does not match any exclude filter.
-
Field Details
-
log
public static final org.slf4j.Logger log -
IMPORT
public static final boolean IMPORTImport mode.- See Also:
-
ANALYZE
public static final boolean ANALYZEAnaylze mode.- See Also:
-
-
Constructor Details
-
ImportFileSystem
public ImportFileSystem(boolean importNotAnalyze, IXConnection conn, ImportOptions options, ProgressCallback progress) Import or analyze file system.
-
-
Method Details
-
setMaximumThreadPoolSize
public void setMaximumThreadPoolSize(int nbOfThreads) Set maximum number documents that are processed simultaneously. Default value is IXConnFactory.PROP_NB_OF_CNNS / 2.- Parameters:
nbOfThreads
- Thread pool size, should be significantly less than IXConnFactory.PROP_NB_OF_CNNS. This value must be greater than 1.
-
getMaximumThreadPoolSize
public int getMaximumThreadPoolSize()Get maximum number of documents that are processed simultaneously.- Returns:
- Thread pool size.
-
doImport
Start import or analyze process.- Parameters:
importResult
- This functional interface is called, when the process has finished.
-
pause
public void pause(boolean pauseNotResume) Pause or resume process.- Parameters:
pauseNotResume
- true, to pause process.
-
isPause
public boolean isPause()Returns true, if the process is paused.- Returns:
- true, if paused.
-
stop
public void stop()Interrupt and stop the process.- See Also:
-
importOrAnalyzeFolder
Import or analyze given folder with all sub-items.- Parameters:
srcDir
- File system folder to be imported.parentId
- Destionation parent ID in ELO archive.destArcPath
- Destination path in ELO archive releative to parentId.- Returns:
- Object ID of imported folder.
-
importFolderSync
Import folder.- Parameters:
srcDir
- File system folder to be imported.parentId
- Destionation parent ID in ELO archive.destArcPath
- Destination path in ELO archive releative to parentId.- Returns:
- Object ID of imported folder.
-
importFolderOrDocument
Import one folder or one file.- Parameters:
file
- File or folder to be imported.folderId
- Parent ID of the destination folder in the ELO archive.- Throws:
Exception
-
importDocument
Import document.- Parameters:
file
-parentId
-- Returns:
- false, if function should be retried.
-
maybeCreateReferenceOnDuplicate
protected boolean maybeCreateReferenceOnDuplicate(File file, int parentId, String internalName, String[] refMD5) throws Exception Create a reference if the given document is a duplicate.- Parameters:
file
- Document file.parentId
-refMD5
-- Returns:
- true, if a reference was created or another duplicate is being imported at the same time.
- Throws:
Exception
-
setOriginalFileName
Store the file name in the ObjKey reserved for this purposse.- Parameters:
sord
- Sord object.fname
- File name.
-
readSordIfExists
- Throws:
Exception
-
checkSordExists
Check whether an object with the given name already exists.- Parameters:
parentId
- Parent ID.name
- File name.- Returns:
- The ID of an existing Sord or 0, if the Sord does not exist.
- Throws:
Exception
-
makeSordNameFromFileName
Replace whitespace characters in file name withImportOptions.getBlankReplacement()
.- Parameters:
fname
- File name or path- Returns:
- Sord name or archive path
-
makeValidSordNameAndExt
Split file name and extension. Truncated name and extension to the maximum allowed characters.- Parameters:
file
- File- Returns:
- Name and extension (starts with a dot).
-
createFolder
Create a new folder in the ELO archive.- Parameters:
srcDir
- Folder in the file system.parentId
- Parent ID.destArcPath
- Path relative to Parent ID to be created.- Returns:
- ID of the last created folder.
- Throws:
Exception
-
assignCustomMembers
Assign additional Members to Sord object. This function can be overwritten in a derived class in order to assign additional values to the Sord object before it is inserted. When importing a document, this function is called before checkinDocBegin. When importing a folder, this function is called before checkinSord.- Parameters:
srcFile
- File or directory to be imported.sord
- Sord objectsordZ
- Valid sord members. Set sordZ.setBset(sordZ.getBset() | SordC.mbElement) for changed members.dv
- DocVersion object if sord is a document, otherwise null.
-
testFiltersMatchThisFile
Test whether file matches any include filter and does not match any exclude filter.- Parameters:
file
- File object.- Returns:
- true, if file should be imported
-
assignFileTimeToSord
protected void assignFileTimeToSord(File sourceFile, Sord sord, SordZ sordZ, DocVersion dv) throws Exception Assing file time values of the given file to the Sord and DocVersion object.- Parameters:
sourceFile
- File to read time properties from.sord
- Sord object that receives the time values.sordZ
- Modified Sord properties are added to this element selector.dv
- DocVersion object that receives time values, can be null for folders.- Throws:
Exception
-
initFolderMaskId
Read the keywording form to be used for folders.- Throws:
Exception
-
getImportEvents
-
setImportEvents
-