public class FCproClient extends Object
// Initialize client.
FCproClient client = new FCproClient();
client.setEndpoint("https://example.com/FileConverterProREST");
client.setUser("admin");
client.setPassword("secret");
client.setApiHash(123456);
// Get server state.
logger.debug("==== Server State ====");
logger.debug("getServerHash():\t" + client.getServerHash());
logger.debug("getServerVersion():\t" + client.getServerVersion());
logger.debug("getAvgSecPerPage():\t" + client.getAvgSecPerPage());
logger.debug("getNrOfDocumentsInQueue():\t" + client.getNrOfDocumentsInQueue());
logger.debug("getNrOfPagesInQueue():\t" + client.getNrOfPagesInQueue());
logger.debug("getAvailablePages():\t" + client.getAvailablePages());
// Get available settings/profiles.
logger.debug("==== getSettings ====");
FCproSetting[] settings = client.getSettings();
for (FCproSetting setting : settings) {
logger.debug(setting.getSettingsName());
}
// Upload file for conversion.
FCproJob upload = client.upload(new File("/tmp/example.pdf"), "application/pdf", "DE-DE", "example-label");
logger.debug(upload.getGuid());
// Wait up to 60 seconds for completion, check every two seconds.
FCproStatus completionStatus = client.waitForCompletion(upload.getGuid(), 60_000, 2_000);
logger.debug(completionStatus.toString());
if (completionStatus == FCproStatus.CONVERTED) {
client.download(upload.getGuid(), new File("/tmp/example-converted.pdf");
}
Constructor and Description |
---|
FCproClient() |
Modifier and Type | Method and Description |
---|---|
void |
cancelJob(String guid)
Cancels a job.
|
void |
deleteAllJobs()
Delets all jobs from the queue.
|
void |
deleteJobsOlderThanDays(int days)
Deletes all jobs older than a given number of days.
|
void |
download(String jobGuid,
File outFile)
Download transformation to a file.
|
void |
download(String jobGuid,
File outFile,
int index)
Download transformation to a file.
|
void |
download(String jobGuid,
OutputStream outs,
int index)
Downloads a result to the given
OutputStream . |
FCproEnumJobsResult |
enumJobs(int pageSize,
String label,
FCproUser user,
FCproStatus status,
String createdFromTo,
String convertedFromTo,
String sortColumns)
Get a filtered job enumeration.
|
List<FCproJob> |
enumJobsGetPage(int enumID,
int pageIndex)
Get a page of jobs from a job enumeration.
|
List<FCproJob> |
getAllJobs()
Query for all jobs but without filtering the results.
|
List<FCproJob> |
getAllJobs(FCproStatus state)
Query for all jobs filtered by state state.
|
int |
getAvailablePages()
Some OCR engines maintain a page limit, which can be queried through this
method.
|
int |
getAvgSecPerPage()
Transformation speed information.
|
int |
getConnectionTimeout()
Getter.
|
String |
getCredentialsCharset()
Getter.
|
String |
getEndpoint()
Getter.
|
FCproJob |
getJob(String guid)
Query for a job.
|
int |
getNrOfDocumentsInQueue()
Returns the total number of documents currently stored in the queue.
|
int |
getNrOfPagesInQueue()
Returns the number of total pages currently stored in the queue.
|
List<FCproJob> |
getOwnJobs(FCproStatus state)
Query for all jobs from a user, having the specified state.
|
protected String |
getPassword()
Getter.
|
int |
getResultCount(String guid)
Queries the number of transformation results.
|
String |
getResultExt(String guid,
int index)
Returns the file extension of the transformed file at the given index.
|
String |
getResultMimetype(String guid,
int index)
Returns the file mimetype of the transformed file at the given index.
|
int |
getServerHash()
Getting the remote API key from AutoOCR-Server.
|
String |
getServerVersion()
Getting version of AutoOCR-Server.
|
FCproSetting[] |
getSettings()
Query AutoOCR server settings.
|
FCproStatus |
getStatus(String guid)
Directly query for a job status.
|
String |
getUrlEncodingCharset()
Getter.
|
String |
getUser()
Getter.
|
List<FCproUser> |
getUsers()
Quering for all users.
|
boolean |
isApiKeyValid(int apikey)
Check if an API key is valid.
|
boolean |
isSecureEndpoint()
Check if the connection to the AutoOCR Service is secured through SSL.
|
boolean |
isStarted()
Asking for AutoOCR-Server status.
|
void |
removeJob(String guid)
Removes a job from the queue.
|
void |
setApiHash(int apiHash)
Setter.
|
void |
setConnectionTimeout(int connectionTimeout)
Setter.
|
void |
setCredentialsCharset(String credentialsCharset)
Setter.
|
void |
setEndpoint(String endpoint)
Setter.
|
void |
setPassword(String password)
Setter.
|
void |
setUrlEncodingCharset(String urlEncodingCharset)
Setter.
|
void |
setUser(String user)
Setter.
|
void |
startServer()
Starts the AutoOCR-Server.
|
void |
stopServer()
Stops the AutoOCR-Server.
|
FCproJob |
upload(File file,
String ext,
String profile,
List<String> additionals,
String label)
Upload and create a job from a local file.
|
FCproJob |
upload(File file,
String ext,
String profile,
String label)
Upload and create a job from a local file.
|
FCproJob |
upload(InputStream ins,
String ext,
String profile,
List<String> additionals,
String label)
Upload and create a job from an
InputStream . |
FCproStatus |
waitForCompletion(String guid,
long timeout,
long sleeptime)
Waits for the completion of a transformation.
|
public boolean isStarted()
public void startServer()
public void stopServer()
public int getAvgSecPerPage()
public int getNrOfDocumentsInQueue()
public int getNrOfPagesInQueue()
public int getAvailablePages()
public void removeJob(String guid)
guid
- the job GUID.public void cancelJob(String guid)
guid
- the job GUID.public void deleteAllJobs()
public void deleteJobsOlderThanDays(int days)
days
- the number of dayspublic String getResultExt(String guid, int index)
guid
- the job GUIDindex
- the indexpublic String getResultMimetype(String guid, int index)
guid
- the job GUIDindex
- the indexpublic int getResultCount(String guid)
guid
- the job GUIDpublic int getServerHash()
public String getServerVersion()
public FCproStatus waitForCompletion(String guid, long timeout, long sleeptime)
TransformationTimedOutException
is thrown. If it
completes in time, the resulting job status is returned and should be
checked for errors.guid
- the job GUIDtimeout
- milliseconds to wait for completion before aborting with
TransformationTimedOutException
sleeptime
- time in milliseconds to wait between pollsTransformationTimedOutException
- if the transformation did not
complete in timeout time.public FCproStatus getStatus(String guid)
guid
- the job GUIDpublic FCproJob getJob(String guid)
FCproJob
object is returned with
status == FCproStatus.INVALID
.guid
- the job GUIDpublic List<FCproJob> getOwnJobs(FCproStatus state)
state
- the statepublic List<FCproJob> getAllJobs(FCproStatus state)
state
- the statspublic List<FCproJob> getAllJobs()
public FCproEnumJobsResult enumJobs(int pageSize, String label, FCproUser user, FCproStatus status, String createdFromTo, String convertedFromTo, String sortColumns)
pageSize
- the page sizelabel
- the label to filter foruser
- the user to filter forstatus
- the status to filter forcreatedFromTo
- the created date range to filter forconvertedFromTo
- the converted date range to filter forsortColumns
- the columns to sort the resultpublic List<FCproJob> enumJobsGetPage(int enumID, int pageIndex)
enumID
- the enumeration IDpageIndex
- the requested page of the enumerationpublic FCproSetting[] getSettings()
public FCproJob upload(File file, String ext, String profile, String label)
file
- the file to uploadext
- the target transformation format as autoocr extension or
mimetypeprofile
- the server profile to uselabel
- description field for document name or something like thatpublic FCproJob upload(File file, String ext, String profile, List<String> additionals, String label)
file
- the file to uploadext
- the target transformation format as autoocr extension or
mimetypeprofile
- the server profile to useadditionals
- a list of file formats to be created as welllabel
- description field for document name or something like thatpublic FCproJob upload(InputStream ins, String ext, String profile, List<String> additionals, String label)
InputStream
. It is the
responsibility of the caller to close the InputStream instance.ins
- the InputStream
ext
- the target transformation format as mimetypeprofile
- the server profile to useadditionals
- a list of file formats to be created as welllabel
- description field for the job, can be nullpublic void download(String jobGuid, File outFile)
jobGuid
- the job GUIDoutFile
- the file to save the transformation result topublic void download(String jobGuid, File outFile, int index)
jobGuid
- the job GUIDoutFile
- the file to save the transformation result toindex
- index of file in the transformation listpublic void download(String jobGuid, OutputStream outs, int index)
OutputStream
. The caller is
responsible to close the stream.jobGuid
- the job GUIDouts
- the OutputStream
index
- index of file in the transformation listpublic boolean isApiKeyValid(int apikey)
apikey
- the API keypublic final String getEndpoint()
public final void setEndpoint(String endpoint)
endpoint
- the endpointpublic final String getUser()
public final void setUser(String user)
user
- the userprotected final String getPassword()
public final void setPassword(String password)
password
- the passwordpublic boolean isSecureEndpoint()
true
, if the connection is SSL securedpublic final String getCredentialsCharset()
public final void setCredentialsCharset(String credentialsCharset)
credentialsCharset
- credentials charsetpublic final String getUrlEncodingCharset()
public final void setUrlEncodingCharset(String urlEncodingCharset)
urlEncodingCharset
- URL encoding charsetpublic final int getConnectionTimeout()
public final void setConnectionTimeout(int connectionTimeout)
connectionTimeout
- connection timeoutpublic final void setApiHash(int apiHash)
apiHash
- API hashCopyright © 2015. All Rights Reserved.