KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > dotmarketing > viewtools > WebEventsWebAPI


1 package com.dotmarketing.viewtools;
2
3 import java.text.SimpleDateFormat JavaDoc;
4 import java.util.ArrayList JavaDoc;
5 import java.util.Collections JavaDoc;
6 import java.util.Date JavaDoc;
7 import java.util.GregorianCalendar JavaDoc;
8 import java.util.HashMap JavaDoc;
9 import java.util.Iterator JavaDoc;
10 import java.util.List JavaDoc;
11 import java.util.Map JavaDoc;
12
13 import javax.servlet.http.HttpServletRequest JavaDoc;
14 import javax.servlet.http.HttpServletResponse JavaDoc;
15
16 import org.apache.velocity.tools.view.context.ViewContext;
17 import org.apache.velocity.tools.view.tools.ViewTool;
18
19 import com.dotmarketing.beans.Identifier;
20 import com.dotmarketing.beans.UserProxy;
21 import com.dotmarketing.db.DbConnectionFactory;
22 import com.dotmarketing.factories.IdentifierFactory;
23 import com.dotmarketing.factories.InodeFactory;
24 import com.dotmarketing.factories.UserProxyFactory;
25 import com.dotmarketing.portlets.files.model.File;
26 import com.dotmarketing.portlets.links.model.Link;
27 import com.dotmarketing.util.Config;
28 import com.dotmarketing.portlets.event_registrations.factories.WebEventRegistrationFactory;
29 import com.dotmarketing.portlets.event_registrations.model.WebEventAttendee;
30 import com.dotmarketing.portlets.event_registrations.model.WebEventRegistration;
31 import com.dotmarketing.portlets.webevents.factories.WebEventFactory;
32 import com.dotmarketing.portlets.webevents.factories.WebEventLocationFactory;
33 import com.dotmarketing.portlets.webevents.model.WebEvent;
34 import com.dotmarketing.portlets.webevents.model.WebEventLocation;
35 import com.dotmarketing.portlets.organization.model.Organization;
36 import com.dotmarketing.util.UtilMethods;
37
38 public class WebEventsWebAPI implements ViewTool {
39     private static final java.text.SimpleDateFormat JavaDoc DATE_TO_PRETTY_HTML_DATE_2 = new java.text.SimpleDateFormat JavaDoc(
40     "MMMM d, yyyy");
41     private HttpServletRequest JavaDoc request;
42
43     public void init(Object JavaDoc obj) {
44         ViewContext context = (ViewContext) obj;
45         this.request = context.getRequest();
46
47     }
48     
49     public void init(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc response) {
50         this.request = req;
51
52     }
53
54     public WebEvent getWebEvent(String JavaDoc inode) {
55         return (WebEvent) InodeFactory.getInodeOfClassByCondition(WebEvent.class, "inode = " + inode + " and show_on_web = " + DbConnectionFactory.getDBTrue());
56     }
57     
58     public WebEventLocation getWebEventLocation(String JavaDoc inode) {
59         return (WebEventLocation) InodeFactory.getInode(inode, WebEventLocation.class);
60     }
61     
62     public WebEvent getWebEvent(long inode) {
63         return (WebEvent) InodeFactory.getInodeOfClassByCondition(WebEvent.class, "inode = " + inode + " and show_on_web = " + DbConnectionFactory.getDBTrue());
64     }
65     public List JavaDoc getWebEventFiles(WebEvent e) {
66         ArrayList JavaDoc<HashMap JavaDoc> files = new ArrayList JavaDoc<HashMap JavaDoc>();
67         List JavaDoc identifiers = InodeFactory.getChildrenClass(e, Identifier.class);
68         Iterator JavaDoc it = identifiers.iterator();
69         while (it.hasNext()) {
70             Identifier identifier = (Identifier)it.next();
71             File file = (File) IdentifierFactory.getWorkingChildOfClass(identifier, File.class);
72             HashMap JavaDoc<String JavaDoc,String JavaDoc> hm = new HashMap JavaDoc<String JavaDoc,String JavaDoc>();
73             hm.put("filepath", identifier.getURI());
74             hm.put("filename", file.getTitle());
75             files.add(hm);
76         }
77         return files;
78     }
79     
80     public WebEventLocation getWebEventLocation(long inode) {
81         return (WebEventLocation) InodeFactory.getInode(inode, WebEventLocation.class);
82     }
83     
84     public List JavaDoc getWebEventLocationsPerEvent(String JavaDoc eventInode) {
85         long inode = 0;
86         try { inode = Long.parseLong(eventInode); } catch (NumberFormatException JavaDoc e) { }
87         return WebEventLocationFactory.getWebEventLocationsPerEvent(inode, "start_date");
88     }
89     
90     public List JavaDoc getWebEventLocationsPerEvent(long eventInode) {
91         return WebEventLocationFactory.getWebEventLocationsPerEvent(eventInode, "start_date");
92     }
93     
94     public List JavaDoc getWebEventLocationsPerEvent(WebEvent event) {
95         return WebEventLocationFactory.getWebEventLocationsPerEvent(event.getInode(), "start_date");
96     }
97     
98     public List JavaDoc getUpcomingWebEventLocationsPerEvent(WebEvent event) {
99         List JavaDoc locations = WebEventLocationFactory.getUpcomingWebEventLocationsPerEvent(event.getInode(), "start_date");
100         return locations.subList(0, locations.size() > 3?3:locations.size());
101     }
102     
103     public List JavaDoc getPastWebEventLocationsPerEvent(WebEvent event) {
104         List JavaDoc locations = WebEventLocationFactory.getPastWebEventLocationsPerEvent(event.getInode(), "start_date");
105         return locations.subList(0, locations.size() > 3?3:locations.size());
106     }
107     
108     public List JavaDoc getUpcomingWebEvents () {
109         List JavaDoc events = WebEventFactory.getUpcomingPublicWebEvents();
110         Collections.sort(events);
111         return events;
112     }
113     
114     public List JavaDoc getUpcomingWebEvents (boolean institute) {
115         List JavaDoc events = WebEventFactory.getUpcomingPublicWebEvents(institute);
116         Collections.sort(events);
117         return events;
118     }
119
120     public List JavaDoc getPastWebEvents () {
121         return WebEventFactory.getPastWebEvents();
122     }
123     
124     public float getEventLocationPrice (WebEventLocation loc) {
125         
126         if (request.getSession().getAttribute("isPartner") != null && request.getSession().getAttribute("isPartner").equals("true")){
127             Organization organization = (Organization)request.getSession().getAttribute("userOrganization");
128             if (organization != null){
129                 if (loc.isDefaultContractPartnerPrice())
130                     if (organization.getInstitute_price() > 0)
131                         return organization.getInstitute_price();
132                     else
133                         return loc.getPartnerPrice();
134                 else
135                     return loc.getPartnerPrice();
136         }
137             else{
138                 return loc.getNonPartnerPrice();
139             }
140         }
141         else
142             return loc.getNonPartnerPrice();
143             
144             
145     }
146     
147     public boolean isEventLocationAlmostAtCapacity (WebEventLocation loc) {
148         return loc.isAlmostAtCapacity();
149     }
150
151     public WebEventRegistration getRegistration (String JavaDoc registrationInode) {
152         return WebEventRegistrationFactory.getWebEventRegistration(registrationInode);
153     }
154
155     public List JavaDoc<WebEventAttendee> getRegistrationAttendees (WebEventRegistration reg) {
156         if (reg == null)
157             return new ArrayList JavaDoc<WebEventAttendee>();
158         
159         return WebEventRegistrationFactory.getEventAttendees(reg);
160     }
161     
162     public String JavaDoc getHotelLinkURL (long linkInode) {
163         Identifier id = (Identifier) InodeFactory.getInode(linkInode, Identifier.class);
164         Link link = (Link) IdentifierFactory.getLiveChildOfClass(id, Link.class);
165         return link.getWorkingURL();
166     }
167     
168     public String JavaDoc getPastEventLinkURL (long linkInode) {
169         Identifier id = (Identifier) InodeFactory.getInode(linkInode, Identifier.class);
170         Link link = (Link) IdentifierFactory.getLiveChildOfClass(id, Link.class);
171         return link.getWorkingURL();
172     }
173     
174     public String JavaDoc getEventDateRange (Date JavaDoc date1, Date JavaDoc date2) {
175         return UtilMethods.getEventDateRange(date1, date2);
176     }
177     
178     @SuppressWarnings JavaDoc("unchecked")
179     public List JavaDoc<Map JavaDoc> getPaymentMethods (boolean institute) {
180         List JavaDoc<Map JavaDoc> paymentsList = new ArrayList JavaDoc<Map JavaDoc> ();
181         String JavaDoc[] paymentMethods;
182         if (institute) {
183             paymentMethods = Config.getStringArrayProperty("EREG_PAYMENT_TYPES");
184         }
185         else {
186             paymentMethods = Config.getStringArrayProperty("EREG_WEBINAR_PAYMENT_TYPES");
187         }
188         String JavaDoc partnerOnly = "EREG_PURCHASE_ORDER";
189         
190         for (String JavaDoc paymentMethod : paymentMethods) {
191             
192             String JavaDoc value = Config.getStringProperty(paymentMethod);
193             String JavaDoc friendlyName = Config.getStringProperty(paymentMethod + "_FN");
194             Map JavaDoc paymentMethodMap = new HashMap JavaDoc ();
195             paymentMethodMap.put("value", value);
196             paymentMethodMap.put("friendlyName", friendlyName);
197             paymentMethodMap.put("name", paymentMethod);
198
199             if (paymentMethod.equals(partnerOnly)) {
200                 if (request.getSession().getAttribute("isPartner") != null && request.getSession().getAttribute("isPartner").equals("true")){
201                     paymentsList.add(paymentMethodMap);
202                 }
203             }
204             else {
205                 paymentsList.add(paymentMethodMap);
206             }
207         }
208         return paymentsList;
209     }
210     
211     public List JavaDoc<Map JavaDoc> getPaymentMethods () {
212         List JavaDoc<Map JavaDoc> paymentsList = new ArrayList JavaDoc<Map JavaDoc> ();
213         String JavaDoc[] paymentMethods = Config.getStringArrayProperty("EREG_PAYMENT_TYPES");
214         for (String JavaDoc paymentMethod : paymentMethods) {
215             String JavaDoc value = Config.getStringProperty(paymentMethod);
216             String JavaDoc friendlyName = Config.getStringProperty(paymentMethod + "_FN");
217             Map JavaDoc paymentMethodMap = new HashMap JavaDoc ();
218             paymentMethodMap.put("value", value);
219             paymentMethodMap.put("friendlyName", friendlyName);
220             paymentMethodMap.put("name", paymentMethod);
221             paymentsList.add(paymentMethodMap);
222         }
223         return paymentsList;
224     }
225
226     public List JavaDoc<String JavaDoc> getCreditCardTypes () {
227         String JavaDoc[] cardTypes = Config.getStringArrayProperty("EREG_CREDIT_CARD_TYPES");
228         ArrayList JavaDoc<String JavaDoc> retList = new ArrayList JavaDoc<String JavaDoc>();
229         for (String JavaDoc type : cardTypes) {
230             retList.add(type);
231         }
232         return retList;
233     }
234     
235     @SuppressWarnings JavaDoc("unchecked")
236     public List JavaDoc<WebEventRegistration> getWebEventRegistrationByUser(String JavaDoc userId){
237         if (userId == null)
238             return new ArrayList JavaDoc<WebEventRegistration>();
239         String JavaDoc inode = String.valueOf(UserProxyFactory.getUserProxy(userId).getInode());
240         return WebEventRegistrationFactory.getWebEventRegistrationsByUser(inode,"date_posted desc");
241     }
242     
243     @SuppressWarnings JavaDoc("unchecked")
244     public List JavaDoc<WebEventRegistration> getWebEventRegistrationByUserInode(String JavaDoc inode){
245         if (inode == null)
246             return new ArrayList JavaDoc<WebEventRegistration>();
247         
248         
249         return WebEventRegistrationFactory.getWebEventRegistrationsByUser(inode);
250     }
251     
252     public java.util.HashMap JavaDoc getRegistrationStatus() {
253         
254         //statuses list
255
String JavaDoc[] statusesArray = com.dotmarketing.util.Config.getStringArrayProperty("EREG_STATUSES");
256         java.util.HashMap JavaDoc<String JavaDoc, String JavaDoc> statuses = new java.util.HashMap JavaDoc<String JavaDoc, String JavaDoc>();
257         for (int i=0;i<statusesArray.length;i++) {
258             String JavaDoc status = statusesArray[i];
259             statuses.put(com.dotmarketing.util.Config.getStringProperty(status),com.dotmarketing.util.Config.getStringProperty(status + "_FN"));
260         }
261         return statuses;
262         
263     }
264     
265     public String JavaDoc valueOfStatus(Object JavaDoc value){
266         
267         return String.valueOf(value);
268     }
269      public String JavaDoc dateToPrettyHTMLDate(java.util.Date JavaDoc x) {
270             if (x == null) {
271                 return "";
272             }
273
274             return DATE_TO_PRETTY_HTML_DATE_2.format(x);
275         }
276      
277      
278      public String JavaDoc getContactOrganizationTitle(WebEventRegistration registration){
279          String JavaDoc title = "";
280          Organization organization;
281          if (registration != null){
282              UserProxy userProxy = UserProxyFactory.getUserProxy(registration.getUserInode());
283              if (userProxy.getInode() > 0){
284                  organization = (Organization) InodeFactory.getParentOfClass(userProxy, Organization.class);
285                  if (organization.getInode() > 0){
286                      title = organization.getTitle()!=null?organization.getTitle():"";
287                  }
288              }
289          }
290          return title;
291      }
292 }
Popular Tags