📍Use lombok, reformat, and optimize the code (#1560)

* Use lombok, reformat, and optimize the code

* Fix merge conflicts and some sonar issues

Co-authored-by: va1m <va1m@email.com>
This commit is contained in:
va1m
2021-03-13 13:19:21 +01:00
committed by GitHub
parent 0e26a6adb5
commit 5cf2fe009b
681 changed files with 2472 additions and 4966 deletions

View File

@ -30,8 +30,7 @@ import com.iluwatar.event.sourcing.processor.DomainEventProcessor;
import com.iluwatar.event.sourcing.state.AccountAggregate;
import java.math.BigDecimal;
import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
/**
* Event Sourcing : Instead of storing just the current state of the data in a domain, use an
@ -50,9 +49,8 @@ import org.slf4j.LoggerFactory;
*
* <p>Created by Serdar Hamzaogullari on 06.08.2017.
*/
@Slf4j
public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
* The constant ACCOUNT OF DAENERYS.
*/

View File

@ -28,8 +28,10 @@ import com.iluwatar.event.sourcing.event.MoneyDepositEvent;
import com.iluwatar.event.sourcing.event.MoneyTransferEvent;
import com.iluwatar.event.sourcing.state.AccountAggregate;
import java.math.BigDecimal;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
/**
* This is the Account class that holds the account info, the account number, account owner name and
@ -38,66 +40,19 @@ import org.slf4j.LoggerFactory;
*
* <p>Created by Serdar Hamzaogullari on 06.08.2017.
*/
@Setter
@Getter
@RequiredArgsConstructor
@Slf4j
public class Account {
private static final Logger LOGGER = LoggerFactory.getLogger(Account.class);
private final int accountNo;
private final String owner;
private BigDecimal money;
private BigDecimal money = BigDecimal.ZERO;
private static final String MSG =
"Some external api for only realtime execution could be called here.";
/**
* Instantiates a new Account.
*
* @param accountNo the account no
* @param owner the owner
*/
public Account(int accountNo, String owner) {
this.accountNo = accountNo;
this.owner = owner;
money = BigDecimal.ZERO;
}
/**
* Gets account no.
*
* @return the account no
*/
public int getAccountNo() {
return accountNo;
}
/**
* Gets owner.
*
* @return the owner
*/
public String getOwner() {
return owner;
}
/**
* Gets money.
*
* @return the money
*/
public BigDecimal getMoney() {
return money;
}
/**
* Sets money.
*
* @param money the money
*/
public void setMoney(BigDecimal money) {
this.money = money;
}
/**
* Copy account.
*

View File

@ -25,6 +25,7 @@ package com.iluwatar.event.sourcing.event;
import com.iluwatar.event.sourcing.domain.Account;
import com.iluwatar.event.sourcing.state.AccountAggregate;
import lombok.Getter;
/**
* This is the class that implements account create event. Holds the necessary info for an account
@ -33,6 +34,7 @@ import com.iluwatar.event.sourcing.state.AccountAggregate;
*
* <p>Created by Serdar Hamzaogullari on 06.08.2017.
*/
@Getter
public class AccountCreateEvent extends DomainEvent {
private final int accountNo;
@ -52,24 +54,6 @@ public class AccountCreateEvent extends DomainEvent {
this.owner = owner;
}
/**
* Gets account no.
*
* @return the account no
*/
public int getAccountNo() {
return accountNo;
}
/**
* Gets owner.
*
* @return the owner
*/
public String getOwner() {
return owner;
}
@Override
public void process() {
var account = AccountAggregate.getAccount(accountNo);

View File

@ -24,12 +24,18 @@
package com.iluwatar.event.sourcing.event;
import java.io.Serializable;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
/**
* This is the base class for domain events. All events must extend this class.
*
* <p>Created by Serdar Hamzaogullari on 06.08.2017.
*/
@Setter
@Getter
@RequiredArgsConstructor
public abstract class DomainEvent implements Serializable {
private final long sequenceId;
@ -37,66 +43,9 @@ public abstract class DomainEvent implements Serializable {
private final String eventClassName;
private boolean realTime = true;
/**
* Instantiates a new Domain event.
*
* @param sequenceId the sequence id
* @param createdTime the created time
* @param eventClassName the event class name
*/
public DomainEvent(long sequenceId, long createdTime, String eventClassName) {
this.sequenceId = sequenceId;
this.createdTime = createdTime;
this.eventClassName = eventClassName;
}
/**
* Gets sequence id.
*
* @return the sequence id
*/
public long getSequenceId() {
return sequenceId;
}
/**
* Gets created time.
*
* @return the created time
*/
public long getCreatedTime() {
return createdTime;
}
/**
* Is real time boolean.
*
* @return the boolean
*/
public boolean isRealTime() {
return realTime;
}
/**
* Sets real time.
*
* @param realTime the real time
*/
public void setRealTime(boolean realTime) {
this.realTime = realTime;
}
/**
* Process.
*/
public abstract void process();
/**
* Gets event class name.
*
* @return the event class name
*/
public String getEventClassName() {
return eventClassName;
}
}

View File

@ -26,6 +26,7 @@ package com.iluwatar.event.sourcing.event;
import com.iluwatar.event.sourcing.state.AccountAggregate;
import java.math.BigDecimal;
import java.util.Optional;
import lombok.Getter;
/**
* This is the class that implements money deposit event. Holds the necessary info for a money
@ -34,6 +35,7 @@ import java.util.Optional;
*
* <p>Created by Serdar Hamzaogullari on 06.08.2017.
*/
@Getter
public class MoneyDepositEvent extends DomainEvent {
private final BigDecimal money;
@ -53,24 +55,6 @@ public class MoneyDepositEvent extends DomainEvent {
this.accountNo = accountNo;
}
/**
* Gets money.
*
* @return the money
*/
public BigDecimal getMoney() {
return money;
}
/**
* Gets account no.
*
* @return the account no
*/
public int getAccountNo() {
return accountNo;
}
@Override
public void process() {
var account = Optional.ofNullable(AccountAggregate.getAccount(accountNo))

View File

@ -26,6 +26,7 @@ package com.iluwatar.event.sourcing.event;
import com.iluwatar.event.sourcing.state.AccountAggregate;
import java.math.BigDecimal;
import java.util.Optional;
import lombok.Getter;
/**
* This is the class that implements money transfer event. Holds the necessary info for a money
@ -34,6 +35,7 @@ import java.util.Optional;
*
* <p>Created by Serdar Hamzaogullari on 06.08.2017.
*/
@Getter
public class MoneyTransferEvent extends DomainEvent {
private final BigDecimal money;
@ -57,33 +59,6 @@ public class MoneyTransferEvent extends DomainEvent {
this.accountNoTo = accountNoTo;
}
/**
* Gets money.
*
* @return the money
*/
public BigDecimal getMoney() {
return money;
}
/**
* Gets account no which the money comes from.
*
* @return the account no from
*/
public int getAccountNoFrom() {
return accountNoFrom;
}
/**
* Gets account no which the money goes to.
*
* @return the account no to
*/
public int getAccountNoTo() {
return accountNoTo;
}
@Override
public void process() {
var accountFrom = Optional.ofNullable(AccountAggregate.getAccount(accountNoFrom))

View File

@ -40,7 +40,7 @@ import org.junit.jupiter.api.Test;
* <p>
* Created by Serdar Hamzaogullari on 19.08.2017.
*/
public class IntegrationTest {
class IntegrationTest {
/**
* The Domain event processor.
@ -51,7 +51,7 @@ public class IntegrationTest {
* Initialize.
*/
@BeforeEach
public void initialize() {
void initialize() {
eventProcessor = new DomainEventProcessor();
}
@ -59,7 +59,7 @@ public class IntegrationTest {
* Test state recovery.
*/
@Test
public void testStateRecovery() {
void testStateRecovery() {
eventProcessor.reset();
eventProcessor.process(new AccountCreateEvent(