1
+ @startuml
2
+ package com . iluwatar . hexagonal . sampledata {
3
+ class SampleData {
4
+ - PLAYERS : List<PlayerDetails> {static}
5
+ - RANDOM : SecureRandom {static}
6
+ + SampleData ()
7
+ - getRandomPlayerDetails() : PlayerDetails {static}
8
+ + submitTickets(lotteryService : LotteryService, numTickets : int) {static}
9
+ }
10
+ }
11
+ package com . iluwatar . hexagonal . service {
12
+ class ConsoleLottery {
13
+ - LOGGER : Logger {static}
14
+ + ConsoleLottery ()
15
+ + main(args : String[]) {static}
16
+ - printMainMenu() {static}
17
+ - readString(scanner : Scanner) : String {static}
18
+ }
19
+ interface LotteryConsoleService {
20
+ + addFundsToLotteryAccount (WireTransfers , Scanner ) {abstract }
21
+ + checkTicket (LotteryService , Scanner ) {abstract }
22
+ + queryLotteryAccountFunds (WireTransfers , Scanner ) {abstract }
23
+ + submitTicket (LotteryService , Scanner ) {abstract }
24
+ }
25
+ class LotteryConsoleServiceImpl {
26
+ - logger : Logger
27
+ + LotteryConsoleServiceImpl(logger : Logger)
28
+ + addFundsToLotteryAccount(bank : WireTransfers, scanner : Scanner)
29
+ + checkTicket(service : LotteryService, scanner : Scanner)
30
+ + queryLotteryAccountFunds(bank : WireTransfers, scanner : Scanner)
31
+ - readString(scanner : Scanner) : String
32
+ + submitTicket(service : LotteryService, scanner : Scanner)
33
+ }
34
+ }
35
+ package com . iluwatar . hexagonal . mongo {
36
+ class MongoConnectionPropertiesLoader {
37
+ - DEFAULT_HOST : String {static}
38
+ - DEFAULT_PORT : int {static}
39
+ - LOGGER : Logger {static}
40
+ + MongoConnectionPropertiesLoader ()
41
+ + load() {static}
42
+ }
43
+ }
44
+ package com . iluwatar . hexagonal . domain {
45
+ class LotteryAdministration {
46
+ - notifications : LotteryEventLog
47
+ - repository : LotteryTicketRepository
48
+ - wireTransfers : WireTransfers
49
+ + LotteryAdministration(repository : LotteryTicketRepository, notifications : LotteryEventLog, wireTransfers : WireTransfers)
50
+ + getAllSubmittedTickets() : Map<LotteryTicketId, LotteryTicket>
51
+ + performLottery () : LotteryNumbers
52
+ + resetLottery ()
53
+ }
54
+ class LotteryConstants {
55
+ + PLAYER_MAX_BALANCE : int {static}
56
+ + PRIZE_AMOUNT : int {static}
57
+ + SERVICE_BANK_ACCOUNT : String {static}
58
+ + SERVICE_BANK_ACCOUNT_BALANCE : int {static}
59
+ + TICKET_PRIZE : int {static}
60
+ - LotteryConstants ()
61
+ }
62
+ class LotteryNumbers {
63
+ + MAX_NUMBER : int {static}
64
+ + MIN_NUMBER : int {static}
65
+ + NUM_NUMBERS : int {static}
66
+ - numbers : Set<Integer>
67
+ - LotteryNumbers ()
68
+ - LotteryNumbers(givenNumbers : Set<Integer>)
69
+ # canEqual(other : Object) : boolean
70
+ + create(givenNumbers : Set<Integer>) : LotteryNumbers {static}
71
+ + createRandom() : LotteryNumbers {static}
72
+ + equals(o : Object) : boolean
73
+ - generateRandomNumbers ()
74
+ + getNumbers() : Set<Integer>
75
+ + getNumbersAsString () : String
76
+ + hashCode () : int
77
+ + toString () : String
78
+ }
79
+ - class RandomNumberGenerator {
80
+ - randomIterator : OfInt
81
+ + RandomNumberGenerator (min : int , max : int )
82
+ + nextInt () : int
83
+ }
84
+ class LotteryService {
85
+ - notifications : LotteryEventLog
86
+ - repository : LotteryTicketRepository
87
+ - wireTransfers : WireTransfers
88
+ + LotteryService(repository : LotteryTicketRepository, notifications : LotteryEventLog, wireTransfers : WireTransfers)
89
+ + checkTicketForPrize(id : LotteryTicketId, winningNumbers : LotteryNumbers) : LotteryTicketCheckResult
90
+ + submitTicket(ticket : LotteryTicket) : Optional<LotteryTicketId>
91
+ }
92
+ class LotteryTicketCheckResult {
93
+ - prizeAmount : int
94
+ - result : CheckResult
95
+ + LotteryTicketCheckResult(result : CheckResult)
96
+ + LotteryTicketCheckResult(result : CheckResult, prizeAmount : int)
97
+ # canEqual(other : Object) : boolean
98
+ + equals(o : Object) : boolean
99
+ + getPrizeAmount () : int
100
+ + getResult () : CheckResult
101
+ + hashCode () : int
102
+ }
103
+ enum CheckResult {
104
+ + NO_PRIZE {static}
105
+ + TICKET_NOT_SUBMITTED {static}
106
+ + WIN_PRIZE {static}
107
+ + valueOf(name : String) : CheckResult {static}
108
+ + values() : CheckResult[] {static}
109
+ }
110
+ class LotteryTicketId {
111
+ - id : int
112
+ - numAllocated : AtomicInteger {static}
113
+ + LotteryTicketId ()
114
+ + LotteryTicketId(id : int)
115
+ # canEqual(other : Object) : boolean
116
+ + equals(o : Object) : boolean
117
+ + getId () : int
118
+ + hashCode () : int
119
+ + toString () : String
120
+ }
121
+ class LotteryUtils {
122
+ - LotteryUtils ()
123
+ + checkTicketForPrize(repository : LotteryTicketRepository, id : LotteryTicketId, winningNumbers : LotteryNumbers) : LotteryTicketCheckResult {static}
124
+ }
125
+ }
126
+ package com . iluwatar . hexagonal . banking {
127
+ class InMemoryBank {
128
+ - accounts : Map<String, Integer> {static}
129
+ + InMemoryBank ()
130
+ + getFunds(bankAccount : String) : int
131
+ + setFunds(bankAccount : String, amount : int)
132
+ + transferFunds(amount : int, sourceAccount : String, destinationAccount : String) : boolean
133
+ }
134
+ class MongoBank {
135
+ - DEFAULT_ACCOUNTS_COLLECTION : String {static}
136
+ - DEFAULT_DB : String {static}
137
+ - accountsCollection : MongoCollection<Document>
138
+ - database : MongoDatabase
139
+ - mongoClient : MongoClient
140
+ + MongoBank ()
141
+ + MongoBank(dbName : String, accountsCollectionName : String)
142
+ + connect ()
143
+ + connect(dbName : String, accountsCollectionName : String)
144
+ + getAccountsCollection() : MongoCollection<Document>
145
+ + getDatabase () : MongoDatabase
146
+ + getFunds(bankAccount : String) : int
147
+ + getMongoClient () : MongoClient
148
+ + setFunds(bankAccount : String, amount : int)
149
+ + transferFunds(amount : int, sourceAccount : String, destinationAccount : String) : boolean
150
+ }
151
+ interface WireTransfers {
152
+ + getFunds (String ) : int {abstract }
153
+ + setFunds (String , int ) {abstract }
154
+ + transferFunds (int , String , String ) : boolean {abstract }
155
+ }
156
+ }
157
+ package com . iluwatar . hexagonal . database {
158
+ class InMemoryTicketRepository {
159
+ - tickets : Map<LotteryTicketId, LotteryTicket> {static}
160
+ + InMemoryTicketRepository ()
161
+ + deleteAll ()
162
+ + findAll() : Map<LotteryTicketId, LotteryTicket>
163
+ + findById(id : LotteryTicketId) : Optional<LotteryTicket>
164
+ + save(ticket : LotteryTicket) : Optional<LotteryTicketId>
165
+ }
166
+ interface LotteryTicketRepository {
167
+ + deleteAll () {abstract }
168
+ + findAll () : Map <LotteryTicketId , LotteryTicket > {abstract }
169
+ + findById (LotteryTicketId ) : Optional <LotteryTicket > {abstract }
170
+ + save (LotteryTicket ) : Optional <LotteryTicketId > {abstract }
171
+ }
172
+ class MongoTicketRepository {
173
+ - DEFAULT_COUNTERS_COLLECTION : String {static}
174
+ - DEFAULT_DB : String {static}
175
+ - DEFAULT_TICKETS_COLLECTION : String {static}
176
+ - TICKET_ID : String {static}
177
+ - countersCollection : MongoCollection<Document>
178
+ - database : MongoDatabase
179
+ - mongoClient : MongoClient
180
+ - ticketsCollection : MongoCollection<Document>
181
+ + MongoTicketRepository ()
182
+ + MongoTicketRepository(dbName : String, ticketsCollectionName : String, countersCollectionName : String)
183
+ + connect ()
184
+ + connect(dbName : String, ticketsCollectionName : String, countersCollectionName : String)
185
+ + deleteAll ()
186
+ - docToTicket(doc : Document) : LotteryTicket
187
+ + findAll() : Map<LotteryTicketId, LotteryTicket>
188
+ + findById(id : LotteryTicketId) : Optional<LotteryTicket>
189
+ + getCountersCollection() : MongoCollection<Document>
190
+ + getNextId () : int
191
+ + getTicketsCollection() : MongoCollection<Document>
192
+ - initCounters ()
193
+ + save(ticket : LotteryTicket) : Optional<LotteryTicketId>
194
+ }
195
+ }
196
+ package com . iluwatar . hexagonal {
197
+ class App {
198
+ + App ()
199
+ + main(args : String[]) {static}
200
+ }
201
+ }
202
+ package com . iluwatar . hexagonal . administration {
203
+ class ConsoleAdministration {
204
+ - LOGGER : Logger {static}
205
+ + ConsoleAdministration ()
206
+ + main(args : String[]) {static}
207
+ - printMainMenu() {static}
208
+ - readString(scanner : Scanner) : String {static}
209
+ }
210
+ interface ConsoleAdministrationSrv {
211
+ + getAllSubmittedTickets () {abstract }
212
+ + performLottery () {abstract }
213
+ + resetLottery () {abstract }
214
+ }
215
+ class ConsoleAdministrationSrvImpl {
216
+ - administration : LotteryAdministration
217
+ - logger : Logger
218
+ + ConsoleAdministrationSrvImpl(administration : LotteryAdministration, logger : Logger)
219
+ + getAllSubmittedTickets ()
220
+ + performLottery ()
221
+ + resetLottery ()
222
+ }
223
+ }
224
+ package com . iluwatar . hexagonal . eventlog {
225
+ interface LotteryEventLog {
226
+ + prizeError (PlayerDetails , int ) {abstract }
227
+ + ticketDidNotWin (PlayerDetails ) {abstract }
228
+ + ticketSubmitError (PlayerDetails ) {abstract }
229
+ + ticketSubmitted (PlayerDetails ) {abstract }
230
+ + ticketWon (PlayerDetails , int ) {abstract }
231
+ }
232
+ class MongoEventLog {
233
+ - DEFAULT_DB : String {static}
234
+ - DEFAULT_EVENTS_COLLECTION : String {static}
235
+ - EMAIL : String {static}
236
+ + MESSAGE : String {static}
237
+ - PHONE : String {static}
238
+ - database : MongoDatabase
239
+ - eventsCollection : MongoCollection<Document>
240
+ - mongoClient : MongoClient
241
+ - stdOutEventLog : StdOutEventLog
242
+ + MongoEventLog ()
243
+ + MongoEventLog(dbName : String, eventsCollectionName : String)
244
+ + connect ()
245
+ + connect(dbName : String, eventsCollectionName : String)
246
+ + getDatabase () : MongoDatabase
247
+ + getEventsCollection() : MongoCollection<Document>
248
+ + getMongoClient () : MongoClient
249
+ + prizeError(details : PlayerDetails, prizeAmount : int)
250
+ + ticketDidNotWin(details : PlayerDetails)
251
+ + ticketSubmitError(details : PlayerDetails)
252
+ + ticketSubmitted(details : PlayerDetails)
253
+ + ticketWon(details : PlayerDetails, prizeAmount : int)
254
+ }
255
+ class StdOutEventLog {
256
+ - LOGGER : Logger {static}
257
+ + StdOutEventLog ()
258
+ + prizeError(details : PlayerDetails, prizeAmount : int)
259
+ + ticketDidNotWin(details : PlayerDetails)
260
+ + ticketSubmitError(details : PlayerDetails)
261
+ + ticketSubmitted(details : PlayerDetails)
262
+ + ticketWon(details : PlayerDetails, prizeAmount : int)
263
+ }
264
+ }
265
+ LotteryAdministration --> "- wireTransfers " WireTransfers
266
+ LotteryService --> "- notifications " LotteryEventLog
267
+ LotteryAdministration --> "- repository " LotteryTicketRepository
268
+ MongoEventLog --> "- stdOutEventLog " StdOutEventLog
269
+ LotteryService --> "- wireTransfers " WireTransfers
270
+ LotteryAdministration --> "- notifications " LotteryEventLog
271
+ ConsoleAdministrationSrvImpl --> "- administration " LotteryAdministration
272
+ LotteryService --> "- repository " LotteryTicketRepository
273
+ LotteryTicketCheckResult --> "- result " CheckResult
274
+ ConsoleAdministrationSrvImpl ..|> ConsoleAdministrationSrv
275
+ InMemoryBank ..|> WireTransfers
276
+ MongoBank ..|> WireTransfers
277
+ InMemoryTicketRepository ..|> LotteryTicketRepository
278
+ MongoTicketRepository ..|> LotteryTicketRepository
279
+ MongoEventLog ..|> LotteryEventLog
280
+ StdOutEventLog ..|> LotteryEventLog
281
+ LotteryConsoleServiceImpl ..|> LotteryConsoleService
282
+ @enduml
0 commit comments