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

CCMSPUI-376: Migrate notification summary from SOA-API to EBS-API #312

Merged
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ repositories {
dependencies {


implementation 'uk.gov.laa.ccms.data:data-api:0.0.21'
implementation 'uk.gov.laa.ccms.data:data-api:0.0.22-ef3e97c-SNAPSHOT'

implementation 'uk.gov.laa.ccms.soa.gateway:soa-gateway-api:0.0.37'
implementation 'uk.gov.laa.ccms.soa.gateway:soa-gateway-api:0.0.38-cfdf45d-SNAPSHOT'

implementation 'uk.gov.laa.ccms.caab:caab-api:0.0.37'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import uk.gov.laa.ccms.data.model.CommonLookupDetail;
import uk.gov.laa.ccms.data.model.CommonLookupValueDetail;
import uk.gov.laa.ccms.data.model.ContactDetail;
import uk.gov.laa.ccms.data.model.NotificationSummary;
import uk.gov.laa.ccms.data.model.OfficeDetail;
import uk.gov.laa.ccms.data.model.ProviderDetail;
import uk.gov.laa.ccms.data.model.UserDetail;
Expand Down Expand Up @@ -195,6 +196,41 @@ public void testGetUsers_notFound() {
}


@Test
public void testGetUserNotificationSummary_returnData() throws Exception {
final String loginId = "user1";
final NotificationSummary expectedNotificationsummary = buildUserNotificationSummary();
final String notificationSummaryJson = objectMapper.writeValueAsString(
expectedNotificationsummary);

wiremock.stubFor(get(String.format("/users/%s/notifications/summary", loginId))
.willReturn(okJson(notificationSummaryJson)));

final Mono<NotificationSummary> userNotificationSummary = ebsApiClient.getUserNotificationSummary(
loginId);

final NotificationSummary userDetails = userNotificationSummary.block();

assertEquals(notificationSummaryJson, objectMapper.writeValueAsString(userDetails));
}

@Test
public void testGetUserNotificationSummary_notFound() {
final String loginId = "user1";
final String expectedMessage = String.format(USER_ERROR_MESSAGE, loginId);

wiremock.stubFor(get(String.format("/users/%s/notifications/summary", loginId))
.willReturn(notFound()));

final Mono<NotificationSummary> notificationSummary = ebsApiClient.getUserNotificationSummary(
loginId);

StepVerifier.create(notificationSummary)
.expectErrorMatches(throwable -> throwable instanceof EbsApiClientException
&& throwable.getMessage().equals(expectedMessage)
).verify();
}

// You may need to build the AmendmentTypeLookupDetail for the test
private AmendmentTypeLookupDetail buildAmendmentTypeLookupDetail() {
final AmendmentTypeLookupDetail detail = new AmendmentTypeLookupDetail();
Expand Down Expand Up @@ -263,4 +299,8 @@ private ProviderDetail buildProviderDetail() {
.name("FeeEarner1")));
}

private NotificationSummary buildUserNotificationSummary() {
return new NotificationSummary().notifications(5).overdueActions(3).standardActions(7);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import uk.gov.laa.ccms.soa.gateway.model.CoverSheet;
import uk.gov.laa.ccms.soa.gateway.model.Document;
import uk.gov.laa.ccms.soa.gateway.model.Notification;
import uk.gov.laa.ccms.soa.gateway.model.NotificationSummary;
import uk.gov.laa.ccms.soa.gateway.model.Notifications;
import uk.gov.laa.ccms.soa.gateway.model.UserDetail;
import uk.gov.laa.ccms.soa.gateway.model.UserOptions;
Expand Down Expand Up @@ -84,26 +83,6 @@ public void testGetContractDetails_returnData() throws Exception {
assertEquals(contractDetailsJson, objectMapper.writeValueAsString(response.block()));
}

@Test
public void testGetNotificationsSummary_returnData() throws Exception {
String loginId = USER_1;
String userType = USER_TYPE;
NotificationSummary expectedSummary = buildNotificationSummary();
String summaryJson = objectMapper.writeValueAsString(expectedSummary);

wiremock.stubFor(get(String.format("/users/%s/notifications/summary", loginId))
.withHeader(SOA_GATEWAY_USER_LOGIN_ID, equalTo(loginId))
.withHeader(SOA_GATEWAY_USER_ROLE, equalTo(userType))
.willReturn(okJson(summaryJson)));

Mono<NotificationSummary> summaryMono =
soaApiClient.getNotificationsSummary(loginId, userType);

NotificationSummary summary = summaryMono.block();

assertEquals(summaryJson, objectMapper.writeValueAsString(summary));
}

@Test
public void testGetCases_returnData() throws Exception {
String loginId = USER_1;
Expand Down Expand Up @@ -382,13 +361,6 @@ public void testUpdateUserOptions_returnsData() throws Exception {
assertEquals(clientTransactionResponse, response);
}

private NotificationSummary buildNotificationSummary() {
return new NotificationSummary()
.notifications(10)
.standardActions(5)
.overdueActions(2);
}

private ContractDetails buildContractDetails() {
return new ContractDetails()
.addContractsItem(new ContractDetail()
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/uk/gov/laa/ccms/caab/client/EbsApiClient.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package uk.gov.laa.ccms.caab.client;

import java.util.Objects;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -20,6 +19,7 @@
import uk.gov.laa.ccms.data.model.EvidenceDocumentTypeLookupDetail;
import uk.gov.laa.ccms.data.model.LevelOfServiceLookupDetail;
import uk.gov.laa.ccms.data.model.MatterTypeLookupDetail;
import uk.gov.laa.ccms.data.model.NotificationSummary;
import uk.gov.laa.ccms.data.model.OutcomeResultLookupDetail;
import uk.gov.laa.ccms.data.model.PriorAuthorityTypeDetails;
import uk.gov.laa.ccms.data.model.ProceedingDetail;
Expand Down Expand Up @@ -68,6 +68,22 @@ public Mono<UserDetail> getUser(final String loginId) {
e, "User", "login id", loginId));
}

/**
* Retrieves a summary of notification counts for a user based on their login ID.
*
* @param loginId the login ID of the user whose notification summary is to be retrieved
* @return a Mono emitting the NotificationSummary for the specified user
*/
public Mono<NotificationSummary> getUserNotificationSummary(final String loginId) {
return ebsApiWebClient
.get()
.uri("/users/{loginId}/notifications/summary", loginId)
.retrieve()
.bodyToMono(NotificationSummary.class)
.onErrorResume(e -> ebsApiClientErrorHandler.handleApiRetrieveError(
e, "User", "login id", loginId));
}

/**
* Retrieves details for a specific provider.
*
Expand Down
23 changes: 0 additions & 23 deletions src/main/java/uk/gov/laa/ccms/caab/client/SoaApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import uk.gov.laa.ccms.soa.gateway.model.ContractDetails;
import uk.gov.laa.ccms.soa.gateway.model.CoverSheet;
import uk.gov.laa.ccms.soa.gateway.model.Document;
import uk.gov.laa.ccms.soa.gateway.model.NotificationSummary;
import uk.gov.laa.ccms.soa.gateway.model.Notifications;
import uk.gov.laa.ccms.soa.gateway.model.OrganisationDetail;
import uk.gov.laa.ccms.soa.gateway.model.OrganisationDetails;
Expand All @@ -53,28 +52,6 @@ public class SoaApiClient {

private final SoaApiClientErrorHandler soaApiClientErrorHandler;

/**
* Retrieve the summary of notifications for a given user.
*
* @param loginId The login identifier for the user.
* @param userType Type of the user (e.g., admin, user).
* @return A Mono wrapping the NotificationSummary for the specified user.
*/
public Mono<NotificationSummary> getNotificationsSummary(
final String loginId,
final String userType) {

return soaApiWebClient
.get()
.uri("/users/{loginId}/notifications/summary", loginId)
.header(SOA_GATEWAY_USER_LOGIN_ID, loginId)
.header(SOA_GATEWAY_USER_ROLE, userType)
.retrieve()
.bodyToMono(NotificationSummary.class)
.onErrorResume(e -> soaApiClientErrorHandler.handleApiRetrieveError(
e, "Notification summary", "user login id", loginId));
}

/**
* Fetches the contract details for the given criteria.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import uk.gov.laa.ccms.caab.config.UserRole;
import uk.gov.laa.ccms.caab.service.NotificationService;
import uk.gov.laa.ccms.caab.util.UserRoleUtil;
import uk.gov.laa.ccms.data.model.NotificationSummary;
import uk.gov.laa.ccms.data.model.UserDetail;
import uk.gov.laa.ccms.soa.gateway.model.NotificationSummary;

/**
* Controller handling home page requests.
Expand All @@ -38,7 +38,7 @@ public String home(Model model, HttpSession session) {

// Retrieve a summary of the User's Notifications & Actions from the SOA Gateway
NotificationSummary notificationSummary = notificationService.getNotificationsSummary(
user.getLoginId(), user.getUserType()).block();
user.getLoginId()).block();

boolean showNotifications =
notificationSummary != null && UserRoleUtil.hasRole(user, UserRole.VIEW_NOTIFICATIONS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import reactor.core.publisher.Mono;
import uk.gov.laa.ccms.caab.bean.NotificationSearchCriteria;
import uk.gov.laa.ccms.caab.client.CaabApiClient;
import uk.gov.laa.ccms.caab.client.EbsApiClient;
import uk.gov.laa.ccms.caab.client.S3ApiClient;
import uk.gov.laa.ccms.caab.client.SoaApiClient;
import uk.gov.laa.ccms.caab.exception.CaabApplicationException;
Expand All @@ -23,9 +24,9 @@
import uk.gov.laa.ccms.caab.model.NotificationAttachmentDetail;
import uk.gov.laa.ccms.caab.model.NotificationAttachmentDetails;
import uk.gov.laa.ccms.caab.util.FileUtil;
import uk.gov.laa.ccms.data.model.NotificationSummary;
import uk.gov.laa.ccms.soa.gateway.model.CoverSheet;
import uk.gov.laa.ccms.soa.gateway.model.Document;
import uk.gov.laa.ccms.soa.gateway.model.NotificationSummary;
import uk.gov.laa.ccms.soa.gateway.model.Notifications;

/**
Expand All @@ -36,6 +37,7 @@
@Slf4j
public class NotificationService {

private final EbsApiClient ebsApiClient;
private final SoaApiClient soaApiClient;
private final CaabApiClient caabApiClient;
private final S3ApiClient s3ApiClient;
Expand All @@ -48,11 +50,10 @@ public class NotificationService {
* Retrieve the summary of notifications for a given user.
*
* @param loginId The login identifier for the user.
* @param userType Type of the user (e.g., admin, user).
* @return A Mono wrapping the NotificationSummary for the specified user.
*/
public Mono<NotificationSummary> getNotificationsSummary(String loginId, String userType) {
return soaApiClient.getNotificationsSummary(loginId, userType);
public Mono<NotificationSummary> getNotificationsSummary(String loginId) {
return ebsApiClient.getUserNotificationSummary(loginId);
}

/**
Expand Down
59 changes: 57 additions & 2 deletions src/test/java/uk/gov/laa/ccms/caab/client/EbsApiClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import uk.gov.laa.ccms.data.model.EvidenceDocumentTypeLookupDetail;
import uk.gov.laa.ccms.data.model.LevelOfServiceLookupDetail;
import uk.gov.laa.ccms.data.model.MatterTypeLookupDetail;
import uk.gov.laa.ccms.data.model.NotificationSummary;
import uk.gov.laa.ccms.data.model.OutcomeResultLookupDetail;
import uk.gov.laa.ccms.data.model.PriorAuthorityTypeDetails;
import uk.gov.laa.ccms.data.model.ProceedingDetail;
Expand Down Expand Up @@ -69,8 +70,6 @@ public class EbsApiClientTest {
@InjectMocks
private EbsApiClient ebsApiClient;



ArgumentCaptor<Function<UriBuilder, URI>> uriCaptor = ArgumentCaptor.forClass(Function.class);

@Test
Expand Down Expand Up @@ -114,6 +113,62 @@ void getUser_notFound() {
.verifyComplete();
}

@Test
void getUserNotificationSummary_returnsData() {
final String loginId = "user1";
final String expectedUri = "/users/{loginId}/notifications/summary";

final NotificationSummary mockNotificationSummary = new NotificationSummary();
mockNotificationSummary.setNotifications(1);
mockNotificationSummary.setStandardActions(3);
mockNotificationSummary.setOverdueActions(2);

when(webClientMock.get()).thenReturn(requestHeadersUriMock);
when(requestHeadersUriMock.uri(expectedUri, loginId)).thenReturn(requestHeadersMock);
when(requestHeadersMock.retrieve()).thenReturn(responseMock);
when(responseMock.bodyToMono(NotificationSummary.class)).thenReturn(
Mono.just(mockNotificationSummary));

final Mono<NotificationSummary> notificationSummary = ebsApiClient.getUserNotificationSummary(
loginId);

StepVerifier.create(notificationSummary)
.expectNextMatches(summary ->
summary.getNotifications().equals(1) &&
summary.getStandardActions().equals(3) &&
summary.getOverdueActions().equals(2)
)
.verifyComplete();
}

@Test
void getUserNotificationSummary_NotFound() {
final String loginId = "user1";
final String expectedUri = "/users/{loginId}/notifications/summary";

final NotificationSummary mockNotificationSummary = new NotificationSummary();
mockNotificationSummary.setNotifications(1);
mockNotificationSummary.setStandardActions(3);
mockNotificationSummary.setOverdueActions(2);

when(webClientMock.get()).thenReturn(requestHeadersUriMock);
when(requestHeadersUriMock.uri(expectedUri, loginId)).thenReturn(requestHeadersMock);
when(requestHeadersMock.retrieve()).thenReturn(responseMock);
when(responseMock.bodyToMono(NotificationSummary.class)).thenReturn(
Mono.just(mockNotificationSummary));

final Mono<NotificationSummary> notificationSummary = ebsApiClient.getUserNotificationSummary(
loginId);

StepVerifier.create(notificationSummary)
.expectNextMatches(summary ->
summary.getNotifications().equals(1) &&
summary.getStandardActions().equals(3) &&
summary.getOverdueActions().equals(2)
)
.verifyComplete();
}

@Test
void getCommonValues_returnsData() {
final String type = "type1";
Expand Down
Loading
Loading