Finished food chain and parties report
This commit is contained in:
parent
80a52752e0
commit
f1e66fc4b7
@ -7,7 +7,6 @@ import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
|||||||
import cz.cvut.fel.sit.omo.foodchain.operation.ProductOperationType;
|
import cz.cvut.fel.sit.omo.foodchain.operation.ProductOperationType;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.operation.TransactionType;
|
import cz.cvut.fel.sit.omo.foodchain.operation.TransactionType;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.parser.ParserResultElement;
|
import cz.cvut.fel.sit.omo.foodchain.parser.ParserResultElement;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
|
||||||
import cz.cvut.fel.sit.omo.foodchain.product.ProductType;
|
import cz.cvut.fel.sit.omo.foodchain.product.ProductType;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.scenario.*;
|
import cz.cvut.fel.sit.omo.foodchain.scenario.*;
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,9 @@ import cz.cvut.fel.sit.omo.foodchain.reporting.ReportTextVisitor;
|
|||||||
import org.javamoney.moneta.Money;
|
import org.javamoney.moneta.Money;
|
||||||
|
|
||||||
import javax.money.MonetaryAmount;
|
import javax.money.MonetaryAmount;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Product class
|
* Product class
|
||||||
@ -155,6 +158,19 @@ public class Product
|
|||||||
|
|
||||||
public MonetaryAmount getStartPrice() { return startPrice; }
|
public MonetaryAmount getStartPrice() { return startPrice; }
|
||||||
|
|
||||||
|
public List<OperationBase> getListOfOperations(){
|
||||||
|
OperationBase operation = this.getCurrentOperation();
|
||||||
|
List<OperationBase> operations = new LinkedList<>();
|
||||||
|
|
||||||
|
while (operation != null) {
|
||||||
|
operations.add(operation);
|
||||||
|
operation = operation.getLastOperation();
|
||||||
|
}
|
||||||
|
Collections.reverse(operations);
|
||||||
|
|
||||||
|
return operations;
|
||||||
|
}
|
||||||
|
|
||||||
public String accept(ReportTextVisitor visitor){
|
public String accept(ReportTextVisitor visitor){
|
||||||
return visitor.visit(this);
|
return visitor.visit(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,34 +2,45 @@ package cz.cvut.fel.sit.omo.foodchain.reporting;
|
|||||||
|
|
||||||
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.operation.Action;
|
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.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;
|
||||||
|
|
||||||
public class FoodChainReportVisitor implements ReportTextVisitor {
|
public class FoodChainReportVisitor implements ReportTextVisitor {
|
||||||
@Override
|
@Override
|
||||||
public String visit(NodeBase node) {
|
public String visit(NodeBase node) {
|
||||||
return null;
|
return node.getNodeType().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(Product product) {
|
public String visit(Product product) {
|
||||||
return null;
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("-----PRODUCT-----").append(ln)
|
||||||
|
.append("Name: ").append(product.getName()).append(ln)
|
||||||
|
.append("Type: ").append(product.getProductType()).append(ln)
|
||||||
|
.append("Started price: ").append(product.getStartPrice()).append(ln)
|
||||||
|
.append("Final price: ").append(product.getPrice()).append(ln)
|
||||||
|
.append("Road map: ").append(ln);
|
||||||
|
|
||||||
|
builder.append("Product pool");
|
||||||
|
db.getNodePoolInstance().findAll()
|
||||||
|
.stream().filter(n -> n.getStorage().getCache().stream().anyMatch(c -> c.getName().equals(product.getName())))
|
||||||
|
.forEach(n -> builder.append(" -> ").append(n.accept(this)));
|
||||||
|
builder.append(ln);
|
||||||
|
|
||||||
|
builder.append("Things happened to this product: ").append(ln);
|
||||||
|
product.getListOfOperations().forEach(o -> builder.append(o.accept(this)).append(" -> "));
|
||||||
|
builder.append("Reported").append(ln);
|
||||||
|
|
||||||
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(ProductTransaction transaction) {
|
public String visit(ProductTransaction transaction) {
|
||||||
return null;
|
return "Moves product from " + transaction.getNodeCreator().accept(this) + " to " + transaction.getNodeReceiver().accept(this);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String visit(FinancialTransaction transaction) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(Action action) {
|
public String visit(Action action) {
|
||||||
return null;
|
return "Action " + action.getType().toString() + " was done on " + action.getNodeCreator().accept(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,17 +1,14 @@
|
|||||||
package cz.cvut.fel.sit.omo.foodchain.reporting;
|
package cz.cvut.fel.sit.omo.foodchain.reporting;
|
||||||
|
|
||||||
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.node.helper.ProductCache;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.operation.Action;
|
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.OperationBase;
|
|
||||||
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;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class PartiesReportVisitor implements ReportTextVisitor {
|
public class PartiesReportVisitor implements ReportTextVisitor {
|
||||||
private NodeBase current;
|
private NodeBase current;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(NodeBase node) {
|
public String visit(NodeBase node) {
|
||||||
current = node;
|
current = node;
|
||||||
@ -21,6 +18,7 @@ public class PartiesReportVisitor implements ReportTextVisitor {
|
|||||||
.append("Node type: ").append(node.getNodeType()).append(ln)
|
.append("Node type: ").append(node.getNodeType()).append(ln)
|
||||||
.append("Allowed seller: ").append(node.getAllowedSeller()).append(ln)
|
.append("Allowed seller: ").append(node.getAllowedSeller()).append(ln)
|
||||||
.append("Allowed purchaser: ").append(node.getAllowedPurchaser()).append(ln)
|
.append("Allowed purchaser: ").append(node.getAllowedPurchaser()).append(ln)
|
||||||
|
.append("Applied margin: ").append(node.getMargin()).append(ln)
|
||||||
.append("Product sold and purchased, action provided: ").append(ln);
|
.append("Product sold and purchased, action provided: ").append(ln);
|
||||||
|
|
||||||
|
|
||||||
@ -32,19 +30,23 @@ public class PartiesReportVisitor implements ReportTextVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(Product product) {
|
public String visit(Product product) {
|
||||||
if (current == null) return "";
|
ProductCache cache = current.getStorage().getCache()
|
||||||
|
.stream().filter(c -> c.getName().equals(product.getName()))
|
||||||
|
.findFirst().orElse(null);
|
||||||
|
|
||||||
|
if (current == null || cache == null)
|
||||||
|
return "";
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
List<OperationBase> operations = new LinkedList<>();
|
|
||||||
|
|
||||||
OperationBase operation = product.getCurrentOperation();
|
builder.append("-----Product: ").append(product.getName()).append("-----").append(ln);
|
||||||
while (operation != null){
|
product.getListOfOperations().forEach(o -> {
|
||||||
operations.add(operation);
|
String result = o.accept(this);
|
||||||
operation = operation.getLastOperation();
|
if (result != null)
|
||||||
}
|
builder.append(o.accept(this));
|
||||||
|
});
|
||||||
operations.forEach(o -> builder.append(o.accept(this)));
|
|
||||||
if (builder.toString().equals("")) return "";
|
if (builder.toString().equals("")) return "";
|
||||||
builder.append(ln);
|
builder.append("Presence of product on Node (in ticks): ").append(cache.getDuration()).append(ln);
|
||||||
|
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
@ -55,25 +57,13 @@ public class PartiesReportVisitor implements ReportTextVisitor {
|
|||||||
return "Sell " + transaction.getProduct().getName() + ln;
|
return "Sell " + transaction.getProduct().getName() + ln;
|
||||||
else if (transaction.getNodeReceiver() == current)
|
else if (transaction.getNodeReceiver() == current)
|
||||||
return "Get " + transaction.getProduct().getName() + ln;
|
return "Get " + transaction.getProduct().getName() + ln;
|
||||||
|
return null;
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String visit(FinancialTransaction transaction) {
|
|
||||||
if (transaction.getNodeCreator() == current)
|
|
||||||
return "Send " + transaction.getAmount() + ln;
|
|
||||||
else if (transaction.getNodeReceiver() == current)
|
|
||||||
return "Get " + transaction.getAmount() + ln;
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(Action action) {
|
public String visit(Action action) {
|
||||||
if (action.getNodeCreator() == current)
|
if (action.getNodeCreator() == current)
|
||||||
return "Action " + action.getType() + " with " + action.getProduct().getName() + ln;
|
return "Action " + action.getType() + " was done with " + action.getProduct().getName() + ln;
|
||||||
|
return null;
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,43 +5,59 @@ import cz.cvut.fel.sit.omo.foodchain.pool.PoolDatabase;
|
|||||||
|
|
||||||
public class ReportBuilder {
|
public class ReportBuilder {
|
||||||
private final StringBuilder report;
|
private final StringBuilder report;
|
||||||
|
private final String ln;
|
||||||
private final PoolDatabase db;
|
private final PoolDatabase db;
|
||||||
|
|
||||||
public ReportBuilder(){
|
public ReportBuilder() {
|
||||||
report = new StringBuilder();
|
report = new StringBuilder();
|
||||||
db = FoodChain.getFactoryManager().getPoolDatabaseInstance();
|
db = FoodChain.getFactoryManager().getPoolDatabaseInstance();
|
||||||
|
ln = System.lineSeparator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReportBuilder addPartiesReport(){
|
public ReportBuilder addPartiesReport() {
|
||||||
ReportTextVisitor reportVisitor = new PartiesReportVisitor();
|
ReportTextVisitor reportVisitor = new PartiesReportVisitor();
|
||||||
|
|
||||||
db.getNodePoolInstance().findAll().forEach(n -> report.append(reportVisitor.visit(n)));
|
report.append("--------------").append(ln)
|
||||||
|
.append("PARTIES REPORT").append(ln)
|
||||||
|
.append("--------------").append(ln).append(ln);
|
||||||
|
|
||||||
|
db.getNodePoolInstance().findAll().forEach(n -> report.append(n.accept(reportVisitor)));
|
||||||
|
report.append(ln);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReportBuilder addFoodChainReport(){
|
public ReportBuilder addFoodChainReport() {
|
||||||
ReportTextVisitor reportVisitor = new FoodChainReportVisitor();
|
ReportTextVisitor reportVisitor = new FoodChainReportVisitor();
|
||||||
|
|
||||||
db.getProductPoolInstance().findAll().forEach(p -> report.append(reportVisitor.visit(p)));
|
report.append("------------------").append(ln)
|
||||||
|
.append("FOOD CHAIN REPORT").append(ln)
|
||||||
|
.append("------------------").append(ln).append(ln);
|
||||||
|
|
||||||
|
db.getProductPoolInstance().findAll().forEach(p -> report.append(p.accept(reportVisitor)));
|
||||||
|
report.append(ln);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReportBuilder addSecurityReport(){
|
public ReportBuilder addSecurityReport() {
|
||||||
ReportTextVisitor reportVisitor = new FoodChainReportVisitor();
|
ReportTextVisitor reportVisitor = new SecurityReportVisitor();
|
||||||
|
|
||||||
db.getNodePoolInstance().findAll().forEach(n -> report.append(reportVisitor.visit(n)));
|
report.append("----------------").append(ln)
|
||||||
|
.append("SECURITY REPORT").append(ln)
|
||||||
|
.append("----------------").append(ln).append(ln);
|
||||||
|
|
||||||
|
db.getNodePoolInstance().findAll().forEach(n -> report.append(n.accept(reportVisitor)));
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReportBuilder addTransactionReport(){
|
public ReportBuilder addTransactionReport() {
|
||||||
//TODO
|
//TODO
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String build(){
|
public String build() {
|
||||||
return report.toString();
|
return report.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,10 @@ package cz.cvut.fel.sit.omo.foodchain.reporting;
|
|||||||
|
|
||||||
import cz.cvut.fel.sit.omo.foodchain.FoodChain;
|
import cz.cvut.fel.sit.omo.foodchain.FoodChain;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.operation.*;
|
import cz.cvut.fel.sit.omo.foodchain.operation.Action;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.operation.OperationBase;
|
||||||
|
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.pool.PoolDatabase;
|
import cz.cvut.fel.sit.omo.foodchain.pool.PoolDatabase;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||||
|
|
||||||
@ -16,25 +19,21 @@ public interface ReportTextVisitor {
|
|||||||
|
|
||||||
String visit(ProductTransaction transaction);
|
String visit(ProductTransaction transaction);
|
||||||
|
|
||||||
String visit(FinancialTransaction transaction);
|
|
||||||
|
|
||||||
String visit(Action action);
|
String visit(Action action);
|
||||||
|
|
||||||
default String visit(OperationBase operationBase){
|
default String visit(OperationBase operationBase) {
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
return visit((Action) operationBase);
|
return visit((Action) operationBase);
|
||||||
} catch (ClassCastException e){
|
} catch (ClassCastException e) {
|
||||||
return visit((Transaction) operationBase);
|
return visit((Transaction) operationBase);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
default String visit(Transaction transaction){
|
default String visit(Transaction transaction) {
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
return visit((ProductTransaction) transaction);
|
return visit((ProductTransaction) transaction);
|
||||||
} catch (ClassCastException e){
|
} catch (ClassCastException ignored) {
|
||||||
return visit((FinancialTransaction) transaction);
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2,14 +2,14 @@ package cz.cvut.fel.sit.omo.foodchain.reporting;
|
|||||||
|
|
||||||
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.operation.Action;
|
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.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;
|
||||||
|
|
||||||
public class SecurityReportVisitor implements ReportTextVisitor {
|
public class SecurityReportVisitor implements ReportTextVisitor {
|
||||||
@Override
|
@Override
|
||||||
public String visit(NodeBase node) {
|
public String visit(NodeBase node) {
|
||||||
return null;
|
return
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -22,11 +22,6 @@ public class SecurityReportVisitor implements ReportTextVisitor {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String visit(FinancialTransaction transaction) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(Action action) { return null; }
|
public String visit(Action action) { return null; }
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,6 @@ package cz.cvut.fel.sit.omo.foodchain.scenario;
|
|||||||
|
|
||||||
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.operation.ProductOperationType;
|
import cz.cvut.fel.sit.omo.foodchain.operation.ProductOperationType;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
|
||||||
|
|
||||||
import javax.naming.InsufficientResourcesException;
|
import javax.naming.InsufficientResourcesException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user