Added end to Transaction and Action, improved Signature
This commit is contained in:
parent
9119ebb8ce
commit
127bdd1270
@ -18,6 +18,11 @@ public class Action extends OperationBase {
|
||||
product.setStateToReadyForDispatch();
|
||||
}
|
||||
|
||||
public void endAction() {
|
||||
this.setTimeEnd();
|
||||
product.setStateToAvailable();
|
||||
}
|
||||
|
||||
public IOperation getLastOperation() {
|
||||
return lastOperation;
|
||||
}
|
||||
|
||||
@ -25,8 +25,8 @@ public class OperationBase {
|
||||
return timeEnd;
|
||||
}
|
||||
|
||||
public void setTimeEnd(LocalDateTime timeEnd) {
|
||||
this.timeEnd = timeEnd;
|
||||
public void setTimeEnd() {
|
||||
this.timeEnd = LocalDateTime.now();
|
||||
}
|
||||
|
||||
public INode getNodeCreator() {
|
||||
|
||||
@ -18,6 +18,12 @@ public class ProductTransaction extends Transaction {
|
||||
product.setStateToReadyForDispatch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endTransaction() {
|
||||
super.endTransaction();
|
||||
product.setStateToAvailable();
|
||||
}
|
||||
|
||||
public IOperation getLastOperation() {
|
||||
return lastOperation;
|
||||
}
|
||||
|
||||
@ -17,6 +17,10 @@ public abstract class Transaction extends OperationBase {
|
||||
signature = SignatureManager.signTransaction(this);
|
||||
}
|
||||
|
||||
public void endTransaction() {
|
||||
this.setTimeEnd();
|
||||
}
|
||||
|
||||
public TransactionType getTransactionType() {
|
||||
return transactionType;
|
||||
}
|
||||
|
||||
@ -3,17 +3,20 @@ 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 String managerCode;
|
||||
private Transaction transaction;
|
||||
private LocalDateTime signedDate;
|
||||
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) {
|
||||
@ -27,4 +30,10 @@ public class Signature {
|
||||
return signedDate;
|
||||
return null;
|
||||
}
|
||||
|
||||
public UUID getUuid(String code) {
|
||||
if (code.equals(managerCode))
|
||||
return uuid;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ public class SignatureManager {
|
||||
}
|
||||
|
||||
public static boolean validateSignature(Transaction transaction) {
|
||||
return transaction == transaction.getSignature().getTransaction(MANAGER_CODE);
|
||||
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