|
17 | 17 | */
|
18 | 18 | package ru.mystamps.web.service;
|
19 | 19 |
|
20 |
| -import java.util.ArrayList; |
21 |
| -import java.util.Collections; |
22 | 20 | import java.util.List;
|
23 | 21 |
|
24 | 22 | import org.apache.commons.lang3.Validate;
|
|
36 | 34 | import ru.mystamps.web.dao.dto.EntityWithIdDto;
|
37 | 35 | import ru.mystamps.web.dao.dto.TransactionParticipantDto;
|
38 | 36 | import ru.mystamps.web.service.dto.AddParticipantDto;
|
39 |
| -import ru.mystamps.web.service.dto.GroupedTransactionParticipantDto; |
40 | 37 | import ru.mystamps.web.support.spring.security.HasAuthority;
|
41 | 38 |
|
42 | 39 | @RequiredArgsConstructor
|
@@ -69,85 +66,15 @@ public void add(AddParticipantDto dto) {
|
69 | 66 | @Override
|
70 | 67 | @Transactional(readOnly = true)
|
71 | 68 | @PreAuthorize(HasAuthority.ADD_SERIES_SALES)
|
72 |
| - @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") |
73 |
| - public List<GroupedTransactionParticipantDto> findAllBuyers() { |
74 |
| - List<TransactionParticipantDto> participants = |
75 |
| - transactionParticipantDao.findBuyersWithParents(); |
76 |
| - if (participants.isEmpty()) { |
77 |
| - return Collections.emptyList(); |
78 |
| - } |
79 |
| - |
80 |
| - // Because of Thymeleaf's restrictions we can't return participants as-is and need this |
81 |
| - // transformation |
82 |
| - List<GroupedTransactionParticipantDto> items = new ArrayList<>(); |
83 |
| - String lastParent = null; |
84 |
| - GroupedTransactionParticipantDto lastItem = null; |
85 |
| - |
86 |
| - for (TransactionParticipantDto participant : participants) { |
87 |
| - String name = participant.getName(); |
88 |
| - Integer id = participant.getId(); |
89 |
| - String parent = participant.getParentName(); |
90 |
| - |
91 |
| - boolean participantWithoutParent = parent == null; |
92 |
| - boolean createNewItem = participantWithoutParent || !parent.equals(lastParent); |
93 |
| - |
94 |
| - if (createNewItem) { |
95 |
| - lastParent = parent; |
96 |
| - if (participantWithoutParent) { |
97 |
| - lastItem = new GroupedTransactionParticipantDto(id, name); |
98 |
| - } else { |
99 |
| - lastItem = new GroupedTransactionParticipantDto(parent); |
100 |
| - lastItem.addChild(id, name); |
101 |
| - } |
102 |
| - items.add(lastItem); |
103 |
| - } else { |
104 |
| - lastItem.addChild(id, name); |
105 |
| - } |
106 |
| - } |
107 |
| - |
108 |
| - return items; |
| 69 | + public List<TransactionParticipantDto> findBuyersWithParents() { |
| 70 | + return transactionParticipantDao.findBuyersWithParents(); |
109 | 71 | }
|
110 | 72 |
|
111 | 73 | @Override
|
112 | 74 | @Transactional(readOnly = true)
|
113 | 75 | @PreAuthorize(HasAuthority.ADD_SERIES_SALES)
|
114 |
| - @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") |
115 |
| - public List<GroupedTransactionParticipantDto> findAllSellers() { |
116 |
| - List<TransactionParticipantDto> participants = |
117 |
| - transactionParticipantDao.findSellersWithParents(); |
118 |
| - if (participants.isEmpty()) { |
119 |
| - return Collections.emptyList(); |
120 |
| - } |
121 |
| - |
122 |
| - // Because of Thymeleaf's restrictions we can't return participants as-is and need this |
123 |
| - // transformation |
124 |
| - List<GroupedTransactionParticipantDto> items = new ArrayList<>(); |
125 |
| - String lastParent = null; |
126 |
| - GroupedTransactionParticipantDto lastItem = null; |
127 |
| - |
128 |
| - for (TransactionParticipantDto participant : participants) { |
129 |
| - String name = participant.getName(); |
130 |
| - Integer id = participant.getId(); |
131 |
| - String parent = participant.getParentName(); |
132 |
| - |
133 |
| - boolean participantWithoutParent = parent == null; |
134 |
| - boolean createNewItem = participantWithoutParent || !parent.equals(lastParent); |
135 |
| - |
136 |
| - if (createNewItem) { |
137 |
| - lastParent = parent; |
138 |
| - if (participantWithoutParent) { |
139 |
| - lastItem = new GroupedTransactionParticipantDto(id, name); |
140 |
| - } else { |
141 |
| - lastItem = new GroupedTransactionParticipantDto(parent); |
142 |
| - lastItem.addChild(id, name); |
143 |
| - } |
144 |
| - items.add(lastItem); |
145 |
| - } else { |
146 |
| - lastItem.addChild(id, name); |
147 |
| - } |
148 |
| - } |
149 |
| - |
150 |
| - return items; |
| 76 | + public List<TransactionParticipantDto> findSellersWithParents() { |
| 77 | + return transactionParticipantDao.findSellersWithParents(); |
151 | 78 | }
|
152 | 79 |
|
153 | 80 | @Override
|
|
0 commit comments