1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.oness.party.model.facade.action;
17
18 import java.util.List;
19
20 import net.sf.oness.common.model.dao.Dao;
21 import net.sf.oness.common.model.exceptions.ExistingInstanceException;
22 import net.sf.oness.party.model.party.bo.Party;
23
24 /***
25 * @author Carlos Sanchez
26 * @version $Revision: 1.6 $
27 */
28 public class CreatePartyAction {
29
30 private Party party;
31
32 private Dao partyDao;
33
34 private boolean ignoreExisting;
35
36 public CreatePartyAction(Dao partyDao, Party party, boolean ignoreExisting) {
37 this.partyDao = partyDao;
38 this.party = party;
39 this.ignoreExisting = ignoreExisting;
40 }
41
42 public Party execute() throws ExistingInstanceException {
43 if (party.getInternalName() == null)
44 throw new NullPointerException();
45
46 if (!ignoreExisting) {
47 Party partyCriteria = new Party();
48 partyCriteria.setInternalName(party.getInternalName());
49 List existing = partyDao.find(partyCriteria, 0, Integer.MAX_VALUE);
50 if (existing.size() > 0) {
51 throw new ExistingInstanceException(party, party.getClass()
52 .getName(), existing);
53 }
54 }
55 return (Party) partyDao.create(party);
56 }
57 }