Skip to content

Commit

Permalink
Merge branch 'master' into test/CIV-15919
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelMolina3691 authored Feb 12, 2025
2 parents d6b37b7 + 4ca302c commit 5cce0ae
Show file tree
Hide file tree
Showing 17 changed files with 231 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface DashboardNotificationsRepository extends CrudRepository<Dashboa

List<DashboardNotificationsEntity> findByReferenceAndCitizenRole(String reference, String role);

Optional<DashboardNotificationsEntity> findByReferenceAndCitizenRoleAndDashboardNotificationsTemplatesId(
List<DashboardNotificationsEntity> findByReferenceAndCitizenRoleAndDashboardNotificationsTemplatesId(
String reference, String role, Long templateId);

int deleteByNameAndReferenceAndCitizenRole(String name, String reference, String role);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import javax.transaction.Transactional;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

@Transactional
Expand All @@ -16,7 +15,7 @@ public interface TaskListRepository extends CrudRepository<TaskListEntity, UUID>

List<TaskListEntity> findByReferenceAndTaskItemTemplateRole(String reference, String role);

Optional<TaskListEntity> findByReferenceAndTaskItemTemplateRoleAndTaskItemTemplateTemplateName(
List<TaskListEntity> findByReferenceAndTaskItemTemplateRoleAndTaskItemTemplateTemplateName(
String reference, String role, String templateName);

List<TaskListEntity> findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotIn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class DashboardNotificationService {

private final IdamApi idamApi;

private String clickAction = "Click";
private final String clickAction = "Click";

@Autowired
public DashboardNotificationService(DashboardNotificationsRepository dashboardNotificationsRepository,
Expand All @@ -56,38 +56,46 @@ public List<Notification> getNotifications(String ccdCaseIdentifier, String role
.findByReferenceAndCitizenRole(ccdCaseIdentifier, roleType);

return dashboardNotificationsEntityList.stream()
.sorted(Comparator.comparing(t -> t.getCreatedAt(), Comparator.reverseOrder()))
.sorted(Comparator.comparing(DashboardNotificationsEntity::getCreatedAt, Comparator.reverseOrder()))
.map(Notification::from)
.toList();
}

public Map<String, List<Notification>> getAllCasesNotifications(List<String> ccdCaseIdentifiers, String roleType) {
Map<String, List<Notification>> gaNotifications = new HashMap<>();
ccdCaseIdentifiers.stream().forEach(gaCaseId -> gaNotifications.put(gaCaseId, getNotifications(gaCaseId, roleType)));
ccdCaseIdentifiers.forEach(gaCaseId -> gaNotifications.put(gaCaseId, getNotifications(gaCaseId, roleType)));
return gaNotifications;
}

public DashboardNotificationsEntity saveOrUpdate(DashboardNotificationsEntity notification) {
log.info(
"saveOrUpdate dashboard notification reference= {}, citizenRole = {}, templateId = {}",
notification.getReference(),
notification.getCitizenRole(),
notification.getDashboardNotificationsTemplates() != null ? notification.getDashboardNotificationsTemplates().getId() : null
);
Optional<DashboardNotificationsEntity> existingNotification = dashboardNotificationsRepository
.findByReferenceAndCitizenRoleAndDashboardNotificationsTemplatesId(
notification.getReference(), notification.getCitizenRole(),
notification.getDashboardNotificationsTemplates().getId()
);

DashboardNotificationsEntity updated = notification;
if (existingNotification.isPresent()) {
log.info("Existing notification present reference = {}, id = {}", notification.getReference(), existingNotification.get().getId());
updated = notification.toBuilder().id(existingNotification.get().getId()).build();
notificationActionRepository.deleteByDashboardNotificationAndActionPerformed(existingNotification.get(),
clickAction
if (nonNull(notification.getDashboardNotificationsTemplates())) {
log.info("Query for dashboard notifications using notification reference= {}, citizenRole = {}, templateId = {}",
notification.getReference(),
notification.getCitizenRole(),
notification.getDashboardNotificationsTemplates().getId()
);
log.info("Existing notification deleted reference = {}, id = {}", notification.getReference(), existingNotification.get().getId());
List<DashboardNotificationsEntity> existingNotification = dashboardNotificationsRepository
.findByReferenceAndCitizenRoleAndDashboardNotificationsTemplatesId(
notification.getReference(), notification.getCitizenRole(),
notification.getDashboardNotificationsTemplates().getId()
);

log.info("Found {} dashboard notifications in database for reference {}",
nonNull(existingNotification) ? existingNotification.size() : null,
notification.getReference());
if (nonNull(existingNotification) && !existingNotification.isEmpty()) {
DashboardNotificationsEntity dashboardNotification = existingNotification.get(0);
updated = notification.toBuilder().id(dashboardNotification.getId()).build();
for (DashboardNotificationsEntity dashNotification : existingNotification) {
notificationActionRepository.deleteByDashboardNotificationAndActionPerformed(
dashNotification,
clickAction
);
log.info("Existing notification deleted reference = {}, id = {}", notification.getReference(), dashNotification.getId());
}
}
} else {
log.info("Existing notification not present reference = {}", notification.getReference());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,22 @@ public List<TaskList> getTaskList(String ccdCaseIdentifier, String roleType) {
public TaskListEntity saveOrUpdate(TaskListEntity taskList) {

TaskItemTemplateEntity taskItemTemplate = taskList.getTaskItemTemplate();
Optional<TaskListEntity> existingEntity = taskListRepository
List<TaskListEntity> entities = taskListRepository
.findByReferenceAndTaskItemTemplateRoleAndTaskItemTemplateTemplateName(
taskList.getReference(),
taskItemTemplate.getRole(),
taskItemTemplate.getTemplateName()
);

Optional<TaskListEntity> latestEntity = entities.stream()
.max(Comparator.comparing(TaskListEntity::getCreatedAt));

TaskListEntity beingUpdated = taskList;
if (existingEntity.isPresent()) {
beingUpdated = taskList.toBuilder().id(existingEntity.get().getId()).build();
if (latestEntity.isPresent()) {
beingUpdated = taskList.toBuilder().id(latestEntity.get().getId()).build();
entities.stream()
.filter(e -> !e.equals(latestEntity.get()))
.forEach(duplicateEntity -> taskListRepository.deleteById(duplicateEntity.getId()));
}

return taskListRepository.save(beingUpdated);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import uk.gov.hmcts.reform.dashboard.data.Notification;
import uk.gov.hmcts.reform.dashboard.entities.DashboardNotificationsEntity;
import uk.gov.hmcts.reform.dashboard.entities.NotificationActionEntity;
import uk.gov.hmcts.reform.dashboard.entities.NotificationTemplateEntity;
import uk.gov.hmcts.reform.dashboard.repositories.DashboardNotificationsRepository;
import uk.gov.hmcts.reform.dashboard.repositories.NotificationActionRepository;
import uk.gov.hmcts.reform.idam.client.IdamApi;
Expand All @@ -23,6 +25,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static uk.gov.hmcts.reform.dashboard.utils.DashboardNotificationsTestUtils.getNotification;
Expand Down Expand Up @@ -134,6 +137,34 @@ void deleteAllNotificationsToDefendant() {
}
}

@Test
public void saveOrUpdate() {

DashboardNotificationsEntity notification1 = createDashboardNotificationsEntity();
DashboardNotificationsEntity notification2 = createDashboardNotificationsEntity();
when(
dashboardNotificationsRepository
.findByReferenceAndCitizenRoleAndDashboardNotificationsTemplatesId(
any(), any(), any())).thenReturn(List.of(notification1, notification2));
NotificationTemplateEntity template = NotificationTemplateEntity.builder()
.id(1L)
.build();
DashboardNotificationsEntity notification = DashboardNotificationsEntity.builder()
.id(UUID.randomUUID())
.dashboardNotificationsTemplates(template)
.build();
dashboardNotificationService.saveOrUpdate(notification);
verify(notificationActionRepository, times(2)).deleteByDashboardNotificationAndActionPerformed(any(DashboardNotificationsEntity.class), any());
final ArgumentCaptor<DashboardNotificationsEntity> captor = ArgumentCaptor.forClass(DashboardNotificationsEntity.class);
verify(dashboardNotificationsRepository).save(captor.capture());
assertThat(captor.getValue()).isNotNull();
assertThat(captor.getValue().getId()).isEqualTo(notification1.getId());
}

private DashboardNotificationsEntity createDashboardNotificationsEntity() {
return DashboardNotificationsEntity.builder().id(UUID.randomUUID()).build();
}

@Nested
class RecordClickOnNotification {

Expand Down Expand Up @@ -163,4 +194,5 @@ void shouldReturnOkWhenRecordingNotificationClick() {
verify(dashboardNotificationsRepository).save(notification);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import uk.gov.hmcts.reform.dashboard.repositories.TaskItemTemplateRepository;
import uk.gov.hmcts.reform.dashboard.repositories.TaskListRepository;

import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -290,4 +291,46 @@ void shouldMakeProgressAbleTaskListInactive_Except_Ga_whenTaskListIsPresent() {
));
}

@Test
public void shouldDeleteWhenThereWereDuplicateEntriesInTheRepository() {
TaskListEntity task = getTaskListEntity(UUID.randomUUID()).toBuilder()
.currentStatus(TaskStatus.AVAILABLE.getPlaceValue())
.taskNameEn("<a href=\"somewhere\">Link name</A >")
.taskNameCy("<A href=\"somewhere\">Link name Welsh</A>")
.createdAt(OffsetDateTime.MAX)
.build();

TaskListEntity task2 = getTaskListEntity(UUID.randomUUID()).toBuilder()
.taskNameEn("<a href=\"somewhere\">Link name</A >")
.taskNameCy("<A href=\"somewhere\">Link name Welsh</A>")
.currentStatus(TaskStatus.NOT_AVAILABLE_YET.getPlaceValue())
.createdAt(OffsetDateTime.MIN.plusDays(99L))
.build();

TaskListEntity task3 = getTaskListEntity(UUID.randomUUID()).toBuilder()
.currentStatus(TaskStatus.INACTIVE.getPlaceValue())
.taskNameEn("<a href=\"somewhere\">Link name</A >")
.taskNameCy("<A href=\"somewhere\">Link name Welsh</A>")
.createdAt(OffsetDateTime.MIN.plusDays(20L))
.build();

List<TaskListEntity> tasks = new ArrayList<>();
tasks.add(task);
tasks.add(task2);
tasks.add(task3);

when(taskListRepository
.findByReferenceAndTaskItemTemplateRoleAndTaskItemTemplateTemplateName(
any(),
any(),
any()
)).thenReturn(tasks);

taskListService.saveOrUpdate(task);

verify(taskListRepository).deleteById(task2.getId());
verify(taskListRepository).deleteById(task3.getId());
verify(taskListRepository).save(task);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import static uk.gov.hmcts.reform.civil.utils.HearingFeeUtils.calculateAndApplyFee;
import static uk.gov.hmcts.reform.civil.utils.HmcDataUtils.getHearingDays;
import static uk.gov.hmcts.reform.civil.utils.HmcDataUtils.getLocationRefData;
import static uk.gov.hmcts.reform.civil.utils.HmcDataUtils.getTotalHearingDurationInMinutes;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -107,7 +108,11 @@ private CallbackResponse generateHearingNotice(CallbackParams callbackParams) {
);

String claimTrack = determineClaimTrack(caseData);

Integer totalDurationInMinutes = getTotalHearingDurationInMinutes(hearing);
if (featureToggleService.isHmcForLipEnabled()) {
caseDataBuilder.hearingDurationInMinutesAHN(totalDurationInMinutes.toString())
.trialReadyNotified(null);
}
return AboutToStartOrSubmitCallbackResponse.builder()
.data(caseDataBuilder
.hearingDate(hearingStartDate.toLocalDate())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument;
import uk.gov.hmcts.reform.civil.enums.CaseRole;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.service.FeatureToggleService;
import uk.gov.hmcts.reform.civil.service.docmosis.trialready.TrialReadyFormGenerator;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

Expand All @@ -39,7 +41,7 @@ public class GenerateTrialReadyFormHandler extends CallbackHandler {
private static final String TASK_ID_RESPONDENT2 = "GenerateTrialReadyFormRespondent2";

private final TrialReadyFormGenerator trialReadyFormGenerator;

private final FeatureToggleService featureToggleService;
private final ObjectMapper objectMapper;

@Override
Expand Down Expand Up @@ -93,6 +95,17 @@ private void buildDocument(CallbackParams callbackParams, CaseData.CaseDataBuild
var documents = caseData.getTrialReadyDocuments();
documents.add(element(caseDocument));
caseDataBuilder.trialReadyDocuments(documents);
if (featureToggleService.isHmcForLipEnabled()) {
addDocumentCreatedDate(role, caseDataBuilder);
}
}

private void addDocumentCreatedDate(CaseRole role, CaseData.CaseDataBuilder<?, ?> caseDataBuilder) {
if (role == CaseRole.CLAIMANT) {
caseDataBuilder.claimantTrialReadyDocumentCreated(LocalDateTime.now());
} else if (role == CaseRole.DEFENDANT) {
caseDataBuilder.defendantTrialReadyDocumentCreated(LocalDateTime.now());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import static uk.gov.hmcts.reform.civil.utils.UserRoleUtils.isLIPClaimant;
import static uk.gov.hmcts.reform.civil.utils.UserRoleUtils.isLIPDefendant;
import static uk.gov.hmcts.reform.civil.utils.UserRoleUtils.isRespondentSolicitorOne;
import static uk.gov.hmcts.reform.civil.utils.UserRoleUtils.isRespondentSolicitorTwo;

@Slf4j
@Service
Expand Down Expand Up @@ -96,7 +97,7 @@ private CallbackResponse populateValues(CallbackParams callbackParams) {
} else if (isRespondentSolicitorOne(userRoles)) {
isRespondent1 = YesOrNo.YES;
updatedData.hearingDurationTextRespondent1(formatHearingDuration(caseData.getHearingDuration()));
} else {
} else if (isRespondentSolicitorTwo(userRoles)) {
isRespondent2 = YesOrNo.YES;
updatedData.hearingDurationTextRespondent2(formatHearingDuration(caseData.getHearingDuration()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ public class CaseDataCaseProgression extends CaseDataCaseSdo implements Mappable
private String information;
private String hearingNoticeListOther;
private LocalDateTime caseDismissedHearingFeeDueDate;
private String hearingDurationInMinutesAHN;
private LocalDateTime claimantTrialReadyDocumentCreated;
private LocalDateTime defendantTrialReadyDocumentCreated;

//Trial Readiness
private YesOrNo trialReadyNotified;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType;
import uk.gov.hmcts.reform.civil.enums.CaseState;
import uk.gov.hmcts.reform.civil.enums.DecisionOnRequestReconsiderationOptions;
import uk.gov.hmcts.reform.civil.enums.YesOrNo;
import uk.gov.hmcts.reform.civil.enums.hearing.ListingOrRelisting;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.service.FeatureToggleService;

Expand Down Expand Up @@ -241,6 +239,7 @@ public boolean isTrialScheduledNoPaymentStatusActive() {
return CaseState.HEARING_READINESS.equals(caseData.getCcdState())
&& (hearingScheduledDate.isPresent())
&& !isTrialArrangementStatusActive()
&& !isBundleCreatedStatusActive()
&& (orderDate.isEmpty()
|| orderDate.get().isBefore(hearingScheduledDate.get()));
}
Expand All @@ -257,35 +256,16 @@ public boolean isTrialScheduledPaymentPaidStatusActive() {
|| orderDate.get().isBefore(hearingScheduledDate.get()));
}

@Override
public boolean isTrialArrangementStatusActive() {
Optional<LocalDate> hearingDate = getHearingDate();
if (caseData.isFastTrackClaim()
&& (CaseState.HEARING_READINESS.equals(caseData.getCcdState()) || CaseState.PREPARE_FOR_HEARING_CONDUCT_HEARING.equals(caseData.getCcdState()))
&& !ListingOrRelisting.RELISTING.equals(caseData.getListingOrRelisting())
&& hearingDate.isPresent()
&& YesOrNo.YES.equals(caseData.getTrialReadyNotified())
&& isHearingLessThanDaysAway(DAY_LIMIT)
&& Objects.isNull(caseData.getTrialReadyChecked())
&& !isBundleCreatedStatusActive()) {
Optional<LocalDateTime> lastOrder = getTimeOfLastNonSDOOrder();
return lastOrder.isEmpty()
|| hearingDate.get().minusDays(DAY_LIMIT)
.isAfter(lastOrder.get().toLocalDate());
} else {
return false;
}
}

@Override
public boolean isBundleCreatedStatusActive() {
Optional<LocalDateTime> bundleDate = getBundleCreationDate();
Optional<LocalDateTime> lastOrderDate = getTimeOfLastNonSDOOrder();
return isHearingScheduled()
&& caseData.getCcdState() == CaseState.PREPARE_FOR_HEARING_CONDUCT_HEARING
&& (CaseState.HEARING_READINESS.equals(caseData.getCcdState())
|| caseData.getCcdState() == CaseState.PREPARE_FOR_HEARING_CONDUCT_HEARING)
&& isHearingLessThanDaysAway(3 * 7)
&& bundleDate.isPresent()
&& (lastOrderDate.isEmpty()
|| lastOrderDate.get().isBefore(bundleDate.get()));
|| lastOrderDate.get().isBefore(bundleDate.get()));
}
}
Loading

0 comments on commit 5cce0ae

Please sign in to comment.