Skip to content

Commit

Permalink
Add case instance migration to REST API
Browse files Browse the repository at this point in the history
  • Loading branch information
tijsrademakers committed Aug 24, 2023
1 parent 37ecb61 commit 135a859
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,11 @@ public interface CmmnRestApiInterceptor {

void migrateCaseInstance(String caseInstanceId, String migrationDocumentJson);

void migrateHistoricCaseInstance(String caseInstanceId, String migrationDocumentJson);

void migrateInstancesOfCaseDefinition(CaseDefinition caseDefinition, String migrationDocument);

void migrateHistoricInstancesOfCaseDefinition(CaseDefinition caseDefinition, String migrationDocument);

void changePlanItemState(String caseInstanceId, ChangePlanItemStateRequest planItemStateRequest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,24 @@
import java.util.Optional;

import org.flowable.cmmn.api.CmmnHistoryService;
import org.flowable.cmmn.api.CmmnMigrationService;
import org.flowable.cmmn.api.CmmnRepositoryService;
import org.flowable.cmmn.api.CmmnRuntimeService;
import org.flowable.cmmn.api.StageResponse;
import org.flowable.cmmn.api.history.HistoricCaseInstance;
import org.flowable.cmmn.api.history.HistoricPlanItemInstance;
import org.flowable.cmmn.api.migration.HistoricCaseInstanceMigrationDocument;
import org.flowable.cmmn.api.repository.CaseDefinition;
import org.flowable.cmmn.engine.impl.migration.HistoricCaseInstanceMigrationDocumentConverter;
import org.flowable.cmmn.model.Stage;
import org.flowable.cmmn.rest.service.api.CmmnRestResponseFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

Expand Down Expand Up @@ -60,6 +65,9 @@ public class HistoricCaseInstanceResource extends HistoricCaseInstanceBaseResour

@Autowired
protected CmmnRuntimeService cmmnRuntimeService;

@Autowired
protected CmmnMigrationService cmmnMigrationService;

@ApiOperation(value = "Get a historic case instance", tags = { "History Case" }, nickname = "getHistoricCaseInstance")
@ApiResponses(value = {
Expand Down Expand Up @@ -93,13 +101,34 @@ public void deleteCaseInstance(@ApiParam(name = "caseInstanceId") @PathVariable
cmmnhistoryService.deleteHistoricCaseInstance(caseInstance.getId());
}

@ApiOperation(value = "Get a stage overview of historic case instance", tags = { "History Case" }, nickname = "getHistoricStageOverview", code = 204)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Indicates that the historic case instance was found."),
@ApiResponse(code = 404, message = "Indicates that the historic case instance could not be found.") })
@GetMapping(value = "/cmmn-history/historic-case-instances/{caseInstanceId}/stage-overview", produces = "application/json")
public List<StageResponse> getStageOverview(@ApiParam(name = "caseInstanceId") @PathVariable String caseInstanceId) {
HistoricCaseInstance caseInstance = getHistoricCaseInstanceFromRequest(caseInstanceId);

return cmmnhistoryService.getStageOverview(caseInstance.getId());
}

@ApiOperation(value = "Migrate historic case instance", tags = { "History Case" }, nickname = "migrateHistoricCaseInstance")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Indicates the historiccase instance was found and migration was executed."),
@ApiResponse(code = 404, message = "Indicates the requested historic case instance was not found.")
})
@PostMapping(value = "/cmmn-history/historic-case-instances/{caseInstanceId}/migrate", produces = "application/json")
public void migrateHistoricCaseInstance(@ApiParam(name = "caseInstanceId") @PathVariable String caseInstanceId,
@RequestBody String migrationDocumentJson) {

if (restApiInterceptor != null) {
restApiInterceptor.migrateHistoricCaseInstance(caseInstanceId, migrationDocumentJson);
}

HistoricCaseInstanceMigrationDocument migrationDocument = HistoricCaseInstanceMigrationDocumentConverter.convertFromJson(migrationDocumentJson);
cmmnMigrationService.migrateHistoricCaseInstance(caseInstanceId, migrationDocument);
}

protected Date getPlanItemInstanceEndTime(List<HistoricPlanItemInstance> stagePlanItemInstances, Stage stage) {
return getPlanItemInstance(stagePlanItemInstances, stage)
.map(HistoricPlanItemInstance::getEndedTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@
package org.flowable.cmmn.rest.service.api.repository;

import org.apache.commons.lang3.StringUtils;
import org.flowable.cmmn.api.CmmnMigrationService;
import org.flowable.cmmn.api.migration.CaseInstanceMigrationDocument;
import org.flowable.cmmn.api.migration.HistoricCaseInstanceMigrationDocument;
import org.flowable.cmmn.api.repository.CaseDefinition;
import org.flowable.cmmn.api.repository.CmmnDeployment;
import org.flowable.cmmn.engine.CmmnEngineConfiguration;
import org.flowable.cmmn.engine.impl.migration.CaseInstanceMigrationDocumentConverter;
import org.flowable.cmmn.engine.impl.migration.HistoricCaseInstanceMigrationDocumentConverter;
import org.flowable.cmmn.model.Case;
import org.flowable.cmmn.model.CmmnModel;
import org.flowable.cmmn.model.Stage;
Expand All @@ -32,6 +37,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -53,6 +59,9 @@ public class CaseDefinitionResource extends BaseCaseDefinitionResource {
@Autowired
protected CmmnEngineConfiguration cmmnEngineConfiguration;

@Autowired
protected CmmnMigrationService cmmnMigrationService;

@Autowired(required=false)
protected CmmnFormHandlerRestApiInterceptor formHandlerRestApiInterceptor;

Expand Down Expand Up @@ -126,6 +135,82 @@ public String getProcessDefinitionStartForm(@ApiParam(name = "caseDefinitionId")
}
}

@ApiOperation(value = "Migrate all instances of case definition", tags = { "Case Definitions" }, notes = "")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Indicates case instances were found and migration was executed."),
@ApiResponse(code = 404, message = "Indicates the requested case definition was not found.")
})
@PostMapping(value = "/cmmn-repository/case-definitions/{caseDefinitionId}/migrate", produces = "application/json")
public void migrateInstancesOfCaseDefinition(@ApiParam(name = "caseDefinitionId") @PathVariable String caseDefinitionId,
@RequestBody String migrationDocumentJson) {

CaseDefinition caseDefinition = getCaseDefinitionFromRequestWithoutAccessCheck(caseDefinitionId);

if (restApiInterceptor != null) {
restApiInterceptor.migrateInstancesOfCaseDefinition(caseDefinition, migrationDocumentJson);
}

CaseInstanceMigrationDocument migrationDocument = CaseInstanceMigrationDocumentConverter.convertFromJson(migrationDocumentJson);
cmmnMigrationService.migrateCaseInstancesOfCaseDefinition(caseDefinitionId, migrationDocument);
}

@ApiOperation(value = "Migrate all historic case instances of case definition", tags = { "Case Definitions" }, notes = "")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Indicates historic case instances were found and migration was executed."),
@ApiResponse(code = 404, message = "Indicates the requested case definition was not found.")
})
@PostMapping(value = "/cmmn-repository/case-definitions/{caseDefinitionId}/migrate-historic-instances", produces = "application/json")
public void migrateHistoricInstancesOfCaseDefinition(@ApiParam(name = "caseDefinitionId") @PathVariable String caseDefinitionId,
@RequestBody String migrationDocumentJson) {

CaseDefinition caseDefinition = getCaseDefinitionFromRequestWithoutAccessCheck(caseDefinitionId);

if (restApiInterceptor != null) {
restApiInterceptor.migrateHistoricInstancesOfCaseDefinition(caseDefinition, migrationDocumentJson);
}

HistoricCaseInstanceMigrationDocument migrationDocument = HistoricCaseInstanceMigrationDocumentConverter.convertFromJson(migrationDocumentJson);
cmmnMigrationService.migrateHistoricCaseInstancesOfCaseDefinition(caseDefinitionId, migrationDocument);
}

@ApiOperation(value = "Batch migrate all instances of case definition", tags = { "Case Definitions" }, notes = "")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Indicates case instances were found and batch migration was started."),
@ApiResponse(code = 404, message = "Indicates the requested case definition was not found.")
})
@PostMapping(value = "/cmmn-repository/case-definitions/{caseDefinitionId}/batch-migrate", produces = "application/json")
public void batchMigrateInstancesOfCaseDefinition(@ApiParam(name = "caseDefinitionId") @PathVariable String caseDefinitionId,
@RequestBody String migrationDocumentJson) {

CaseDefinition caseDefinition = getCaseDefinitionFromRequestWithoutAccessCheck(caseDefinitionId);

if (restApiInterceptor != null) {
restApiInterceptor.migrateInstancesOfCaseDefinition(caseDefinition, migrationDocumentJson);
}

CaseInstanceMigrationDocument migrationDocument = CaseInstanceMigrationDocumentConverter.convertFromJson(migrationDocumentJson);
cmmnMigrationService.batchMigrateCaseInstancesOfCaseDefinition(caseDefinitionId, migrationDocument);
}

@ApiOperation(value = "Batch migrate all historic instances of case definition", tags = { "Case Definitions" }, notes = "")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Indicates historic case instances were found and batch migration was started."),
@ApiResponse(code = 404, message = "Indicates the requested case definition was not found.")
})
@PostMapping(value = "/cmmn-repository/case-definitions/{caseDefinitionId}/batch-migrate-historic-instances", produces = "application/json")
public void batchMigrateHistoricInstancesOfCaseDefinition(@ApiParam(name = "caseDefinitionId") @PathVariable String caseDefinitionId,
@RequestBody String migrationDocumentJson) {

CaseDefinition caseDefinition = getCaseDefinitionFromRequestWithoutAccessCheck(caseDefinitionId);

if (restApiInterceptor != null) {
restApiInterceptor.migrateHistoricInstancesOfCaseDefinition(caseDefinition, migrationDocumentJson);
}

HistoricCaseInstanceMigrationDocument migrationDocument = HistoricCaseInstanceMigrationDocumentConverter.convertFromJson(migrationDocumentJson);
cmmnMigrationService.batchMigrateHistoricCaseInstancesOfCaseDefinition(caseDefinitionId, migrationDocument);
}

protected FormInfo getStartForm(FormRepositoryService formRepositoryService, CaseDefinition caseDefinition) {
FormInfo formInfo = null;
CmmnModel cmmnModel = repositoryService.getCmmnModel(caseDefinition.getId());
Expand Down

0 comments on commit 135a859

Please sign in to comment.