1 | package org.cardanofoundation.explorer.api.service.impl; | |
2 | ||
3 | import java.math.BigDecimal; | |
4 | import java.math.BigInteger; | |
5 | import java.math.RoundingMode; | |
6 | import java.sql.Timestamp; | |
7 | import java.time.LocalDateTime; | |
8 | import java.time.ZoneOffset; | |
9 | import java.util.ArrayList; | |
10 | import java.util.Collections; | |
11 | import java.util.Comparator; | |
12 | import java.util.HashSet; | |
13 | import java.util.List; | |
14 | import java.util.Map; | |
15 | import java.util.Objects; | |
16 | import java.util.Optional; | |
17 | import java.util.Set; | |
18 | import java.util.concurrent.CompletableFuture; | |
19 | import java.util.function.Function; | |
20 | import java.util.stream.Collectors; | |
21 | ||
22 | import lombok.RequiredArgsConstructor; | |
23 | import lombok.extern.log4j.Log4j2; | |
24 | ||
25 | import org.springframework.beans.factory.annotation.Value; | |
26 | import org.springframework.data.domain.Page; | |
27 | import org.springframework.data.domain.PageImpl; | |
28 | import org.springframework.data.domain.PageRequest; | |
29 | import org.springframework.data.domain.Pageable; | |
30 | import org.springframework.data.domain.Sort; | |
31 | import org.springframework.data.redis.core.RedisTemplate; | |
32 | import org.springframework.stereotype.Service; | |
33 | ||
34 | import com.google.common.collect.Lists; | |
35 | import com.google.gson.Gson; | |
36 | import com.google.gson.JsonObject; | |
37 | ||
38 | import org.cardanofoundation.explorer.api.common.constant.CommonConstant; | |
39 | import org.cardanofoundation.explorer.api.exception.BusinessCode; | |
40 | import org.cardanofoundation.explorer.api.exception.NoContentException; | |
41 | import org.cardanofoundation.explorer.api.model.request.pool.PoolListFilter; | |
42 | import org.cardanofoundation.explorer.api.model.response.BaseFilterResponse; | |
43 | import org.cardanofoundation.explorer.api.model.response.DelegationResponse; | |
44 | import org.cardanofoundation.explorer.api.model.response.PoolDetailDelegatorResponse; | |
45 | import org.cardanofoundation.explorer.api.model.response.address.DelegationPoolResponse; | |
46 | import org.cardanofoundation.explorer.api.model.response.dashboard.EpochSummary; | |
47 | import org.cardanofoundation.explorer.api.model.response.pool.DelegationHeaderResponse; | |
48 | import org.cardanofoundation.explorer.api.model.response.pool.PoolDetailEpochResponse; | |
49 | import org.cardanofoundation.explorer.api.model.response.pool.PoolDetailHeaderResponse; | |
50 | import org.cardanofoundation.explorer.api.model.response.pool.PoolResponse; | |
51 | import org.cardanofoundation.explorer.api.model.response.pool.chart.DelegatorChartList; | |
52 | import org.cardanofoundation.explorer.api.model.response.pool.chart.DelegatorChartResponse; | |
53 | import org.cardanofoundation.explorer.api.model.response.pool.chart.EpochChartList; | |
54 | import org.cardanofoundation.explorer.api.model.response.pool.chart.EpochChartResponse; | |
55 | import org.cardanofoundation.explorer.api.model.response.pool.chart.PoolDetailAnalyticsResponse; | |
56 | import org.cardanofoundation.explorer.api.model.response.pool.projection.BasePoolChartProjection; | |
57 | import org.cardanofoundation.explorer.api.model.response.pool.projection.DelegatorChartProjection; | |
58 | import org.cardanofoundation.explorer.api.model.response.pool.projection.EpochChartProjection; | |
59 | import org.cardanofoundation.explorer.api.model.response.pool.projection.PoolCountProjection; | |
60 | import org.cardanofoundation.explorer.api.model.response.pool.projection.PoolDetailDelegatorProjection; | |
61 | import org.cardanofoundation.explorer.api.model.response.pool.projection.PoolDetailEpochProjection; | |
62 | import org.cardanofoundation.explorer.api.model.response.pool.projection.PoolDetailUpdateProjection; | |
63 | import org.cardanofoundation.explorer.api.model.response.pool.projection.PoolHistoryKoiosProjection; | |
64 | import org.cardanofoundation.explorer.api.model.response.pool.projection.PoolInfoKoiosProjection; | |
65 | import org.cardanofoundation.explorer.api.model.response.pool.projection.PoolListProjection; | |
66 | import org.cardanofoundation.explorer.api.projection.DelegationProjection; | |
67 | import org.cardanofoundation.explorer.api.projection.PoolDelegationSummaryProjection; | |
68 | import org.cardanofoundation.explorer.api.projection.StakeAddressProjection; | |
69 | import org.cardanofoundation.explorer.api.projection.TxIOProjection; | |
70 | import org.cardanofoundation.explorer.api.repository.ledgersync.AggregatePoolInfoRepository; | |
71 | import org.cardanofoundation.explorer.api.repository.ledgersync.BlockRepository; | |
72 | import org.cardanofoundation.explorer.api.repository.ledgersync.DelegationRepository; | |
73 | import org.cardanofoundation.explorer.api.repository.ledgersync.EpochRepository; | |
74 | import org.cardanofoundation.explorer.api.repository.ledgersync.EpochStakeRepository; | |
75 | import org.cardanofoundation.explorer.api.repository.ledgersync.PoolHashRepository; | |
76 | import org.cardanofoundation.explorer.api.repository.ledgersync.PoolHistoryRepository; | |
77 | import org.cardanofoundation.explorer.api.repository.ledgersync.PoolInfoRepository; | |
78 | import org.cardanofoundation.explorer.api.repository.ledgersync.PoolUpdateRepository; | |
79 | import org.cardanofoundation.explorer.api.repository.ledgersync.RewardRepository; | |
80 | import org.cardanofoundation.explorer.api.repository.ledgersync.StakeAddressRepository; | |
81 | import org.cardanofoundation.explorer.api.repository.ledgersync.TxRepository; | |
82 | import org.cardanofoundation.explorer.api.repository.ledgersync.WithdrawalRepository; | |
83 | import org.cardanofoundation.explorer.api.repository.ledgersyncagg.StakeAddressBalanceRepository; | |
84 | import org.cardanofoundation.explorer.api.service.DelegationService; | |
85 | import org.cardanofoundation.explorer.api.service.EpochService; | |
86 | import org.cardanofoundation.explorer.api.service.FetchRewardDataService; | |
87 | import org.cardanofoundation.explorer.api.service.PoolCertificateService; | |
88 | import org.cardanofoundation.explorer.api.util.DataUtil; | |
89 | import org.cardanofoundation.explorer.common.entity.ledgersync.AggregatePoolInfo; | |
90 | import org.cardanofoundation.explorer.common.entity.ledgersync.BaseEntity_; | |
91 | import org.cardanofoundation.explorer.common.entity.ledgersync.Delegation_; | |
92 | import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHash; | |
93 | import org.cardanofoundation.explorer.common.entity.ledgersync.PoolOfflineData_; | |
94 | import org.cardanofoundation.explorer.common.exception.BusinessException; | |
95 | import org.cardanofoundation.explorer.common.exception.CommonErrorCode; | |
96 | ||
97 | @Service | |
98 | @RequiredArgsConstructor | |
99 | @Log4j2 | |
100 | public class DelegationServiceImpl implements DelegationService { | |
101 | ||
102 | private final DelegationRepository delegationRepository; | |
103 | ||
104 | private final BlockRepository blockRepository; | |
105 | ||
106 | private final EpochRepository epochRepository; | |
107 | ||
108 | private final EpochStakeRepository epochStakeRepository; | |
109 | ||
110 | private final PoolHashRepository poolHashRepository; | |
111 | ||
112 | private final PoolUpdateRepository poolUpdateRepository; | |
113 | ||
114 | private final RewardRepository rewardRepository; | |
115 | ||
116 | private final PoolInfoRepository poolInfoRepository; | |
117 | ||
118 | private final PoolHistoryRepository poolHistoryRepository; | |
119 | ||
120 | private final RedisTemplate<String, Object> redisTemplate; | |
121 | ||
122 | private final FetchRewardDataService fetchRewardDataService; | |
123 | ||
124 | private final StakeAddressRepository stakeAddressRepository; | |
125 | ||
126 | private final WithdrawalRepository withdrawalRepository; | |
127 | private final StakeAddressBalanceRepository stakeAddressBalanceRepository; | |
128 | ||
129 | private final TxRepository txRepository; | |
130 | ||
131 | private final EpochService epochService; | |
132 | ||
133 | private final AggregatePoolInfoRepository aggregatePoolInfoRepository; | |
134 | ||
135 | private final PoolCertificateService poolCertificateService; | |
136 | ||
137 | private static final int MAX_TOTAL_ELEMENTS = 1000; | |
138 | ||
139 | @Value("${spring.data.web.pageable.default-page-size}") | |
140 | private int defaultSize; | |
141 | ||
142 | @Value("${application.network}") | |
143 | private String network; | |
144 | ||
145 | @Override | |
146 | public BaseFilterResponse<DelegationResponse> getDelegations(Pageable pageable) { | |
147 | Page<Long> txIdPage = delegationRepository.findAllDelegations(pageable); | |
148 | List<TxIOProjection> txs = txRepository.findTxIn(txIdPage.getContent()); | |
149 | Map<Long, TxIOProjection> txMap = | |
150 | txs.stream().collect(Collectors.toMap(TxIOProjection::getId, Function.identity())); | |
151 | List<DelegationProjection> delegations = | |
152 | delegationRepository.findDelegationByTxIdIn(txIdPage.getContent()); | |
153 | Map<Long, List<String>> delegationStakeKeyMap = | |
154 | delegations.stream() | |
155 | .collect( | |
156 | Collectors.groupingBy( | |
157 | DelegationProjection::getTxId, | |
158 | Collectors.mapping( | |
159 | DelegationProjection::getStakeAddress, Collectors.toList()))); | |
160 | Map<Long, Set<DelegationPoolResponse>> delegationPoolMap = | |
161 | delegations.stream() | |
162 | .collect( | |
163 | Collectors.groupingBy( | |
164 | DelegationProjection::getTxId, | |
165 | Collectors.mapping( | |
166 | item -> | |
167 |
1
1. lambda$getDelegations$0 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::lambda$getDelegations$0 → SURVIVED |
DelegationPoolResponse.builder() |
168 | .poolName(item.getPoolName()) | |
169 | .tickerName(item.getTickerName()) | |
170 | .poolId(item.getPoolView()) | |
171 | .build(), | |
172 | Collectors.toSet()))); | |
173 | List<DelegationResponse> responses = | |
174 | txIdPage.stream() | |
175 | .map( | |
176 | item -> | |
177 |
1
1. lambda$getDelegations$1 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::lambda$getDelegations$1 → KILLED |
DelegationResponse.builder() |
178 | .txHash(txMap.get(item).getHash()) | |
179 | .blockNo(txMap.get(item).getBlockNo()) | |
180 | .epochNo(txMap.get(item).getEpochNo()) | |
181 | .epochSlotNo(txMap.get(item).getEpochSlotNo()) | |
182 | .time(txMap.get(item).getTime()) | |
183 | .epochSlotNo(txMap.get(item).getEpochSlotNo()) | |
184 | .slotNo(txMap.get(item).getSlot()) | |
185 | .stakeKeys(delegationStakeKeyMap.get(item)) | |
186 | .pools(delegationPoolMap.get(item).stream().toList()) | |
187 | .build()) | |
188 | .toList(); | |
189 |
1
1. getDelegations : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::getDelegations → KILLED |
return new BaseFilterResponse<>(txIdPage, responses); |
190 | } | |
191 | ||
192 | @Override | |
193 | public DelegationHeaderResponse getDataForDelegationHeader() { | |
194 | EpochSummary epoch = epochService.getCurrentEpochSummary(); | |
195 | Integer epochNo = epoch.getNo(); | |
196 | Object poolActiveObj = | |
197 | redisTemplate.opsForValue().get(CommonConstant.REDIS_POOL_ACTIVATE + network); | |
198 | Object poolInActiveObj = | |
199 | redisTemplate.opsForValue().get(CommonConstant.REDIS_POOL_INACTIVATE + network); | |
200 | LocalDateTime endTime = epoch.getEndTime(); | |
201 | Integer slot = epoch.getSlot(); | |
202 | long countDownTime = | |
203 | Timestamp.valueOf(endTime).getTime() | |
204 |
1
1. getDataForDelegationHeader : Replaced long subtraction with addition → SURVIVED |
- Timestamp.valueOf(LocalDateTime.now(ZoneOffset.UTC)).getTime(); |
205 | BigInteger liveStake; | |
206 | boolean useKoiOs = fetchRewardDataService.useKoios(); | |
207 |
1
1. getDataForDelegationHeader : negated conditional → KILLED |
if (useKoiOs) { |
208 | log.info("using koiOs flow..."); | |
209 |
1
1. getDataForDelegationHeader : negated conditional → KILLED |
if (Boolean.FALSE.equals(fetchRewardDataService.checkAdaPots(epochNo))) { |
210 | fetchRewardDataService.fetchAdaPots(List.of(epochNo)); | |
211 | } | |
212 | liveStake = poolInfoRepository.getTotalLiveStake(epochNo); | |
213 | } else { | |
214 | log.info("using base flow..."); | |
215 | liveStake = null; | |
216 | } | |
217 | Object delegatorCached = | |
218 | redisTemplate.opsForValue().get(CommonConstant.REDIS_TOTAL_DELEGATOR + network); | |
219 | Integer delegators = | |
220 |
1
1. getDataForDelegationHeader : negated conditional → KILLED |
Objects.nonNull(delegatorCached) |
221 | ? Integer.parseInt(String.valueOf(delegatorCached)) | |
222 | : CommonConstant.ZERO; | |
223 |
1
1. getDataForDelegationHeader : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::getDataForDelegationHeader → KILLED |
return DelegationHeaderResponse.builder() |
224 | .epochNo(epochNo) | |
225 | .epochSlotNo(slot) | |
226 | .liveStake(liveStake) | |
227 | .delegators(delegators) | |
228 |
1
1. getDataForDelegationHeader : negated conditional → SURVIVED |
.activePools(Objects.nonNull(poolActiveObj) ? (Integer) poolActiveObj : CommonConstant.ZERO) |
229 | .retiredPools( | |
230 |
1
1. getDataForDelegationHeader : negated conditional → SURVIVED |
Objects.nonNull(poolInActiveObj) ? (Integer) poolInActiveObj : CommonConstant.ZERO) |
231 |
2
1. getDataForDelegationHeader : negated conditional → SURVIVED 2. getDataForDelegationHeader : changed conditional boundary → SURVIVED |
.countDownEndTime(countDownTime > CommonConstant.ZERO ? countDownTime : CommonConstant.ZERO) |
232 | .build(); | |
233 | } | |
234 | ||
235 | @Override | |
236 | public BaseFilterResponse<PoolResponse> getDataForPoolTable( | |
237 | Pageable pageable, PoolListFilter filter) { | |
238 | BaseFilterResponse<PoolResponse> response = new BaseFilterResponse<>(); | |
239 | Set<Long> poolRetiredIds = new HashSet<>(); | |
240 |
1
1. getDataForPoolTable : negated conditional → KILLED |
if (!Boolean.TRUE.equals(filter.getIsShowRetired())) { |
241 | String poolRetiredIdKey = CommonConstant.POOL_IDS_INACTIVATE + network; | |
242 | poolRetiredIds = | |
243 | redisTemplate.opsForHash().values(poolRetiredIdKey).stream() | |
244 |
1
1. lambda$getDataForPoolTable$2 : replaced Long return value with 0L for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::lambda$getDataForPoolTable$2 → NO_COVERAGE |
.map(item -> Long.parseLong(String.valueOf(item))) |
245 | .collect(Collectors.toSet()); | |
246 | } | |
247 | // add -1L to poolRetiredIds to avoid empty list | |
248 | poolRetiredIds.add(-1L); | |
249 | boolean isQueryEmpty = DataUtil.isNullOrEmpty(filter.getQuery()); | |
250 |
1
1. getDataForPoolTable : negated conditional → SURVIVED |
if (isQueryEmpty) { |
251 | pageable = createPageableWithSort(pageable, Sort.by(Sort.Direction.ASC, BaseEntity_.ID)); | |
252 | } else { | |
253 | String poolNameLength = "poolNameLength"; | |
254 |
3
1. getDataForPoolTable : changed conditional boundary → SURVIVED 2. getDataForPoolTable : Replaced integer division with multiplication → SURVIVED 3. getDataForPoolTable : negated conditional → KILLED |
if (MAX_TOTAL_ELEMENTS / pageable.getPageSize() <= pageable.getPageNumber()) { |
255 | throw new BusinessException(BusinessCode.OUT_OF_QUERY_LIMIT); | |
256 | } | |
257 | pageable = | |
258 | createPageableWithSort( | |
259 | pageable, Sort.by(Sort.Direction.ASC, poolNameLength, PoolOfflineData_.POOL_NAME)); | |
260 | } | |
261 | Integer epochNo = epochRepository.findCurrentEpochNo().orElse(CommonConstant.ZERO); | |
262 | Page<PoolResponse> poolResponse = | |
263 | getPoolResponseList(pageable, poolRetiredIds, epochNo, filter); | |
264 |
1
1. getDataForPoolTable : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setData → KILLED |
response.setData(poolResponse.getContent()); |
265 |
1
1. getDataForPoolTable : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalItems → SURVIVED |
response.setTotalItems(poolResponse.getTotalElements()); |
266 |
1
1. getDataForPoolTable : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalPages → SURVIVED |
response.setTotalPages(poolResponse.getTotalPages()); |
267 |
1
1. getDataForPoolTable : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setCurrentPage → SURVIVED |
response.setCurrentPage(pageable.getPageNumber()); |
268 |
1
1. getDataForPoolTable : negated conditional → SURVIVED |
if (!isQueryEmpty) { |
269 |
3
1. getDataForPoolTable : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setIsDataOverSize → SURVIVED 2. getDataForPoolTable : changed conditional boundary → SURVIVED 3. getDataForPoolTable : negated conditional → SURVIVED |
response.setIsDataOverSize(poolResponse.getTotalElements() >= 1000); |
270 | } | |
271 |
1
1. getDataForPoolTable : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::getDataForPoolTable → KILLED |
return response; |
272 | } | |
273 | ||
274 | private Page<PoolResponse> getPoolResponseList( | |
275 | Pageable pageable, Set<Long> retiredIds, int epochNo, PoolListFilter filter) { | |
276 | boolean isKoiOs = fetchRewardDataService.useKoios(); | |
277 | BaseFilterResponse<PoolResponse> response = new BaseFilterResponse<>(); | |
278 |
1
1. getPoolResponseList : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setData → SURVIVED |
response.setData(List.of()); |
279 | Page<PoolListProjection> poolInfoProjections; | |
280 | List<PoolResponse> poolResponseList; | |
281 |
1
1. getPoolResponseList : removed call to org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::standardFilter → SURVIVED |
standardFilter(filter); |
282 | ||
283 |
1
1. getPoolResponseList : negated conditional → KILLED |
if (isKoiOs) { |
284 | poolInfoProjections = | |
285 | poolHashRepository.findAllWithUsingKoiOs( | |
286 | filter.getQuery(), | |
287 | retiredIds, | |
288 | epochNo, | |
289 | filter.getMinPoolSize(), | |
290 | filter.getMaxPoolSize(), | |
291 | filter.getMinPledge(), | |
292 | filter.getMaxPledge(), | |
293 | filter.getMinSaturation(), | |
294 | filter.getMaxSaturation(), | |
295 | filter.getMinVotingPower(), | |
296 | filter.getMaxVotingPower(), | |
297 | filter.getMinGovParticipationRate(), | |
298 | filter.getMaxGovParticipationRate(), | |
299 | filter.getMinBlockLifetime(), | |
300 | filter.getMaxBlockLifetime(), | |
301 | pageable); | |
302 | } else { | |
303 | poolInfoProjections = | |
304 | poolHashRepository.findAllWithoutUsingKoi0s( | |
305 | filter.getQuery(), | |
306 | retiredIds, | |
307 | filter.getMinPledge(), | |
308 | filter.getMaxPledge(), | |
309 | filter.getMinVotingPower(), | |
310 | filter.getMaxVotingPower(), | |
311 | filter.getMinGovParticipationRate(), | |
312 | filter.getMaxGovParticipationRate(), | |
313 | filter.getMinBlockLifetime(), | |
314 | filter.getMaxBlockLifetime(), | |
315 | pageable); | |
316 | } | |
317 | poolResponseList = mapAggPoolInfoToPoolResponse(retiredIds, poolInfoProjections); | |
318 |
1
1. getPoolResponseList : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setData → SURVIVED |
response.setData(poolResponseList); |
319 |
1
1. getPoolResponseList : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalItems → SURVIVED |
response.setTotalItems(poolInfoProjections.getTotalElements()); |
320 |
1
1. getPoolResponseList : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setCurrentPage → SURVIVED |
response.setCurrentPage(pageable.getPageNumber()); |
321 |
1
1. getPoolResponseList : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalPages → SURVIVED |
response.setTotalPages(poolInfoProjections.getTotalPages()); |
322 |
1
1. getPoolResponseList : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::getPoolResponseList → KILLED |
return new PageImpl<>(poolResponseList, pageable, poolInfoProjections.getTotalElements()); |
323 | } | |
324 | /** | |
325 | * Map aggregate pool info for pool response | |
326 | * | |
327 | * @param retiredIds set of retired pool ids | |
328 | * @param poolListProjections | |
329 | * @return | |
330 | */ | |
331 | private List<PoolResponse> mapAggPoolInfoToPoolResponse( | |
332 | Set<Long> retiredIds, Page<PoolListProjection> poolListProjections) { | |
333 |
1
1. mapAggPoolInfoToPoolResponse : replaced return value with Collections.emptyList for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::mapAggPoolInfoToPoolResponse → KILLED |
return poolListProjections.stream() |
334 | .map( | |
335 | projection -> | |
336 |
1
1. lambda$mapAggPoolInfoToPoolResponse$3 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::lambda$mapAggPoolInfoToPoolResponse$3 → KILLED |
PoolResponse.builder() |
337 | .poolId(projection.getPoolView()) | |
338 | .id(projection.getPoolId()) | |
339 | .poolName(projection.getPoolName()) | |
340 | .tickerName(projection.getTickerName()) | |
341 | .pledge(projection.getPledge()) | |
342 | .poolSize( | |
343 |
1
1. lambda$mapAggPoolInfoToPoolResponse$3 : negated conditional → SURVIVED |
BigInteger.valueOf(-1).equals(projection.getPoolSize()) |
344 | ? null | |
345 | : projection.getPoolSize()) | |
346 | .saturation( | |
347 |
1
1. lambda$mapAggPoolInfoToPoolResponse$3 : negated conditional → SURVIVED |
Double.valueOf(-1).equals(projection.getSaturation()) |
348 | ? null | |
349 | : projection.getSaturation()) | |
350 | .lifetimeBlock(projection.getLifetimeBlock()) | |
351 | .votingPower( | |
352 |
1
1. lambda$mapAggPoolInfoToPoolResponse$3 : negated conditional → SURVIVED |
Double.valueOf(-1).equals(projection.getVotingPower()) |
353 | ? null | |
354 | : projection.getVotingPower()) | |
355 | .governanceParticipationRate( | |
356 |
1
1. lambda$mapAggPoolInfoToPoolResponse$3 : negated conditional → SURVIVED |
Double.valueOf(-1).equals(projection.getGovernanceParticipationRate()) |
357 | ? null | |
358 | : projection.getGovernanceParticipationRate()) | |
359 | .epochBlock(projection.getEpochBlock()) | |
360 | .retired(retiredIds.contains(projection.getPoolId())) | |
361 | .build()) | |
362 | .collect(Collectors.toList()); | |
363 | } | |
364 | ||
365 | /** | |
366 | * Create pageable with sort, if sort is unsorted then use default sort | |
367 | * | |
368 | * @param pageable page information | |
369 | * @param defaultSort default sort condition | |
370 | * @return pageable with sort | |
371 | */ | |
372 | private Pageable createPageableWithSort(Pageable pageable, Sort defaultSort) { | |
373 | Sort sort = pageable.getSort(); | |
374 |
1
1. createPageableWithSort : negated conditional → SURVIVED |
if (sort.isUnsorted()) { |
375 | sort = defaultSort; | |
376 | } | |
377 |
1
1. createPageableWithSort : negated conditional → SURVIVED |
if (Objects.isNull(sort.getOrderFor(BaseEntity_.ID))) { |
378 | sort = sort.and(Sort.by(Sort.Direction.ASC, BaseEntity_.ID)); | |
379 | } | |
380 |
1
1. createPageableWithSort : negated conditional → SURVIVED |
if (!fetchRewardDataService.useKoios()) { |
381 | sort = | |
382 | sort.stream() | |
383 | .filter( | |
384 | order -> | |
385 |
2
1. lambda$createPageableWithSort$4 : replaced boolean return with true for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::lambda$createPageableWithSort$4 → NO_COVERAGE 2. lambda$createPageableWithSort$4 : negated conditional → NO_COVERAGE |
!order.getProperty().equals("saturation") |
386 |
1
1. lambda$createPageableWithSort$4 : negated conditional → NO_COVERAGE |
&& !order.getProperty().equals("poolSize")) |
387 |
1
1. lambda$createPageableWithSort$5 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::lambda$createPageableWithSort$5 → NO_COVERAGE |
.map(Sort::by) |
388 | .findFirst() | |
389 | .orElse(defaultSort); | |
390 | } | |
391 | pageable = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), sort); | |
392 |
1
1. createPageableWithSort : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::createPageableWithSort → KILLED |
return pageable; |
393 | } | |
394 | ||
395 | void standardFilter(PoolListFilter filter) { | |
396 |
1
1. standardFilter : negated conditional → KILLED |
if (Objects.nonNull(filter.getQuery())) { |
397 | String queryLowerCase = filter.getQuery().toLowerCase(); | |
398 |
1
1. standardFilter : removed call to org/cardanofoundation/explorer/api/model/request/pool/PoolListFilter::setQuery → SURVIVED |
filter.setQuery(queryLowerCase); |
399 | } | |
400 |
1
1. standardFilter : removed call to org/cardanofoundation/explorer/api/model/request/pool/PoolListFilter::setMaxPoolSize → SURVIVED |
filter.setMaxPoolSize( |
401 | Optional.ofNullable(filter.getMaxPoolSize()).orElse(CommonConstant.MAX_VALUE_BIGINT)); | |
402 |
1
1. standardFilter : removed call to org/cardanofoundation/explorer/api/model/request/pool/PoolListFilter::setMinPoolSize → SURVIVED |
filter.setMinPoolSize(Optional.ofNullable(filter.getMinPoolSize()).orElse(BigInteger.ZERO)); |
403 |
1
1. standardFilter : removed call to org/cardanofoundation/explorer/api/model/request/pool/PoolListFilter::setMaxSaturation → SURVIVED |
filter.setMaxSaturation( |
404 | Optional.ofNullable(filter.getMaxSaturation()).orElse(Double.MAX_VALUE)); | |
405 |
1
1. standardFilter : removed call to org/cardanofoundation/explorer/api/model/request/pool/PoolListFilter::setMinSaturation → SURVIVED |
filter.setMinSaturation(Optional.ofNullable(filter.getMinSaturation()).orElse(0.0)); |
406 |
1
1. standardFilter : removed call to org/cardanofoundation/explorer/api/model/request/pool/PoolListFilter::setMaxPledge → SURVIVED |
filter.setMaxPledge( |
407 | Optional.ofNullable(filter.getMaxPledge()).orElse(CommonConstant.MAX_VALUE_BIGINT)); | |
408 |
1
1. standardFilter : removed call to org/cardanofoundation/explorer/api/model/request/pool/PoolListFilter::setMinPledge → SURVIVED |
filter.setMinPledge(Optional.ofNullable(filter.getMinPledge()).orElse(BigInteger.ZERO)); |
409 |
1
1. standardFilter : removed call to org/cardanofoundation/explorer/api/model/request/pool/PoolListFilter::setMaxBlockLifetime → SURVIVED |
filter.setMaxBlockLifetime( |
410 | Optional.ofNullable(filter.getMaxBlockLifetime()).orElse(Integer.MAX_VALUE)); | |
411 |
1
1. standardFilter : removed call to org/cardanofoundation/explorer/api/model/request/pool/PoolListFilter::setMinBlockLifetime → SURVIVED |
filter.setMinBlockLifetime(Optional.ofNullable(filter.getMinBlockLifetime()).orElse(0)); |
412 |
1
1. standardFilter : removed call to org/cardanofoundation/explorer/api/model/request/pool/PoolListFilter::setMaxVotingPower → SURVIVED |
filter.setMaxVotingPower( |
413 | Optional.ofNullable(filter.getMaxVotingPower()).orElse(CommonConstant.MAX_PERCENT)); | |
414 |
1
1. standardFilter : removed call to org/cardanofoundation/explorer/api/model/request/pool/PoolListFilter::setMinVotingPower → SURVIVED |
filter.setMinVotingPower( |
415 | Optional.ofNullable(filter.getMinVotingPower()).orElse(CommonConstant.MIN_PERCENT)); | |
416 |
1
1. standardFilter : removed call to org/cardanofoundation/explorer/api/model/request/pool/PoolListFilter::setMinGovParticipationRate → SURVIVED |
filter.setMinGovParticipationRate( |
417 | Optional.ofNullable(filter.getMinGovParticipationRate()) | |
418 | .orElse(CommonConstant.MIN_PERCENT)); | |
419 |
1
1. standardFilter : removed call to org/cardanofoundation/explorer/api/model/request/pool/PoolListFilter::setMaxGovParticipationRate → SURVIVED |
filter.setMaxGovParticipationRate( |
420 | Optional.ofNullable(filter.getMaxGovParticipationRate()) | |
421 | .orElse(CommonConstant.MAX_PERCENT)); | |
422 | } | |
423 | ||
424 | @Override | |
425 | public List<PoolResponse> findTopDelegationPool(Pageable pageable) { | |
426 | int size = pageable.getPageSize(); | |
427 |
2
1. findTopDelegationPool : changed conditional boundary → SURVIVED 2. findTopDelegationPool : negated conditional → KILLED |
if (size > defaultSize) { |
428 | pageable = PageRequest.of(pageable.getPageNumber(), defaultSize); | |
429 | } | |
430 | ||
431 | List<PoolResponse> response; | |
432 | ||
433 | Integer currentEpoch = | |
434 | epochRepository | |
435 | .findCurrentEpochNo() | |
436 |
1
1. lambda$findTopDelegationPool$6 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::lambda$findTopDelegationPool$6 → NO_COVERAGE |
.orElseThrow(() -> new NoContentException(CommonErrorCode.UNKNOWN_ERROR)); |
437 | ||
438 | List<PoolCountProjection> poolCountProjections = | |
439 | blockRepository.findTopDelegationByEpochBlock(currentEpoch, pageable); | |
440 | Set<String> poolViewsTop = | |
441 | poolCountProjections.stream() | |
442 | .map(PoolCountProjection::getPoolView) | |
443 | .collect(Collectors.toSet()); | |
444 | Map<Long, Integer> blockEpochsMap = | |
445 | poolCountProjections.stream() | |
446 | .collect( | |
447 | Collectors.toMap( | |
448 | PoolCountProjection::getPoolId, PoolCountProjection::getCountValue)); | |
449 | ||
450 | Set<Long> poolIds = poolHashRepository.getListPoolIdIn(poolViewsTop); | |
451 | List<PoolDelegationSummaryProjection> pools = | |
452 | delegationRepository.findDelegationPoolsSummary(poolIds); | |
453 | List<PoolCountProjection> blockLifetimeProjections = | |
454 | blockRepository.getCountBlockByPools(poolIds); | |
455 | Map<Long, Integer> blockLifetimesMap = | |
456 | blockLifetimeProjections.stream() | |
457 | .collect( | |
458 | Collectors.toMap( | |
459 | PoolCountProjection::getPoolId, PoolCountProjection::getCountValue)); | |
460 | response = | |
461 | pools.stream() | |
462 | .map( | |
463 | pool -> | |
464 |
1
1. lambda$findTopDelegationPool$7 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::lambda$findTopDelegationPool$7 → KILLED |
PoolResponse.builder() |
465 | .poolId(pool.getPoolView()) | |
466 | .poolName(pool.getPoolName()) | |
467 | .pledge(pool.getPledge()) | |
468 | .id(pool.getPoolId()) | |
469 | .epochBlock(blockEpochsMap.get(pool.getPoolId())) | |
470 | .lifetimeBlock(blockLifetimesMap.get(pool.getPoolId())) | |
471 | .build()) | |
472 | .toList(); | |
473 | ||
474 | boolean useKoiOs = fetchRewardDataService.useKoios(); | |
475 |
1
1. findTopDelegationPool : negated conditional → SURVIVED |
if (useKoiOs) { |
476 |
1
1. findTopDelegationPool : removed call to org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::setPoolInfoKoios → SURVIVED |
setPoolInfoKoios(response, currentEpoch, poolViewsTop); |
477 | } | |
478 | ||
479 |
1
1. findTopDelegationPool : replaced return value with Collections.emptyList for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::findTopDelegationPool → SURVIVED |
return response.stream() |
480 | .sorted(Comparator.comparing(PoolResponse::getEpochBlock).reversed()) | |
481 | .toList(); | |
482 | } | |
483 | ||
484 | @Override | |
485 | public PoolDetailHeaderResponse getDataForPoolDetail(String poolViewOrHash) { | |
486 | Integer currentEpoch = epochRepository.findCurrentEpochNo().orElse(CommonConstant.ZERO); | |
487 | boolean useKoiOs = fetchRewardDataService.useKoios(); | |
488 |
2
1. getDataForPoolDetail : negated conditional → KILLED 2. getDataForPoolDetail : negated conditional → KILLED |
if (useKoiOs && !fetchRewardDataService.checkAdaPots(currentEpoch)) { |
489 | fetchRewardDataService.fetchAdaPots(List.of(currentEpoch)); | |
490 | } | |
491 | PoolDetailUpdateProjection projection = | |
492 |
1
1. getDataForPoolDetail : negated conditional → KILLED |
useKoiOs |
493 | ? poolHashRepository.getDataForPoolDetail(poolViewOrHash, currentEpoch) | |
494 | : poolHashRepository.getDataForPoolDetailNoReward(poolViewOrHash, currentEpoch); | |
495 | String poolView = projection.getPoolView(); | |
496 | Long poolId = projection.getPoolId(); | |
497 | AggregatePoolInfo aggregatePoolInfo = aggregatePoolInfoRepository.findByPoolId(poolId); | |
498 | PoolDetailHeaderResponse poolDetailResponse = | |
499 | new PoolDetailHeaderResponse(projection, aggregatePoolInfo); | |
500 | Gson gson = new Gson(); | |
501 | JsonObject jsonObject = gson.fromJson(projection.getJson(), JsonObject.class); | |
502 |
2
1. getDataForPoolDetail : negated conditional → NO_COVERAGE 2. getDataForPoolDetail : negated conditional → KILLED |
if (Objects.nonNull(jsonObject) && jsonObject.has("homepage")) { |
503 |
1
1. getDataForPoolDetail : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolDetailHeaderResponse::setHomepage → NO_COVERAGE |
poolDetailResponse.setHomepage(jsonObject.get("homepage").getAsString()); |
504 | } | |
505 |
2
1. getDataForPoolDetail : negated conditional → NO_COVERAGE 2. getDataForPoolDetail : negated conditional → KILLED |
if (Objects.nonNull(jsonObject) && jsonObject.has("description")) { |
506 |
1
1. getDataForPoolDetail : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolDetailHeaderResponse::setDescription → NO_COVERAGE |
poolDetailResponse.setDescription(jsonObject.get("description").getAsString()); |
507 | } | |
508 |
1
1. getDataForPoolDetail : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolDetailHeaderResponse::setCreateDate → SURVIVED |
poolDetailResponse.setCreateDate(poolUpdateRepository.getCreatedTimeOfPool(poolId)); |
509 | ||
510 | List<String> ownerAddress = poolUpdateRepository.findOwnerAccountByPool(poolId); | |
511 |
1
1. getDataForPoolDetail : removed call to java/util/Collections::sort → SURVIVED |
Collections.sort(ownerAddress); |
512 | ||
513 |
1
1. getDataForPoolDetail : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolDetailHeaderResponse::setOwnerAccounts → KILLED |
poolDetailResponse.setOwnerAccounts(ownerAddress); |
514 |
1
1. getDataForPoolDetail : negated conditional → KILLED |
if (useKoiOs) { |
515 | Set<String> poolIdList = new HashSet<>(Collections.singletonList(poolView)); | |
516 |
1
1. getDataForPoolDetail : removed call to org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::setPoolInfoKoios → SURVIVED |
setPoolInfoKoios(poolDetailResponse, currentEpoch, poolIdList); |
517 |
1
1. getDataForPoolDetail : negated conditional → SURVIVED |
if (!fetchRewardDataService.checkRewardForPool(ownerAddress)) { |
518 | fetchRewardDataService.fetchRewardForPool(ownerAddress); | |
519 | } | |
520 | BigDecimal stakeLimit = getPoolSaturation(projection.getReserves(), projection.getParamK()); | |
521 |
1
1. getDataForPoolDetail : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolDetailHeaderResponse::setStakeLimit → SURVIVED |
poolDetailResponse.setStakeLimit(stakeLimit); |
522 | BigInteger totalBalanceOfPoolOwners = | |
523 | stakeAddressBalanceRepository | |
524 | .sumBalanceByStakeAddressIn(ownerAddress) | |
525 | .add(rewardRepository.getAvailableRewardByAddressList(ownerAddress)) | |
526 | .subtract(withdrawalRepository.getRewardWithdrawnByAddressList(ownerAddress)); | |
527 |
1
1. getDataForPoolDetail : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolDetailHeaderResponse::setTotalBalanceOfPoolOwners → SURVIVED |
poolDetailResponse.setTotalBalanceOfPoolOwners(totalBalanceOfPoolOwners); |
528 | } | |
529 |
1
1. getDataForPoolDetail : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolDetailHeaderResponse::setPoolStatus → KILLED |
poolDetailResponse.setPoolStatus(poolCertificateService.getCurrentPoolStatus(poolViewOrHash)); |
530 |
1
1. getDataForPoolDetail : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::getDataForPoolDetail → KILLED |
return poolDetailResponse; |
531 | } | |
532 | ||
533 | @Override | |
534 | public BaseFilterResponse<PoolDetailEpochResponse> getEpochListForPoolDetail( | |
535 | Pageable pageable, String poolViewOrHash) { | |
536 | BaseFilterResponse<PoolDetailEpochResponse> epochRes = new BaseFilterResponse<>(); | |
537 | boolean useKoiOs = fetchRewardDataService.useKoios(); | |
538 |
1
1. getEpochListForPoolDetail : negated conditional → KILLED |
if (!useKoiOs) { |
539 |
1
1. getEpochListForPoolDetail : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setData → NO_COVERAGE |
epochRes.setData(null); |
540 |
1
1. getEpochListForPoolDetail : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalItems → NO_COVERAGE |
epochRes.setTotalItems(0); |
541 |
1
1. getEpochListForPoolDetail : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalPages → NO_COVERAGE |
epochRes.setTotalPages(0); |
542 |
1
1. getEpochListForPoolDetail : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::getEpochListForPoolDetail → NO_COVERAGE |
return epochRes; |
543 | } | |
544 | List<PoolDetailEpochResponse> epochOfPools; | |
545 | PoolHash poolHash = | |
546 | poolHashRepository | |
547 | .findByViewOrHashRaw(poolViewOrHash) | |
548 |
1
1. lambda$getEpochListForPoolDetail$8 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::lambda$getEpochListForPoolDetail$8 → NO_COVERAGE |
.orElseThrow(() -> new NoContentException(CommonErrorCode.UNKNOWN_ERROR)); |
549 | Long poolId = poolHash.getId(); | |
550 | String poolView = poolHash.getView(); | |
551 | Page<PoolHistoryKoiosProjection> poolHistoryKoiosProjections = Page.empty(); | |
552 | Boolean isHistory = | |
553 | fetchRewardDataService.checkPoolHistoryForPool(Collections.singleton(poolView)); | |
554 |
1
1. getEpochListForPoolDetail : negated conditional → KILLED |
if (Boolean.FALSE.equals(isHistory)) { |
555 | Boolean isFetch = | |
556 | fetchRewardDataService.fetchPoolHistoryForPool(Collections.singleton(poolView)); | |
557 |
1
1. getEpochListForPoolDetail : negated conditional → KILLED |
if (Boolean.TRUE.equals(isFetch)) { |
558 | poolHistoryKoiosProjections = poolHistoryRepository.getPoolHistoryKoios(poolView, pageable); | |
559 | } | |
560 | } else { | |
561 | poolHistoryKoiosProjections = poolHistoryRepository.getPoolHistoryKoios(poolView, pageable); | |
562 | } | |
563 | epochOfPools = poolHistoryKoiosProjections.stream().map(PoolDetailEpochResponse::new).toList(); | |
564 | long totalElm = poolHistoryKoiosProjections.getTotalElements(); | |
565 | Set<Integer> epochNos = | |
566 | poolHistoryKoiosProjections.stream() | |
567 | .map(PoolHistoryKoiosProjection::getEpochNo) | |
568 | .collect(Collectors.toSet()); | |
569 | int totalPage = poolHistoryKoiosProjections.getTotalPages(); | |
570 | Integer currentEpoch = | |
571 | epochRepository | |
572 | .findCurrentEpochNo() | |
573 |
1
1. lambda$getEpochListForPoolDetail$9 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::lambda$getEpochListForPoolDetail$9 → NO_COVERAGE |
.orElseThrow(() -> new BusinessException(BusinessCode.EPOCH_NOT_FOUND)); |
574 | List<PoolDetailEpochProjection> epochBlockProjections = | |
575 | poolHashRepository.findEpochByPool(poolId, epochNos); | |
576 | Map<Integer, Long> epochBlockMap = | |
577 | epochBlockProjections.stream() | |
578 | .collect( | |
579 | Collectors.toMap( | |
580 | PoolDetailEpochProjection::getEpochNo, | |
581 | PoolDetailEpochProjection::getCountBlock)); | |
582 |
1
1. getEpochListForPoolDetail : removed call to java/util/List::forEach → SURVIVED |
epochOfPools.forEach( |
583 | epochOfPool -> { | |
584 |
1
1. lambda$getEpochListForPoolDetail$10 : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolDetailEpochResponse::setBlock → SURVIVED |
epochOfPool.setBlock(epochBlockMap.get(epochOfPool.getEpoch())); |
585 |
2
1. lambda$getEpochListForPoolDetail$10 : Replaced integer subtraction with addition → SURVIVED 2. lambda$getEpochListForPoolDetail$10 : negated conditional → SURVIVED |
if (epochOfPool.getEpoch().equals(currentEpoch - 1)) { |
586 |
1
1. lambda$getEpochListForPoolDetail$10 : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolDetailEpochResponse::setDelegators → NO_COVERAGE |
epochOfPool.setDelegators(null); |
587 |
1
1. lambda$getEpochListForPoolDetail$10 : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolDetailEpochResponse::setFee → NO_COVERAGE |
epochOfPool.setFee(null); |
588 | } | |
589 | }); | |
590 |
1
1. getEpochListForPoolDetail : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setData → SURVIVED |
epochRes.setData(epochOfPools); |
591 |
1
1. getEpochListForPoolDetail : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalItems → SURVIVED |
epochRes.setTotalItems(totalElm); |
592 |
1
1. getEpochListForPoolDetail : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalPages → SURVIVED |
epochRes.setTotalPages(totalPage); |
593 |
1
1. getEpochListForPoolDetail : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setCurrentPage → SURVIVED |
epochRes.setCurrentPage(pageable.getPageNumber()); |
594 |
1
1. getEpochListForPoolDetail : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::getEpochListForPoolDetail → SURVIVED |
return epochRes; |
595 | } | |
596 | ||
597 | @Override | |
598 | public PoolDetailAnalyticsResponse getAnalyticsForPoolDetail(String findByViewOrHashRaw) { | |
599 | boolean useKoiOs = fetchRewardDataService.useKoios(); | |
600 |
1
1. getAnalyticsForPoolDetail : negated conditional → KILLED |
if (!useKoiOs) { |
601 |
1
1. getAnalyticsForPoolDetail : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::getAnalyticsForPoolDetail → KILLED |
return PoolDetailAnalyticsResponse.builder().epochChart(null).delegatorChart(null).build(); |
602 | } | |
603 | PoolHash poolHash = | |
604 | poolHashRepository | |
605 | .findByViewOrHashRaw(findByViewOrHashRaw) | |
606 |
1
1. lambda$getAnalyticsForPoolDetail$11 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::lambda$getAnalyticsForPoolDetail$11 → NO_COVERAGE |
.orElseThrow(() -> new BusinessException(CommonErrorCode.UNKNOWN_ERROR)); |
607 | String poolView = poolHash.getView(); | |
608 | EpochChartResponse epochChart = new EpochChartResponse(); | |
609 | List<EpochChartProjection> epochDataCharts = new ArrayList<>(); | |
610 | Boolean isHistory = | |
611 | fetchRewardDataService.checkPoolHistoryForPool(Collections.singleton(poolView)); | |
612 |
1
1. getAnalyticsForPoolDetail : negated conditional → KILLED |
if (Boolean.FALSE.equals(isHistory)) { |
613 | Boolean isFetch = | |
614 | fetchRewardDataService.fetchPoolHistoryForPool(Collections.singleton(poolView)); | |
615 |
1
1. getAnalyticsForPoolDetail : negated conditional → KILLED |
if (Boolean.TRUE.equals(isFetch)) { |
616 | epochDataCharts = poolHistoryRepository.getPoolHistoryKoiosForEpochChart(poolView); | |
617 | } | |
618 | } else { | |
619 | epochDataCharts = poolHistoryRepository.getPoolHistoryKoiosForEpochChart(poolView); | |
620 | } | |
621 |
1
1. getAnalyticsForPoolDetail : negated conditional → KILLED |
if (!epochDataCharts.isEmpty()) { |
622 |
1
1. getAnalyticsForPoolDetail : removed call to org/cardanofoundation/explorer/api/model/response/pool/chart/EpochChartResponse::setDataByDays → SURVIVED |
epochChart.setDataByDays(epochDataCharts.stream().map(EpochChartList::new).toList()); |
623 | Optional<EpochChartProjection> maxEpochOpt = | |
624 | epochDataCharts.stream().max(Comparator.comparing(EpochChartProjection::getChartValue)); | |
625 |
1
1. getAnalyticsForPoolDetail : removed call to org/cardanofoundation/explorer/api/model/response/pool/chart/EpochChartResponse::setHighest → SURVIVED |
epochChart.setHighest(maxEpochOpt.map(BasePoolChartProjection::getChartValue).orElse(null)); |
626 | Optional<EpochChartProjection> minEpochOpt = | |
627 | epochDataCharts.stream().min(Comparator.comparing(EpochChartProjection::getChartValue)); | |
628 |
1
1. getAnalyticsForPoolDetail : removed call to org/cardanofoundation/explorer/api/model/response/pool/chart/EpochChartResponse::setLowest → SURVIVED |
epochChart.setLowest(minEpochOpt.map(BasePoolChartProjection::getChartValue).orElse(null)); |
629 | } | |
630 | DelegatorChartResponse delegatorChart = getDelegatorChartResponse(poolHash); | |
631 |
1
1. getAnalyticsForPoolDetail : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::getAnalyticsForPoolDetail → SURVIVED |
return PoolDetailAnalyticsResponse.builder() |
632 | .epochChart(epochChart) | |
633 | .delegatorChart(delegatorChart) | |
634 | .build(); | |
635 | } | |
636 | ||
637 | private DelegatorChartResponse getDelegatorChartResponse(PoolHash poolHash) { | |
638 | DelegatorChartResponse delegatorChart = new DelegatorChartResponse(); | |
639 | List<DelegatorChartProjection> delegatorDataCharts = | |
640 | poolHistoryRepository.getDataForDelegatorChart(poolHash.getView()); | |
641 |
1
1. getDelegatorChartResponse : negated conditional → KILLED |
if (!delegatorDataCharts.isEmpty()) { |
642 |
1
1. getDelegatorChartResponse : removed call to org/cardanofoundation/explorer/api/model/response/pool/chart/DelegatorChartResponse::setDataByDays → SURVIVED |
delegatorChart.setDataByDays( |
643 | delegatorDataCharts.stream().map(DelegatorChartList::new).toList()); | |
644 | Optional<DelegatorChartProjection> maxDelegatorOpt = | |
645 | delegatorDataCharts.stream() | |
646 | .max(Comparator.comparing(DelegatorChartProjection::getChartValue)); | |
647 |
1
1. getDelegatorChartResponse : removed call to org/cardanofoundation/explorer/api/model/response/pool/chart/DelegatorChartResponse::setHighest → SURVIVED |
delegatorChart.setHighest( |
648 | maxDelegatorOpt.map(BasePoolChartProjection::getChartValue).orElse(null)); | |
649 | Optional<DelegatorChartProjection> minDelegatorOpt = | |
650 | delegatorDataCharts.stream() | |
651 | .min(Comparator.comparing(DelegatorChartProjection::getChartValue)); | |
652 |
1
1. getDelegatorChartResponse : removed call to org/cardanofoundation/explorer/api/model/response/pool/chart/DelegatorChartResponse::setLowest → SURVIVED |
delegatorChart.setLowest( |
653 | minDelegatorOpt.map(BasePoolChartProjection::getChartValue).orElse(null)); | |
654 | } | |
655 |
1
1. getDelegatorChartResponse : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::getDelegatorChartResponse → SURVIVED |
return delegatorChart; |
656 | } | |
657 | ||
658 | @Override | |
659 | public BaseFilterResponse<PoolDetailDelegatorResponse> getDelegatorsForPoolDetail( | |
660 | Pageable pageable, String poolViewOrHash) { | |
661 |
1
1. getDelegatorsForPoolDetail : negated conditional → KILLED |
if (pageable.getSort().isUnsorted()) { |
662 | pageable = | |
663 | PageRequest.of( | |
664 | pageable.getPageNumber(), | |
665 | pageable.getPageSize(), | |
666 | Sort.by(Sort.Direction.DESC, Delegation_.TX_ID)); | |
667 | } | |
668 | BaseFilterResponse<PoolDetailDelegatorResponse> delegatorResponse = new BaseFilterResponse<>(); | |
669 |
1
1. getDelegatorsForPoolDetail : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setData → SURVIVED |
delegatorResponse.setData(List.of()); |
670 | Page<Long> addressIdPage = delegationRepository.liveDelegatorsList(poolViewOrHash, pageable); | |
671 |
1
1. getDelegatorsForPoolDetail : negated conditional → KILLED |
if (!addressIdPage.isEmpty()) { |
672 | Set<Long> addressIds = addressIdPage.stream().collect(Collectors.toSet()); | |
673 | Integer currentEpoch = | |
674 | epochRepository | |
675 | .findCurrentEpochNo() | |
676 |
1
1. lambda$getDelegatorsForPoolDetail$12 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::lambda$getDelegatorsForPoolDetail$12 → NO_COVERAGE |
.orElseThrow(() -> new NoContentException(CommonErrorCode.UNKNOWN_ERROR)); |
677 | List<PoolDetailDelegatorProjection> delegatorPage = | |
678 | delegationRepository.getDelegatorsByAddress(addressIds); | |
679 | List<PoolDetailDelegatorResponse> delegatorList = | |
680 | delegatorPage.stream().map(PoolDetailDelegatorResponse::new).toList(); | |
681 | boolean useKoiOs = fetchRewardDataService.useKoios(); | |
682 |
1
1. getDelegatorsForPoolDetail : negated conditional → KILLED |
if (useKoiOs) { |
683 | List<String> addressViews = stakeAddressRepository.getViewByAddressId(addressIds); | |
684 | Boolean isStake = fetchRewardDataService.checkEpochStakeForPool(addressViews); | |
685 |
1
1. getDelegatorsForPoolDetail : negated conditional → KILLED |
if (Boolean.FALSE.equals(isStake)) { |
686 | Boolean isFetch = | |
687 |
2
1. getDelegatorsForPoolDetail : changed conditional boundary → SURVIVED 2. getDelegatorsForPoolDetail : negated conditional → KILLED |
addressViews.size() > 40 |
688 | ? null | |
689 | : fetchRewardDataService.fetchEpochStakeForPool(addressViews); | |
690 |
1
1. getDelegatorsForPoolDetail : negated conditional → SURVIVED |
if (Objects.isNull(isFetch)) { |
691 | List<CompletableFuture<Boolean>> completableFutures = new ArrayList<>(); | |
692 | List<List<String>> subAddressList = Lists.partition(addressViews, 25); | |
693 |
1
1. getDelegatorsForPoolDetail : removed call to java/util/List::forEach → SURVIVED |
subAddressList.forEach( |
694 | addressList -> completableFutures.add(fetchEpochStakeKoios(addressList))); | |
695 | CompletableFuture<Void> combinedFuture = | |
696 | CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[0])); | |
697 | CompletableFuture<List<Boolean>> allResultFuture = | |
698 | combinedFuture.thenApply( | |
699 |
1
1. lambda$getDelegatorsForPoolDetail$14 : replaced return value with Collections.emptyList for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::lambda$getDelegatorsForPoolDetail$14 → SURVIVED |
v -> completableFutures.stream().map(CompletableFuture::join).toList()); |
700 | allResultFuture | |
701 | .thenApply( | |
702 |
4
1. lambda$getDelegatorsForPoolDetail$15 : replaced boolean return with false for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::lambda$getDelegatorsForPoolDetail$15 → NO_COVERAGE 2. lambda$getDelegatorsForPoolDetail$16 : replaced Boolean return with True for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::lambda$getDelegatorsForPoolDetail$16 → NO_COVERAGE 3. lambda$getDelegatorsForPoolDetail$16 : replaced Boolean return with False for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::lambda$getDelegatorsForPoolDetail$16 → NO_COVERAGE 4. lambda$getDelegatorsForPoolDetail$15 : replaced boolean return with true for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::lambda$getDelegatorsForPoolDetail$15 → NO_COVERAGE |
results -> results.stream().allMatch(result -> result.equals(Boolean.TRUE))) |
703 | .exceptionally( | |
704 | ex -> { | |
705 | log.error("Error: when fetch data from koios"); | |
706 |
1
1. lambda$getDelegatorsForPoolDetail$17 : replaced Boolean return with True for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::lambda$getDelegatorsForPoolDetail$17 → SURVIVED |
return Boolean.FALSE; |
707 | }); | |
708 | } | |
709 | } | |
710 | List<StakeAddressProjection> stakeAddressProjections = | |
711 | epochStakeRepository.totalStakeByAddressAndPool(addressIds, currentEpoch); | |
712 | Map<Long, BigInteger> stakeAddressProjectionMap = | |
713 | stakeAddressProjections.stream() | |
714 | .collect( | |
715 | Collectors.toMap( | |
716 | StakeAddressProjection::getAddress, StakeAddressProjection::getTotalStake)); | |
717 |
1
1. getDelegatorsForPoolDetail : removed call to java/util/List::forEach → SURVIVED |
delegatorList.forEach( |
718 | delegator -> | |
719 |
1
1. lambda$getDelegatorsForPoolDetail$18 : removed call to org/cardanofoundation/explorer/api/model/response/PoolDetailDelegatorResponse::setTotalStake → SURVIVED |
delegator.setTotalStake( |
720 | stakeAddressProjectionMap.get(delegator.getStakeAddressId()))); | |
721 | } | |
722 |
1
1. getDelegatorsForPoolDetail : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalItems → SURVIVED |
delegatorResponse.setTotalItems(addressIdPage.getTotalElements()); |
723 |
1
1. getDelegatorsForPoolDetail : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setData → SURVIVED |
delegatorResponse.setData(delegatorList); |
724 |
1
1. getDelegatorsForPoolDetail : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalPages → SURVIVED |
delegatorResponse.setTotalPages(addressIdPage.getTotalPages()); |
725 |
1
1. getDelegatorsForPoolDetail : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setCurrentPage → SURVIVED |
delegatorResponse.setCurrentPage(pageable.getPageNumber()); |
726 | } | |
727 |
1
1. getDelegatorsForPoolDetail : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::getDelegatorsForPoolDetail → SURVIVED |
return delegatorResponse; |
728 | } | |
729 | ||
730 | /** | |
731 | * calculate stake limit | |
732 | * | |
733 | * @return BigDecimal | |
734 | */ | |
735 | private BigDecimal getPoolSaturation(BigInteger reserves, Integer k) { | |
736 |
2
1. getPoolSaturation : negated conditional → SURVIVED 2. getPoolSaturation : negated conditional → SURVIVED |
if (Objects.isNull(k) || Objects.isNull(reserves)) { |
737 |
1
1. getPoolSaturation : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::getPoolSaturation → NO_COVERAGE |
return BigDecimal.ZERO; |
738 | } | |
739 |
1
1. getPoolSaturation : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::getPoolSaturation → SURVIVED |
return (CommonConstant.TOTAL_ADA.subtract(new BigDecimal(reserves))) |
740 | .divide(new BigDecimal(k), CommonConstant.SCALE, RoundingMode.HALF_UP); | |
741 | } | |
742 | ||
743 | /** | |
744 | * set data for pool list from koios | |
745 | * | |
746 | * @return | |
747 | */ | |
748 | private void setPoolInfoKoios(List<PoolResponse> poolList, Integer epochNo, Set<String> poolIds) { | |
749 | List<PoolInfoKoiosProjection> poolInfoProjections = | |
750 | poolInfoRepository.getPoolInfoKoios(poolIds, epochNo); | |
751 | Map<String, PoolInfoKoiosProjection> poolInfoMap = | |
752 | poolInfoProjections.stream() | |
753 | .collect(Collectors.toMap(PoolInfoKoiosProjection::getView, Function.identity())); | |
754 | poolList.parallelStream() | |
755 |
1
1. setPoolInfoKoios : removed call to java/util/stream/Stream::forEach → SURVIVED |
.forEach( |
756 | pool -> { | |
757 | PoolInfoKoiosProjection projection = poolInfoMap.get(pool.getPoolId()); | |
758 |
1
1. lambda$setPoolInfoKoios$19 : negated conditional → KILLED |
if (Objects.nonNull(projection)) { |
759 |
1
1. lambda$setPoolInfoKoios$19 : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolResponse::setPoolSize → NO_COVERAGE |
pool.setPoolSize(projection.getActiveStake()); |
760 |
1
1. lambda$setPoolInfoKoios$19 : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolResponse::setSaturation → NO_COVERAGE |
pool.setSaturation(projection.getSaturation()); |
761 | } | |
762 | }); | |
763 | } | |
764 | ||
765 | /** | |
766 | * set data for pool from koios | |
767 | * | |
768 | * @return | |
769 | */ | |
770 | private void setPoolInfoKoios( | |
771 | PoolDetailHeaderResponse poolDetailHeader, Integer epochNo, Set<String> poolIds) { | |
772 | List<PoolInfoKoiosProjection> poolInfoProjections = | |
773 | poolInfoRepository.getPoolInfoKoios(poolIds, epochNo); | |
774 | PoolInfoKoiosProjection projection = | |
775 |
1
1. setPoolInfoKoios : negated conditional → KILLED |
poolInfoProjections.isEmpty() ? null : poolInfoProjections.get(CommonConstant.ZERO); |
776 |
1
1. setPoolInfoKoios : negated conditional → KILLED |
if (Objects.nonNull(projection)) { |
777 |
1
1. setPoolInfoKoios : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolDetailHeaderResponse::setPoolSize → NO_COVERAGE |
poolDetailHeader.setPoolSize(projection.getActiveStake()); |
778 |
1
1. setPoolInfoKoios : removed call to org/cardanofoundation/explorer/api/model/response/pool/PoolDetailHeaderResponse::setSaturation → NO_COVERAGE |
poolDetailHeader.setSaturation(projection.getSaturation()); |
779 | } | |
780 | } | |
781 | ||
782 | /** | |
783 | * fet epoch_stake from koios using multi thread | |
784 | * | |
785 | * @return CompletableFuture | |
786 | */ | |
787 | private CompletableFuture<Boolean> fetchEpochStakeKoios(List<String> addressIds) { | |
788 |
1
1. fetchEpochStakeKoios : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::fetchEpochStakeKoios → KILLED |
return CompletableFuture.supplyAsync( |
789 |
2
1. lambda$fetchEpochStakeKoios$20 : replaced Boolean return with True for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::lambda$fetchEpochStakeKoios$20 → SURVIVED 2. lambda$fetchEpochStakeKoios$20 : replaced Boolean return with False for org/cardanofoundation/explorer/api/service/impl/DelegationServiceImpl::lambda$fetchEpochStakeKoios$20 → SURVIVED |
() -> fetchRewardDataService.fetchEpochStakeForPool(addressIds)); |
790 | } | |
791 | } | |
Mutations | ||
167 |
1.1 |
|
177 |
1.1 |
|
189 |
1.1 |
|
204 |
1.1 |
|
207 |
1.1 |
|
209 |
1.1 |
|
220 |
1.1 |
|
223 |
1.1 |
|
228 |
1.1 |
|
230 |
1.1 |
|
231 |
1.1 2.2 |
|
240 |
1.1 |
|
244 |
1.1 |
|
250 |
1.1 |
|
254 |
1.1 2.2 3.3 |
|
264 |
1.1 |
|
265 |
1.1 |
|
266 |
1.1 |
|
267 |
1.1 |
|
268 |
1.1 |
|
269 |
1.1 2.2 3.3 |
|
271 |
1.1 |
|
278 |
1.1 |
|
281 |
1.1 |
|
283 |
1.1 |
|
318 |
1.1 |
|
319 |
1.1 |
|
320 |
1.1 |
|
321 |
1.1 |
|
322 |
1.1 |
|
333 |
1.1 |
|
336 |
1.1 |
|
343 |
1.1 |
|
347 |
1.1 |
|
352 |
1.1 |
|
356 |
1.1 |
|
374 |
1.1 |
|
377 |
1.1 |
|
380 |
1.1 |
|
385 |
1.1 2.2 |
|
386 |
1.1 |
|
387 |
1.1 |
|
392 |
1.1 |
|
396 |
1.1 |
|
398 |
1.1 |
|
400 |
1.1 |
|
402 |
1.1 |
|
403 |
1.1 |
|
405 |
1.1 |
|
406 |
1.1 |
|
408 |
1.1 |
|
409 |
1.1 |
|
411 |
1.1 |
|
412 |
1.1 |
|
414 |
1.1 |
|
416 |
1.1 |
|
419 |
1.1 |
|
427 |
1.1 2.2 |
|
436 |
1.1 |
|
464 |
1.1 |
|
475 |
1.1 |
|
476 |
1.1 |
|
479 |
1.1 |
|
488 |
1.1 2.2 |
|
492 |
1.1 |
|
502 |
1.1 2.2 |
|
503 |
1.1 |
|
505 |
1.1 2.2 |
|
506 |
1.1 |
|
508 |
1.1 |
|
511 |
1.1 |
|
513 |
1.1 |
|
514 |
1.1 |
|
516 |
1.1 |
|
517 |
1.1 |
|
521 |
1.1 |
|
527 |
1.1 |
|
529 |
1.1 |
|
530 |
1.1 |
|
538 |
1.1 |
|
539 |
1.1 |
|
540 |
1.1 |
|
541 |
1.1 |
|
542 |
1.1 |
|
548 |
1.1 |
|
554 |
1.1 |
|
557 |
1.1 |
|
573 |
1.1 |
|
582 |
1.1 |
|
584 |
1.1 |
|
585 |
1.1 2.2 |
|
586 |
1.1 |
|
587 |
1.1 |
|
590 |
1.1 |
|
591 |
1.1 |
|
592 |
1.1 |
|
593 |
1.1 |
|
594 |
1.1 |
|
600 |
1.1 |
|
601 |
1.1 |
|
606 |
1.1 |
|
612 |
1.1 |
|
615 |
1.1 |
|
621 |
1.1 |
|
622 |
1.1 |
|
625 |
1.1 |
|
628 |
1.1 |
|
631 |
1.1 |
|
641 |
1.1 |
|
642 |
1.1 |
|
647 |
1.1 |
|
652 |
1.1 |
|
655 |
1.1 |
|
661 |
1.1 |
|
669 |
1.1 |
|
671 |
1.1 |
|
676 |
1.1 |
|
682 |
1.1 |
|
685 |
1.1 |
|
687 |
1.1 2.2 |
|
690 |
1.1 |
|
693 |
1.1 |
|
699 |
1.1 |
|
702 |
1.1 2.2 3.3 4.4 |
|
706 |
1.1 |
|
717 |
1.1 |
|
719 |
1.1 |
|
722 |
1.1 |
|
723 |
1.1 |
|
724 |
1.1 |
|
725 |
1.1 |
|
727 |
1.1 |
|
736 |
1.1 2.2 |
|
737 |
1.1 |
|
739 |
1.1 |
|
755 |
1.1 |
|
758 |
1.1 |
|
759 |
1.1 |
|
760 |
1.1 |
|
775 |
1.1 |
|
776 |
1.1 |
|
777 |
1.1 |
|
778 |
1.1 |
|
788 |
1.1 |
|
789 |
1.1 2.2 |