1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.imca.services;
17
18 import java.util.Date;
19 import java.util.Hashtable;
20 import java.util.List;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24
25 import net.sf.imca.model.PersonBO;
26 import net.sf.imca.model.AssociationBO;
27 import net.sf.imca.model.entities.AssociationDAO;
28 import net.sf.imca.model.entities.AssociationEntity;
29 import net.sf.imca.model.entities.MembershipDAO;
30 import net.sf.imca.model.entities.MembershipEntity;
31 import net.sf.imca.model.entities.PersonEntity;
32
33
34
35
36
37
38 public class UiService extends Service {
39
40
41
42
43 public UiService() {
44 super();
45 }
46
47
48
49
50 private Log log = LogFactory.getLog(UiService.class);
51
52 public AssociationBO[] getAssociationsWithWebsites() {
53 this.startTransaction();
54 AssociationDAO dao = new AssociationDAO();
55 List<AssociationEntity> list = dao.getAssociationsWithWebsites(em);
56
57 AssociationBO[] associations = new AssociationBO[list.size()];
58
59 for (int i=0; i < associations.length;i++ ){
60 associations[i] = new AssociationBO(list.get(i));
61 }
62
63 try {
64 this.endTransaction();
65 } catch (Exception ex) {
66 log.error(ex);
67 return null;
68 }
69 return associations;
70 }
71
72 public PersonBO[] getMembersWithWebsites() {
73
74 this.startTransaction();
75
76 MembershipDAO dao = new MembershipDAO();
77 List<MembershipEntity> list =
78 dao.findActiveMembersOnDate(em, new Date());
79
80
81 for (int i=0; i < list.size(); i++){
82 if (list.get(i).getPerson().getUrl().length() == 0) {
83 list.remove(i);
84 i--;
85 }
86 }
87
88
89 Hashtable<Long, PersonEntity> uniquePersons =
90 new Hashtable<Long, PersonEntity>();
91 for (int i=0; i < list.size(); i++){
92 if (uniquePersons.get(new Long(list.get(i).getPerson().getId()))
93 != null) {
94 list.remove(i);
95 i--;
96 } else {
97 uniquePersons.put(
98 new Long(list.get(i).getPerson().getId()),
99 list.get(i).getPerson());
100 }
101 }
102
103
104 PersonBO[] members = new PersonBO[list.size()];
105 for (int i=0; i < members.length;i++ ){
106 members[i] = new PersonBO(list.get(i).getPerson());
107 }
108
109 try {
110 this.endTransaction();
111 } catch (Exception ex) {
112 log.error(ex);
113 return null;
114 }
115 return members;
116 }
117 }