Git Repository Public Repository

RRRRHHHH_Code

URLs

Copy to Clipboard
 
64482a77de099254dbbbcc12347864080f5f3782
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package businessLogic;

import java.rmi.RemoteException;
import java.sql.Date;

import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;

import dataAccess.DB4oManager;
import domain.Booking;
import domain.Offer;
import domain.RuralHouse;
import exceptions.BadDates;
import exceptions.OfferCanNotBeBooked;
import exceptions.OverlappingOfferExists;

public final class OfferManager {

	private int offerNumber = 0;
	dataAccess.DB4oManager dbMngr;
	private static OfferManager theOfferManager;

	public OfferManager() {
		try {
			this.dbMngr = DB4oManager.getInstance();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static int getNumber() {
		ObjectContainer db=DB4oManager.getContainer();
		OfferManager o=getInstance();
		o.offerNumber++;
		db.store(o);
		db.commit();
		return o.offerNumber;
	}

	/**
	 * This method returns the instance of the OfferManager class 
	 * 
	 * @return the offer manager
	 */
	public static OfferManager getInstance()  {
		ObjectContainer db=DB4oManager.getContainer();
		OfferManager b = new OfferManager();
		ObjectSet result = db.queryByExample(b);
		if (!result.hasNext()){
			theOfferManager = new OfferManager();
			db.store(theOfferManager);
			db.commit();
		} else theOfferManager=(OfferManager)result.next();
		return theOfferManager;
	}
	
	/**
	 * 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.compareTo(lastDay)>=0) throw new BadDates();

		boolean b = dbMngr.existsOverlappingOffer(ruralHouse,firstDay,lastDay); // The ruralHouse object in the client may not be updated
		if (!b) {
			ruralHouse.createOffer(offerNumber, firstDay, lastDay, price);
			return dbMngr.createOffer(ruralHouse,firstDay,lastDay,price);			
		}
		return null;
	}

	public Offer modifyOffer(RuralHouse ruralHouse, Date firstDay, Date lastDay,
			float price, Offer offer) throws OverlappingOfferExists, BadDates, RemoteException, Exception {
		if (firstDay.compareTo(lastDay)>=0) throw new BadDates();
		offer.setFirstDay(firstDay);
		offer.setLastDay(lastDay);
		offer.setPrice(price);
		
		return dbMngr.modifyOffer(offer);			
		
	}
	public void deleteOffer(RuralHouse rh, Offer o) throws RemoteException, Exception{
		rh.offers.removeElement(o);
		dbMngr.deleteOffer(rh, o);
	}

}

Commits for RRRRHHHH_CoderuralHouses/src/businessLogic/OfferManager.java

Diff revisions: vs.
Revision Author Commited Message
64482a ... Diff Diff Eneko Pinzolas Murua Sat 04 Apr, 2015 12:23:48 +0000

DeleteOffers and Modify Offers completed, both logic and GUI

95c4ff ... Diff Diff pinene picture pinene Tue 10 Mar, 2015 18:36:52 +0000

deleted: ruralHouses/hs_err_pid6014.log
modified: ruralHouses/src/businessLogic/OfferManager.java
modified: ruralHouses/src/dataAccess/DB4oManager.java
renamed: ruralHouses/src/gui/SetAvailability2GUI.java -> ruralHouses/src/gui/AddOffersGUI.java
modified: ruralHouses/src/gui/DeleteHouseGUI.java
new file: ruralHouses/src/gui/DeleteOfferGUI.java
deleted: ruralHouses/src/gui/SetAvailabilityGUI.java

e16868 ... Diff Diff Eneko Pinzolas Murua Mon 09 Mar, 2015 13:02:33 +0000

deleted aplicationFacade and imported it’s functions to specific business logics.

e0d74d ... unknown Thu 26 Feb, 2015 19:24:02 +0000

Given code uploaded