Prepare visitor and objects for reporting
This commit is contained in:
parent
c0fc73218e
commit
5426ffcf02
@ -3,6 +3,7 @@ package cz.cvut.fel.sit.omo.foodchain.channel;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.operation.Transaction;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.ProductType;
|
||||
import cz.cvut.fel.sit.omo.foodchain.reporting.ReportTextVisitor;
|
||||
import cz.cvut.fel.sit.omo.foodchain.requirement.Requirement;
|
||||
import cz.cvut.fel.sit.omo.foodchain.util.ChannelObserver;
|
||||
import cz.cvut.fel.sit.omo.foodchain.util.Observable;
|
||||
@ -98,4 +99,8 @@ public abstract class ChannelBase implements Observable {
|
||||
public ProductType getProductType() {
|
||||
return productType;
|
||||
}
|
||||
|
||||
public String accept(ReportTextVisitor visitor){
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,8 +7,8 @@ import cz.cvut.fel.sit.omo.foodchain.operation.*;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.ProductState;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.ProductType;
|
||||
import cz.cvut.fel.sit.omo.foodchain.reporting.ReportTextVisitor;
|
||||
import cz.cvut.fel.sit.omo.foodchain.requirement.Requirement;
|
||||
import cz.cvut.fel.sit.omo.foodchain.signature.Signature;
|
||||
import cz.cvut.fel.sit.omo.foodchain.signature.SignatureManager;
|
||||
import cz.cvut.fel.sit.omo.foodchain.util.ChannelObserver;
|
||||
import org.javamoney.moneta.Money;
|
||||
@ -226,4 +226,8 @@ public class NodeBase implements ChannelObserver {
|
||||
receiveTransactions();
|
||||
System.out.println(this.getClass().getSimpleName() + ": " + money.getNumber());
|
||||
}
|
||||
|
||||
public String accept(ReportTextVisitor visitor){
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,9 +2,9 @@ package cz.cvut.fel.sit.omo.foodchain.product;
|
||||
|
||||
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.reporting.ReportTextVisitor;
|
||||
import org.javamoney.moneta.Money;
|
||||
|
||||
import javax.money.Monetary;
|
||||
import javax.money.MonetaryAmount;
|
||||
|
||||
public class Product
|
||||
@ -158,4 +158,8 @@ public class Product
|
||||
public MonetaryAmount getPrice() { return price; }
|
||||
|
||||
public void setPrice(MonetaryAmount price) { this.price = price; }
|
||||
|
||||
public String accept(ReportTextVisitor visitor){
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
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.OperationBase;
|
||||
|
||||
public class ReportTextFileVisitor {
|
||||
public void visit(NodeBase node){
|
||||
|
||||
}
|
||||
|
||||
public void visit(OperationBase operationBase){
|
||||
|
||||
}
|
||||
|
||||
public void visit(ChannelBase channel){
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
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.OperationBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||
|
||||
public class ReportTextVisitor {
|
||||
public String visit(NodeBase node){
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String visit(ChannelBase channel){
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String visit(Product product){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,38 @@
|
||||
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;
|
||||
import java.nio.file.FileAlreadyExistsException;
|
||||
|
||||
public class ReportingManager {
|
||||
|
||||
public void createFileTextReport(String pathname) {
|
||||
File reportFile = new File(pathname);
|
||||
try {
|
||||
FileWriter fileWriter = new FileWriter(reportFile);
|
||||
if (!reportFile.createNewFile()) {
|
||||
throw new FileAlreadyExistsException(pathname);
|
||||
}
|
||||
fileWriter.write(acceptAllObjects());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String acceptAllObjects(){
|
||||
ReportTextVisitor visitor = new ReportTextVisitor();
|
||||
PoolDatabase db = FoodChain.getFactoryManager().getPoolDatabaseInstance();
|
||||
StringBuilder string = new StringBuilder();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user