Skip to content

Commit

Permalink
open specific view on button click (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
LaviniaStiliadou authored Feb 10, 2025
1 parent 3cf8a7b commit a629b33
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 77 deletions.
50 changes: 10 additions & 40 deletions frontend/src/process-instance-runtime-action/ProcessViewButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ function ProcessViewButton({ camundaAPI, processInstanceId }) {
const processViewEndpoint = `${cockpitApi}/plugin/camunda-process-views-plugin/${engine}/process-instance/${processInstanceId}`
console.log('URL to server-side plugin: ', processViewEndpoint);

const patternView = "view-with-patterns.xml";
const quantumView = "view-before-rewriting.xml";

// get the currently active view by retrieving the corresponding variable of the process instance
useEffect(() => {
fetch(
Expand All @@ -41,46 +44,13 @@ function ProcessViewButton({ camundaAPI, processInstanceId }) {
});
}, []);

async function openDeploymentView() {
const rawResponse = await fetch(`/engine-rest/process-instance/${processInstanceId}`,
{
method: 'GET',
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
"X-XSRF-TOKEN": camundaAPI.CSRFToken,
}
});
const response = await rawResponse.json();

if (!rawResponse.ok) {
throw new Error(`Failed to fetch process instance: ${response.message}`);
}

console.log('Switching to next view resulted in: ', response);
const definitionId = response.definitionId;
const splitDefinitionId = definitionId.split(':');
const result = splitDefinitionId[0] + '.bpmn';
setActivatedView(result);
const updateview = await fetch(processViewEndpoint + '/change-view/' + result,
{
method: 'POST', body: '{}',
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
"X-XSRF-TOKEN": camundaAPI.CSRFToken,
}
});
console.log('Currently activated view: ', result)
location.reload();
}

async function openDialog(activatedView) {
console.log('Switching from currently activated view: ', activatedView);
async function openView(viewName) {
console.log('Switching to specified view: ', viewName);

// switch to next view for the process instance
console.log('Performing POST request at following URL to switch view: ', processViewEndpoint + '/change-view');
const rawResponse = await fetch(processViewEndpoint + '/change-view',
console.log('Performing POST request at following URL to switch view: ', processViewEndpoint + '/view');
const rawResponse = await fetch(processViewEndpoint + '/view/'+ viewName,
{
method: 'POST', body: '{}',
headers: {
Expand All @@ -89,7 +59,7 @@ function ProcessViewButton({ camundaAPI, processInstanceId }) {
"X-XSRF-TOKEN": camundaAPI.CSRFToken,
}
});
console.log('Switching to next view resulted in: ', rawResponse);
console.log('Switching to view resulted in: ', rawResponse);
location.reload();
}

Expand All @@ -105,10 +75,10 @@ function ProcessViewButton({ camundaAPI, processInstanceId }) {

return (
<>
<button id="pattern-view-button" className="btn btn-default btn-toolbar ng-scope process-view-button" title="Toggle Pattern View" onClick={() => openDialog(activatedView)} tooltip-placement="left">
<button id="pattern-view-button" className="btn btn-default btn-toolbar ng-scope process-view-button" title="Toggle Pattern View" onClick={() => openView(patternView)} tooltip-placement="left">
<img class="process-view-button-picture" src="https://raw.githubusercontent.com/UST-QuAntiL/camunda-process-view-plugins/refs/heads/main/frontend/resources/pattern-icon.png" />
</button>
<button id="quantum-view-button" className="btn btn-default btn-toolbar ng-scope process-view-button" title="Toggle Quantum View" onClick={() => openDialog(activatedView)} tooltip-placement="left">
<button id="quantum-view-button" className="btn btn-default btn-toolbar ng-scope process-view-button" title="Toggle Quantum View" onClick={() => openView(quantumView)} tooltip-placement="left">
<img class="process-view-button-picture" src="https://raw.githubusercontent.com/UST-QuAntiL/camunda-process-view-plugins/refs/heads/main/frontend/resources/QuantumViewIcon.svg" />
</button>
<button id="deployment-view-button" className="btn btn-default btn-toolbar ng-scope process-view-button" title="Toggle Deployment View" onClick={() => { triggerDeployment() }} tooltip-placement="left">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ public ProcessViewPluginRootResource() {

@GET
@Path("{engineName}/process-instance/{processInstanceId}/active-view")
public ActiveProcessViewDto getCurrentlyActiveProcessView(@Context UriInfo uriInfo, @PathParam("engineName") String engineName,
@PathParam("processInstanceId") String processInstanceId)
throws IOException, NotFoundException {
// workaround to access the Camunda REST API, as the Java API does not provide all required details
public ActiveProcessViewDto getCurrentlyActiveProcessView(@Context UriInfo uriInfo,
@PathParam("engineName") String engineName,
@PathParam("processInstanceId") String processInstanceId)
throws IOException, NotFoundException {
// workaround to access the Camunda REST API, as the Java API does not provide
// all required details
String baseUrl = "http://" + uriInfo.getAbsolutePath().getHost() + ":" + uriInfo.getAbsolutePath().getPort();
System.out.println("Received request for host and port: " + baseUrl);

Expand All @@ -55,15 +57,16 @@ public ActiveProcessViewDto getCurrentlyActiveProcessView(@Context UriInfo uriIn

// get variable storing the active process view
ProcessViewService processViewService = new ProcessViewService();
Object activeProcessViewVariable = runtimeService.getVariable(processInstanceId, "process-view-extension-active-view");
Object activeProcessViewVariable = runtimeService.getVariable(processInstanceId,
"process-view-extension-active-view");
String activeProcessView;
if (Objects.isNull(activeProcessViewVariable)){
if (Objects.isNull(activeProcessViewVariable)) {
System.out.println("Adding default value as active process view is currently not set!");

// set original workflow as initial view if not yet set
activeProcessView = processViewService.findInitialViewName(processInstanceId, baseUrl);
runtimeService.setVariable(processInstanceId, "process-view-extension-active-view", activeProcessView);
} else{
} else {
activeProcessView = activeProcessViewVariable.toString();
}

Expand All @@ -80,8 +83,9 @@ public ActiveProcessViewDto getCurrentlyActiveProcessView(@Context UriInfo uriIn
@POST
@Path("{engineName}/process-instance/{processInstanceId}/change-view")
public Response switchToNextProcessView(@Context UriInfo uriInfo, @PathParam("engineName") String engineName,
@PathParam("processInstanceId") String processInstanceId) throws IOException {
// workaround to access the Camunda REST API, as the Java API does not provide all required details
@PathParam("processInstanceId") String processInstanceId) throws IOException {
// workaround to access the Camunda REST API, as the Java API does not provide
// all required details
String baseUrl = "http://" + uriInfo.getAbsolutePath().getHost() + ":" + uriInfo.getAbsolutePath().getPort();
System.out.println("Received request for host and port: " + baseUrl);

Expand All @@ -90,10 +94,12 @@ public Response switchToNextProcessView(@Context UriInfo uriInfo, @PathParam("en
RuntimeService runtimeService = processEngine.getRuntimeService();

// get variable storing the active process view
Object activeProcessViewVariable = runtimeService.getVariable(processInstanceId, "process-view-extension-active-view");
if (Objects.isNull(activeProcessViewVariable)){
Object activeProcessViewVariable = runtimeService.getVariable(processInstanceId,
"process-view-extension-active-view");
if (Objects.isNull(activeProcessViewVariable)) {
return Response.status(404).build();
}

String activeProcessView = activeProcessViewVariable.toString();

// get name of next view
Expand All @@ -104,13 +110,49 @@ public Response switchToNextProcessView(@Context UriInfo uriInfo, @PathParam("en
return Response.ok().build();
}

@POST
@Path("{engineName}/process-instance/{processInstanceId}/view/{viewName}")
public Response getSpecifiedProcessView(@Context UriInfo uriInfo, @PathParam("engineName") String engineName,
@PathParam("processInstanceId") String processInstanceId, @PathParam("viewName") String viewName)
throws IOException {

// workaround to access the Camunda REST API, as the Java API does not provide
// all required details
String baseUrl = "http://" + uriInfo.getAbsolutePath().getHost() + ":" + uriInfo.getAbsolutePath().getPort();
System.out.println("Received request for host and port for specific view: " + baseUrl);

// get runtime service to access variables of process instances
ProcessEngine processEngine = ProcessEngines.getProcessEngine(engineName);
RuntimeService runtimeService = processEngine.getRuntimeService();

// get variable storing the active process view
ProcessViewService processViewService = new ProcessViewService();
Object activeProcessViewVariable = runtimeService.getVariable(processInstanceId,
"process-view-extension-active-view");
String activeProcessView;
if (Objects.isNull(activeProcessViewVariable)) {
System.out.println("Adding default value as active process view is currently not set!");

// set original workflow as initial view if not yet set
activeProcessView = processViewService.findInitialViewName(processInstanceId, baseUrl);
runtimeService.setVariable(processInstanceId, "process-view-extension-active-view", activeProcessView);
} else {
activeProcessView = activeProcessViewVariable.toString();
}
String newProcessView = processViewService.getProcessView(processInstanceId, activeProcessView, viewName, baseUrl);
runtimeService.setVariable(processInstanceId, "process-view-extension-active-view", newProcessView);
System.out.println("New active process view has name: " + newProcessView);
return Response.ok().build();
}

@POST
@Path("{engineName}/process-instance/{processInstanceId}/change-view/{viewId}")
public Response switchToProcessView(@Context UriInfo uriInfo, @PathParam("engineName") String engineName,
@PathParam("processInstanceId") String processInstanceId,
@PathParam("viewId") String viewId) throws IOException {

// workaround to access the Camunda REST API, as the Java API does not provide all required details
@PathParam("processInstanceId") String processInstanceId,
@PathParam("viewId") String viewId) throws IOException {

// workaround to access the Camunda REST API, as the Java API does not provide
// all required details
String baseUrl = "http://" + uriInfo.getAbsolutePath().getHost() + ":" + uriInfo.getAbsolutePath().getPort();
System.out.println("Received request for host and port: " + baseUrl);

Expand All @@ -119,8 +161,9 @@ public Response switchToProcessView(@Context UriInfo uriInfo, @PathParam("engine
RuntimeService runtimeService = processEngine.getRuntimeService();

// get variable storing the active process view
Object activeProcessViewVariable = runtimeService.getVariable(processInstanceId, "process-view-extension-active-view");
if (Objects.isNull(activeProcessViewVariable)){
Object activeProcessViewVariable = runtimeService.getVariable(processInstanceId,
"process-view-extension-active-view");
if (Objects.isNull(activeProcessViewVariable)) {
return Response.status(404).build();
}
String activeProcessView = activeProcessViewVariable.toString();
Expand Down
Loading

0 comments on commit a629b33

Please sign in to comment.