As in Chapter 6, The Activiti ProcessEngine API, we have gone through the deployment of a business process and used the Repository API for deployment purposes. In this section, we will perform the following steps to install and deploy the business process using the Repository REST API:
url/repository/deployments
in the browser with the GET method; the response will fetch all the deployed processes from the repository./repository /deployments/{deploymentId}
, with the GET method. In the following screenshot, we have provided the deployment ID 23
:url /repository/deployment/{deploymentId}
, as shown in the following screenshot:Repository_Deployment
with the following code:private static String REST_URI = "http://localhost:8080/activiti-rest/service"; private static ClientResource getClientResource(String uri) { ClientResource resource = new ClientResource(uri); resource.setChallengeResponse(ChallengeScheme.HTTP_BASIC, "kermit", "kermit"); return resource; } public static JSONArray getDeployments() throws JSONException, IOException { String deploymentURI = REST_URI + "/repository/deployments"; Representation response = getClientResource(deploymentURI).get( MediaType.APPLICATION_JSON); JSONObject object = new JSONObject(response.getText()); if (object != null) { JSONArray dataArray = (JSONArray) object.get("data"); return dataArray; } return null; }
kermit
; the getDeployments()
method will fetch all the deployed processes from the engine and return it as a JSONArray
object.Test
Rest API class within src/test/java
, which will have the following code:@Test public void deploymentTest() throws JSONException, IOException { JSONArray procesArray = Repository_Deployment.getDeployments(); for (int i = 0; i < processArray.length(); i++) { JSONObject jasonObject = (JSONObject) processArray.get(i); assertNotNull(jasonObject); System.out.println(jasonObject.toString()); } }
Repository_Deployment
class that takes the process ID as an input parameter and provides the result for that process, as shown in the following code:public static JSONObject getDeployments(int id) throws JSONException, IOException { String deploymentURI = REST_URI + "/repository/deployments/" + id; Representation response = getClientResource(deploymentURI).get( MediaType.APPLICATION_JSON); JSONObject object = new JSONObject(response.getText()); if (object != null) { return object; } return null; }
@Test public void deploymentById() throws JSONException, IOException { JSONObject processObject = Repository_Deployment.getDeployments(23); assertNotNull(processObject); System.out.println(processObject.toString()); }
deleteDeployment
method in the Repository_Deployment
class; here in the response, we are calling the delete
method, as shown in the following code:public static void deleteDeployment(int id) { String deploymentURI = REST_URI + "/repository/deployments/" + id; Representation response = getClientResource(deploymentURI).delete( MediaType.ALL); }
deleteDeployment
method of Repository_Deployment
; on performing the test, the process with the ID 23
will be deleted from the repository, as shown in the following code:@Test public void deleteDeployment() throws JSONException, IOException { Repository_Deployment.deleteDeployment(23); }
url /repository/deployments/{deploymentId}/resources
.getDeploymentResources
method in the Repository_Deployments
class, where we will pass the deployment ID to access its resources, as shown in the following code:public static JSONArray getDeploymentResources(int id) throws IOException, JSONException { String deploymentURI = REST_URI + "/repository/deployments/" + id + "/resources"; Representation response = getClientResource(deploymentURI).get( MediaType.APPLICATION_JSON); String json = "{data :" + response.getText() + "}"; JSONObject object = new JSONObject(json); if (object != null) { JSONArray arr = (JSONArray) object.get("data"); return arr; } return null; }
deploymentResource
method in the Repository_Deployment
class as follows:@Test public void deploymentResource() throws JSONException, IOException { JSONArray processArray = Repository_Deployment.getDeploymentResources(23); assertNotNull(processArray); for (int i=0;i<processArray.length();i++){ JSONObject object = (JSONObject) processArray.get(i); assertNotNull(object); System.out.println(object.toString()); } }