The Concurrent Processing Framework Client API for Java (1.6+) allows client applications to use the CPF REST Web Service API to query the available business applications, create jobs and download the results of jobs on behalf of their users.
The client can be used from Java applications developed using Maven with the following Maven settings.
The ErrorCode enum describes the types of error that can be returned in an error file.
Constant | Description |
---|---|
BAD_INPUT_DATA_TYPE | Invalid mime type for request input data. |
BAD_INPUT_DATA_VALUE | Illegal value in request input data. |
BAD_INPUT_DATA_VALUES | Illegal combination of values in request input data. |
BAD_NUMBER_REQUESTS | Invalid number of batch job requests. |
BAD_RESPONSE_DATA | Invalid response data returned from the Business Application. |
BAD_RESULT_DATA_TYPE | Invalid mime type for result data. |
ERROR_PROCESSING_REQUEST | An unknown error occurred processing the request. |
INPUT_DATA_UNREADABLE | Unable to read batch job input data. |
INVALID_PARAMETER_VALUE | A supplied request or job parameter has an invalid type or value. |
MISSING_REQUIRED_PARAMETER | A required request or job parameter is missing. |
RECOVERABLE_EXCEPTION | A temporary exception that can be recovered from. |
TOO_MANY_REQUESTS | Too many batch job requests for this business application. |
The callback interface is used by the CpfClient API to invoke code in a client application to process a objects returned from the CPF REST API.
The use of a callback mechanism ensures that any connections to the server are closed correctly after processing a request. The connections are closed even if there was a communications error or an exception thrown by the callback.
A callback can also used to reduce the memory overhead of a client application. The CpfClient reads the each result from the server and calls the process method for each object in turn. Keeping only one result in memory at a time.
Parameter | Type | Description |
---|---|---|
object | T | The object to process. |
The CPF Java (6+) client allows applications to use the CPF Web ArcGisRestService REST API to query the available business applications, create jobs and download the results of jobs on behalf of their users.
NOTE: The CpfClient is not thread safe. A separate instance must be created for each thread that uses the API.
The following code fragment shows an example of using the API for an application that accepts and returns structured data. Additional methods are provided for opaque data. The documentation of each method in this API provides an example of use.
NOTE: The examples are simplified versions of using the API. They should not be considered the correct way to write an application.. In the following example it waits a maximum of 2 seconds (2000 milliseconds) to see if the structured result file is available. In the real world jobs will take a longer undetermined time to execute. Applications should use the notification callback mechanism rather than polling the server or if that is not possible something like the Java ScheduledExecutorService.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("mapGridName", "BCGS 1:20 000"); parameters.put("mapTileId", "92j025"); String jobId = client.createJobWithStructuredSingleRequest( "MapTileByTileId", parameters, "application/json"); try { List<Map<String, Object>> results = client.getJobStructuredResults(jobId, 2000); for (Map<String, Object> result : results) { System.out.println(result); } } finally { client.closeJob(jobId); } } finally { client.closeConnection(); }
The CPF requires that UTF-8 encoding be used for all text files. This includes the text in a .dbf file for a .shpz archive, unless a .cpf file is provided in the shpz archive.
Construct a new CpfClient connected to the specified server using the consumerKey and consumerSecret for authentication.
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret);
Parameter | Type | Description |
---|---|---|
url | String | The full URL of the CPF Web Services, including the domain, port number and path e.g. https://apps.gov.bc.ca/cpf/ws/ |
consumerKey | String | The application's OAuth Consumer Key (user name) to connect to the service. |
consumerSecret | String | The OAuth Consumer Secret (encryption key) used to sign the requests for the Consumer Key. |
Close the connection to the CPF service. Once this method has been called the client can no longer be used and a new instance must be created. This should be called when the client is no longer needed to clean up resources.
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; try (CpfClient client = new CpfClient(url, consumerKey, consumerSecret)) { // Use the client }
Close the connection to the CPF service. Once this method has been called the client can no longer be used and a new instance must be created. This should be called when the client is no longer needed to clean up resources.
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { // Use the client } finally { client.closeConnection(); }
Delete the job using the Delete Job REST API.
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("mapGridName", "BCGS 1:20 000"); parameters.put("mapTileId", "92g025"); String jobId = client.createJobWithStructuredSingleRequest( "MapTileByTileId", parameters, "application/json"); // Download the results of the job client.closeJob(jobId); } finally { client.closeConnection(); }
Parameter | Type | Description |
---|---|---|
jobUrl | String | The URL of the job to be closed. |
Construct a new new job on the CPF server for a business application that accepts opaque input data using the Create Job With Multiple Requests REST API.
The content of the opaque data for each request is specified using a spring framework Resource object.
NOTE: There is a limit of 20MB of data for a multipart/form-data HTTP request. For jobs with large volumes of data make the data available on a HTTP server use the URL versions of this method instead.
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("algorithmName", "MD5"); List<Resource> requests = new ArrayList<Resource>(); requests.add(new ByteArrayResource("Test string".getBytes())); // requests.add(new FileSystemResource(pathToFile)); String jobId = client.createJobWithOpaqueResourceRequests("Digest", "1.0.0", parameters, "text/plain", "application/json", requests); // Download the results of the job client.closeJob(jobId); } finally { client.closeConnection(); }
Parameter | Type | Description |
---|---|---|
businessApplicationName | String | The name of the business application. |
jobParameters | Map<String, Object> | The global job parameters. |
inputDataContentType | String | The media type used for all the requests. |
resultContentType | String | The media type to return the result data using. |
requests | Collection<com.revolsys.spring.resource.Resource> | The resource for the requests. |
Construct a new new job on the CPF server for a business application that accepts opaque input data using the Create Job With Multiple Requests REST API.
The content of the opaque data for each request is specified using a spring framework Resource object.
NOTE: There is a limit of 20MB of data for a multipart/form-data HTTP request. For jobs with large volumes of data make the data available on a HTTP server use the URL versions of this method instead.
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("algorithmName", "MD5"); List<Resource> requests = new ArrayList<Resource>(); requests.add(new ByteArrayResource("Test string".getBytes())); // requests.add(Resource resource = new FileSystemResource(pathToFile)); String jobId = client.createJobWithOpaqueResourceRequests("Digest", "1.0.0", parameters, "text/plain", "application/json", requests); // Download the results of the job client.closeJob(jobId); } finally { client.closeConnection(); }
Parameter | Type | Description |
---|---|---|
businessApplicationName | String | The name of the business application. |
jobParameters | Map<String, Object> | The global job parameters. |
inputDataContentType | String | The media type used for all the requests. |
resultContentType | String | The media type to return the result data using. |
requests | com.revolsys.spring.resource.Resource[] | The resource for the requests. |
Construct a new new job on the CPF server for a business application that accepts opaque input data using the Create Job With Multiple Requests REST API.
The content of the opaque data for each request is specified using a URL to the data on a publicly accessible HTTP server.
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("algorithmName", "MD5"); <Resource> inputDataUrls = new Array<Resource>(); inputDataUrls.add("https://apps.gov.bc.ca/pub/cpf/css/cpf.css"); String jobId = client.createJobWithOpaqueUrlRequests("Digest", "1.0.0", parameters, "text/plain", "application/json", inputDataUrls); // Download the results of the job client.closeJob(jobId); } finally { client.closeConnection(); }
Parameter | Type | Description |
---|---|---|
businessApplicationName | String | The name of the business application. |
jobParameters | Map<String, ? extends Object> | The global job parameters. |
inputDataContentType | String | The media type used for all the requests. |
resultContentType | String | The media type to return the result data using. |
inputDataUrls | Collection<String> | The collection of URLs for the requests. |
Construct a new new job on the CPF server for a business application that accepts opaque input data using the Create Job With Multiple Requests REST API.
The content of the opaque data for each request is specified using a URL to the data on a publicly accessible HTTP server.
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("algorithmName", "MD5"); String inputDataUrl = "https://apps.gov.bc.ca/pub/cpf/css/cpf.css"; String jobId = client.createJobWithOpaqueUrlRequests("Digest", "1.0.0", parameters, "text/plain", "application/json", inputDataUrl); // Download the results of the job client.closeJob(jobId); } finally { client.closeConnection(); }
Parameter | Type | Description |
---|---|---|
businessApplicationName | String | The name of the business application. |
jobParameters | Map<String, ? extends Object> | The global job parameters. |
inputDataContentType | String | The media type used for all the requests. |
resultContentType | String | The media type to return the result data using. |
inputDataUrls | String[] | The collection of resources for the requests. |
Construct a new new job on the CPF server for a business application that accepts structured input data using the Create Job With Multiple Requests REST API.
The content of the structured data is specified as a list of requests. Each request is specified as a map containing the request parameters.
NOTE: There is a limit of 20MB of data for a multipart/form-data HTTP request. For jobs with large volumes of data make the data available on a HTTP server use the URL version of this method instead.
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { Map<String, Object> jobParameters = new HashMap<String, Object>(); jobParameters.put("mapGridName", "BCGS 1:20 000"); List<Map<String,?extends Object>> requests = new ArrayList<Map<String,?extends Object>>(); requests.add(Collections.singletonMap("mapTileId", "92j025")); requests.add(Collections.singletonMap("mapTileId", "92j016")); String jobId = client.createJobWithStructuredMultipleRequestsList( "MapTileByTileId", jobParameters, requests,"application/json"); try { List<Map<String, Object>> results = client.getJobStructuredResults( jobId, 5000); for (Map<String, Object> result : results) { System.out.println(result); } } finally { client.closeJob(jobId); } } finally { client.closeConnection(); }
Parameter | Type | Description |
---|---|---|
businessApplicationName | String | The name of the web services business application. |
jobParameters | Map<String, ? extends Object> | A map of additional parameters specific to the requested Business Application. |
requests | List<Map<String, ? extends Object>> | A list of data Maps of the requests. |
resultContentType | String | The media type of the result data. |
Construct a new new job on the CPF server for a business application that accepts structured input data using the Create Job With Multiple Requests REST API.
The content of the structured in data for each request is specified using a spring framework Resource object. The resource must be encoded using the file format specified by the inputDataContentType. The resource must contain one record containing the request parameters for each request to be processed by the business application.
NOTE: There is a limit of 20MB of data for a multipart/form-data HTTP request. For jobs with large volumes of data make the data available on a HTTP server use the URL version of this method instead.
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { Map<String, Object> jobParameters = new HashMap<String, Object>(); jobParameters.put("mapGridName", "NTS 1:500 000"); int numRequests = 48; Resource inputData = new FileSystemResource( "../cpf-war-app/src/main/webapp/docs/sample/NTS-500000-by-name.csv"); String jobId = client.createJobWithStructuredMultipleRequestsResource( "MapTileByTileId", jobParameters, numRequests, inputData, "text/csv", "application/json"); try { List<Map<String, Object>> results = client.getJobStructuredResults( jobId, 30000); for (Map<String, Object> result : results) { System.out.println(result); } } finally { client.closeJob(jobId); } } finally { client.closeConnection(); }
Parameter | Type | Description |
---|---|---|
businessApplicationName | String | The name of the business application. |
jobParameters | Map<String, ? extends Object> | The global job parameters. |
numRequests | int | The number of requests in the input data. |
inputData | com.revolsys.spring.resource.Resource | The resource containing the request input data. |
inputDataContentType | String | The media type used for all the requests. |
resultContentType | String | The media type to return the result data using. |
Construct a new new job on the CPF server for a business application that accepts structured input data using the Create Job With Multiple Requests REST API.
The content of the structured in data for each request is specified using a URL to the data on a publicly accessible HTTP server. The data must be encoded using the file format specified by the inputDataContentType. The data must contain one record containing the request parameters for each request to be processed by the business application.
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { Map<String, Object> jobParameters = new HashMap<String, Object>(); jobParameters.put("mapGridName", "NTS 1:500 000"); int numRequests = 48; String inputDataUrl = "https://apps.gov.bc.ca/pub/cpf/docs/sample/NTS-500000-by-name.csv"; String jobId = client.createJobWithStructuredMultipleRequestsUrl( "MapTileByTileId", jobParameters, numRequests, inputDataUrl, "text/csv", "application/json"); try { List<Map<String, Object>> results = client.getJobStructuredResults( jobId, 30000); for (Map<String, Object> result : results) { System.out.println(result); } } finally { client.closeJob(jobId); } } finally { client.closeConnection(); }
Parameter | Type | Description |
---|---|---|
businessApplicationName | String | The name of the business application. |
jobParameters | Map<String, ? extends Object> | The global job parameters. |
numRequests | int | The number of requests in the input data. |
inputDataUrl | String | The URL containing the request input data. |
inputDataContentType | String | The media type used for all the requests. |
resultContentType | String | The media type to return the result data using. |
Construct a new new job on the CPF server for a business application that accepts structured input data using the Create Job With Multiple Requests REST API.
The job and request parameters for the single request in the job are specified using a map of parameter values.
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("mapGridName", "BCGS 1:20 000"); parameters.put("mapTileId", "92j025"); String jobId = client.createJobWithStructuredSingleRequest( "MapTileByTileId", parameters, "application/json"); try { List<Map<String, Object>> results = client.getJobStructuredResults( jobId, 5000); for (Map<String, Object> result : results) { System.out.println(result); } } finally { client.closeJob(jobId); } } finally { client.closeConnection(); }
Parameter | Type | Description |
---|---|---|
businessApplicationName | String | The name of the business application. |
parameters | Map<String, ? extends Object> | The job and request parameters. |
resultContentType | String | The media type to return the result data using. |
Get the specification of the instant execution service for a business application using the Get Business Applications Instant REST API.
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { Map<String, Object> specification = client.getBusinessApplicationInstantSpecification( "MapTileByTileId"); System.out.println(specification); } finally { client.closeConnection(); }
Parameter | Type | Description |
---|---|---|
businessApplicationName | String | The name of the business application. |
Get the specification of the create job with multiple requests service for a business application using the Get Business Applications Multiple REST API.
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { Map<String, Object> specification = client.getBusinessApplicationMultipleSpecification( "MapTileByTileId"); System.out.println(specification); } finally { client.closeConnection(); }
Parameter | Type | Description |
---|---|---|
businessApplicationName | String | The name of the business application. |
Get the list of business application names a user has access to using the Get Business Applications REST API.
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { <Resource> businessApplicationNames = client.getBusinessApplicationNames(); for (String businessApplicationName : businessApplicationNames) { System.out.println(businessApplicationName); } } finally { client.closeConnection(); }
Get the specification of the create job with a single request service for a business application using the Get Business Applications Single REST API.
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { Map<String, Object> specification = client.getBusinessApplicationSingleSpecification( "MapTileByTileId"); System.out.println(specification); } finally { client.closeConnection(); }
Parameter | Type | Description |
---|---|---|
businessApplicationName | String | The name of the business application. |
Get the list of error results for a job using the using the Get Users Job Results and Get Users Job Result REST API.
Each error record is a map containing the following fields.
Field Name | Description |
---|---|
sequenceNumber | The sequence number of the request that caused the error. |
errorCode | The Error code. |
errorMessage | A more detailed message describing the error code. |
NOTE: This method loads all the error results into memory. If a larger number of errors were generated use the processJobErrorResults method.
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("mapGridName", "BCGS 1:20 000"); parameters.put("mapTileId", "INVALID"); String jobId = client.createJobWithStructuredSingleRequest( "MapTileByTileId", parameters, "application/json"); try { List<Map<String, Object>> results = client.getJobErrorResults( jobId, 2000); for (Map<String, Object> error : results) { System.out.println(error); } } finally { client.closeJob(jobId); } } finally { client.closeConnection(); }
Parameter | Type | Description |
---|---|---|
jobIdUrl | String | The job id URL. |
maxWait | long | The maximum number of milliseconds to wait for the job to be completed. |
Get the list of result file descriptions for a job using the using the Get Users Job Results REST API.
Each result file description contains the following fields.
Field Name | Description |
---|---|
resourceUri | The URL the result file can be downloaded from. |
title | A title of the result file (e.g. Batch Job 913 result 384). |
batchJobResultType | The type of result file structuredResultData, opaqueResultData, or errorResultData. |
batchJobResultContentType | The media type of the data in the result file. |
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("mapGridName", "BCGS 1:20 000"); parameters.put("mapTileId", "INVALID"); String jobId = client.createJobWithStructuredSingleRequest( "MapTileByTileId", parameters, "application/json"); try { List<Map<String, Object>> files = client.getJobResultFileList(jobId, 2000); for (Map<String, Object> file : files) { System.out.println(file); } } finally { client.closeJob(jobId); } } finally { client.closeConnection(); }
Parameter | Type | Description |
---|---|---|
jobIdUrl | String | The job id URL. |
maxWait | long | The maximum number of milliseconds to wait for the job to be completed. |
Get the job status using the Get Users Jobs Info REST API.
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("mapGridName", "BCGS 1:20 000"); parameters.put("mapTileId", "INVALID"); String jobId = client.createJobWithStructuredSingleRequest( "MapTileByTileId", parameters, "application/json"); try { Map<String, Object> status = client.getJobStatus(jobId); System.out.println(status); } finally { client.closeJob(jobId); } } finally { client.closeConnection(); }
Parameter | Type | Description |
---|---|---|
jobUrl | String | WS URL of the job. |
Get the list of structured data results for a job using the using the Get Users Job Results and Get Users Job Result REST API.
Each structured data record is a map containing the following fields.
Field Name | Description |
---|---|
sequenceNumber | The sequence number of the request that caused the error. |
resultNumber | If the business application returned multiple results for a single request there will be one record per result with an incrementing result number. |
resultFieldName | One field for each of the business application specific result fields. |
NOTE: This method loads all the structured data results into memory. If a larger number of results were generated use the processJobErrorResults method.
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("mapGridName", "BCGS 1:20 000"); parameters.put("mapTileId", "92j025"); String jobId = client.createJobWithStructuredSingleRequest( "MapTileByTileId", parameters, "application/json"); try { List<Map<String, Object>> results = client.getJobStructuredResults(jobId, 2000); for (Map<String, Object> result : results) { System.out.println(result); } } finally { client.closeJob(jobId); } } finally { client.closeConnection(); }
Parameter | Type | Description |
---|---|---|
jobIdUrl | String | The job id (URL) of the job. |
maxWait | long | The maximum number of milliseconds to wait for the job to be completed. |
Get the job id URLs for all the user's jobs using the Get Users Jobs REST API.
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("mapGridName", "BCGS 1:20 000"); parameters.put("mapTileId", "INVALID"); String jobId = client.createJobWithStructuredSingleRequest( "MapTileByTileId", parameters, "application/json"); try { <Resource> jobIds = client.getUserJobIdUrls(); for (String jobIdUrl : jobIds) { System.out.println(jobIdUrl); } if (!jobIds.contains(jobId)) { System.err.println("Missing job " + jobId); } } finally { client.closeJob(jobId); } } finally { client.closeConnection(); }
Get the job id URLs to the user's jobs for a business application using the Get Business Applications Users Jobs REST API.
Get the list of all job id URLs the user created.The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("mapGridName", "BCGS 1:20 000"); parameters.put("mapTileId", "INVALID"); String jobId = client.createJobWithStructuredSingleRequest( "MapTileByTileId", parameters, "application/json"); try { <Resource> jobIds = client.getUserJobIdUrls("MapTileByTileId"); for (String jobIdUrl : jobIds) { System.out.println(jobIdUrl); } if (!jobIds.contains(jobId)) { System.err.println("Missing job " + jobId); } } finally { client.closeJob(jobId); } } finally { client.closeConnection(); }
Parameter | Type | Description |
---|---|---|
businessApplicationName | String | The name of the business application. |
Check the job status to see if it has been completed using the Get Users Jobs Info REST API.
If the job has not been completed within the maxWait number of milliseconds false will be returned.
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("mapGridName", "BCGS 1:20 000"); parameters.put("mapTileId", "INVALID"); String jobId = client.createJobWithStructuredSingleRequest( "MapTileByTileId", parameters, "application/json"); try { boolean completed = client.isJobCompleted(jobId, 2000); if (completed) { System.out.println("Job Completed"); } } finally { client.closeJob(jobId); } } finally { client.closeConnection(); }
Parameter | Type | Description |
---|---|---|
jobIdUrl | String | The job id URL. |
maxWait | long | The maximum number of milliseconds to wait. |
Process the list of error results for a job using the using the Get Users Job Results and Get Users Job Result REST API.
Each error record is a map containing the following fields.
Field Name | Description |
---|---|
sequenceNumber | The sequence number of the request that caused the error. |
errorCode | The Error code. |
errorMessage | A more detailed message describing the error code. |
The callback method will be invoked for each record in the error file.
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("mapGridName", "BCGS 1:20 000"); parameters.put("mapTileId", "INVALID"); String jobId = client.createJobWithStructuredSingleRequest( "MapTileByTileId", parameters, "application/json"); try { int numErrors = client.processJobErrorResults(jobId, 10000, new Callback<Map<String, Object>>() { public void process(Map<String, Object> error) { System.out.println(error); } }); System.out.println(numErrors); } finally { client.closeJob(jobId); } } finally { client.closeConnection(); }
Parameter | Type | Description |
---|---|---|
jobIdUrl | String | The job id (URL) of the job. |
maxWait | long | The maximum number of milliseconds to wait for the job to be completed. |
callback | Callback<Map<String, Object>> | The call back in the client application that will be called for each error record. |
Process the list of structured data results for a job using the using the Get Users Job Results and Get Users Job Result REST API.
Each structured record is a map with the fields sequenceNumber (to map back to the input request), resultNumber (if multiple results were returned for a single request and the business application specific result fields.
The callback method will be invoked for each record in the structured result data file.
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("mapGridName", "BCGS 1:20 000"); parameters.put("mapTileId", "92j025"); String jobId = client.createJobWithStructuredSingleRequest( "MapTileByTileId", parameters, "application/json"); try { int numResults = client.processJobStructuredResults(jobId, 10000, new Callback<Map<String, Object>>() { public void process(Map<String, Object> result) { System.out.println(result); } }); System.out.println(numResults); } finally { client.closeJob(jobId); } } finally { client.closeConnection(); }
Parameter | Type | Description |
---|---|---|
jobIdUrl | String | The job id (URL) of the job. |
maxWait | long | The maximum number of milliseconds to wait for the job to be completed. |
callback | Callback<Map<String, Object>> | The call back in the client application that will be called for each result record. |
Process the result file for a job using the Get Users Job Result REST API.
The callback method will be invoked with the input stream to the file. This method ensures that the input stream is closed correctly after being processed.
The following code fragment shows an example of using the API.
String url = "https://apps.gov.bc.ca/pub/cpf"; String consumerKey = "cpftest"; String consumerSecret = "cpftest"; CpfClient client = new CpfClient(url, consumerKey, consumerSecret); try { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("mapGridName", "BCGS 1:20 000"); parameters.put("mapTileId", "92j016"); String jobId = client.createJobWithStructuredSingleRequest( "MapTileByTileId", parameters, "application/json"); try { List<Map<String, Object>> files = client.getJobResultFileList( jobId, 5000); for (Map<String, Object> file : files) { String jobResultUrl = (String)file.get("resourceUri"); client.processResultFile(jobResultUrl , new Callback<Base64InputStream>() { public void process(Base64InputStream in) { // Read file from input stream } }); } } finally { client.closeJob(jobId); } } finally { client.closeConnection(); }
Parameter | Type | Description |
---|---|---|
jobResultUrl | String | The URL to the job result file. |
resultProcessor | Callback<InputStream> | The processor to process the input stream returned from the web service. |