Skip to content

Commit

Permalink
DTSSTCI-946 Add Publish to Camunda Flag for System Events (#1887)
Browse files Browse the repository at this point in the history
* [DTSSTCI-946] Update hyperlink for next steps of completeHearingOutcome task

* [DTSSTCI-946] Add publishToCamunda flags for system events to create tasks
  • Loading branch information
oleon23 authored Aug 29, 2024
1 parent c4e559e commit f864b85
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
package uk.gov.hmcts.sptribs.systemupdate.event;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.ccd.sdk.api.CCDConfig;
import uk.gov.hmcts.ccd.sdk.api.ConfigBuilder;
import uk.gov.hmcts.ccd.sdk.api.Event;
import uk.gov.hmcts.sptribs.ciccase.model.CaseData;
import uk.gov.hmcts.sptribs.ciccase.model.State;
import uk.gov.hmcts.sptribs.ciccase.model.UserRole;

import static uk.gov.hmcts.sptribs.ciccase.model.State.AwaitingHearing;
import static uk.gov.hmcts.sptribs.ciccase.model.UserRole.ST_CIC_WA_CONFIG_USER;
import static uk.gov.hmcts.sptribs.ciccase.model.UserRole.SYSTEM_UPDATE;
import static uk.gov.hmcts.sptribs.ciccase.model.access.Permissions.CREATE_READ_UPDATE;
import static uk.gov.hmcts.sptribs.ciccase.model.access.Permissions.CREATE_READ_UPDATE_DELETE;

@Component
public class SystemTriggerCompleteHearingOutcome implements CCDConfig<CaseData, State, UserRole> {

public static final String SYSTEM_TRIGGER_COMPLETE_HEARING_OUTCOME = "system-trigger-complete-hearing-outcome";

@Value("${feature.wa.enabled}")
private boolean isWorkAllocationEnabled;

@Override
public void configure(ConfigBuilder<CaseData, State, UserRole> configBuilder) {
configBuilder
Event.EventBuilder<CaseData, UserRole, State> eventBuilder = configBuilder
.event(SYSTEM_TRIGGER_COMPLETE_HEARING_OUTCOME)
.forState(AwaitingHearing)
.name("Trigger hearing outcome")
.description("Trigger hearing outcome")
.grant(CREATE_READ_UPDATE_DELETE, SYSTEM_UPDATE);

if (isWorkAllocationEnabled) {
eventBuilder.publishToCamunda()
.grant(CREATE_READ_UPDATE, ST_CIC_WA_CONFIG_USER);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@
package uk.gov.hmcts.sptribs.systemupdate.event;

import org.springframework.beans.factory.annotation.Value;
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.Event;
import uk.gov.hmcts.ccd.sdk.api.callback.AboutToStartOrSubmitResponse;
import uk.gov.hmcts.sptribs.ciccase.model.CaseData;
import uk.gov.hmcts.sptribs.ciccase.model.State;
import uk.gov.hmcts.sptribs.ciccase.model.UserRole;

import static uk.gov.hmcts.sptribs.caseworker.model.YesNo.YES;
import static uk.gov.hmcts.sptribs.ciccase.model.State.AwaitingHearing;
import static uk.gov.hmcts.sptribs.ciccase.model.UserRole.ST_CIC_WA_CONFIG_USER;
import static uk.gov.hmcts.sptribs.ciccase.model.UserRole.SYSTEM_UPDATE;
import static uk.gov.hmcts.sptribs.ciccase.model.access.Permissions.CREATE_READ_UPDATE;
import static uk.gov.hmcts.sptribs.ciccase.model.access.Permissions.CREATE_READ_UPDATE_DELETE;

@Component
public class SystemTriggerStitchCollateHearingBundle implements CCDConfig<CaseData, State, UserRole> {
public static final String SYSTEM_TRIGGER_STITCH_COLLATE_HEARING_BUNDLE = "system-trigger-stitch-collate-hearing-bundle";

@Value("${feature.wa.enabled}")
private boolean isWorkAllocationEnabled;

@Override
public void configure(final ConfigBuilder<CaseData, State, UserRole> configBuilder) {
configBuilder
Event.EventBuilder<CaseData, UserRole, State> eventBuilder = configBuilder
.event(SYSTEM_TRIGGER_STITCH_COLLATE_HEARING_BUNDLE)
.forState(AwaitingHearing)
.name("Trigger stitch hearing bundle")
.description("Trigger stitch hearing bundle")
.aboutToSubmitCallback(this::aboutToSubmit)
.grant(CREATE_READ_UPDATE_DELETE, SYSTEM_UPDATE);

if (isWorkAllocationEnabled) {
eventBuilder.publishToCamunda()
.grant(CREATE_READ_UPDATE, ST_CIC_WA_CONFIG_USER);
}
}

public AboutToStartOrSubmitResponse<CaseData, State> aboutToSubmit(final CaseDetails<CaseData, State> details,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import uk.gov.hmcts.ccd.sdk.ConfigBuilderImpl;
import uk.gov.hmcts.ccd.sdk.api.Event;
import uk.gov.hmcts.sptribs.ciccase.model.CaseData;
import uk.gov.hmcts.sptribs.ciccase.model.State;
import uk.gov.hmcts.sptribs.ciccase.model.UserRole;
import uk.gov.hmcts.sptribs.ciccase.model.access.Permissions;

import static org.assertj.core.api.Assertions.assertThat;
import static uk.gov.hmcts.sptribs.ciccase.model.UserRole.ST_CIC_WA_CONFIG_USER;
import static uk.gov.hmcts.sptribs.systemupdate.event.SystemTriggerCompleteHearingOutcome.SYSTEM_TRIGGER_COMPLETE_HEARING_OUTCOME;
import static uk.gov.hmcts.sptribs.testutil.ConfigTestUtil.createCaseDataConfigBuilder;
import static uk.gov.hmcts.sptribs.testutil.ConfigTestUtil.getEventsFrom;
Expand All @@ -30,5 +33,37 @@ void shouldAddConfigurationToConfigBuilder() {
assertThat(getEventsFrom(configBuilder).values())
.extracting(Event::getId)
.contains(SYSTEM_TRIGGER_COMPLETE_HEARING_OUTCOME);

assertThat(getEventsFrom(configBuilder).values())
.extracting(Event::isPublishToCamunda)
.contains(false);

assertThat(getEventsFrom(configBuilder).values())
.extracting(Event::getGrants)
.extracting(map -> map.containsKey(ST_CIC_WA_CONFIG_USER))
.contains(false);
}

@Test
void shouldAddPublishToCamundaWhenWAIsEnabled() {
ReflectionTestUtils.setField(systemTriggerCompleteHearingOutcome, "isWorkAllocationEnabled", true);

final ConfigBuilderImpl<CaseData, State, UserRole> configBuilder = createCaseDataConfigBuilder();

systemTriggerCompleteHearingOutcome.configure(configBuilder);

assertThat(getEventsFrom(configBuilder).values())
.extracting(Event::isPublishToCamunda)
.contains(true);

assertThat(getEventsFrom(configBuilder).values())
.extracting(Event::getGrants)
.extracting(map -> map.containsKey(ST_CIC_WA_CONFIG_USER))
.contains(true);

assertThat(getEventsFrom(configBuilder).values())
.extracting(Event::getGrants)
.extracting(map -> map.get(ST_CIC_WA_CONFIG_USER))
.contains(Permissions.CREATE_READ_UPDATE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import uk.gov.hmcts.ccd.sdk.ConfigBuilderImpl;
import uk.gov.hmcts.ccd.sdk.api.CaseDetails;
import uk.gov.hmcts.ccd.sdk.api.Event;
import uk.gov.hmcts.ccd.sdk.api.callback.AboutToStartOrSubmitResponse;
import uk.gov.hmcts.sptribs.ciccase.model.CaseData;
import uk.gov.hmcts.sptribs.ciccase.model.State;
import uk.gov.hmcts.sptribs.ciccase.model.UserRole;
import uk.gov.hmcts.sptribs.ciccase.model.access.Permissions;

import static org.assertj.core.api.Assertions.assertThat;
import static uk.gov.hmcts.sptribs.caseworker.model.YesNo.YES;
import static uk.gov.hmcts.sptribs.ciccase.model.UserRole.ST_CIC_WA_CONFIG_USER;
import static uk.gov.hmcts.sptribs.systemupdate.event.SystemTriggerStitchCollateHearingBundle.SYSTEM_TRIGGER_STITCH_COLLATE_HEARING_BUNDLE;
import static uk.gov.hmcts.sptribs.testutil.ConfigTestUtil.createCaseDataConfigBuilder;
import static uk.gov.hmcts.sptribs.testutil.ConfigTestUtil.getEventsFrom;
Expand All @@ -33,6 +36,38 @@ void shouldAddConfigurationToConfigBuilder() {
assertThat(getEventsFrom(configBuilder).values())
.extracting(Event::getId)
.contains(SYSTEM_TRIGGER_STITCH_COLLATE_HEARING_BUNDLE);

assertThat(getEventsFrom(configBuilder).values())
.extracting(Event::isPublishToCamunda)
.contains(false);

assertThat(getEventsFrom(configBuilder).values())
.extracting(Event::getGrants)
.extracting(map -> map.containsKey(ST_CIC_WA_CONFIG_USER))
.contains(false);
}

@Test
void shouldAddPublishToCamundaWhenWAIsEnabled() {
ReflectionTestUtils.setField(systemTriggerStitchCollateHearingBundle, "isWorkAllocationEnabled", true);

final ConfigBuilderImpl<CaseData, State, UserRole> configBuilder = createCaseDataConfigBuilder();

systemTriggerStitchCollateHearingBundle.configure(configBuilder);

assertThat(getEventsFrom(configBuilder).values())
.extracting(Event::isPublishToCamunda)
.contains(true);

assertThat(getEventsFrom(configBuilder).values())
.extracting(Event::getGrants)
.extracting(map -> map.containsKey(ST_CIC_WA_CONFIG_USER))
.contains(true);

assertThat(getEventsFrom(configBuilder).values())
.extracting(Event::getGrants)
.extracting(map -> map.get(ST_CIC_WA_CONFIG_USER))
.contains(Permissions.CREATE_READ_UPDATE);
}

@Test
Expand Down

0 comments on commit f864b85

Please sign in to comment.