SI-2280 Anzeige der FailureInfos nicht mit Status Beendet oder cancelled wenn resupplied mehr als 4 Wochen in der Vergangenheit liegt
diff --git a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/repository/FailureInformationRepository.java b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/repository/FailureInformationRepository.java
index bfbb4e3..51621ef 100644
--- a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/repository/FailureInformationRepository.java
+++ b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/repository/FailureInformationRepository.java
@@ -23,13 +23,19 @@
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
+import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@Repository
public interface FailureInformationRepository extends PagingAndSortingRepository<TblFailureInformation, Long > {
- Page<TblFailureInformation> findByTblFailureInformationCondensedIdIsNullOrderByFailureBeginDescIdAsc(Pageable pageable); // NOSONAR
+
+ @Query("SELECT a from TblFailureInformation a WHERE a.tblFailureInformationCondensed IS NULL " +
+ "AND ( (a.refStatusIntern.id NOT IN (:statusClosedId, :statusCancelledId) OR a.failureEndResupplied IS NULL ) OR " +
+ "(a.refStatusIntern.id IN (:statusClosedId, :statusCancelledId) AND a.failureEndResupplied >= :dateNowFourWeeksAgo) ) ORDER BY a.failureBegin ASC")
+ Page<TblFailureInformation> findByTblFailureInformationForDisplay(long statusClosedId, long statusCancelledId,
+ Date dateNowFourWeeksAgo, Pageable pageable); // NOSONAR
Optional<TblFailureInformation> findByUuid(UUID uuid);
diff --git a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/ExportService.java b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/ExportService.java
index 2f842ec..0c035ae 100644
--- a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/ExportService.java
+++ b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/ExportService.java
@@ -202,8 +202,8 @@
List<TblFailureInformation> tblFailureInfosVeroeffentlicht = failureInformationRepository
.findByPublicationStatus(Constants.PUB_STATUS_VEROEFFENTLICHT);
- Set<UUID> currTableViewUuidSet = failureInformationRepository
- .findByTblFailureInformationCondensedIdIsNullOrderByFailureBeginDescIdAsc(Pageable.unpaged())
+ Set<UUID> currTableViewUuidSet = failureInformationService
+ .findFailureInformationsForDisplay(Pageable.unpaged())
.stream()
.map(TblFailureInformation::getUuid)
.collect(Collectors.toSet());
diff --git a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/FailureInformationReminderMailSentService.java b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/FailureInformationReminderMailSentService.java
index ee58a47..29b0592 100644
--- a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/FailureInformationReminderMailSentService.java
+++ b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/FailureInformationReminderMailSentService.java
@@ -41,6 +41,9 @@
public class FailureInformationReminderMailSentService {
@Autowired
+ private FailureInformationService failureInformationService;
+
+ @Autowired
private FailureInformationReminderMailSentRepository failureInformationReminderMailSentRepository;
@Autowired
@@ -62,8 +65,8 @@
long minutesBefore;
public Boolean displayStatusChangeReminderAndSendMails() {
- Page<FailureInformationDto> failureInfoPage = failureInformationRepository
- .findByTblFailureInformationCondensedIdIsNullOrderByFailureBeginDescIdAsc(PageRequest.of(0, 9999999))
+ Page<FailureInformationDto> failureInfoPage = failureInformationService
+ .findFailureInformationsForDisplay(PageRequest.of(0, 9999999))
.map(failureInformationMapper::toFailureInformationDto);
LocalDateTime reminderDate = LocalDateTime.now().plusMinutes(minutesBefore);
diff --git a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/FailureInformationService.java b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/FailureInformationService.java
index 229ce91..e67bc70 100644
--- a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/FailureInformationService.java
+++ b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/FailureInformationService.java
@@ -28,8 +28,30 @@
import org.eclipse.openk.gridfailureinformation.exceptions.OperationDeniedException;
import org.eclipse.openk.gridfailureinformation.mapper.FailureInformationMapper;
import org.eclipse.openk.gridfailureinformation.mapper.FailureInformationPublicationChannelMapper;
-import org.eclipse.openk.gridfailureinformation.model.*;
-import org.eclipse.openk.gridfailureinformation.repository.*;
+import org.eclipse.openk.gridfailureinformation.model.HtblFailureInformation;
+import org.eclipse.openk.gridfailureinformation.model.RefBranch;
+import org.eclipse.openk.gridfailureinformation.model.RefExpectedReason;
+import org.eclipse.openk.gridfailureinformation.model.RefStatus;
+import org.eclipse.openk.gridfailureinformation.model.TblAddress;
+import org.eclipse.openk.gridfailureinformation.model.TblFailureInformation;
+import org.eclipse.openk.gridfailureinformation.model.TblFailureInformationPublicationChannel;
+import org.eclipse.openk.gridfailureinformation.model.TblFailureInformationReminderMailSent;
+import org.eclipse.openk.gridfailureinformation.model.TblFailureInformationStation;
+import org.eclipse.openk.gridfailureinformation.model.TblStation;
+import org.eclipse.openk.gridfailureinformation.repository.AddressRepository;
+import org.eclipse.openk.gridfailureinformation.repository.BranchRepository;
+import org.eclipse.openk.gridfailureinformation.repository.DistributionGroupRepository;
+import org.eclipse.openk.gridfailureinformation.repository.ExpectedReasonRepository;
+import org.eclipse.openk.gridfailureinformation.repository.FailureClassificationRepository;
+import org.eclipse.openk.gridfailureinformation.repository.FailureInformationDistributionGroupRepository;
+import org.eclipse.openk.gridfailureinformation.repository.FailureInformationPublicationChannelRepository;
+import org.eclipse.openk.gridfailureinformation.repository.FailureInformationReminderMailSentRepository;
+import org.eclipse.openk.gridfailureinformation.repository.FailureInformationRepository;
+import org.eclipse.openk.gridfailureinformation.repository.FailureInformationStationRepository;
+import org.eclipse.openk.gridfailureinformation.repository.HistFailureInformationRepository;
+import org.eclipse.openk.gridfailureinformation.repository.RadiusRepository;
+import org.eclipse.openk.gridfailureinformation.repository.StationRepository;
+import org.eclipse.openk.gridfailureinformation.repository.StatusRepository;
import org.eclipse.openk.gridfailureinformation.util.ExternalStatusCalculator;
import org.eclipse.openk.gridfailureinformation.util.GrahamScan;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
@@ -43,8 +65,17 @@
import java.awt.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
-import java.util.*;
+import java.util.Optional;
+import java.util.Set;
+import java.util.UUID;
import java.util.stream.Collectors;
@Log4j2
@@ -117,14 +148,24 @@
}
public Page<FailureInformationDto> findFailureInformations(Pageable pageable) {
- Page<FailureInformationDto> retPage = failureInformationRepository
- .findByTblFailureInformationCondensedIdIsNullOrderByFailureBeginDescIdAsc(pageable)
+ Page<FailureInformationDto> retPage = findFailureInformationsForDisplay(pageable)
.map(failureInformationMapper::toFailureInformationDto);
retPage.getContent().forEach(this::enrichFailureInfo);
return retPage;
}
+ public Page<TblFailureInformation> findFailureInformationsForDisplay(Pageable pageable) {
+ LocalDateTime now = LocalDateTime.now();
+ LocalDateTime ldt = LocalDateTime.of(now.getYear(), now.getMonth(), now.getDayOfMonth(), 0, 0, 0);
+ ldt = ldt.minusWeeks(4);
+ Date nowMinusFourWeeks = Date.from(ldt.atZone(ZoneId.of("UTC")).toInstant());
+ return failureInformationRepository.findByTblFailureInformationForDisplay(
+ GfiProcessState.COMPLETED.getStatusValue(),
+ GfiProcessState.CANCELED.getStatusValue(),
+ nowMinusFourWeeks, pageable);
+ }
+
public List<FailureInformationDto> findFailureInformationsByCondensedUuid(UUID uuid) {
List<FailureInformationDto> listFailureInformationDtos = new LinkedList<>();
@@ -500,7 +541,7 @@
final List<TblFailureInformationStation> byFkTblFailureInformation = failureInformationStationRepository.findByFkTblFailureInformation(condensedFailureInformation.getId());
Set<String> stationsOfOldExistingCondensedFi =
byFkTblFailureInformation.stream()
- .map( x -> x.getStationStationId() )
+ .map( TblFailureInformationStation::getStationStationId )
.collect(Collectors.toSet());
// store the set for the newly created failure info
diff --git a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/service/FailureInformationReminderMailSentServiceTest.java b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/service/FailureInformationReminderMailSentServiceTest.java
index a8538f3..f243ca5 100644
--- a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/service/FailureInformationReminderMailSentServiceTest.java
+++ b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/service/FailureInformationReminderMailSentServiceTest.java
@@ -57,6 +57,9 @@
private FailureInformationReminderMailSentService failureInformationReminderMailSentService;
@MockBean
+ private FailureInformationService failureInformationService;
+
+ @MockBean
private FailureInformationRepository failureInformationRepository;
@MockBean
@@ -77,7 +80,7 @@
mockfailurePage.getContent().stream().findFirst().get().setFailureEndPlanned(reminderDate);
TblFailureInformation tblFailureInformation = MockDataHelper.mockTblFailureInformation();
- when(failureInformationRepository.findByTblFailureInformationCondensedIdIsNullOrderByFailureBeginDescIdAsc(any(Pageable.class))).thenReturn(mockfailurePage);
+ when(failureInformationService.findFailureInformationsForDisplay(any(Pageable.class))).thenReturn(mockfailurePage);
when(statusRepository.findById(any(Long.class))).thenReturn(Optional.of(mockRefStatus));
when(failureInformationRepository.findByUuid(any(UUID.class))).thenReturn(Optional.of(tblFailureInformation));
when(failureInformationReminderMailSentRepository.findByTblFailureInformation(any(TblFailureInformation.class))).thenReturn(Optional.empty());
@@ -92,7 +95,7 @@
Page<TblFailureInformation> mockfailurePage = MockDataHelper.mockTblFailureInformationPage();
RefStatus mockRefStatus = MockDataHelper.mockRefStatusCreated();
- when(failureInformationRepository.findByTblFailureInformationCondensedIdIsNullOrderByFailureBeginDescIdAsc(any(Pageable.class))).thenReturn(mockfailurePage);
+ when(failureInformationService.findFailureInformationsForDisplay(any(Pageable.class))).thenReturn(mockfailurePage);
when(statusRepository.findById(any(Long.class))).thenReturn(Optional.of(mockRefStatus));
Boolean reminderIsDisplayed = failureInformationReminderMailSentService.displayStatusChangeReminderAndSendMails();
@@ -110,7 +113,7 @@
mockfailurePage.getContent().stream().findFirst().get().setRefStatusIntern(mockRefStatus);
TblFailureInformation tblFailureInformation = MockDataHelper.mockTblFailureInformation();
- when(failureInformationRepository.findByTblFailureInformationCondensedIdIsNullOrderByFailureBeginDescIdAsc(any(Pageable.class))).thenReturn(mockfailurePage);
+ when(failureInformationService.findFailureInformationsForDisplay(any(Pageable.class))).thenReturn(mockfailurePage);
when(statusRepository.findById(any(Long.class))).thenReturn(Optional.of(mockRefStatus));
when(failureInformationRepository.findByUuid(any(UUID.class))).thenReturn(Optional.of(tblFailureInformation));
when(failureInformationReminderMailSentRepository.findByTblFailureInformation(any(TblFailureInformation.class))).thenReturn(Optional.empty());
@@ -130,7 +133,7 @@
mockfailurePage.getContent().stream().findFirst().get().setRefStatusIntern(mockRefStatus);
TblFailureInformation tblFailureInformation = MockDataHelper.mockTblFailureInformation();
- when(failureInformationRepository.findByTblFailureInformationCondensedIdIsNullOrderByFailureBeginDescIdAsc(any(Pageable.class))).thenReturn(mockfailurePage);
+ when(failureInformationService.findFailureInformationsForDisplay(any(Pageable.class))).thenReturn(mockfailurePage);
when(statusRepository.findById(any(Long.class))).thenReturn(Optional.of(mockRefStatus));
when(failureInformationRepository.findByUuid(any(UUID.class))).thenReturn(Optional.of(tblFailureInformation));
when(failureInformationReminderMailSentRepository.findByTblFailureInformation(any(TblFailureInformation.class))).thenReturn(Optional.empty());
@@ -149,7 +152,7 @@
RefStatus mockRefStatus = MockDataHelper.mockRefStatusCreated();
List<FailureInformationDto> failureInformationDtoList = MockDataHelper.mockGridFailureInformationDtos();
- when(failureInformationRepository.findByTblFailureInformationCondensedIdIsNullOrderByFailureBeginDescIdAsc(any(Pageable.class))).thenReturn(mockfailurePage);
+ when(failureInformationService.findFailureInformationsForDisplay(any(Pageable.class))).thenReturn(mockfailurePage);
when(statusRepository.findById(any(Long.class))).thenReturn(Optional.of(mockRefStatus));
when(exportService.exportFailureInformationReminderMail(any(UUID.class))).thenReturn(true);
@@ -165,7 +168,7 @@
RefStatus mockRefStatus = MockDataHelper.mockRefStatusCreated();
List<FailureInformationDto> failureInformationDtoList = MockDataHelper.mockGridFailureInformationDtos();
- when(failureInformationRepository.findByTblFailureInformationCondensedIdIsNullOrderByFailureBeginDescIdAsc(any(Pageable.class))).thenReturn(mockfailurePage);
+ when(failureInformationService.findFailureInformationsForDisplay(any(Pageable.class))).thenReturn(mockfailurePage);
when(statusRepository.findById(any(Long.class))).thenReturn(Optional.of(mockRefStatus));
when(exportService.exportFailureInformationReminderMail(any(UUID.class))).thenReturn(true);
@@ -227,9 +230,8 @@
Page<TblFailureInformation> mockfailurePage = MockDataHelper.mockTblFailureInformationPage();
RefStatus mockRefStatus = MockDataHelper.mockRefStatusCOMPLETED();
mockfailurePage.getContent().stream().forEach(f -> f.setRefStatusIntern(null));
- List<FailureInformationDto> failureInformationDtoList = MockDataHelper.mockGridFailureInformationDtos();
- when(failureInformationRepository.findByTblFailureInformationCondensedIdIsNullOrderByFailureBeginDescIdAsc(any(Pageable.class))).thenReturn(mockfailurePage);
+ when(failureInformationService.findFailureInformationsForDisplay(any(Pageable.class))).thenReturn(mockfailurePage);
when(statusRepository.findById(any(Long.class))).thenReturn(Optional.of(mockRefStatus));
when(exportService.exportFailureInformationReminderMail(any(UUID.class))).thenReturn(true);
diff --git a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/service/FailureInformationServiceTest.java b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/service/FailureInformationServiceTest.java
index a63d6eb..18cac8d 100644
--- a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/service/FailureInformationServiceTest.java
+++ b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/service/FailureInformationServiceTest.java
@@ -21,13 +21,38 @@
import org.eclipse.openk.gridfailureinformation.exceptions.BadRequestException;
import org.eclipse.openk.gridfailureinformation.exceptions.NotFoundException;
import org.eclipse.openk.gridfailureinformation.exceptions.OperationDeniedException;
-import org.eclipse.openk.gridfailureinformation.model.*;
-import org.eclipse.openk.gridfailureinformation.repository.*;
+import org.eclipse.openk.gridfailureinformation.model.HtblFailureInformation;
+import org.eclipse.openk.gridfailureinformation.model.RefBranch;
+import org.eclipse.openk.gridfailureinformation.model.RefExpectedReason;
+import org.eclipse.openk.gridfailureinformation.model.RefFailureClassification;
+import org.eclipse.openk.gridfailureinformation.model.RefRadius;
+import org.eclipse.openk.gridfailureinformation.model.RefStatus;
+import org.eclipse.openk.gridfailureinformation.model.TblAddress;
+import org.eclipse.openk.gridfailureinformation.model.TblDistributionGroup;
+import org.eclipse.openk.gridfailureinformation.model.TblFailureInformation;
+import org.eclipse.openk.gridfailureinformation.model.TblFailureInformationDistributionGroup;
+import org.eclipse.openk.gridfailureinformation.model.TblFailureInformationPublicationChannel;
+import org.eclipse.openk.gridfailureinformation.model.TblFailureInformationReminderMailSent;
+import org.eclipse.openk.gridfailureinformation.model.TblFailureInformationStation;
+import org.eclipse.openk.gridfailureinformation.model.TblStation;
+import org.eclipse.openk.gridfailureinformation.repository.AddressRepository;
+import org.eclipse.openk.gridfailureinformation.repository.BranchRepository;
+import org.eclipse.openk.gridfailureinformation.repository.DistributionGroupRepository;
+import org.eclipse.openk.gridfailureinformation.repository.ExpectedReasonRepository;
+import org.eclipse.openk.gridfailureinformation.repository.FailureClassificationRepository;
+import org.eclipse.openk.gridfailureinformation.repository.FailureInformationDistributionGroupRepository;
+import org.eclipse.openk.gridfailureinformation.repository.FailureInformationPublicationChannelRepository;
+import org.eclipse.openk.gridfailureinformation.repository.FailureInformationReminderMailSentRepository;
+import org.eclipse.openk.gridfailureinformation.repository.FailureInformationRepository;
+import org.eclipse.openk.gridfailureinformation.repository.FailureInformationStationRepository;
+import org.eclipse.openk.gridfailureinformation.repository.HistFailureInformationRepository;
+import org.eclipse.openk.gridfailureinformation.repository.RadiusRepository;
+import org.eclipse.openk.gridfailureinformation.repository.StationRepository;
+import org.eclipse.openk.gridfailureinformation.repository.StatusRepository;
import org.eclipse.openk.gridfailureinformation.support.MockDataHelper;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationPublicationChannelDto;
import org.junit.jupiter.api.Test;
-import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;
import org.springframework.beans.factory.annotation.Autowired;
@@ -40,13 +65,21 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
-import static org.junit.jupiter.api.Assertions.*;
-import static org.mockito.ArgumentMatchers.*;
-import static org.mockito.Mockito.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
//import java.sql.Date;
@Log4j2
@@ -90,7 +123,7 @@
public void shouldFindFailureInformations() {
Page<TblFailureInformation> mockfailurePage = MockDataHelper.mockTblFailureInformationPage();
RefStatus refStatus = MockDataHelper.mockRefStatusCreated();
- when(failureInformationRepository.findByTblFailureInformationCondensedIdIsNullOrderByFailureBeginDescIdAsc(any(Pageable.class))).thenReturn(mockfailurePage);
+ when(failureInformationRepository.findByTblFailureInformationForDisplay(anyLong(), anyLong(), any(Date.class), any(Pageable.class))).thenReturn(mockfailurePage);
when(statusRepository.findByUuid(any(UUID.class))).thenReturn(Optional.of(refStatus));
Page<FailureInformationDto> retPage = failureInformationService.findFailureInformations(Pageable.unpaged());