generated from hmcts/spring-boot-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADOP-2566: Set up migratecase event for migration tool (#958)
* ADOP-2566: Set up migratecase event for migration tool * remove unused object * Fix checkstyle * Update MigrateCase.java * name migration * update function generics * refactor duplicate code, move caseworker event tests into the right package * Add migrate-case tests, refactor some unnecessary constants * ADOP-2566: Update tests, remove ADOP-test migration * rename func * test migration demo * Revert test migration --------- Co-authored-by: Daniel Catchpole <daniel.catchpole@justice.gov.uk>
- Loading branch information
1 parent
cc8a7be
commit fb45491
Showing
24 changed files
with
381 additions
and
797 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
src/main/java/uk/gov/hmcts/reform/adoption/adoptioncase/event/MigrateCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package uk.gov.hmcts.reform.adoption.adoptioncase.event; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
import uk.gov.hmcts.ccd.sdk.api.CCDConfig; | ||
import uk.gov.hmcts.ccd.sdk.api.CaseDetails; | ||
import uk.gov.hmcts.ccd.sdk.api.ConfigBuilder; | ||
import uk.gov.hmcts.ccd.sdk.api.callback.AboutToStartOrSubmitResponse; | ||
import uk.gov.hmcts.reform.adoption.adoptioncase.model.CaseData; | ||
import uk.gov.hmcts.reform.adoption.adoptioncase.model.State; | ||
import uk.gov.hmcts.reform.adoption.adoptioncase.model.UserRole; | ||
|
||
import java.util.Map; | ||
import java.util.function.Consumer; | ||
|
||
import static uk.gov.hmcts.reform.adoption.adoptioncase.model.State.AwaitingPayment; | ||
import static uk.gov.hmcts.reform.adoption.adoptioncase.model.State.Draft; | ||
import static uk.gov.hmcts.reform.adoption.adoptioncase.model.State.LaSubmitted; | ||
import static uk.gov.hmcts.reform.adoption.adoptioncase.model.State.Submitted; | ||
import static uk.gov.hmcts.reform.adoption.adoptioncase.model.UserRole.SYSTEM_UPDATE; | ||
import static uk.gov.hmcts.reform.adoption.adoptioncase.model.access.Permissions.CREATE_READ_UPDATE_DELETE; | ||
|
||
@Slf4j | ||
@Component | ||
public class MigrateCase implements CCDConfig<CaseData, State, UserRole> { | ||
|
||
public static final String MIGRATE_CASE = "migrate-case"; | ||
|
||
// Note - keep "ADOP-log", it is useful for triggering an "event" without updating data | ||
private final Map<String, Consumer<CaseDetails<CaseData, State>>> migrations = Map.of( | ||
"ADOP-log", this::runLog | ||
); | ||
|
||
@Override | ||
public void configure(final ConfigBuilder<CaseData, State, UserRole> configBuilder) { | ||
|
||
configBuilder | ||
.event(MIGRATE_CASE) | ||
.forStates(Draft, AwaitingPayment, Submitted, LaSubmitted) | ||
.name("Migrate case") | ||
.description("Migrate case") | ||
.retries(120, 120) | ||
.grant(CREATE_READ_UPDATE_DELETE, SYSTEM_UPDATE) | ||
.aboutToSubmitCallback(this::aboutToSubmit); | ||
} | ||
|
||
public AboutToStartOrSubmitResponse<CaseData, State> aboutToSubmit(CaseDetails<CaseData, State> details, | ||
CaseDetails<CaseData, State> beforeDetails) { | ||
CaseData data = details.getData(); | ||
String migrationId = data.getMigrationId(); | ||
Long id = details.getId(); | ||
|
||
log.info("Migration {id = {}, case reference = {}} started", migrationId, id); | ||
|
||
if (!migrations.containsKey(migrationId)) { | ||
throw new RuntimeException("No migration mapped to " + migrationId); | ||
} | ||
|
||
migrations.get(migrationId).accept(details); | ||
|
||
log.info("Migration {id = {}, case reference = {}} finished", migrationId, id); | ||
|
||
State state = details.getState(); | ||
|
||
data.setMigrationId(null); | ||
return AboutToStartOrSubmitResponse.<CaseData, State>builder() | ||
.data(data) | ||
.state(state) | ||
.build(); | ||
} | ||
|
||
private void runLog(CaseDetails<CaseData, State> caseDetails) { | ||
log.info("Logging migration on case {}", caseDetails.getId()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...n/java/uk/gov/hmcts/reform/adoption/adoptioncase/model/access/SystemUpdateOnlyAccess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package uk.gov.hmcts.reform.adoption.adoptioncase.model.access; | ||
|
||
import com.google.common.collect.HashMultimap; | ||
import com.google.common.collect.SetMultimap; | ||
import uk.gov.hmcts.ccd.sdk.api.HasAccessControl; | ||
import uk.gov.hmcts.ccd.sdk.api.HasRole; | ||
import uk.gov.hmcts.ccd.sdk.api.Permission; | ||
|
||
import static uk.gov.hmcts.reform.adoption.adoptioncase.model.UserRole.SYSTEM_UPDATE; | ||
|
||
public class SystemUpdateOnlyAccess implements HasAccessControl { | ||
@Override | ||
public SetMultimap<HasRole, Permission> getGrants() { | ||
SetMultimap<HasRole, Permission> grants = HashMultimap.create(); | ||
grants.putAll(SYSTEM_UPDATE, Permissions.CREATE_READ_UPDATE_DELETE); | ||
|
||
return grants; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.