PoolCertificateServiceImpl.java

1
package org.cardanofoundation.explorer.api.service.impl;
2
3
import java.util.Comparator;
4
import java.util.List;
5
import java.util.Objects;
6
import java.util.stream.Collectors;
7
import java.util.stream.Stream;
8
9
import lombok.RequiredArgsConstructor;
10
11
import org.springframework.data.domain.Pageable;
12
import org.springframework.data.domain.Sort;
13
import org.springframework.stereotype.Service;
14
15
import org.cardanofoundation.explorer.api.common.enumeration.PoolActionType;
16
import org.cardanofoundation.explorer.api.common.enumeration.PoolStatus;
17
import org.cardanofoundation.explorer.api.mapper.PoolCertificateMapper;
18
import org.cardanofoundation.explorer.api.model.response.BaseFilterResponse;
19
import org.cardanofoundation.explorer.api.model.response.pool.PoolCertificateHistory;
20
import org.cardanofoundation.explorer.api.model.response.pool.TxPoolCertificateHistory;
21
import org.cardanofoundation.explorer.api.model.response.pool.projection.PoolCertificateProjection;
22
import org.cardanofoundation.explorer.api.repository.ledgersync.EpochRepository;
23
import org.cardanofoundation.explorer.api.repository.ledgersync.PoolRetireRepository;
24
import org.cardanofoundation.explorer.api.repository.ledgersync.PoolUpdateRepository;
25
import org.cardanofoundation.explorer.api.service.PoolCertificateService;
26
27
@Service
28
@RequiredArgsConstructor
29
public class PoolCertificateServiceImpl implements PoolCertificateService {
30
31
  private final PoolUpdateRepository poolUpdateRepository;
32
  private final PoolRetireRepository poolRetireRepository;
33
  private final EpochRepository epochRepository;
34
35
  private final PoolCertificateMapper poolCertificateMapper;
36
37
  @Override
38
  public BaseFilterResponse<TxPoolCertificateHistory> getTxPoolCertificateHistory(
39
      String poolViewOrHash, Pageable pageable) {
40
41
    List<TxPoolCertificateHistory> txCertificateHistories =
42
        getAllPoolCertificateHistories(poolViewOrHash).stream()
43
            .collect(Collectors.groupingBy(PoolCertificateHistory::getTxId))
44
            .values()
45
            .stream()
46
            .map(
47
                poolCertificateHistoryList -> {
48
                  TxPoolCertificateHistory txPoolCertificateHistory =
49
                      poolCertificateMapper.fromPoolCertificateHistory(
50
                          poolCertificateHistoryList.get(0));
51 1 1. lambda$getTxPoolCertificateHistory$0 : removed call to org/cardanofoundation/explorer/api/model/response/pool/TxPoolCertificateHistory::setActions → KILLED
                  txPoolCertificateHistory.setActions(
52
                      poolCertificateHistoryList.stream()
53
                          .map(PoolCertificateHistory::getActionType)
54
                          .toList());
55 1 1. lambda$getTxPoolCertificateHistory$0 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolCertificateServiceImpl::lambda$getTxPoolCertificateHistory$0 → KILLED
                  return txPoolCertificateHistory;
56
                })
57
            .collect(Collectors.toList());
58
59 1 1. getTxPoolCertificateHistory : removed call to java/util/List::sort → SURVIVED
    txCertificateHistories.sort(
60 1 1. getTxPoolCertificateHistory : negated conditional → KILLED
        Sort.Direction.DESC.equals(pageable.getSort().getOrderFor("createdAt").getDirection())
61
            ? Comparator.comparing(TxPoolCertificateHistory::getBlockTime).reversed()
62
            : Comparator.comparing(TxPoolCertificateHistory::getBlockTime));
63
64 1 1. getTxPoolCertificateHistory : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolCertificateServiceImpl::getTxPoolCertificateHistory → KILLED
    return new BaseFilterResponse<>(
65
        BaseFilterResponse.getPageImpl(txCertificateHistories, pageable));
66
  }
67
68
  @Override
69
  public PoolStatus getCurrentPoolStatus(String poolViewOrHash) {
70
    PoolCertificateHistory latestPoolUpdate =
71
        poolCertificateMapper.fromPoolCertificateProjection(
72
            poolUpdateRepository.getLastPoolUpdateByPoolHash(poolViewOrHash));
73
74
    PoolCertificateHistory latestPoolRetire =
75
        poolCertificateMapper.fromPoolCertificateProjection(
76
            poolRetireRepository.getLastPoolRetireByPoolHash(poolViewOrHash));
77
78
    PoolStatus poolStatus = null;
79 1 1. getCurrentPoolStatus : negated conditional → KILLED
    long latestPoolUpdateTxId = latestPoolUpdate == null ? -1 : latestPoolUpdate.getTxId();
80 1 1. getCurrentPoolStatus : negated conditional → KILLED
    long latestPoolRetireTxId = latestPoolRetire == null ? -1 : latestPoolRetire.getTxId();
81
    long latestPoolUpdateCertIndex =
82 1 1. getCurrentPoolStatus : negated conditional → SURVIVED
        latestPoolUpdate == null ? -1 : latestPoolUpdate.getCertIndex();
83
    long latestPoolRetireCertIndex =
84 1 1. getCurrentPoolStatus : negated conditional → SURVIVED
        latestPoolRetire == null ? -1 : latestPoolRetire.getCertIndex();
85 2 1. getCurrentPoolStatus : changed conditional boundary → SURVIVED
2. getCurrentPoolStatus : negated conditional → KILLED
    if (latestPoolUpdateTxId > latestPoolRetireTxId) {
86
      poolStatus = PoolStatus.ACTIVE;
87 5 1. getCurrentPoolStatus : changed conditional boundary → NO_COVERAGE
2. getCurrentPoolStatus : changed conditional boundary → SURVIVED
3. getCurrentPoolStatus : negated conditional → NO_COVERAGE
4. getCurrentPoolStatus : negated conditional → NO_COVERAGE
5. getCurrentPoolStatus : negated conditional → KILLED
    } else if (latestPoolUpdateTxId < latestPoolRetireTxId
88
        || (latestPoolUpdateTxId == latestPoolRetireTxId
89
            && latestPoolUpdateCertIndex < latestPoolRetireCertIndex)) {
90
      Integer currentEpochNo = epochRepository.findCurrentEpochNo().orElse(0);
91
      poolStatus =
92 2 1. getCurrentPoolStatus : changed conditional boundary → SURVIVED
2. getCurrentPoolStatus : negated conditional → KILLED
          latestPoolRetire.getCertEpochNo() > currentEpochNo
93
              ? PoolStatus.RETIRING
94
              : PoolStatus.RETIRED;
95
    }
96 1 1. getCurrentPoolStatus : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolCertificateServiceImpl::getCurrentPoolStatus → KILLED
    return poolStatus;
97
  }
98
99
  @Override
100
  public List<PoolCertificateHistory> getPoolCertificateByAction(
101
      String poolViewOrHash, PoolActionType action) {
102 1 1. getPoolCertificateByAction : replaced return value with Collections.emptyList for org/cardanofoundation/explorer/api/service/impl/PoolCertificateServiceImpl::getPoolCertificateByAction → NO_COVERAGE
    return getAllPoolCertificateHistories(poolViewOrHash).stream()
103 2 1. lambda$getPoolCertificateByAction$1 : replaced boolean return with true for org/cardanofoundation/explorer/api/service/impl/PoolCertificateServiceImpl::lambda$getPoolCertificateByAction$1 → NO_COVERAGE
2. lambda$getPoolCertificateByAction$1 : replaced boolean return with false for org/cardanofoundation/explorer/api/service/impl/PoolCertificateServiceImpl::lambda$getPoolCertificateByAction$1 → NO_COVERAGE
        .filter(poolCertificate -> poolCertificate.getActionType().equals(action))
104
        .sorted(Comparator.comparing(PoolCertificateHistory::getTxId))
105
        .toList();
106
  }
107
108
  private List<PoolCertificateHistory> getAllPoolCertificateHistories(String poolViewOrHash) {
109
    List<PoolCertificateHistory> certificateHistories =
110
        Stream.concat(
111
                poolUpdateRepository.getPoolUpdateByPoolViewOrHash(poolViewOrHash).stream(),
112
                poolRetireRepository.getPoolRetireByPoolViewOrHash(poolViewOrHash).stream())
113
            .sorted(
114
                Comparator.comparing(PoolCertificateProjection::getTxId)
115
                    .thenComparing(PoolCertificateProjection::getCertIndex))
116
            .map(poolCertificateMapper::fromPoolCertificateProjection)
117
            .toList();
118
119 2 1. getAllPoolCertificateHistories : negated conditional → KILLED
2. getAllPoolCertificateHistories : changed conditional boundary → KILLED
    for (int i = 0; i < certificateHistories.size(); i++) {
120
      PoolCertificateHistory certificateHistory = certificateHistories.get(i);
121 1 1. getAllPoolCertificateHistories : negated conditional → KILLED
      if (i == 0) {
122 1 1. getAllPoolCertificateHistories : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolCertificateHistory::setActionType → KILLED
        certificateHistory.setActionType(PoolActionType.POOL_REGISTRATION);
123
        continue;
124
      }
125 1 1. getAllPoolCertificateHistories : negated conditional → KILLED
      if (!Objects.isNull(certificateHistory.getPoolRetireId())) {
126 1 1. getAllPoolCertificateHistories : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolCertificateHistory::setActionType → KILLED
        certificateHistory.setActionType(PoolActionType.POOL_DEREGISTRATION);
127 1 1. getAllPoolCertificateHistories : negated conditional → KILLED
      } else if (!Objects.isNull(certificateHistory.getPoolUpdateId())) {
128 1 1. getAllPoolCertificateHistories : Replaced integer subtraction with addition → KILLED
        PoolCertificateHistory previousCertificateHistory = certificateHistories.get(i - 1);
129 1 1. getAllPoolCertificateHistories : negated conditional → KILLED
        if (previousCertificateHistory.getActionType().equals(PoolActionType.POOL_DEREGISTRATION)
130 2 1. getAllPoolCertificateHistories : changed conditional boundary → SURVIVED
2. getAllPoolCertificateHistories : negated conditional → KILLED
            && certificateHistory.getTxEpochNo() >= previousCertificateHistory.getCertEpochNo()) {
131 1 1. getAllPoolCertificateHistories : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolCertificateHistory::setActionType → KILLED
          certificateHistory.setActionType(PoolActionType.POOL_REGISTRATION);
132
        } else {
133 1 1. getAllPoolCertificateHistories : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolCertificateHistory::setActionType → KILLED
          certificateHistory.setActionType(PoolActionType.POOL_UPDATE);
134
        }
135
      }
136
    }
137
138 1 1. getAllPoolCertificateHistories : replaced return value with Collections.emptyList for org/cardanofoundation/explorer/api/service/impl/PoolCertificateServiceImpl::getAllPoolCertificateHistories → KILLED
    return certificateHistories;
139
  }
140
}

Mutations

51

1.1
Location : lambda$getTxPoolCertificateHistory$0
Killed by : org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest]/[method:getTxPoolCertificateHistory_shouldReturnTxPoolCertificateHistory()]
removed call to org/cardanofoundation/explorer/api/model/response/pool/TxPoolCertificateHistory::setActions → KILLED

55

1.1
Location : lambda$getTxPoolCertificateHistory$0
Killed by : org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest]/[method:getTxPoolCertificateHistory_shouldReturnTxPoolCertificateHistory()]
replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolCertificateServiceImpl::lambda$getTxPoolCertificateHistory$0 → KILLED

59

1.1
Location : getTxPoolCertificateHistory
Killed by : none
removed call to java/util/List::sort → SURVIVED

60

1.1
Location : getTxPoolCertificateHistory
Killed by : org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest]/[method:getTxPoolCertificateHistory_shouldReturnTxPoolCertificateHistory()]
negated conditional → KILLED

64

1.1
Location : getTxPoolCertificateHistory
Killed by : org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest]/[method:getTxPoolCertificateHistory_shouldReturnTxPoolCertificateHistory()]
replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolCertificateServiceImpl::getTxPoolCertificateHistory → KILLED

79

1.1
Location : getCurrentPoolStatus
Killed by : org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest]/[method:getCurrentPoolStatus_shouldReturnPoolActive()]
negated conditional → KILLED

80

1.1
Location : getCurrentPoolStatus
Killed by : org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest]/[method:getCurrentPoolStatus_shouldReturnPoolRetired()]
negated conditional → KILLED

82

1.1
Location : getCurrentPoolStatus
Killed by : none
negated conditional → SURVIVED

84

1.1
Location : getCurrentPoolStatus
Killed by : none
negated conditional → SURVIVED

85

1.1
Location : getCurrentPoolStatus
Killed by : org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest]/[method:getCurrentPoolStatus_shouldReturnPoolActive()]
negated conditional → KILLED

2.2
Location : getCurrentPoolStatus
Killed by : none
changed conditional boundary → SURVIVED

87

1.1
Location : getCurrentPoolStatus
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : getCurrentPoolStatus
Killed by : none
changed conditional boundary → SURVIVED

3.3
Location : getCurrentPoolStatus
Killed by : none
negated conditional → NO_COVERAGE

4.4
Location : getCurrentPoolStatus
Killed by : org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest]/[method:getCurrentPoolStatus_shouldReturnPoolRetired()]
negated conditional → KILLED

5.5
Location : getCurrentPoolStatus
Killed by : none
negated conditional → NO_COVERAGE

92

1.1
Location : getCurrentPoolStatus
Killed by : org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest]/[method:getCurrentPoolStatus_shouldReturnPoolRetired()]
negated conditional → KILLED

2.2
Location : getCurrentPoolStatus
Killed by : none
changed conditional boundary → SURVIVED

96

1.1
Location : getCurrentPoolStatus
Killed by : org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest]/[method:getCurrentPoolStatus_shouldReturnPoolActive()]
replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolCertificateServiceImpl::getCurrentPoolStatus → KILLED

102

1.1
Location : getPoolCertificateByAction
Killed by : none
replaced return value with Collections.emptyList for org/cardanofoundation/explorer/api/service/impl/PoolCertificateServiceImpl::getPoolCertificateByAction → NO_COVERAGE

103

1.1
Location : lambda$getPoolCertificateByAction$1
Killed by : none
replaced boolean return with true for org/cardanofoundation/explorer/api/service/impl/PoolCertificateServiceImpl::lambda$getPoolCertificateByAction$1 → NO_COVERAGE

2.2
Location : lambda$getPoolCertificateByAction$1
Killed by : none
replaced boolean return with false for org/cardanofoundation/explorer/api/service/impl/PoolCertificateServiceImpl::lambda$getPoolCertificateByAction$1 → NO_COVERAGE

119

1.1
Location : getAllPoolCertificateHistories
Killed by : org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest]/[method:getTxPoolCertificateHistory_shouldReturnTxPoolCertificateHistory()]
negated conditional → KILLED

2.2
Location : getAllPoolCertificateHistories
Killed by : org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest]/[method:getTxPoolCertificateHistory_shouldReturnTxPoolCertificateHistory()]
changed conditional boundary → KILLED

121

1.1
Location : getAllPoolCertificateHistories
Killed by : org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest]/[method:getTxPoolCertificateHistory_shouldReturnTxPoolCertificateHistory()]
negated conditional → KILLED

122

1.1
Location : getAllPoolCertificateHistories
Killed by : org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest]/[method:getTxPoolCertificateHistory_shouldReturnTxPoolCertificateHistory()]
removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolCertificateHistory::setActionType → KILLED

125

1.1
Location : getAllPoolCertificateHistories
Killed by : org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest]/[method:getTxPoolCertificateHistory_shouldReturnTxPoolCertificateHistory()]
negated conditional → KILLED

126

1.1
Location : getAllPoolCertificateHistories
Killed by : org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest]/[method:getTxPoolCertificateHistory_shouldReturnTxPoolCertificateHistory()]
removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolCertificateHistory::setActionType → KILLED

127

1.1
Location : getAllPoolCertificateHistories
Killed by : org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest]/[method:getTxPoolCertificateHistory_shouldReturnTxPoolCertificateHistory()]
negated conditional → KILLED

128

1.1
Location : getAllPoolCertificateHistories
Killed by : org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest]/[method:getTxPoolCertificateHistory_shouldReturnTxPoolCertificateHistory()]
Replaced integer subtraction with addition → KILLED

129

1.1
Location : getAllPoolCertificateHistories
Killed by : org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest]/[method:getTxPoolCertificateHistory_shouldReturnTxPoolCertificateHistory()]
negated conditional → KILLED

130

1.1
Location : getAllPoolCertificateHistories
Killed by : org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest]/[method:getTxPoolCertificateHistory_shouldReturnTxPoolCertificateHistory()]
negated conditional → KILLED

2.2
Location : getAllPoolCertificateHistories
Killed by : none
changed conditional boundary → SURVIVED

131

1.1
Location : getAllPoolCertificateHistories
Killed by : org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest]/[method:getTxPoolCertificateHistory_shouldReturnTxPoolCertificateHistory()]
removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolCertificateHistory::setActionType → KILLED

133

1.1
Location : getAllPoolCertificateHistories
Killed by : org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest]/[method:getTxPoolCertificateHistory_shouldReturnTxPoolCertificateHistory()]
removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolCertificateHistory::setActionType → KILLED

138

1.1
Location : getAllPoolCertificateHistories
Killed by : org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolCertificateServiceTest]/[method:getTxPoolCertificateHistory_shouldReturnTxPoolCertificateHistory()]
replaced return value with Collections.emptyList for org/cardanofoundation/explorer/api/service/impl/PoolCertificateServiceImpl::getAllPoolCertificateHistories → KILLED

Active mutators

Tests examined


Report generated by PIT 1.14.2