[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();
|
ReportingManager reportingManager = new ReportingManager();
|
||||||
|
|
||||||
System.out.println(reportingManager.acceptAllObjects());
|
System.out.println(reportingManager.generateReport());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FactoryManager getFactoryManager()
|
public static FactoryManager getFactoryManager()
|
||||||
|
|||||||
@ -196,18 +196,10 @@ public class NodeBase implements ChannelObserver {
|
|||||||
return money;
|
return money;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NodeType getNodeType() {
|
|
||||||
return nodeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<ChannelBase, ChannelSubscriptionType> getSubscribedChannels() {
|
public Map<ChannelBase, ChannelSubscriptionType> getSubscribedChannels() {
|
||||||
return subscribedChannels;
|
return subscribedChannels;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Product> getProducts() {
|
|
||||||
return products;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Transaction> getRefusedTransactions() {
|
public List<Transaction> getRefusedTransactions() {
|
||||||
return refusedTransactions;
|
return refusedTransactions;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
public class OperationBase {
|
public abstract class OperationBase {
|
||||||
|
|
||||||
private final LocalDateTime timeStart;
|
private final LocalDateTime timeStart;
|
||||||
private LocalDateTime timeEnd;
|
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.operation.Transaction;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||||
|
|
||||||
public class ReportTextVisitor {
|
public interface ReportTextVisitor {
|
||||||
private static final String ln = System.lineSeparator();
|
String ln = System.lineSeparator();
|
||||||
|
|
||||||
public String visit(NodeBase node) {
|
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);
|
|
||||||
|
|
||||||
return result.toString();
|
String visit(ChannelBase channel);
|
||||||
}
|
|
||||||
|
String visit(Product product);
|
||||||
public String visit(ChannelBase channel) {
|
|
||||||
|
String visit(ProductTransaction transaction);
|
||||||
return "";
|
|
||||||
}
|
String visit(FinancialTransaction transaction);
|
||||||
|
|
||||||
public String visit(Product product) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String visit(ProductTransaction transaction) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String visit(FinancialTransaction transaction) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,8 +1,5 @@
|
|||||||
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.pool.PoolDatabase;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -17,22 +14,21 @@ public class ReportingManager {
|
|||||||
if (!reportFile.createNewFile()) {
|
if (!reportFile.createNewFile()) {
|
||||||
throw new FileAlreadyExistsException(pathname);
|
throw new FileAlreadyExistsException(pathname);
|
||||||
}
|
}
|
||||||
fileWriter.write(acceptAllObjects());
|
fileWriter.write(generateReport());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String acceptAllObjects(){
|
public String generateReport(){
|
||||||
ReportTextVisitor visitor = new ReportTextVisitor();
|
ReportBuilder reportBuilder = new ReportBuilder();
|
||||||
PoolDatabase db = FoodChain.getFactoryManager().getPoolDatabaseInstance();
|
|
||||||
StringBuilder string = new StringBuilder();
|
|
||||||
|
|
||||||
db.getChannelPoolInstance().findAll().forEach(ch -> string.append(ch.accept(visitor)));
|
return reportBuilder
|
||||||
db.getNodePoolInstance().findAll().forEach(n-> string.append(n.accept(visitor)));
|
.addPartiesReport()
|
||||||
db.getProductPoolInstance().findAll().forEach(p -> string.append(p.accept(visitor)));
|
.addFoodChainReport()
|
||||||
|
.addSecurityReport()
|
||||||
return string.toString();
|
.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