Commit 511fd550 authored by dietricf's avatar dietricf
Browse files

SI-2280 Anzeige der FailureInfos nicht mit Status Beendet oder cancelled wenn...

SI-2280 Anzeige der FailureInfos nicht mit Status Beendet oder cancelled wenn resupplied mehr als 4 Wochen in der Vergangenheit liegt
parent 554276bb
......@@ -23,13 +23,19 @@ import org.springframework.data.repository.PagingAndSortingRepository;
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);
......
......@@ -202,8 +202,8 @@ public class ExportService {
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());
......
......@@ -40,6 +40,9 @@ import java.util.stream.Collectors;
@Service
public class FailureInformationReminderMailSentService {
@Autowired
private FailureInformationService failureInformationService;
@Autowired
private FailureInformationReminderMailSentRepository failureInformationReminderMailSentRepository;
......@@ -62,8 +65,8 @@ public class FailureInformationReminderMailSentService {
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);
......
......@@ -28,8 +28,30 @@ import org.eclipse.openk.gridfailureinformation.exceptions.NotFoundException;
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 org.springframework.transaction.annotation.Transactional;
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 class FailureInformationService {
}
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 @@ public class FailureInformationService {
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
......
......@@ -56,6 +56,9 @@ public class FailureInformationReminderMailSentServiceTest {
@Autowired
private FailureInformationReminderMailSentService failureInformationReminderMailSentService;
@MockBean
private FailureInformationService failureInformationService;
@MockBean
private FailureInformationRepository failureInformationRepository;
......@@ -77,7 +80,7 @@ public class FailureInformationReminderMailSentServiceTest {
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 @@ public class FailureInformationReminderMailSentServiceTest {
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 @@ public class FailureInformationReminderMailSentServiceTest {
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 @@ public class FailureInformationReminderMailSentServiceTest {
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 @@ public class FailureInformationReminderMailSentServiceTest {
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 @@ public class FailureInformationReminderMailSentServiceTest {
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 @@ public class FailureInformationReminderMailSentServiceTest {
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);
......
......@@ -21,13 +21,38 @@ import org.eclipse.openk.gridfailureinformation.constants.Constants;
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 org.springframework.test.context.ContextConfiguration;
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 class FailureInformationServiceTest {
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());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment