Git Repository Public Repository

RRRRHHHH_Code

URLs

Copy to Clipboard

Diff Revisions e0d74d ... vs e16868 ... for ruralHouses/src/businessLogic/OfferManager.java

Diff revisions: vs.
  @@ -1,9 +1,18 @@
1 1 package businessLogic;
2 2
3 + import java.rmi.RemoteException;
4 + import java.sql.Date;
5 +
3 6 import com.db4o.ObjectContainer;
4 7 import com.db4o.ObjectSet;
5 8
6 9 import dataAccess.DB4oManager;
10 + import domain.Booking;
11 + import domain.Offer;
12 + import domain.RuralHouse;
13 + import exceptions.BadDates;
14 + import exceptions.OfferCanNotBeBooked;
15 + import exceptions.OverlappingOfferExists;
7 16
8 17 public final class OfferManager {
9 18
  @@ -11,7 +20,13 @@
11 20 dataAccess.DB4oManager dbMngr;
12 21 private static OfferManager theOfferManager;
13 22
14 - private OfferManager() {}
23 + public OfferManager() {
24 + try {
25 + this.dbMngr = DB4oManager.getInstance();
26 + } catch (Exception e) {
27 + e.printStackTrace();
28 + }
29 + }
15 30
16 31 public static int getNumber() {
17 32 ObjectContainer db=DB4oManager.getContainer();
  @@ -38,4 +53,22 @@
38 53 } else theOfferManager=(OfferManager)result.next();
39 54 return theOfferManager;
40 55 }
56 +
57 + /**
58 + * This method creates an offer with a house number, first day, last day and price
59 + *
60 + * @param House
61 + * number, start day, last day and price
62 + * @return the created offer, or null, or an exception
63 + */
64 + public Offer createOffer(RuralHouse ruralHouse, Date firstDay, Date lastDay,
65 + float price) throws OverlappingOfferExists, BadDates, RemoteException, Exception {
66 + if (firstDay.compareTo(lastDay)>=0) throw new BadDates();
67 +
68 + boolean b = dbMngr.existsOverlappingOffer(ruralHouse,firstDay,lastDay); // The ruralHouse object in the client may not be updated
69 + if (!b) return dbMngr.createOffer(ruralHouse,firstDay,lastDay,price);
70 + return null;
71 + }
72 +
73 +
41 74 }