Skip to content

Commit

Permalink
fest(engine-rest): add method to delete all historic variables
Browse files Browse the repository at this point in the history
- add method for historic process instances

related to CAM-9647
  • Loading branch information
tmetzke committed Jan 21, 2019
1 parent e9c5204 commit a9092f5
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2013-2018 camunda services GmbH and various authors (info@camunda.com)
* Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,10 @@
*/
package org.camunda.bpm.engine.rest.history;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
Expand All @@ -27,7 +30,7 @@
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.util.List;

import org.camunda.bpm.engine.history.HistoricProcessInstanceQuery;
import org.camunda.bpm.engine.rest.dto.CountResultDto;
import org.camunda.bpm.engine.rest.dto.batch.BatchDto;
Expand Down Expand Up @@ -92,4 +95,8 @@ List<HistoricProcessInstanceDto> queryHistoricProcessInstances(HistoricProcessIn
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
BatchDto deleteAsync(DeleteHistoricProcessInstancesDto dto);

@DELETE
@Path("/{id}/variable-instances")
Response deleteHistoricVariableInstancesByProcessInstanceId(@PathParam("id") String processInstanceId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.camunda.bpm.engine.HistoryService;
import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.batch.Batch;
import org.camunda.bpm.engine.exception.NotFoundException;
import org.camunda.bpm.engine.history.HistoricProcessInstance;
import org.camunda.bpm.engine.history.HistoricProcessInstanceQuery;
import org.camunda.bpm.engine.history.ReportResult;
Expand Down Expand Up @@ -182,4 +183,15 @@ protected String getReportResultAsCsv(UriInfo uriInfo) {
String reportType = queryParameters.getFirst("reportType");
return ReportResultToCsvConverter.convertReportResult(reports, reportType);
}

@Override
public Response deleteHistoricVariableInstancesByProcessInstanceId(String processInstanceId) {
try {
processEngine.getHistoryService().deleteHistoricVariableInstancesByProcessInstanceId(processInstanceId);
} catch (NotFoundException nfe) { // rewrite status code from bad request (400) to not found (404)
throw new InvalidRequestException(Status.NOT_FOUND, nfe.getMessage());
}
// return no content (204) since resource is deleted
return Response.noContent().build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2013-2018 camunda services GmbH and various authors (info@camunda.com)
* Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,17 +22,17 @@
import org.camunda.bpm.engine.HistoryService;
import org.camunda.bpm.engine.ProcessEngineException;
import org.camunda.bpm.engine.batch.Batch;
import org.camunda.bpm.engine.exception.NotFoundException;
import org.camunda.bpm.engine.history.HistoricProcessInstance;
import org.camunda.bpm.engine.history.HistoricProcessInstanceQuery;
import org.camunda.bpm.engine.impl.batch.BatchEntity;
import org.camunda.bpm.engine.history.HistoricVariableInstance;
import org.camunda.bpm.engine.rest.AbstractRestServiceTest;
import org.camunda.bpm.engine.rest.dto.batch.BatchDto;
import org.camunda.bpm.engine.rest.dto.history.HistoricProcessInstanceQueryDto;
import org.camunda.bpm.engine.rest.exception.InvalidRequestException;
import org.camunda.bpm.engine.rest.helper.MockProvider;
import org.camunda.bpm.engine.rest.util.JsonPathUtil;
import org.camunda.bpm.engine.rest.util.container.TestContainerRule;
import org.camunda.bpm.engine.runtime.ProcessInstanceQuery;
import org.junit.Assert;
import org.junit.Before;
import org.junit.ClassRule;
Expand All @@ -47,6 +47,7 @@

import static io.restassured.RestAssured.given;
import static io.restassured.path.json.JsonPath.from;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand All @@ -70,6 +71,7 @@ public class HistoricProcessInstanceRestServiceInteractionTest extends AbstractR
protected static final String HISTORIC_PROCESS_INSTANCE_URL = TEST_RESOURCE_ROOT_PATH + "/history/process-instance";
protected static final String HISTORIC_SINGLE_PROCESS_INSTANCE_URL = HISTORIC_PROCESS_INSTANCE_URL + "/{id}";
protected static final String DELETE_HISTORIC_PROCESS_INSTANCES_ASYNC_URL = HISTORIC_PROCESS_INSTANCE_URL + "/delete";
protected static final String HISTORIC_SINGLE_PROCESS_INSTANCE_VARIABLES_URL = HISTORIC_PROCESS_INSTANCE_URL + "/{id}/variable-instances";

private HistoryService historyServiceMock;

Expand Down Expand Up @@ -248,6 +250,34 @@ public void testDeleteAsyncWithBadRequestQuery() {
.statusCode(Status.BAD_REQUEST.getStatusCode())
.when().post(DELETE_HISTORIC_PROCESS_INSTANCES_ASYNC_URL);
}

@Test
public void testDeleteAllVariablesByProcessInstanceId() {
HistoricVariableInstance variableInstanceMock = MockProvider.mockHistoricVariableInstance().build();

given()
.pathParam("id", variableInstanceMock.getId())
.expect()
.statusCode(Status.NO_CONTENT.getStatusCode())
.when()
.delete(HISTORIC_SINGLE_PROCESS_INSTANCE_VARIABLES_URL);

verify(historyServiceMock).deleteHistoricVariableInstancesByProcessInstanceId(variableInstanceMock.getId());
}

@Test
public void testDeleteAllVariablesForNonExistingProcessInstance() {
doThrow(new NotFoundException("No historic process instance found with id: 'NON_EXISTING_ID'"))
.when(historyServiceMock).deleteHistoricVariableInstancesByProcessInstanceId("NON_EXISTING_ID");

given()
.pathParam("id", "NON_EXISTING_ID")
.expect()
.statusCode(Status.NOT_FOUND.getStatusCode())
.body(containsString("No historic process instance found with id: 'NON_EXISTING_ID'"))
.when()
.delete(HISTORIC_SINGLE_PROCESS_INSTANCE_VARIABLES_URL);
}

protected void verifyBatchJson(String batchJson) {
BatchDto batch = JsonPathUtil.from(batchJson).getObject("", BatchDto.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Arrays;

import org.camunda.bpm.engine.BadUserRequestException;
import org.camunda.bpm.engine.exception.NotFoundException;
import org.camunda.bpm.engine.impl.cfg.CommandChecker;
import org.camunda.bpm.engine.impl.interceptor.Command;
import org.camunda.bpm.engine.impl.interceptor.CommandContext;
Expand All @@ -44,7 +45,7 @@ public Void execute(CommandContext commandContext) {
ensureNotEmpty(BadUserRequestException.class,"processInstanceId", processInstanceId);

HistoricProcessInstanceEntity instance = commandContext.getHistoricProcessInstanceManager().findHistoricProcessInstance(processInstanceId);
ensureNotNull("No historic process instance found with id: " + processInstanceId, "instance", instance);
ensureNotNull(NotFoundException.class, "No historic process instance found with id: " + processInstanceId, "instance", instance);

for(CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
checker.checkDeleteHistoricVariableInstancesByProcessInstance(instance);
Expand Down

0 comments on commit a9092f5

Please sign in to comment.