1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.oness.party.model.facade;
17
18 import net.sf.oness.common.model.dao.Dao;
19 import net.sf.oness.common.model.exceptions.ExistingInstanceException;
20 import net.sf.oness.common.model.util.PaginatedList;
21 import net.sf.oness.party.model.contact.bo.ContactInfo;
22 import net.sf.oness.party.model.contact.bo.Country;
23 import net.sf.oness.party.model.contact.bo.PhoneNumber;
24 import net.sf.oness.party.model.contact.dao.CountryDao;
25 import net.sf.oness.party.model.facade.action.CreatePartyAction;
26 import net.sf.oness.party.model.party.bo.Party;
27
28 /***
29 * Facade that uses the Spring framework
30 *
31 * @author Carlos Sanchez
32 * @version $Revision: 1.14 $
33 */
34 public class PartySpringFacadeDelegate implements PartyFacadeDelegate {
35
36 private Dao partyDao, contactInfoDao;
37
38 private CountryDao countryDao;
39
40 /***
41 * @param partyDao
42 * The party DAO to set.
43 */
44 public void setPartyDao(Dao partyDao) {
45 this.partyDao = partyDao;
46 }
47
48 /***
49 * @return Returns the party DAO.
50 */
51 public Dao getPartyDao() {
52 return partyDao;
53 }
54
55 /***
56 * @param contactInfoDao
57 * The contactInfo DAO to set.
58 */
59 public void setContactInfoDao(Dao contactInfoDao) {
60 this.contactInfoDao = contactInfoDao;
61 }
62
63 /***
64 * @return Returns the contactInfo DAO.
65 */
66 public Dao getContactInfoDao() {
67 return contactInfoDao;
68 }
69
70 /***
71 * @param countryDao
72 * The country DAO to set.
73 */
74 public void setCountryDao(CountryDao countryDao) {
75 this.countryDao = countryDao;
76 }
77
78 /***
79 * @return Returns the contactInfo DAO.
80 */
81 public CountryDao getCountryDao() {
82 return countryDao;
83 }
84
85
86
87 /***
88 * @see net.sf.oness.party.model.facade.PartyFacadeDelegate#createParty(net.sf.oness.party.model.party.bo.Party)
89 */
90 public Party createParty(Party party) throws ExistingInstanceException {
91 return createParty(party, true);
92 }
93
94 /***
95 *
96 * @see net.sf.oness.party.model.facade.PartyFacadeDelegate#createParty(net.sf.oness.party.model.party.bo.Party,
97 * boolean)
98 */
99 public Party createParty(Party party, boolean ignoreExisting)
100 throws ExistingInstanceException {
101 CreatePartyAction action = new CreatePartyAction(getPartyDao(), party,
102 ignoreExisting);
103 return action.execute();
104 }
105
106 /***
107 *
108 * @see net.sf.oness.party.model.facade.PartyFacadeDelegate#updateParty(net.sf.oness.party.model.party.bo.Party)
109 */
110 public Party updateParty(Party party) {
111 return (Party) getPartyDao().update(party);
112 }
113
114 /***
115 * @see net.sf.oness.party.model.facade.PartyFacadeDelegate#findParty(Party,
116 * int, int)
117 */
118 public PaginatedList findParty(Party party, int firstElement,
119 int maxElements) {
120 return getPartyDao().find(party, firstElement, maxElements);
121 }
122
123 /***
124 * @see net.sf.oness.party.model.facade.PartyFacadeDelegate#findParty(java.lang.Long)
125 */
126 public Party findParty(Long id) {
127 return (Party) getPartyDao().findById(id);
128 }
129
130 /***
131 * @see net.sf.oness.party.model.facade.PartyFacadeDelegate#findPartyWithDetails(java.lang.Long)
132 */
133 public Party findPartyWithDetails(Long id) {
134 return (Party) getPartyDao().findWithDetails(id);
135 }
136
137 /***
138 * @see net.sf.oness.party.model.facade.PartyFacadeDelegate#deleteParty(java.lang.Long)
139 */
140 public void deleteParty(Long id) {
141 getPartyDao().delete(id);
142 }
143
144
145
146 /***
147 * @see net.sf.oness.party.model.facade.PartyFacadeDelegate#createContactInfo(net.sf.oness.party.model.contact.bo.ContactInfo)
148 */
149 public ContactInfo createContactInfo(ContactInfo contactInfo) {
150 if (contactInfo instanceof PhoneNumber) {
151 PhoneNumber phoneNumber = (PhoneNumber) contactInfo;
152 phoneNumber.setCountry((Country) getCountryDao().findById(
153 phoneNumber.getCountry().getIsoCode()));
154 }
155 return (ContactInfo) getContactInfoDao().create(contactInfo);
156 }
157
158 /***
159 * @see net.sf.oness.party.model.facade.PartyFacadeDelegate#updateContactInfo(net.sf.oness.party.model.contact.bo.ContactInfo)
160 */
161 public ContactInfo updateContactInfo(ContactInfo contactInfo) {
162 return (ContactInfo) getContactInfoDao().update(contactInfo);
163 }
164
165 /***
166 * @see net.sf.oness.party.model.facade.PartyFacadeDelegate#findContactInfo(net.sf.oness.party.model.contact.bo.ContactInfo,
167 * int, int)
168 */
169 public PaginatedList findContactInfo(ContactInfo contactInfo,
170 int firstElement, int maxElements) {
171 return getContactInfoDao().find(contactInfo, firstElement, maxElements);
172 }
173
174 /***
175 * @see net.sf.oness.party.model.facade.PartyFacadeDelegate#findContactInfo(java.lang.Long)
176 */
177 public ContactInfo findContactInfo(Long id) {
178 return (ContactInfo) getContactInfoDao().findById(id);
179 }
180
181 /***
182 * @see net.sf.oness.party.model.facade.PartyFacadeDelegate#deleteContactInfo(java.lang.Long)
183 */
184 public void deleteContactInfo(Long id) {
185 getContactInfoDao().delete(id);
186 }
187
188 }