Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DIAC-577 integrating Timed Event Service into bail-case-api #537 #541

Merged
merged 16 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Jenkinsfile_nightly
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ withNightlyPipeline(type, product, component) {

env.IA_CASE_DOCUMENTS_API_URL = "http://ia-case-documents-api-aat.service.core-compute-aat.internal/"
env.IA_CASE_NOTIFICATIONS_API_URL = "http://ia-case-notifications-api-aat.service.core-compute-aat.internal/"
env.IA_TIMED_EVENT_SERVICE_URL = "http://ia-timed-event-service-aat.service.core-compute-aat.internal/"
env.IA_IDAM_REDIRECT_URI = "https://ia-bail-case-api-aat.service.core-compute-aat.internal/oauth2/callback"
env.CCD_URL = "http://ccd-data-store-api-aat.service.core-compute-aat.internal"
env.CCD_GW_URL = "http://dm-store-aat.service.core-compute-aat.internal"
Expand Down
1 change: 1 addition & 0 deletions Jenkinsfile_parameterized
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ withParameterizedPipeline(params.TYPE, params.PRODUCT_NAME, params.APP, params.E

env.IA_CASE_DOCUMENTS_API_URL = "http://ia-case-documents-api-aat.service.core-compute-aat.internal/"
env.IA_CASE_NOTIFICATIONS_API_URL = "http://ia-case-notifications-api-aat.service.core-compute-aat.internal/"
env.IA_TIMED_EVENT_SERVICE_URL = "http://ia-timed-event-service-aat.service.core-compute-aat.internal/"
env.IA_IDAM_REDIRECT_URI = "https://ia-bail-case-api-aat.service.core-compute-aat.internal/oauth2/callback"
env.CCD_URL = "http://ccd-data-store-api-aat.service.core-compute-aat.internal"
env.CCD_GW_URL = "http://dm-store-aat.service.core-compute-aat.internal"
Expand Down
2 changes: 1 addition & 1 deletion charts/ia-bail-case-api/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
description: A Helm chart for Bail Case API App
name: ia-bail-case-api
home: https://github.com/hmcts/ia-bail-case-api
version: 0.0.22
version: 0.0.23
maintainers:
- name: Immigration & Asylum Team
email: [email protected]
Expand Down
5 changes: 4 additions & 1 deletion charts/ia-bail-case-api/values.preview.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ java:
IA_CASE_DOCUMENTS_API_URL: "http://ia-case-documents-api-{{ .Values.global.environment }}.service.core-compute-{{ .Values.global.environment }}.internal/"
IA_CASE_NOTIFICATIONS_API_URL: "http://ia-case-notifications-api-{{ .Values.global.environment }}.service.core-compute-{{ .Values.global.environment }}.internal/"
CASE_DOCUMENT_AM_URL: "http://ccd-case-document-am-api-{{ .Values.global.environment }}.service.core-compute-{{ .Values.global.environment }}.internal"
LOCATION_REF_DATA_URL: "http://rd-location-ref-api-aat.service.core-compute-aat.internal"
LOCATION_REF_DATA_URL: "http://rd-location-ref-api-aat.service.core-compute-aat.internal"
IA_TIMED_EVENT_SERVICE_URL: "https://ia-timed-event-service-pr-183.preview.platform.hmcts.net/"
IA_TIMED_EVENT_SERVICE_ENABLED: "true"

2 changes: 2 additions & 0 deletions charts/ia-bail-case-api/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ java:
IA_CASE_NOTIFICATIONS_API_URL: "http://ia-case-notifications-api-{{ .Values.global.environment }}.service.core-compute-{{ .Values.global.environment }}.internal/"
CASE_DOCUMENT_AM_URL: "http://ccd-case-document-am-api-{{ .Values.global.environment }}.service.core-compute-{{ .Values.global.environment }}.internal"
COMMON_DATA_API: http://rd-commondata-api-{{ .Values.global.environment }}.service.core-compute-{{ .Values.global.environment }}.internal
IA_TIMED_EVENT_SERVICE_URL: "http://ia-timed-event-service-{{ .Values.global.environment }}.service.core-compute-{{ .Values.global.environment }}.internal/"
IA_TIMED_EVENT_SERVICE_ENABLED: "false"
keyVaults:
ia:
resourceGroup: ia
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public enum Event {
UPLOAD_DOCUMENTS("uploadDocuments"),
UPLOAD_SIGNED_DECISION_NOTICE("uploadSignedDecisionNotice"),
VIEW_PREVIOUS_APPLICATIONS("viewPreviousApplications"),
TEST_TIMED_EVENT_SCHEDULE("testTimedEventSchedule"),
UPLOAD_HEARING_RECORDING("uploadHearingRecording"),

@JsonEnumDefaultValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public PostSubmitCallbackResponse handle(Callback<BailCase> callback) {
+ "the 'Next step' dropdown list from your case details page.\n\n"
+ "#### Not ready to submit your application yet?\n"
+ "You can return to the case details page to make changes from the ‘Next step’ dropdown list."
);
);

return postSubmitResponse;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package uk.gov.hmcts.reform.bailcaseapi.domain.handlers.postsubmit;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.reform.bailcaseapi.domain.DateProvider;
import uk.gov.hmcts.reform.bailcaseapi.domain.UserDetailsHelper;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.BailCase;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.BailCaseFieldDefinition;
Expand All @@ -12,8 +14,13 @@
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ccd.callback.Callback;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ccd.callback.PostSubmitCallbackResponse;
import uk.gov.hmcts.reform.bailcaseapi.domain.handlers.PostSubmitCallbackHandler;
import uk.gov.hmcts.reform.bailcaseapi.domain.service.Scheduler;
import uk.gov.hmcts.reform.bailcaseapi.infrastructure.clients.CcdCaseAssignment;
import uk.gov.hmcts.reform.bailcaseapi.infrastructure.clients.ProfessionalOrganisationRetriever;
import uk.gov.hmcts.reform.bailcaseapi.infrastructure.clients.model.TimedEvent;

import java.time.ZoneId;
import java.time.ZonedDateTime;

@Slf4j
@Component
Expand All @@ -23,15 +30,24 @@ public class BailApplicationSubmittedConfirmation implements PostSubmitCallbackH
private final CcdCaseAssignment ccdCaseAssignment;
private UserDetails userDetails;
private UserDetailsHelper userDetailsHelper;
private final boolean timedEventServiceEnabled;
private final DateProvider dateProvider;
private final Scheduler scheduler;

public BailApplicationSubmittedConfirmation(ProfessionalOrganisationRetriever professionalOrganisationRetriever,
CcdCaseAssignment ccdCaseAssignment,
UserDetails userDetails,
UserDetailsHelper userDetailsHelper) {
UserDetailsHelper userDetailsHelper,
@Value("${featureFlag.timedEventServiceEnabled}") boolean timedEventServiceEnabled,
DateProvider dateProvider,
Scheduler scheduler) {
this.professionalOrganisationRetriever = professionalOrganisationRetriever;
this.ccdCaseAssignment = ccdCaseAssignment;
this.userDetails = userDetails;
this.userDetailsHelper = userDetailsHelper;
this.timedEventServiceEnabled = timedEventServiceEnabled;
this.dateProvider = dateProvider;
this.scheduler = scheduler;
}

@Override
Expand All @@ -54,7 +70,7 @@ public PostSubmitCallbackResponse handle(Callback<BailCase> callback) {

postSubmitResponse.setConfirmationBody(
"### What happens next\n\n"
+ "All parties will be notified that the application has been submitted."
+ "All parties will be notified that the application has been submitted."
);

postSubmitResponse.setConfirmationHeader("# You have submitted this application");
Expand All @@ -73,9 +89,27 @@ public PostSubmitCallbackResponse handle(Callback<BailCase> callback) {
);

ccdCaseAssignment.assignAccessToCase(callback);
ccdCaseAssignment.revokeAccessToCase(callback, organisationIdentifier);
// TODO: uncomment revokeAccessToCase
// ccdCaseAssignment.revokeAccessToCase(callback, organisationIdentifier);
}
if (timedEventServiceEnabled) {
log.info("Triggering event to test timed event service schedule feature");
int scheduleDelayInMinutes = 1;
ZonedDateTime scheduledDate = ZonedDateTime.of(
dateProvider.nowWithTime(),
ZoneId.systemDefault()
).plusMinutes(scheduleDelayInMinutes);
scheduler.schedule(
new TimedEvent(
"",
Event.TEST_TIMED_EVENT_SCHEDULE,
scheduledDate,
"IA",
"Bail",
callback.getCaseDetails().getId()
)
);
}

return postSubmitResponse;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import uk.gov.hmcts.reform.bailcaseapi.domain.BailCaseUtils;
import uk.gov.hmcts.reform.bailcaseapi.domain.DateProvider;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.BailCase;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ListingEvent;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ListingHearingCentre;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ccd.CaseDetails;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ccd.DecisionType;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ccd.Event;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package uk.gov.hmcts.reform.bailcaseapi.domain.service;

import uk.gov.hmcts.reform.bailcaseapi.infrastructure.clients.model.TimedEvent;

public interface Scheduler {

TimedEvent schedule(TimedEvent timedEvent);

boolean deleteSchedule(String timedEventId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package uk.gov.hmcts.reform.bailcaseapi.infrastructure.clients;

public class AsylumCaseServiceResponseException extends RuntimeException {

public AsylumCaseServiceResponseException(
String message,
Throwable cause
) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package uk.gov.hmcts.reform.bailcaseapi.infrastructure.clients;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.ObjectProvider;

import java.util.function.Consumer;

public class TimedEventMessageConverterCustomizer<T> implements ObjectProvider<T> {
@Override
public T getObject() throws BeansException {
return null;
}

@Override
public T getObject(Object... args) throws BeansException {
return null;
}

@Override
public T getIfAvailable() throws BeansException {
return null;
}

@Override
public T getIfUnique() throws BeansException {
return null;
}

@Override
public void forEach(Consumer action) {
// do nothing
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package uk.gov.hmcts.reform.bailcaseapi.infrastructure.clients;

import com.fasterxml.jackson.databind.ObjectMapper;
import feign.Feign;
import feign.codec.Decoder;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.support.ResponseEntityDecoder;
import org.springframework.cloud.openfeign.support.SpringDecoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.bind.annotation.*;
import uk.gov.hmcts.reform.bailcaseapi.infrastructure.clients.model.TimedEvent;
import uk.gov.hmcts.reform.bailcaseapi.infrastructure.config.DisableHystrixFeignConfiguration;

import static org.springframework.http.HttpHeaders.AUTHORIZATION;
import static uk.gov.hmcts.reform.bailcaseapi.infrastructure.config.ServiceTokenGeneratorConfiguration.SERVICE_AUTHORIZATION;

@FeignClient(
name = "timed-event-service-api",
url = "${timed-event-service.url}",
configuration = {TimedEventServiceApi.Configuration.class, DisableHystrixFeignConfiguration.class}
)
public interface TimedEventServiceApi {

@PostMapping(value = "/timed-event", produces = "application/json", consumes = "application/json")
TimedEvent submitTimedEvent(
@RequestHeader(AUTHORIZATION) String userToken,
@RequestHeader(SERVICE_AUTHORIZATION) String s2sToken,
@RequestBody TimedEvent content
);

@DeleteMapping(value = "/timed-event/{id}", produces = "application/json", consumes = "application/json")
void deleteTimedEvent(
@RequestHeader(AUTHORIZATION) String userToken,
@RequestHeader(SERVICE_AUTHORIZATION) String s2sToken,
@PathVariable("id") String jobKey
);


class Configuration {

@Bean
public Decoder decoder(ObjectMapper objectMapper) {
HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter(objectMapper);
return new ResponseEntityDecoder(new SpringDecoder(() -> new HttpMessageConverters(jacksonConverter), new TimedEventMessageConverterCustomizer<>()));
}

@Bean
@Scope("prototype")
public Feign.Builder feignBuilder() {
return Feign.builder();
}

}



}

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package uk.gov.hmcts.reform.bailcaseapi.infrastructure.clients;

import feign.FeignException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.reform.authorisation.generators.AuthTokenGenerator;
import uk.gov.hmcts.reform.bailcaseapi.domain.service.Scheduler;
import uk.gov.hmcts.reform.bailcaseapi.infrastructure.clients.model.TimedEvent;
import uk.gov.hmcts.reform.bailcaseapi.infrastructure.security.AccessTokenProvider;

@Service
@Slf4j
public class TimedEventServiceScheduler implements Scheduler {

private final AuthTokenGenerator serviceAuthTokenGenerator;
private final AccessTokenProvider accessTokenProvider;
private final TimedEventServiceApi timedEventServiceApi;

public TimedEventServiceScheduler(
AuthTokenGenerator serviceAuthTokenGenerator,
@Qualifier("requestUser") AccessTokenProvider accessTokenProvider,
TimedEventServiceApi timedEventServiceApi
) {
this.serviceAuthTokenGenerator = serviceAuthTokenGenerator;
this.accessTokenProvider = accessTokenProvider;
this.timedEventServiceApi = timedEventServiceApi;
}

@Override
public TimedEvent schedule(TimedEvent timedEvent) {

String serviceAuthorizationToken = serviceAuthTokenGenerator.generate();
String accessToken = accessTokenProvider.getAccessToken();

try {

return timedEventServiceApi.submitTimedEvent(
accessToken,
serviceAuthorizationToken,
timedEvent
);

} catch (FeignException e) {

throw new AsylumCaseServiceResponseException(
String.format(
"Couldn't schedule timed event for caseId: %d, event: %s",
timedEvent.getCaseId(),
timedEvent.getEvent()
),
e
);
}
}

public boolean deleteSchedule(String timedEventId) {
String serviceAuthorizationToken = serviceAuthTokenGenerator.generate();
String accessToken = accessTokenProvider.getAccessToken();

try {
timedEventServiceApi.deleteTimedEvent(
accessToken,
serviceAuthorizationToken,
timedEventId
);
} catch (FeignException ex) {
log.warn("The schedule with id {} could not be deleted. This should not happen and may cause problems. " +
"Check that the schedule ID is correct.",
timedEventId);
return false;
}

return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package uk.gov.hmcts.reform.bailcaseapi.infrastructure.clients.model;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ccd.Event;

import java.time.ZonedDateTime;

@NoArgsConstructor
@AllArgsConstructor
@Getter
public class TimedEvent {

private String id;
private Event event;
private ZonedDateTime scheduledDateTime;
private String jurisdiction;
private String caseType;
private long caseId;

}
Loading
Loading