Added functions (need consultation)
This commit is contained in:
parent
6f7c11a878
commit
6a7fc972fd
@ -6,24 +6,27 @@ 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.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 javax.money.MonetaryAmount;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class NodeBase {
|
||||
public class NodeBase implements ChannelObserver {
|
||||
private final List<ChannelBase> subscribedChannels;
|
||||
private final List<Product> products;
|
||||
private MonetaryAmount money;
|
||||
|
||||
public NodeBase(){
|
||||
public NodeBase() {
|
||||
subscribedChannels = new LinkedList<>();
|
||||
products = new LinkedList<>();
|
||||
}
|
||||
|
||||
|
||||
public void sendTransaction(Product product, NodeBase node) {
|
||||
Transaction transaction = new ProductTransaction(this, node, TransactionType.SALE, product); //TODO wrong constructor
|
||||
Transaction transaction = new ProductTransaction(this, node, TransactionType.SALE, product);
|
||||
|
||||
subscribedChannels.stream()
|
||||
.filter(ch -> ch.getProductType().equals(product.getProductType()))
|
||||
@ -32,7 +35,11 @@ public class NodeBase {
|
||||
|
||||
|
||||
public void sendTransaction(MonetaryAmount amount, NodeBase node) {
|
||||
Transaction transaction = new FinancialTransaction(this, node, TransactionType.PURCHASE, amount, );
|
||||
|
||||
subscribedChannels.stream()
|
||||
.filter(ch -> ch.getProductType().equals(product.getProductType()))
|
||||
.findAny().ifPresent(channel -> channel.addTransaction(transaction));
|
||||
}
|
||||
|
||||
|
||||
@ -83,7 +90,7 @@ public class NodeBase {
|
||||
|
||||
|
||||
public void doAction(ProductOperationType action, Product product) {
|
||||
//create new action
|
||||
Action actionProcess = new Action(this, product);
|
||||
}
|
||||
|
||||
|
||||
@ -93,26 +100,32 @@ public class NodeBase {
|
||||
|
||||
|
||||
public void storeProduct(Product product) {
|
||||
|
||||
this.products.add(product);
|
||||
}
|
||||
|
||||
|
||||
public void storeProducts(List<Product> products) {
|
||||
|
||||
this.products.addAll(products);
|
||||
}
|
||||
|
||||
|
||||
public Product getProductFromStorage(String name, ProductType type) {
|
||||
return null;
|
||||
return products.stream().filter(ch -> ch.getProductType() == type && ch.getName().equals(name)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
|
||||
public Signature generateSignature(Transaction transaction) {
|
||||
return null;
|
||||
return SignatureManager.signTransaction(transaction);
|
||||
}
|
||||
|
||||
|
||||
public boolean validateSignature(Signature signature) {
|
||||
return false;
|
||||
public boolean validateSignature(Transaction transaction) {
|
||||
return SignatureManager.validateSignature(transaction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Requirement requirement) {
|
||||
if (!requirement.getCreator().equals(this))
|
||||
acceptRequirement(requirement);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user