1 | package com.fwmotion.threescale.cms.support; | |
2 | ||
3 | import com.fasterxml.jackson.databind.ObjectMapper; | |
4 | import com.fwmotion.threescale.cms.mappers.CmsFileMapper; | |
5 | import com.fwmotion.threescale.cms.model.CmsFile; | |
6 | import com.redhat.threescale.rest.cms.ApiException; | |
7 | import com.redhat.threescale.rest.cms.api.FilesApi; | |
8 | import com.redhat.threescale.rest.cms.model.FileList; | |
9 | import jakarta.annotation.Nonnull; | |
10 | import jakarta.annotation.Nullable; | |
11 | import jakarta.validation.constraints.Positive; | |
12 | import jakarta.validation.constraints.PositiveOrZero; | |
13 | import org.apache.commons.collections4.ListUtils; | |
14 | import org.mapstruct.factory.Mappers; | |
15 | ||
16 | import java.util.*; | |
17 | import java.util.stream.Collectors; | |
18 | ||
19 | public class PagedFilesSpliterator extends AbstractPagedRestApiSpliterator<CmsFile> { | |
20 | ||
21 | private static final CmsFileMapper FILE_MAPPER = Mappers.getMapper(CmsFileMapper.class); | |
22 | ||
23 | private final FilesApi filesApi; | |
24 | ||
25 | public PagedFilesSpliterator(@Nonnull FilesApi filesApi, | |
26 | @Nonnull ObjectMapper objectMapper) { | |
27 | super(Collections.emptySet(), objectMapper, 0); | |
28 | this.filesApi = filesApi; | |
29 | } | |
30 | ||
31 | public PagedFilesSpliterator(@Nonnull FilesApi filesApi, | |
32 | @Nonnull ObjectMapper objectMapper, | |
33 | @Positive int requestedPageSize) { | |
34 | super(requestedPageSize, objectMapper, Collections.emptySet(), 0); | |
35 | this.filesApi = filesApi; | |
36 | } | |
37 | ||
38 | private PagedFilesSpliterator(@Nonnull FilesApi filesApi, | |
39 | @Nonnull ObjectMapper objectMapper, | |
40 | @Positive int requestedPageSize, | |
41 | @Nonnull Collection<CmsFile> currentPage, | |
42 | @PositiveOrZero int currentPageNumber) { | |
43 | super(requestedPageSize, objectMapper, currentPage, currentPageNumber); | |
44 | this.filesApi = filesApi; | |
45 | } | |
46 | ||
47 | @Nullable | |
48 | @Override | |
49 | protected Collection<CmsFile> getPage(@PositiveOrZero int pageNumber, | |
50 | @Positive int pageSize) { | |
51 | ||
52 | try { | |
53 | FileList fileList = filesApi.listFiles(pageNumber, pageSize, null); | |
54 | ||
55 | List<CmsFile> resultPage = ListUtils.emptyIfNull(fileList.getCollection()) | |
56 | .stream() | |
57 | .map(FILE_MAPPER::fromRest) | |
58 | .collect(Collectors.toList()); | |
59 | ||
60 |
1
1. getPage : removed call to com/fwmotion/threescale/cms/support/PagedFilesSpliterator::validateResultPageSize → SURVIVED |
validateResultPageSize( |
61 | "file", | |
62 | pageNumber, | |
63 | pageSize, | |
64 | resultPage, | |
65 | fileList.getMetadata()); | |
66 | ||
67 |
1
1. getPage : replaced return value with Collections.emptyList for com/fwmotion/threescale/cms/support/PagedFilesSpliterator::getPage → KILLED |
return resultPage; |
68 | } catch (ApiException e) { | |
69 | throw handleApiException(e, "file", pageNumber, pageSize); | |
70 | } | |
71 | } | |
72 | ||
73 | @Nonnull | |
74 | @Override | |
75 | protected AbstractPagedRestApiSpliterator<CmsFile> doSplit( | |
76 | @Positive int requestedPageSize, | |
77 | @Nonnull Collection<CmsFile> currentPage, | |
78 | @PositiveOrZero int currentPageNumber) { | |
79 |
1
1. doSplit : replaced return value with null for com/fwmotion/threescale/cms/support/PagedFilesSpliterator::doSplit → KILLED |
return new PagedFilesSpliterator(filesApi, getObjectMapper(), requestedPageSize, currentPage, currentPageNumber); |
80 | } | |
81 | ||
82 | @Override | |
83 | public int characteristics() { | |
84 |
1
1. characteristics : replaced int return with 0 for com/fwmotion/threescale/cms/support/PagedFilesSpliterator::characteristics → SURVIVED |
return Spliterator.DISTINCT | |
85 | Spliterator.SORTED | | |
86 | Spliterator.ORDERED | | |
87 | Spliterator.NONNULL | | |
88 | Spliterator.IMMUTABLE; | |
89 | } | |
90 | ||
91 | @Nonnull | |
92 | @Override | |
93 | public Comparator<? super CmsFile> getComparator() { | |
94 |
1
1. getComparator : replaced return value with null for com/fwmotion/threescale/cms/support/PagedFilesSpliterator::getComparator → SURVIVED |
return Comparator.comparing(CmsFile::getId); |
95 | } | |
96 | } | |
Mutations | ||
60 |
1.1 |
|
67 |
1.1 |
|
79 |
1.1 |
|
84 |
1.1 |
|
94 |
1.1 |