package backend;

public class BackendRentalTerminal {
	Database db = new Database();
	Backend be = new Backend();
	
	public BackendRentalTerminal(){
		
	}
	
	private boolean MutualAuthenticationRTS(){
		boolean states = false;
		//TODO:
		//Check Mutual Authentication between Rental Terminal and SmartCards
		//if succeed then states = true
		return states;
		
	}
	
	public void RegisterNewCustomer(String name){
		//add to database customer
		Integer customerId = db.insertCustomer(name);
		//get the customer ID that just inserted
//		int id = db.getLastID();		
		
		//add new smartcard
		InitData init = be.registerNewCard(customerId);
	}

}

@@ -11,16 +11,97 @@
 ckend;%0A%0A
+import java.sql.ResultSet;%0Aimport java.sql.SQLException;%0A%0Aimport terminal.Card;%0A%0A
 public c
@@ -238,14 +238,13 @@
 %09%0A%09p
-rivate
+ublic
  boo
@@ -270,16 +270,17 @@
 cationRT
+_
 S()%7B%0A%09%09b
@@ -299,12 +299,11 @@
 s = 
-fals
+tru
 e;%0A%09
@@ -571,153 +571,1465 @@
 ;%0A%09%09
-//get the customer ID that just inserted%0A//%09%09int id = db.getLas
+%0A%09%09//add new smartcard%0A%09%09InitData init = be.registerNewCard(customerId);%0A%09%7D%0A%09%0A%09/**%0A%09 * %0A%09 * @param cardPublicKey: the public key that stored in the card%0A%09 * @param cardKm: the kilometers amount that stored in the card%0A%09 */%0A%09public Card topUpCard(byte%5B%5D cert, Card card, short cardKm)%7B%0A%09%09byte%5B%5D newCert = null;%0A%09%09%0A%09%09try %7B%0A%09%09%09/* renew the certificate */%0A%09%09%09newCert = be.renewCertificate(cert);%0A%09%09%09%0A%09%09%09/* Update the Card data (in a struct) */%0A%09%09%09card.setKilometers(card.getKilometers() + cardKm);%0A%09%09%09//TODO EXTRACT KILOMETERS FROM CERTIFICATES%0A%09%09%09//card.setExpiration(expNew);%0A%09%09%09%0A%09%09%09/* update to database  */%0A%09%09%09db.updateKilometersExpiration(card.getKilometers(), card.getExpDate(), card.ge
 tID()
-;
+);%0A
 %09%09
-%0A
 %09%09%0A%09%09
+%09
 //
-add new smart
+TODO update to Card%0A%09%09%09%0A%09%09%7D catch (RevokedException e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%09return 
 card
+;
 %0A%09
-%09InitData init = be.registerNewCard(customerId)
+%7D%0A%09%0A%09public Card getCardDB(byte%5B%5D cardPublicKey)%7B%0A%09%09Card card = new Card();%0A%09%09%0A%09%09ResultSet rs = db.selectCard(cardPublicKey);%0A%09%09try %7B%0A%09%09%09if(rs.next())%7B%0A%09%09%09%09card = new Card(rs.getInt(%22id%22), rs.getInt(%22custID%22), rs.getString(%22custName%22), %0A%09%09%09%09%09%09rs.getInt(%22km%22), rs.getLong(%22exp%22) , rs.getInt(%22revoke%22), rs.getBytes(%22cardPK%22));%0A%09%09%09%7Delse%7B%0A%09%09%09%09System.out.println(%22That card has not been issued%22);%0A%09%09%09%09card = null;%0A%09%09%09%7D%0A%09%09%7D catch (SQLException e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%09return card;%0A%09%7D%0A%09%0A%09//Refund the kilometers%0A%09public Card refundKilometers(Card card)%7B%0A%09%09%0A%09%09return card
 ;%0A%09%7D

update functions topupcard and getcarddb