PoolRegistrationServiceImpl.java

1
package org.cardanofoundation.explorer.api.service.impl;
2
3
import java.sql.Timestamp;
4
import java.util.Collections;
5
import java.util.HashMap;
6
import java.util.List;
7
import java.util.Map;
8
import java.util.Objects;
9
import java.util.Set;
10
import java.util.function.Function;
11
import java.util.stream.Collectors;
12
13
import lombok.RequiredArgsConstructor;
14
import lombok.extern.log4j.Log4j2;
15
16
import org.springframework.data.domain.Page;
17
import org.springframework.data.domain.Pageable;
18
import org.springframework.stereotype.Service;
19
20
import org.cardanofoundation.explorer.api.model.response.BaseFilterResponse;
21
import org.cardanofoundation.explorer.api.model.response.pool.PoolTxResponse;
22
import org.cardanofoundation.explorer.api.model.response.pool.projection.PoolOwnerProjection;
23
import org.cardanofoundation.explorer.api.model.response.pool.projection.TxBlockEpochProjection;
24
import org.cardanofoundation.explorer.api.projection.TxIOProjection;
25
import org.cardanofoundation.explorer.api.repository.ledgersync.PoolOwnerRepository;
26
import org.cardanofoundation.explorer.api.repository.ledgersync.PoolRetireRepository;
27
import org.cardanofoundation.explorer.api.repository.ledgersync.PoolUpdateRepository;
28
import org.cardanofoundation.explorer.api.repository.ledgersync.TxRepository;
29
import org.cardanofoundation.explorer.api.service.PoolRegistrationService;
30
31
@Service
32
@RequiredArgsConstructor
33
@Log4j2
34
public class PoolRegistrationServiceImpl implements PoolRegistrationService {
35
36
  private final PoolUpdateRepository poolUpdateRepository;
37
38
  private final PoolRetireRepository poolRetireRepository;
39
40
  private final PoolOwnerRepository poolOwnerRepository;
41
42
  private final TxRepository txRepository;
43
44
  @Override
45
  public BaseFilterResponse<PoolTxResponse> getDataForPoolRegistration(Pageable pageable) {
46
    BaseFilterResponse<PoolTxResponse> response = new BaseFilterResponse<>();
47
    Page<TxBlockEpochProjection> trxBlockEpochPage =
48
        poolUpdateRepository.getDataForPoolRegistration(pageable);
49
    List<PoolTxResponse> poolTxRes = trxBlockEpochPage.stream().map(PoolTxResponse::new).toList();
50 1 1. getDataForPoolRegistration : removed call to org/cardanofoundation/explorer/api/service/impl/PoolRegistrationServiceImpl::setValueForPoolRegistration → KILLED
    setValueForPoolRegistration(poolTxRes);
51 1 1. getDataForPoolRegistration : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setData → KILLED
    response.setData(poolTxRes);
52 1 1. getDataForPoolRegistration : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalItems → KILLED
    response.setTotalItems(trxBlockEpochPage.getTotalElements());
53 1 1. getDataForPoolRegistration : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setCurrentPage → SURVIVED
    response.setCurrentPage(pageable.getPageNumber());
54 1 1. getDataForPoolRegistration : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalPages → SURVIVED
    response.setTotalPages(trxBlockEpochPage.getTotalPages());
55 1 1. getDataForPoolRegistration : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolRegistrationServiceImpl::getDataForPoolRegistration → KILLED
    return response;
56
  }
57
58
  @Override
59
  public BaseFilterResponse<PoolTxResponse> getDataForPoolDeRegistration(Pageable pageable) {
60
    BaseFilterResponse<PoolTxResponse> response = new BaseFilterResponse<>();
61
    Page<TxBlockEpochProjection> trxBlockEpochPage =
62
        poolRetireRepository.getDataForPoolDeRegistration(pageable);
63
    List<PoolTxResponse> poolTxRes = trxBlockEpochPage.stream().map(PoolTxResponse::new).toList();
64 1 1. getDataForPoolDeRegistration : removed call to org/cardanofoundation/explorer/api/service/impl/PoolRegistrationServiceImpl::setValueForPoolRegistration → KILLED
    setValueForPoolRegistration(poolTxRes);
65 1 1. getDataForPoolDeRegistration : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setData → KILLED
    response.setData(poolTxRes);
66 1 1. getDataForPoolDeRegistration : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalItems → KILLED
    response.setTotalItems(trxBlockEpochPage.getTotalElements());
67 1 1. getDataForPoolDeRegistration : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setCurrentPage → SURVIVED
    response.setCurrentPage(pageable.getPageNumber());
68 1 1. getDataForPoolDeRegistration : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalPages → SURVIVED
    response.setTotalPages(trxBlockEpochPage.getTotalPages());
69 1 1. getDataForPoolDeRegistration : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolRegistrationServiceImpl::getDataForPoolDeRegistration → KILLED
    return response;
70
  }
71
72
  /**
73
   * set value for pool registration list
74
   *
75
   * <p>
76
   */
77
  private void setValueForPoolRegistration(List<PoolTxResponse> poolTxRes) {
78
    Set<Long> poolIds =
79
        poolTxRes.stream().map(PoolTxResponse::getPoolId).collect(Collectors.toSet());
80
    Set<Long> txIds = poolTxRes.stream().map(PoolTxResponse::getTxId).collect(Collectors.toSet());
81
    List<TxIOProjection> txList = txRepository.findTxIn(txIds);
82
    Map<Long, TxIOProjection> txMap =
83
        txList.stream().collect(Collectors.toMap(TxIOProjection::getId, Function.identity()));
84
    List<PoolOwnerProjection> blockOwnerProjections = poolOwnerRepository.getStakeKeyList(poolIds);
85
    Map<Long, List<PoolOwnerProjection>> poolOwnerProjectionMap =
86
        blockOwnerProjections.stream()
87
            .collect(Collectors.groupingBy(PoolOwnerProjection::getPoolId));
88
    Map<Long, List<String>> stakeKeyStrMap = new HashMap<>();
89 1 1. setValueForPoolRegistration : removed call to java/util/Map::forEach → KILLED
    poolOwnerProjectionMap.forEach(
90
        (k, v) ->
91
            stakeKeyStrMap.put(
92
                k, v.stream().map(PoolOwnerProjection::getAddress).collect(Collectors.toList())));
93 1 1. setValueForPoolRegistration : removed call to java/util/List::forEach → KILLED
    poolTxRes.forEach(
94
        pool -> {
95 1 1. lambda$setValueForPoolRegistration$1 : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolTxResponse::setTxHash → SURVIVED
          pool.setTxHash(txMap.get(pool.getTxId()).getHash());
96 1 1. lambda$setValueForPoolRegistration$1 : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolTxResponse::setBlock → SURVIVED
          pool.setBlock(txMap.get(pool.getTxId()).getBlockNo());
97 1 1. lambda$setValueForPoolRegistration$1 : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolTxResponse::setEpoch → SURVIVED
          pool.setEpoch(txMap.get(pool.getTxId()).getEpochNo());
98 1 1. lambda$setValueForPoolRegistration$1 : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolTxResponse::setEpochSlotNo → SURVIVED
          pool.setEpochSlotNo(txMap.get(pool.getTxId()).getEpochSlotNo());
99 1 1. lambda$setValueForPoolRegistration$1 : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolTxResponse::setSlotNo → SURVIVED
          pool.setSlotNo(txMap.get(pool.getTxId()).getSlot());
100 1 1. lambda$setValueForPoolRegistration$1 : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolTxResponse::setTxTime → SURVIVED
          pool.setTxTime(Timestamp.valueOf(txMap.get(pool.getTxId()).getTime()));
101
          List<String> stakeKeys = stakeKeyStrMap.get(pool.getPoolId());
102 1 1. lambda$setValueForPoolRegistration$1 : negated conditional → KILLED
          if (Objects.nonNull(stakeKeys)) {
103 1 1. lambda$setValueForPoolRegistration$1 : removed call to java/util/Collections::sort → SURVIVED
            Collections.sort(stakeKeys);
104 1 1. lambda$setValueForPoolRegistration$1 : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolTxResponse::setStakeKey → KILLED
            pool.setStakeKey(stakeKeys);
105
          }
106
        });
107
  }
108
}

Mutations

50

1.1
Location : getDataForPoolRegistration
Killed by : org.cardanofoundation.explorer.api.service.PoolRegistrationServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolRegistrationServiceTest]/[method:whenPoolRegistrationIsEmpty_returnEmptyPage()]
removed call to org/cardanofoundation/explorer/api/service/impl/PoolRegistrationServiceImpl::setValueForPoolRegistration → KILLED

51

1.1
Location : getDataForPoolRegistration
Killed by : org.cardanofoundation.explorer.api.service.PoolRegistrationServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolRegistrationServiceTest]/[method:whenPoolRegistrationIsEmpty_returnEmptyPage()]
removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setData → KILLED

52

1.1
Location : getDataForPoolRegistration
Killed by : org.cardanofoundation.explorer.api.service.PoolRegistrationServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolRegistrationServiceTest]/[method:whenPoolRegistrationIsNotEmptyAndStakeKeyIsEmpty_returnResponseWithStakeKeyIsNull()]
removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalItems → KILLED

53

1.1
Location : getDataForPoolRegistration
Killed by : none
removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setCurrentPage → SURVIVED

54

1.1
Location : getDataForPoolRegistration
Killed by : none
removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalPages → SURVIVED

55

1.1
Location : getDataForPoolRegistration
Killed by : org.cardanofoundation.explorer.api.service.PoolRegistrationServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolRegistrationServiceTest]/[method:whenPoolRegistrationIsEmpty_returnEmptyPage()]
replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolRegistrationServiceImpl::getDataForPoolRegistration → KILLED

64

1.1
Location : getDataForPoolDeRegistration
Killed by : org.cardanofoundation.explorer.api.service.PoolRegistrationServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolRegistrationServiceTest]/[method:whenPoolDeRegistrationIsNotEmptyAndStakeKeyIsEmpty_returnResponseWithStakeKeyIsNull()]
removed call to org/cardanofoundation/explorer/api/service/impl/PoolRegistrationServiceImpl::setValueForPoolRegistration → KILLED

65

1.1
Location : getDataForPoolDeRegistration
Killed by : org.cardanofoundation.explorer.api.service.PoolRegistrationServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolRegistrationServiceTest]/[method:whenPoolDeRegistrationIsNotEmptyAndStakeKeyIsEmpty_returnResponseWithStakeKeyIsNull()]
removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setData → KILLED

66

1.1
Location : getDataForPoolDeRegistration
Killed by : org.cardanofoundation.explorer.api.service.PoolRegistrationServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolRegistrationServiceTest]/[method:whenPoolDeRegistrationIsNotEmptyAndStakeKeyIsEmpty_returnResponseWithStakeKeyIsNull()]
removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalItems → KILLED

67

1.1
Location : getDataForPoolDeRegistration
Killed by : none
removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setCurrentPage → SURVIVED

68

1.1
Location : getDataForPoolDeRegistration
Killed by : none
removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalPages → SURVIVED

69

1.1
Location : getDataForPoolDeRegistration
Killed by : org.cardanofoundation.explorer.api.service.PoolRegistrationServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolRegistrationServiceTest]/[method:whenPoolDeRegistrationIsNotEmptyAndStakeKeyIsEmpty_returnResponseWithStakeKeyIsNull()]
replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolRegistrationServiceImpl::getDataForPoolDeRegistration → KILLED

89

1.1
Location : setValueForPoolRegistration
Killed by : org.cardanofoundation.explorer.api.service.PoolRegistrationServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolRegistrationServiceTest]/[method:whenPoolDeRegistrationIsNotEmpty_returnResponse()]
removed call to java/util/Map::forEach → KILLED

93

1.1
Location : setValueForPoolRegistration
Killed by : org.cardanofoundation.explorer.api.service.PoolRegistrationServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolRegistrationServiceTest]/[method:whenPoolRegistrationIsNotEmptyAndStakeKeyIsEmpty_returnResponseWithStakeKeyIsNull()]
removed call to java/util/List::forEach → KILLED

95

1.1
Location : lambda$setValueForPoolRegistration$1
Killed by : none
removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolTxResponse::setTxHash → SURVIVED

96

1.1
Location : lambda$setValueForPoolRegistration$1
Killed by : none
removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolTxResponse::setBlock → SURVIVED

97

1.1
Location : lambda$setValueForPoolRegistration$1
Killed by : none
removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolTxResponse::setEpoch → SURVIVED

98

1.1
Location : lambda$setValueForPoolRegistration$1
Killed by : none
removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolTxResponse::setEpochSlotNo → SURVIVED

99

1.1
Location : lambda$setValueForPoolRegistration$1
Killed by : none
removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolTxResponse::setSlotNo → SURVIVED

100

1.1
Location : lambda$setValueForPoolRegistration$1
Killed by : none
removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolTxResponse::setTxTime → SURVIVED

102

1.1
Location : lambda$setValueForPoolRegistration$1
Killed by : org.cardanofoundation.explorer.api.service.PoolRegistrationServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolRegistrationServiceTest]/[method:whenPoolRegistrationIsNotEmptyAndStakeKeyIsEmpty_returnResponseWithStakeKeyIsNull()]
negated conditional → KILLED

103

1.1
Location : lambda$setValueForPoolRegistration$1
Killed by : none
removed call to java/util/Collections::sort → SURVIVED

104

1.1
Location : lambda$setValueForPoolRegistration$1
Killed by : org.cardanofoundation.explorer.api.service.PoolRegistrationServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.PoolRegistrationServiceTest]/[method:whenPoolDeRegistrationIsNotEmpty_returnResponse()]
removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolTxResponse::setStakeKey → KILLED

Active mutators

Tests examined


Report generated by PIT 1.14.2