diff --git a/engine-rest/engine-rest/src/main/java/org/camunda/bpm/engine/rest/history/HistoricProcessInstanceRestService.java b/engine-rest/engine-rest/src/main/java/org/camunda/bpm/engine/rest/history/HistoricProcessInstanceRestService.java index 128b041746f..f4128066484 100644 --- a/engine-rest/engine-rest/src/main/java/org/camunda/bpm/engine/rest/history/HistoricProcessInstanceRestService.java +++ b/engine-rest/engine-rest/src/main/java/org/camunda/bpm/engine/rest/history/HistoricProcessInstanceRestService.java @@ -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. @@ -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; @@ -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; @@ -92,4 +95,8 @@ List 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); } diff --git a/engine-rest/engine-rest/src/main/java/org/camunda/bpm/engine/rest/impl/history/HistoricProcessInstanceRestServiceImpl.java b/engine-rest/engine-rest/src/main/java/org/camunda/bpm/engine/rest/impl/history/HistoricProcessInstanceRestServiceImpl.java index 21c48c784ce..50a9a64787c 100644 --- a/engine-rest/engine-rest/src/main/java/org/camunda/bpm/engine/rest/impl/history/HistoricProcessInstanceRestServiceImpl.java +++ b/engine-rest/engine-rest/src/main/java/org/camunda/bpm/engine/rest/impl/history/HistoricProcessInstanceRestServiceImpl.java @@ -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; @@ -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(); + } } diff --git a/engine-rest/engine-rest/src/test/java/org/camunda/bpm/engine/rest/history/HistoricProcessInstanceRestServiceInteractionTest.java b/engine-rest/engine-rest/src/test/java/org/camunda/bpm/engine/rest/history/HistoricProcessInstanceRestServiceInteractionTest.java index 0c9c832924e..910ed1c970e 100644 --- a/engine-rest/engine-rest/src/test/java/org/camunda/bpm/engine/rest/history/HistoricProcessInstanceRestServiceInteractionTest.java +++ b/engine-rest/engine-rest/src/test/java/org/camunda/bpm/engine/rest/history/HistoricProcessInstanceRestServiceInteractionTest.java @@ -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. @@ -22,9 +22,10 @@ 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; @@ -32,7 +33,6 @@ 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; @@ -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; @@ -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; @@ -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); diff --git a/engine/src/main/java/org/camunda/bpm/engine/impl/cmd/DeleteHistoricVariableInstancesByProcessInstanceIdCmd.java b/engine/src/main/java/org/camunda/bpm/engine/impl/cmd/DeleteHistoricVariableInstancesByProcessInstanceIdCmd.java index b2579bb3a3d..ffa136d822b 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/impl/cmd/DeleteHistoricVariableInstancesByProcessInstanceIdCmd.java +++ b/engine/src/main/java/org/camunda/bpm/engine/impl/cmd/DeleteHistoricVariableInstancesByProcessInstanceIdCmd.java @@ -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; @@ -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);