[Draft] Recononstruct Reporting for 3 types of Visitors, add ReportBuilder
This commit is contained in:
parent
5e9113cb98
commit
79d7afecc5
@ -38,7 +38,7 @@ public class FoodChain
|
||||
|
||||
ReportingManager reportingManager = new ReportingManager();
|
||||
|
||||
System.out.println(reportingManager.acceptAllObjects());
|
||||
System.out.println(reportingManager.generateReport());
|
||||
}
|
||||
|
||||
public static FactoryManager getFactoryManager()
|
||||
|
||||
@ -196,18 +196,10 @@ public class NodeBase implements ChannelObserver {
|
||||
return money;
|
||||
}
|
||||
|
||||
public NodeType getNodeType() {
|
||||
return nodeType;
|
||||
}
|
||||
|
||||
public Map<ChannelBase, ChannelSubscriptionType> getSubscribedChannels() {
|
||||
return subscribedChannels;
|
||||
}
|
||||
|
||||
public List<Product> getProducts() {
|
||||
return products;
|
||||
}
|
||||
|
||||
public List<Transaction> getRefusedTransactions() {
|
||||
return refusedTransactions;
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class OperationBase {
|
||||
public abstract class OperationBase {
|
||||
|
||||
private final LocalDateTime timeStart;
|
||||
private LocalDateTime timeEnd;
|
||||
|
||||
@ -0,0 +1,34 @@
|
||||
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.operation.FinancialTransaction;
|
||||
import cz.cvut.fel.sit.omo.foodchain.operation.ProductTransaction;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||
|
||||
public class FoodChainReportVisitor implements ReportTextVisitor {
|
||||
@Override
|
||||
public String visit(NodeBase node) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(ChannelBase channel) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(Product product) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(ProductTransaction transaction) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(FinancialTransaction transaction) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
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.operation.FinancialTransaction;
|
||||
import cz.cvut.fel.sit.omo.foodchain.operation.ProductTransaction;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||
|
||||
public class PartiesReportVisitor implements ReportTextVisitor {
|
||||
@Override
|
||||
public String visit(NodeBase node) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(ChannelBase channel) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(Product product) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(ProductTransaction transaction) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(FinancialTransaction transaction) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.reporting;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.FoodChain;
|
||||
import cz.cvut.fel.sit.omo.foodchain.pool.PoolDatabase;
|
||||
|
||||
public class ReportBuilder {
|
||||
private final StringBuilder report;
|
||||
private final PoolDatabase db;
|
||||
|
||||
public ReportBuilder(){
|
||||
report = new StringBuilder();
|
||||
db = FoodChain.getFactoryManager().getPoolDatabaseInstance();
|
||||
}
|
||||
|
||||
public ReportBuilder addPartiesReport(){
|
||||
ReportTextVisitor reportVisitor = new PartiesReportVisitor();
|
||||
|
||||
db.getNodePoolInstance().findAll().forEach(n -> report.append(reportVisitor.visit(n)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ReportBuilder addFoodChainReport(){
|
||||
ReportTextVisitor reportVisitor = new FoodChainReportVisitor();
|
||||
|
||||
db.getProductPoolInstance().findAll().forEach(p -> report.append(reportVisitor.visit(p)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ReportBuilder addSecurityReport(){
|
||||
ReportTextVisitor reportVisitor = new FoodChainReportVisitor();
|
||||
|
||||
db.getNodePoolInstance().findAll().forEach(n -> report.append(reportVisitor.visit(n)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ReportBuilder addTransactionReport(){
|
||||
//TODO
|
||||
return this;
|
||||
}
|
||||
|
||||
public String build(){
|
||||
return report.toString();
|
||||
}
|
||||
}
|
||||
@ -8,36 +8,16 @@ 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;
|
||||
|
||||
public class ReportTextVisitor {
|
||||
private static final String ln = System.lineSeparator();
|
||||
public interface ReportTextVisitor {
|
||||
String ln = System.lineSeparator();
|
||||
|
||||
public String visit(NodeBase node) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.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("Money: ").append(node.getMoney()).append(ln)
|
||||
.append("Refused transactions: ");
|
||||
node.getRefusedTransactions().forEach(tr -> result.append(tr.accept(this)));
|
||||
result.append(ln).append(ln);
|
||||
String visit(NodeBase node);
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public String visit(ChannelBase channel) {
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public String visit(Product product) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String visit(ProductTransaction transaction) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String visit(FinancialTransaction transaction) {
|
||||
return "";
|
||||
}
|
||||
String visit(ChannelBase channel);
|
||||
|
||||
String visit(Product product);
|
||||
|
||||
String visit(ProductTransaction transaction);
|
||||
|
||||
String visit(FinancialTransaction transaction);
|
||||
}
|
||||
@ -1,8 +1,5 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.reporting;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.FoodChain;
|
||||
import cz.cvut.fel.sit.omo.foodchain.pool.PoolDatabase;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
@ -17,22 +14,21 @@ public class ReportingManager {
|
||||
if (!reportFile.createNewFile()) {
|
||||
throw new FileAlreadyExistsException(pathname);
|
||||
}
|
||||
fileWriter.write(acceptAllObjects());
|
||||
fileWriter.write(generateReport());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String acceptAllObjects(){
|
||||
ReportTextVisitor visitor = new ReportTextVisitor();
|
||||
PoolDatabase db = FoodChain.getFactoryManager().getPoolDatabaseInstance();
|
||||
StringBuilder string = new StringBuilder();
|
||||
public String generateReport(){
|
||||
ReportBuilder reportBuilder = new ReportBuilder();
|
||||
|
||||
db.getChannelPoolInstance().findAll().forEach(ch -> string.append(ch.accept(visitor)));
|
||||
db.getNodePoolInstance().findAll().forEach(n-> string.append(n.accept(visitor)));
|
||||
db.getProductPoolInstance().findAll().forEach(p -> string.append(p.accept(visitor)));
|
||||
|
||||
return string.toString();
|
||||
return reportBuilder
|
||||
.addPartiesReport()
|
||||
.addFoodChainReport()
|
||||
.addSecurityReport()
|
||||
.addTransactionReport()
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,34 @@
|
||||
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.operation.FinancialTransaction;
|
||||
import cz.cvut.fel.sit.omo.foodchain.operation.ProductTransaction;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||
|
||||
public class SecurityReportReportVisitor implements ReportTextVisitor {
|
||||
@Override
|
||||
public String visit(NodeBase node) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(ChannelBase channel) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(Product product) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(ProductTransaction transaction) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(FinancialTransaction transaction) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user