Implemented Operation and Signature packages (basic)
This commit is contained in:
parent
7815e0df70
commit
9119ebb8ce
@ -1,4 +1,32 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.operation;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.INode;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||
|
||||
public class Action extends OperationBase {
|
||||
|
||||
private final IOperation lastOperation;
|
||||
private final Product product;
|
||||
private final ProductOperationType type;
|
||||
|
||||
Action(INode node, Product product) {
|
||||
super(node);
|
||||
this.product = product;
|
||||
type = null;
|
||||
lastOperation = product.getCurrentOperation();
|
||||
product.setCurrentOperation(this);
|
||||
product.setStateToReadyForDispatch();
|
||||
}
|
||||
|
||||
public IOperation getLastOperation() {
|
||||
return lastOperation;
|
||||
}
|
||||
|
||||
public Product getProduct() {
|
||||
return product;
|
||||
}
|
||||
|
||||
public ProductOperationType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,24 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.operation;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.INode;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||
|
||||
public class FinancialTransaction extends Transaction {
|
||||
|
||||
private final Float amount;
|
||||
private final ProductTransaction transactionPaid;
|
||||
|
||||
FinancialTransaction(INode creator, INode receiver, TransactionType type, Float amount, ProductTransaction transactionPaid) {
|
||||
super(creator, receiver, type);
|
||||
this.amount = amount;
|
||||
this.transactionPaid = transactionPaid;
|
||||
}
|
||||
|
||||
public Float getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public ProductTransaction getTransactionPaid() {
|
||||
return transactionPaid;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,35 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.operation;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.INode;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class OperationBase {
|
||||
IOperation lastOperation;
|
||||
|
||||
private final LocalDateTime timeStart;
|
||||
private LocalDateTime timeEnd;
|
||||
|
||||
private final INode nodeCreator;
|
||||
|
||||
OperationBase(INode node) {
|
||||
nodeCreator = node;
|
||||
timeStart = LocalDateTime.now();
|
||||
}
|
||||
|
||||
public LocalDateTime getTimeStart() {
|
||||
return timeStart;
|
||||
}
|
||||
|
||||
public LocalDateTime getTimeEnd() {
|
||||
return timeEnd;
|
||||
}
|
||||
|
||||
public void setTimeEnd(LocalDateTime timeEnd) {
|
||||
this.timeEnd = timeEnd;
|
||||
}
|
||||
|
||||
public INode getNodeCreator() {
|
||||
return nodeCreator;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,32 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.operation;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.INode;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||
|
||||
public class ProductTransaction extends Transaction {
|
||||
|
||||
private final IOperation lastOperation;
|
||||
private final Product product;
|
||||
private final ProductOperationType type;
|
||||
|
||||
ProductTransaction(INode creator, INode receiver, TransactionType transactionType, Product product) {
|
||||
super(creator, receiver, transactionType);
|
||||
this.product = product;
|
||||
type = null;
|
||||
lastOperation = product.getCurrentOperation();
|
||||
product.setCurrentOperation(this);
|
||||
product.setStateToReadyForDispatch();
|
||||
}
|
||||
|
||||
public IOperation getLastOperation() {
|
||||
return lastOperation;
|
||||
}
|
||||
|
||||
public Product getProduct() {
|
||||
return product;
|
||||
}
|
||||
|
||||
public ProductOperationType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,31 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.operation;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.INode;
|
||||
import cz.cvut.fel.sit.omo.foodchain.signature.Signature;
|
||||
import cz.cvut.fel.sit.omo.foodchain.signature.SignatureManager;
|
||||
|
||||
public abstract class Transaction extends OperationBase {
|
||||
|
||||
private final TransactionType transactionType;
|
||||
private final Signature signature;
|
||||
private final INode nodeReceiver;
|
||||
|
||||
Transaction(INode creator, INode receiver, TransactionType type) {
|
||||
super(creator);
|
||||
transactionType = type;
|
||||
nodeReceiver = receiver;
|
||||
signature = SignatureManager.signTransaction(this);
|
||||
}
|
||||
|
||||
public TransactionType getTransactionType() {
|
||||
return transactionType;
|
||||
}
|
||||
|
||||
public Signature getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
public INode getNodeReceiver() {
|
||||
return nodeReceiver;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.operation;
|
||||
|
||||
public enum TransactionType {
|
||||
|
||||
SALE, PURCHASE
|
||||
}
|
||||
|
||||
@ -1,4 +1,30 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.signature;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.operation.Transaction;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class Signature {
|
||||
|
||||
private String managerCode;
|
||||
private Transaction transaction;
|
||||
private LocalDateTime signedDate;
|
||||
|
||||
public Signature(String code, Transaction transaction) {
|
||||
managerCode = code;
|
||||
this.transaction = transaction;
|
||||
signedDate = LocalDateTime.now();
|
||||
}
|
||||
|
||||
public Transaction getTransaction(String code) {
|
||||
if (code.equals(managerCode))
|
||||
return transaction;
|
||||
return null;
|
||||
}
|
||||
|
||||
public LocalDateTime getSignedDate(String code) {
|
||||
if (code.equals(managerCode))
|
||||
return signedDate;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,16 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.signature;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.operation.Transaction;
|
||||
|
||||
public class SignatureManager {
|
||||
|
||||
private static final String MANAGER_CODE = "iW91AJWNOCmX1pbpLlW0";
|
||||
|
||||
public static Signature signTransaction(Transaction transaction) {
|
||||
return new Signature(MANAGER_CODE, transaction);
|
||||
}
|
||||
|
||||
public static boolean validateSignature(Transaction transaction) {
|
||||
return transaction == transaction.getSignature().getTransaction(MANAGER_CODE);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user