Merge branch 'feature/operation_impl' into develop
This commit is contained in:
commit
e0b53db736
@ -1,4 +1,37 @@
|
||||
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 void endAction() {
|
||||
this.setTimeEnd();
|
||||
product.setStateToAvailable();
|
||||
}
|
||||
|
||||
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,4 +1,5 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.operation;
|
||||
|
||||
public interface IOperation {
|
||||
//TODO Tomas Angelo
|
||||
}
|
||||
|
||||
@ -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() {
|
||||
this.timeEnd = LocalDateTime.now();
|
||||
}
|
||||
|
||||
public INode getNodeCreator() {
|
||||
return nodeCreator;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,38 @@
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endTransaction() {
|
||||
super.endTransaction();
|
||||
product.setStateToAvailable();
|
||||
}
|
||||
|
||||
public IOperation getLastOperation() {
|
||||
return lastOperation;
|
||||
}
|
||||
|
||||
public Product getProduct() {
|
||||
return product;
|
||||
}
|
||||
|
||||
public ProductOperationType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +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.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 void endTransaction() {
|
||||
this.setTimeEnd();
|
||||
}
|
||||
|
||||
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,39 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.signature;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.operation.Transaction;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Signature {
|
||||
|
||||
private final String managerCode;
|
||||
private final Transaction transaction;
|
||||
private final LocalDateTime signedDate;
|
||||
private final UUID uuid;
|
||||
|
||||
public Signature(String code, Transaction transaction) {
|
||||
managerCode = code;
|
||||
this.transaction = transaction;
|
||||
signedDate = LocalDateTime.now();
|
||||
uuid = UUID.randomUUID();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public UUID getUuid(String code) {
|
||||
if (code.equals(managerCode))
|
||||
return uuid;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,17 @@
|
||||
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.equals(transaction.getSignature().getTransaction(MANAGER_CODE))
|
||||
&& transaction.getSignature().getUuid(MANAGER_CODE).equals(transaction.getSignature().getTransaction(MANAGER_CODE).getSignature().getUuid(MANAGER_CODE));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user