package businessLogic; import java.rmi.RemoteException; import java.sql.Date; import dataAccess.DB4oManager; import domain.Offer; import domain.RuralHouse; import exceptions.BadDates; import exceptions.OverlappingOfferExists; public final class OfferManager { private int offerNumber = 0; dataAccess.DB4oManager dbMngr; public OfferManager() { try { this.dbMngr = DB4oManager.getInstance(); } catch (Exception e) { e.printStackTrace(); } } /** * This method creates an offer with a house number, first day, last day and price * * @param House * number, start day, last day and price * @return the created offer, or null, or an exception */ public Offer createOffer(RuralHouse ruralHouse, Date firstDay, Date lastDay, float price) throws OverlappingOfferExists, BadDates, RemoteException, Exception { if (firstDay.after(lastDay)||firstDay==null||lastDay==null) throw new BadDates(); boolean b = dbMngr.existsOverlappingOffer(ruralHouse,firstDay,lastDay); // The ruralHouse object in the client may not be updated if (!b) { dbMngr.createOffer(ruralHouse,firstDay,lastDay,price); return ruralHouse.createOffer(offerNumber, firstDay, lastDay, price); } return null; } public void deleteOffer(RuralHouse rh, Offer o) throws RemoteException, Exception{ rh.offers.removeElement(o); dbMngr.deleteOffer( o); } }