This repository has been archived by the owner on Dec 14, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial part in showing the dashboard for a user
- Loading branch information
Showing
30 changed files
with
473 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...org/axonframework/samples/trader/app/command/trading/PortfolioManagementUserListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,46 @@ | |||
/* | |||
* Copyright (c) 2011. Gridshore | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package org.axonframework.samples.trader.app.command.trading; | |||
|
|||
import org.axonframework.commandhandling.CommandBus; | |||
import org.axonframework.eventhandling.annotation.EventHandler; | |||
import org.axonframework.samples.trader.app.api.portfolio.CreatePortfolioCommand; | |||
import org.axonframework.samples.trader.app.api.user.UserCreatedEvent; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Component; | |||
|
|||
/** | |||
* @author Jettro Coenradie | |||
*/ | |||
@Component | |||
public class PortfolioManagementUserListener { | |||
private final static Logger logger = LoggerFactory.getLogger(PortfolioManagementUserListener.class); | |||
private CommandBus commandBus; | |||
|
|||
@EventHandler | |||
public void createNewPortfolioWhenUserIsCreated(UserCreatedEvent event) { | |||
logger.debug("About to dispatch a new command to create a Portfolio for the new user {}", event.getUserIdentifier()); | |||
CreatePortfolioCommand command = new CreatePortfolioCommand(event.getUserIdentifier()); | |||
commandBus.dispatch(command); | |||
} | |||
|
|||
@Autowired | |||
public void setCommandBus(CommandBus commandBus) { | |||
this.commandBus = commandBus; | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
app/src/main/java/org/axonframework/samples/trader/app/query/portfolio/PortfolioEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,61 @@ | |||
/* | |||
* Copyright (c) 2011. Gridshore | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package org.axonframework.samples.trader.app.query.portfolio; | |||
|
|||
import org.springframework.data.annotation.Id; | |||
|
|||
/** | |||
* @author Jettro Coenradie | |||
*/ | |||
public class PortfolioEntry { | |||
@Id | |||
private String identifier; | |||
private String userIdentifier; | |||
private long amountOfMoney; | |||
private long reservedAmountOfMoney; | |||
|
|||
public String getUserIdentifier() { | |||
return userIdentifier; | |||
} | |||
|
|||
public void setUserIdentifier(String userIdentifier) { | |||
this.userIdentifier = userIdentifier; | |||
} | |||
|
|||
public long getAmountOfMoney() { | |||
return amountOfMoney; | |||
} | |||
|
|||
public void setAmountOfMoney(long amountOfMoney) { | |||
this.amountOfMoney = amountOfMoney; | |||
} | |||
|
|||
public String getIdentifier() { | |||
return identifier; | |||
} | |||
|
|||
public void setIdentifier(String identifier) { | |||
this.identifier = identifier; | |||
} | |||
|
|||
public long getReservedAmountOfMoney() { | |||
return reservedAmountOfMoney; | |||
} | |||
|
|||
public void setReservedAmountOfMoney(long reservedAmountOfMoney) { | |||
this.reservedAmountOfMoney = reservedAmountOfMoney; | |||
} | |||
} |
79 changes: 79 additions & 0 deletions
79
...src/main/java/org/axonframework/samples/trader/app/query/portfolio/PortfolioListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,79 @@ | |||
/* | |||
* Copyright (c) 2011. Gridshore | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package org.axonframework.samples.trader.app.query.portfolio; | |||
|
|||
import org.axonframework.eventhandling.annotation.EventHandler; | |||
import org.axonframework.samples.trader.app.api.portfolio.PortfolioCreatedEvent; | |||
import org.axonframework.samples.trader.app.api.portfolio.money.MoneyAddedToPortfolioEvent; | |||
import org.axonframework.samples.trader.app.api.portfolio.money.MoneyReservedFromPortfolioEvent; | |||
import org.axonframework.samples.trader.app.api.portfolio.money.PaymentMadeFromPortfolioEvent; | |||
import org.axonframework.samples.trader.app.query.portfolio.repositories.PortfolioQueryRepository; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Component; | |||
|
|||
/** | |||
* @author Jettro Coenradie | |||
*/ | |||
@Component | |||
public class PortfolioListener { | |||
private final static Logger logger = LoggerFactory.getLogger(PortfolioListener.class); | |||
|
|||
private PortfolioQueryRepository portfolioRepository; | |||
|
|||
@EventHandler | |||
public void handleEvent(PortfolioCreatedEvent event) { | |||
logger.debug("About to handle the PortfolioCreatedEvent for user with identifier {}", | |||
event.getUserIdentifier().asString()); | |||
|
|||
PortfolioEntry portfolioEntry = new PortfolioEntry(); | |||
portfolioEntry.setIdentifier(event.getPortfolioIdentifier().asString()); | |||
portfolioEntry.setUserIdentifier(event.getUserIdentifier().asString()); | |||
portfolioEntry.setAmountOfMoney(0); | |||
portfolioEntry.setReservedAmountOfMoney(0); | |||
|
|||
portfolioRepository.save(portfolioEntry); | |||
} | |||
|
|||
@EventHandler | |||
public void handleEvent(MoneyAddedToPortfolioEvent event) { | |||
PortfolioEntry portfolioEntry = portfolioRepository.findOne(event.getPortfolioIdentifier().asString()); | |||
portfolioEntry.setAmountOfMoney(portfolioEntry.getAmountOfMoney() + event.getMoneyAddedInCents()); | |||
portfolioRepository.save(portfolioEntry); | |||
} | |||
|
|||
@EventHandler | |||
public void handleEvent(PaymentMadeFromPortfolioEvent event) { | |||
PortfolioEntry portfolioEntry = portfolioRepository.findOne(event.getPortfolioIdentifier().asString()); | |||
portfolioEntry.setAmountOfMoney(portfolioEntry.getAmountOfMoney() - event.getAmountPaidInCents()); | |||
portfolioRepository.save(portfolioEntry); | |||
} | |||
|
|||
@EventHandler | |||
public void handleEvent(MoneyReservedFromPortfolioEvent event) { | |||
PortfolioEntry portfolioEntry = portfolioRepository.findOne(event.getPortfolioIdentifier().asString()); | |||
portfolioEntry.setReservedAmountOfMoney(portfolioEntry.getReservedAmountOfMoney() + event.getAmountToReserve()); | |||
portfolioEntry.setAmountOfMoney(portfolioEntry.getAmountOfMoney() - event.getAmountToReserve()); | |||
portfolioRepository.save(portfolioEntry); | |||
} | |||
|
|||
|
|||
@Autowired | |||
public void setPortfolioRepository(PortfolioQueryRepository portfolioRepository) { | |||
this.portfolioRepository = portfolioRepository; | |||
} | |||
} |
26 changes: 26 additions & 0 deletions
26
...onframework/samples/trader/app/query/portfolio/repositories/PortfolioQueryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,26 @@ | |||
/* | |||
* Copyright (c) 2011. Gridshore | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package org.axonframework.samples.trader.app.query.portfolio.repositories; | |||
|
|||
import org.axonframework.samples.trader.app.query.portfolio.PortfolioEntry; | |||
import org.springframework.data.repository.PagingAndSortingRepository; | |||
|
|||
/** | |||
* @author Jettro Coenradie | |||
*/ | |||
public interface PortfolioQueryRepository extends PagingAndSortingRepository<PortfolioEntry, String> { | |||
PortfolioEntry findByUserIdentifier(String userIdentifier); | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.