Implemented parties report
This commit is contained in:
parent
099dd81246
commit
fa4ea75a21
@ -53,6 +53,7 @@ public class NodeBase implements ChannelObserver {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends product transaction to node through a channel based on its type.
|
* Sends product transaction to node through a channel based on its type.
|
||||||
|
*
|
||||||
* @param product product to be sent
|
* @param product product to be sent
|
||||||
* @param node receiver node
|
* @param node receiver node
|
||||||
*/
|
*/
|
||||||
@ -70,6 +71,7 @@ public class NodeBase implements ChannelObserver {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends financial transaction to node through a channel based on previous transaction type.
|
* Sends financial transaction to node through a channel based on previous transaction type.
|
||||||
|
*
|
||||||
* @param amount amount to be sent
|
* @param amount amount to be sent
|
||||||
* @param node receiver node
|
* @param node receiver node
|
||||||
* @param prevTransaction previous product transaction
|
* @param prevTransaction previous product transaction
|
||||||
@ -87,17 +89,16 @@ public class NodeBase implements ChannelObserver {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Receives (processes) transaction.
|
* Receives (processes) transaction.
|
||||||
|
*
|
||||||
* @param transaction transaction to be received
|
* @param transaction transaction to be received
|
||||||
*/
|
*/
|
||||||
public void receiveTransaction(Transaction transaction) {
|
public void receiveTransaction(Transaction transaction) {
|
||||||
try {
|
try {
|
||||||
receiveTransaction((ProductTransaction) transaction);
|
receiveTransaction((ProductTransaction) transaction);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
try {
|
try {
|
||||||
receiveTransaction((FinancialTransaction) transaction);
|
receiveTransaction((FinancialTransaction) transaction);
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (Exception ex) {
|
|
||||||
LOGGER.log(Level.WARNING, e.getMessage());
|
LOGGER.log(Level.WARNING, e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,6 +106,7 @@ public class NodeBase implements ChannelObserver {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Receives (validates) product transaction and sends financial transaction as response.
|
* Receives (validates) product transaction and sends financial transaction as response.
|
||||||
|
*
|
||||||
* @param transaction transaction to be received
|
* @param transaction transaction to be received
|
||||||
*/
|
*/
|
||||||
public void receiveTransaction(ProductTransaction transaction) {
|
public void receiveTransaction(ProductTransaction transaction) {
|
||||||
@ -113,12 +115,12 @@ public class NodeBase implements ChannelObserver {
|
|||||||
transaction.endTransaction();
|
transaction.endTransaction();
|
||||||
sendTransaction(transaction.getProduct().getPrice(), transaction.getNodeCreator(), transaction);
|
sendTransaction(transaction.getProduct().getPrice(), transaction.getNodeCreator(), transaction);
|
||||||
|
|
||||||
}
|
} else refuseTransaction(transaction);
|
||||||
else refuseTransaction(transaction);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Receives (validates) financial transaction.
|
* Receives (validates) financial transaction.
|
||||||
|
*
|
||||||
* @param transaction transaction to be received
|
* @param transaction transaction to be received
|
||||||
*/
|
*/
|
||||||
public void receiveTransaction(FinancialTransaction transaction) {
|
public void receiveTransaction(FinancialTransaction transaction) {
|
||||||
@ -129,6 +131,7 @@ public class NodeBase implements ChannelObserver {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds transaction to refused transactions.
|
* Adds transaction to refused transactions.
|
||||||
|
*
|
||||||
* @param transaction
|
* @param transaction
|
||||||
*/
|
*/
|
||||||
public void refuseTransaction(Transaction transaction) {
|
public void refuseTransaction(Transaction transaction) {
|
||||||
@ -140,11 +143,15 @@ public class NodeBase implements ChannelObserver {
|
|||||||
* Receives all transactions for this node.
|
* Receives all transactions for this node.
|
||||||
*/
|
*/
|
||||||
public void receiveTransactions() {
|
public void receiveTransactions() {
|
||||||
subscribedChannels.keySet().forEach(ch -> ch.getTransactions(this).forEach(t -> {receiveTransaction(t); ch.disposeOf(t);}));
|
subscribedChannels.keySet().forEach(ch -> ch.getTransactions(this).forEach(t -> {
|
||||||
|
receiveTransaction(t);
|
||||||
|
ch.disposeOf(t);
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates requirement based on data provided.
|
* Creates requirement based on data provided.
|
||||||
|
*
|
||||||
* @param tType transaction type
|
* @param tType transaction type
|
||||||
* @param pType product type
|
* @param pType product type
|
||||||
* @param pName product name
|
* @param pName product name
|
||||||
@ -155,8 +162,7 @@ public class NodeBase implements ChannelObserver {
|
|||||||
if (price == null) {
|
if (price == null) {
|
||||||
try {
|
try {
|
||||||
price = storage.getProduct(pName, pType).getPrice();
|
price = storage.getProduct(pName, pType).getPrice();
|
||||||
}
|
} catch (NullPointerException e) {
|
||||||
catch (NullPointerException e) {
|
|
||||||
refusedRequirements.add(new RefusedRequirement(tType, pType, pName, price));
|
refusedRequirements.add(new RefusedRequirement(tType, pType, pName, price));
|
||||||
throw new InsufficientResourcesException("product unavailable");
|
throw new InsufficientResourcesException("product unavailable");
|
||||||
}
|
}
|
||||||
@ -164,8 +170,7 @@ public class NodeBase implements ChannelObserver {
|
|||||||
if (tType == TransactionType.SALE) {
|
if (tType == TransactionType.SALE) {
|
||||||
try {
|
try {
|
||||||
storage.getProduct(pName, pType).setStateToInRequirement();
|
storage.getProduct(pName, pType).setStateToInRequirement();
|
||||||
}
|
} catch (NullPointerException | IllegalStateException e) {
|
||||||
catch (NullPointerException | IllegalStateException e) {
|
|
||||||
refusedRequirements.add(new RefusedRequirement(tType, pType, pName, price));
|
refusedRequirements.add(new RefusedRequirement(tType, pType, pName, price));
|
||||||
throw new InsufficientResourcesException("product unavailable");
|
throw new InsufficientResourcesException("product unavailable");
|
||||||
}
|
}
|
||||||
@ -178,6 +183,7 @@ public class NodeBase implements ChannelObserver {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Accepts requirement and creates response.
|
* Accepts requirement and creates response.
|
||||||
|
*
|
||||||
* @param req requirement to be accepted
|
* @param req requirement to be accepted
|
||||||
* @throws InsufficientResourcesException if product is unavailable
|
* @throws InsufficientResourcesException if product is unavailable
|
||||||
*/
|
*/
|
||||||
@ -185,19 +191,18 @@ public class NodeBase implements ChannelObserver {
|
|||||||
LOGGER.log(Level.INFO, this.nodeType.toString() + " accepted " + req.toString());
|
LOGGER.log(Level.INFO, this.nodeType.toString() + " accepted " + req.toString());
|
||||||
if (req.getTransactionType() == TransactionType.SALE) {
|
if (req.getTransactionType() == TransactionType.SALE) {
|
||||||
createRequirement(TransactionType.PURCHASE, req.getProductType(), req.getProductName(), req.getPrice());
|
createRequirement(TransactionType.PURCHASE, req.getProductType(), req.getProductName(), req.getPrice());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (req.getPrice().isGreaterThanOrEqualTo(storage.getProduct(req.getProductName(), req.getProductType()).getPrice().multiply(0.9))) {
|
if (req.getPrice().isGreaterThanOrEqualTo(storage.getProduct(req.getProductName(), req.getProductType()).getPrice().multiply(0.9))) {
|
||||||
storage.getProduct(req.getProductName(), req.getProductType()).setPrice(req.getPrice());
|
storage.getProduct(req.getProductName(), req.getProductType()).setPrice(req.getPrice());
|
||||||
sendTransaction(storage.getProduct(req.getProductName(), req.getProductType()), req.getCreator());
|
sendTransaction(storage.getProduct(req.getProductName(), req.getProductType()), req.getCreator());
|
||||||
}
|
} else createRequirement(TransactionType.SALE, req.getProductType(), req.getProductName(), req.getPrice());
|
||||||
else createRequirement(TransactionType.SALE, req.getProductType(), req.getProductName(), req.getPrice());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds channel to subscribed channels with correct type.
|
* Adds channel to subscribed channels with correct type.
|
||||||
|
*
|
||||||
* @param channel channel to be subscribed
|
* @param channel channel to be subscribed
|
||||||
* @param type type of subscription
|
* @param type type of subscription
|
||||||
*/
|
*/
|
||||||
@ -209,6 +214,7 @@ public class NodeBase implements ChannelObserver {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes channel from subscribed channels.
|
* Removes channel from subscribed channels.
|
||||||
|
*
|
||||||
* @param channel
|
* @param channel
|
||||||
*/
|
*/
|
||||||
public void unsubscribeFromChannel(ChannelBase channel) {
|
public void unsubscribeFromChannel(ChannelBase channel) {
|
||||||
@ -218,20 +224,20 @@ public class NodeBase implements ChannelObserver {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Proceed specific type of action on provided product if its possible. (Propagated to its storage).
|
* Proceed specific type of action on provided product if its possible. (Propagated to its storage).
|
||||||
|
*
|
||||||
* @param action type of product operation to do
|
* @param action type of product operation to do
|
||||||
* @param product product to proceed
|
* @param product product to proceed
|
||||||
*/
|
*/
|
||||||
public void doAction(ProductOperationType action, Product product) throws IllegalCallerException
|
public void doAction(ProductOperationType action, Product product) throws IllegalCallerException {
|
||||||
{
|
this.storage.doAction(action, product);
|
||||||
this.storage.doAction(action,product);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls specific ProductOperation on each product in stock (Propagated to its storage).
|
* Calls specific ProductOperation on each product in stock (Propagated to its storage).
|
||||||
|
*
|
||||||
* @param action ProductOperationType
|
* @param action ProductOperationType
|
||||||
*/
|
*/
|
||||||
public void doAction(ProductOperationType action)
|
public void doAction(ProductOperationType action) {
|
||||||
{
|
|
||||||
this.storage.doAction(action);
|
this.storage.doAction(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,7 +253,7 @@ public class NodeBase implements ChannelObserver {
|
|||||||
return money;
|
return money;
|
||||||
}
|
}
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
public Map<ChannelBase, ChannelSubscriptionType> getSubscribedChannels() {
|
public Map<ChannelBase, ChannelSubscriptionType> getSubscribedChannels() {
|
||||||
return subscribedChannels;
|
return subscribedChannels;
|
||||||
}
|
}
|
||||||
@ -264,18 +270,20 @@ public class NodeBase implements ChannelObserver {
|
|||||||
return allowedPurchaser;
|
return allowedPurchaser;
|
||||||
}
|
}
|
||||||
|
|
||||||
=======
|
|
||||||
/**
|
/**
|
||||||
* Adds amount to current assets
|
* Adds amount to current assets
|
||||||
|
*
|
||||||
* @param m amount to be added
|
* @param m amount to be added
|
||||||
*/
|
*/
|
||||||
>>>>>>> develop
|
|
||||||
public void addMoney(MonetaryAmount m) {
|
public void addMoney(MonetaryAmount m) {
|
||||||
this.money = this.money.add(m);
|
this.money = this.money.add(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subtracts amount from current assets.
|
* Subtracts amount from current assets.
|
||||||
|
*
|
||||||
* @param m amount to be subtracted
|
* @param m amount to be subtracted
|
||||||
*/
|
*/
|
||||||
public void subtractMoney(MonetaryAmount m) {
|
public void subtractMoney(MonetaryAmount m) {
|
||||||
@ -284,6 +292,7 @@ public class NodeBase implements ChannelObserver {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates signature on transaction.
|
* Validates signature on transaction.
|
||||||
|
*
|
||||||
* @param transaction transaction to be validated
|
* @param transaction transaction to be validated
|
||||||
* @return signature is valid
|
* @return signature is valid
|
||||||
*/
|
*/
|
||||||
@ -293,6 +302,7 @@ public class NodeBase implements ChannelObserver {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if requirement creator is an allowed purchaser or allowed seller.
|
* Checks if requirement creator is an allowed purchaser or allowed seller.
|
||||||
|
*
|
||||||
* @param req requirement
|
* @param req requirement
|
||||||
* @return creator is valid
|
* @return creator is valid
|
||||||
*/
|
*/
|
||||||
@ -306,6 +316,7 @@ public class NodeBase implements ChannelObserver {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if requirement type corresponds with channel subscription type.
|
* Checks if requirement type corresponds with channel subscription type.
|
||||||
|
*
|
||||||
* @param requirement requirement
|
* @param requirement requirement
|
||||||
* @param channel channel
|
* @param channel channel
|
||||||
* @return requirement type corresponds with channel subscription type
|
* @return requirement type corresponds with channel subscription type
|
||||||
@ -325,6 +336,7 @@ public class NodeBase implements ChannelObserver {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Chacks if product is available or if node has enough money
|
* Chacks if product is available or if node has enough money
|
||||||
|
*
|
||||||
* @param req requirement
|
* @param req requirement
|
||||||
* @return product is available or node has enough money
|
* @return product is available or node has enough money
|
||||||
*/
|
*/
|
||||||
@ -337,6 +349,7 @@ public class NodeBase implements ChannelObserver {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Chacks incomming requirement.
|
* Chacks incomming requirement.
|
||||||
|
*
|
||||||
* @param requirement requirement
|
* @param requirement requirement
|
||||||
* @param channel channel
|
* @param channel channel
|
||||||
*/
|
*/
|
||||||
@ -373,7 +386,7 @@ public class NodeBase implements ChannelObserver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String accept(ReportTextVisitor visitor){
|
public String accept(ReportTextVisitor visitor) {
|
||||||
return visitor.visit(this);
|
return visitor.visit(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package cz.cvut.fel.sit.omo.foodchain.operation;
|
|||||||
|
|
||||||
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.reporting.ReportTextVisitor;
|
||||||
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@ -10,16 +11,14 @@ import java.util.logging.Logger;
|
|||||||
* Operation for processing products in storage
|
* Operation for processing products in storage
|
||||||
*/
|
*/
|
||||||
public class Action extends OperationBase {
|
public class Action extends OperationBase {
|
||||||
private final OperationBase lastOperation;
|
|
||||||
private final Product product;
|
private final Product product;
|
||||||
private final ProductOperationType type;
|
private final ProductOperationType type;
|
||||||
private int duration;
|
private int duration;
|
||||||
|
|
||||||
public Action(NodeBase node, Product product, ProductOperationType type) {
|
public Action(NodeBase node, Product product, ProductOperationType type) {
|
||||||
super(node);
|
super(node, product.getCurrentOperation());
|
||||||
this.product = product;
|
this.product = product;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
lastOperation = product.getCurrentOperation();
|
|
||||||
duration = type.getDuration();
|
duration = type.getDuration();
|
||||||
product.setCurrentOperation(this);
|
product.setCurrentOperation(this);
|
||||||
product.setStateToInAction();
|
product.setStateToInAction();
|
||||||
@ -48,10 +47,6 @@ public class Action extends OperationBase {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OperationBase getLastOperation() {
|
|
||||||
return lastOperation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Product getProduct() {
|
public Product getProduct() {
|
||||||
return product;
|
return product;
|
||||||
}
|
}
|
||||||
@ -68,4 +63,8 @@ public class Action extends OperationBase {
|
|||||||
", duration=" + duration +
|
", duration=" + duration +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String accept(ReportTextVisitor visitor) {
|
||||||
|
return visitor.visit(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@ public class FinancialTransaction extends Transaction {
|
|||||||
private final ProductTransaction transactionPaid;
|
private final ProductTransaction transactionPaid;
|
||||||
|
|
||||||
public FinancialTransaction(NodeBase creator, NodeBase receiver, TransactionType type, MonetaryAmount amount, ProductTransaction transactionPaid) throws InsufficientResourcesException {
|
public FinancialTransaction(NodeBase creator, NodeBase receiver, TransactionType type, MonetaryAmount amount, ProductTransaction transactionPaid) throws InsufficientResourcesException {
|
||||||
super(creator, receiver, type);
|
super(creator, receiver, type, transactionPaid);
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
this.transactionPaid = transactionPaid;
|
this.transactionPaid = transactionPaid;
|
||||||
if (creator.getMoney().isLessThan(amount)) throw new InsufficientResourcesException("not enough money");
|
if (creator.getMoney().isLessThan(amount)) throw new InsufficientResourcesException("not enough money");
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
package cz.cvut.fel.sit.omo.foodchain.operation;
|
package cz.cvut.fel.sit.omo.foodchain.operation;
|
||||||
|
|
||||||
import cz.cvut.fel.sit.omo.foodchain.factory.ScenarioFactory;
|
|
||||||
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.reporting.PartiesReportVisitor;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.reporting.ReportTextVisitor;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@ -17,9 +18,11 @@ public abstract class OperationBase {
|
|||||||
private LocalDateTime timeEnd;
|
private LocalDateTime timeEnd;
|
||||||
|
|
||||||
private final NodeBase nodeCreator;
|
private final NodeBase nodeCreator;
|
||||||
|
private final OperationBase lastOperation;
|
||||||
|
|
||||||
OperationBase(NodeBase node) {
|
OperationBase(NodeBase node, OperationBase lastOperation) {
|
||||||
nodeCreator = node;
|
nodeCreator = node;
|
||||||
|
this.lastOperation = lastOperation;
|
||||||
timeStart = LocalDateTime.now();
|
timeStart = LocalDateTime.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,4 +41,12 @@ public abstract class OperationBase {
|
|||||||
public NodeBase getNodeCreator() {
|
public NodeBase getNodeCreator() {
|
||||||
return nodeCreator;
|
return nodeCreator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public OperationBase getLastOperation() {
|
||||||
|
return lastOperation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String accept(ReportTextVisitor reportVisitor){
|
||||||
|
return reportVisitor.visit(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,15 +13,13 @@ import java.util.logging.Level;
|
|||||||
*/
|
*/
|
||||||
public class ProductTransaction extends Transaction {
|
public class ProductTransaction extends Transaction {
|
||||||
|
|
||||||
private final OperationBase lastOperation;
|
|
||||||
private final Product product;
|
private final Product product;
|
||||||
private final ProductOperationType type;
|
private final ProductOperationType type;
|
||||||
|
|
||||||
public ProductTransaction(NodeBase creator, NodeBase receiver, TransactionType transactionType, Product product) throws InsufficientResourcesException {
|
public ProductTransaction(NodeBase creator, NodeBase receiver, TransactionType transactionType, Product product) throws InsufficientResourcesException {
|
||||||
super(creator, receiver, transactionType);
|
super(creator, receiver, transactionType, product.getCurrentOperation());
|
||||||
this.product = product;
|
this.product = product;
|
||||||
type = null;
|
type = null;
|
||||||
lastOperation = product.getCurrentOperation();
|
|
||||||
if (product == null || product.getProductState() != ProductState.IN_REQUIREMENT) throw new InsufficientResourcesException("product unavailable");
|
if (product == null || product.getProductState() != ProductState.IN_REQUIREMENT) throw new InsufficientResourcesException("product unavailable");
|
||||||
product.setCurrentOperation(this);
|
product.setCurrentOperation(this);
|
||||||
product.setStateToReadyForDispatch();
|
product.setStateToReadyForDispatch();
|
||||||
@ -40,10 +38,6 @@ public class ProductTransaction extends Transaction {
|
|||||||
product.setStateToAvailable();
|
product.setStateToAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public OperationBase getLastOperation() {
|
|
||||||
return lastOperation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Product getProduct() {
|
public Product getProduct() {
|
||||||
return product;
|
return product;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,8 +14,8 @@ public abstract class Transaction extends OperationBase {
|
|||||||
private final Signature signature;
|
private final Signature signature;
|
||||||
private final NodeBase nodeReceiver;
|
private final NodeBase nodeReceiver;
|
||||||
|
|
||||||
Transaction(NodeBase creator, NodeBase receiver, TransactionType type) {
|
Transaction(NodeBase creator, NodeBase receiver, TransactionType type, OperationBase lastOperation) {
|
||||||
super(creator);
|
super(creator, lastOperation);
|
||||||
transactionType = type;
|
transactionType = type;
|
||||||
nodeReceiver = receiver;
|
nodeReceiver = receiver;
|
||||||
signature = SignatureManager.signTransaction(this);
|
signature = SignatureManager.signTransaction(this);
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
package cz.cvut.fel.sit.omo.foodchain.reporting;
|
package cz.cvut.fel.sit.omo.foodchain.reporting;
|
||||||
|
|
||||||
import cz.cvut.fel.sit.omo.foodchain.channel.ChannelBase;
|
|
||||||
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.operation.Action;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.operation.FinancialTransaction;
|
import cz.cvut.fel.sit.omo.foodchain.operation.FinancialTransaction;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.operation.ProductTransaction;
|
import cz.cvut.fel.sit.omo.foodchain.operation.ProductTransaction;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||||
@ -15,6 +15,7 @@ public class FoodChainReportVisitor implements ReportTextVisitor {
|
|||||||
@Override
|
@Override
|
||||||
public String visit(Product product) {
|
public String visit(Product product) {
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -26,4 +27,9 @@ public class FoodChainReportVisitor implements ReportTextVisitor {
|
|||||||
public String visit(FinancialTransaction transaction) {
|
public String visit(FinancialTransaction transaction) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String visit(Action action) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,28 +2,76 @@ package cz.cvut.fel.sit.omo.foodchain.reporting;
|
|||||||
|
|
||||||
import cz.cvut.fel.sit.omo.foodchain.channel.ChannelBase;
|
import cz.cvut.fel.sit.omo.foodchain.channel.ChannelBase;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.operation.FinancialTransaction;
|
import cz.cvut.fel.sit.omo.foodchain.operation.*;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.operation.ProductTransaction;
|
|
||||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class PartiesReportVisitor implements ReportTextVisitor {
|
public class PartiesReportVisitor implements ReportTextVisitor {
|
||||||
|
private NodeBase current;
|
||||||
@Override
|
@Override
|
||||||
public String visit(NodeBase node) {
|
public String visit(NodeBase node) {
|
||||||
return null;
|
current = node;
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
|
builder.append("------NODE------").append(ln)
|
||||||
|
.append("Node type: ").append(node.getNodeType()).append(ln)
|
||||||
|
.append("Allowed seller: ").append(node.getAllowedSeller()).append(ln)
|
||||||
|
.append("Allowed purchaser: ").append(node.getAllowedPurchaser()).append(ln)
|
||||||
|
.append("Product sold and purchased, action provided: ").append(ln);
|
||||||
|
|
||||||
|
|
||||||
|
db.getProductPoolInstance().findAll().forEach(p -> builder.append(p.accept(this)));
|
||||||
|
builder.append(ln);
|
||||||
|
|
||||||
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(Product product) {
|
public String visit(Product product) {
|
||||||
return null;
|
if (current == null) return "";
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
List<OperationBase> operations = new LinkedList<>();
|
||||||
|
|
||||||
|
OperationBase operation = product.getCurrentOperation();
|
||||||
|
while (operation != null){
|
||||||
|
operations.add(operation);
|
||||||
|
operation = operation.getLastOperation();
|
||||||
|
}
|
||||||
|
|
||||||
|
operations.forEach(o -> builder.append(o.accept(this)));
|
||||||
|
if (builder.toString().equals("")) return "";
|
||||||
|
builder.append(ln);
|
||||||
|
|
||||||
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(ProductTransaction transaction) {
|
public String visit(ProductTransaction transaction) {
|
||||||
return null;
|
if (transaction.getNodeCreator() == current)
|
||||||
|
return "Sell " + transaction.getProduct().getName() + ln;
|
||||||
|
else if (transaction.getNodeReceiver() == current)
|
||||||
|
return "Get " + transaction.getProduct().getName() + ln;
|
||||||
|
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(FinancialTransaction transaction) {
|
public String visit(FinancialTransaction transaction) {
|
||||||
return null;
|
if (transaction.getNodeCreator() == current)
|
||||||
|
return "Send " + transaction.getAmount() + ln;
|
||||||
|
else if (transaction.getNodeReceiver() == current)
|
||||||
|
return "Get " + transaction.getAmount() + ln;
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String visit(Action action) {
|
||||||
|
if (action.getNodeCreator() == current)
|
||||||
|
return "Action " + action.getType() + " with " + action.getProduct().getName() + ln;
|
||||||
|
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,15 +1,15 @@
|
|||||||
package cz.cvut.fel.sit.omo.foodchain.reporting;
|
package cz.cvut.fel.sit.omo.foodchain.reporting;
|
||||||
|
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.FoodChain;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.channel.ChannelBase;
|
import cz.cvut.fel.sit.omo.foodchain.channel.ChannelBase;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.operation.FinancialTransaction;
|
import cz.cvut.fel.sit.omo.foodchain.operation.*;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.operation.OperationBase;
|
import cz.cvut.fel.sit.omo.foodchain.pool.PoolDatabase;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.operation.ProductTransaction;
|
|
||||||
import cz.cvut.fel.sit.omo.foodchain.operation.Transaction;
|
|
||||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||||
|
|
||||||
public interface ReportTextVisitor {
|
public interface ReportTextVisitor {
|
||||||
String ln = System.lineSeparator();
|
String ln = System.lineSeparator();
|
||||||
|
PoolDatabase db = FoodChain.getFactoryManager().getPoolDatabaseInstance();
|
||||||
|
|
||||||
String visit(NodeBase node);
|
String visit(NodeBase node);
|
||||||
|
|
||||||
@ -18,4 +18,24 @@ public interface ReportTextVisitor {
|
|||||||
String visit(ProductTransaction transaction);
|
String visit(ProductTransaction transaction);
|
||||||
|
|
||||||
String visit(FinancialTransaction transaction);
|
String visit(FinancialTransaction transaction);
|
||||||
|
|
||||||
|
String visit(Action action);
|
||||||
|
|
||||||
|
default String visit(OperationBase operationBase){
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return visit((Action) operationBase);
|
||||||
|
} catch (ClassCastException e){
|
||||||
|
return visit((Transaction) operationBase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
default String visit(Transaction transaction){
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return visit((ProductTransaction) transaction);
|
||||||
|
} catch (ClassCastException e){
|
||||||
|
return visit((FinancialTransaction) transaction);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -2,8 +2,7 @@ package cz.cvut.fel.sit.omo.foodchain.reporting;
|
|||||||
|
|
||||||
import cz.cvut.fel.sit.omo.foodchain.channel.ChannelBase;
|
import cz.cvut.fel.sit.omo.foodchain.channel.ChannelBase;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.operation.FinancialTransaction;
|
import cz.cvut.fel.sit.omo.foodchain.operation.*;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.operation.ProductTransaction;
|
|
||||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||||
|
|
||||||
public class SecurityReportReportVisitor implements ReportTextVisitor {
|
public class SecurityReportReportVisitor implements ReportTextVisitor {
|
||||||
@ -26,4 +25,10 @@ public class SecurityReportReportVisitor implements ReportTextVisitor {
|
|||||||
public String visit(FinancialTransaction transaction) {
|
public String visit(FinancialTransaction transaction) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String visit(Action action) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user