KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > killingar > forum > actions > planning > View


1 /* Copyright 2000-2005 Anders Hovmöller
2  *
3  * The person or persons who have associated their work with
4  * this document (the "Dedicator") hereby dedicate the entire
5  * copyright in the work of authorship identified below (the
6  * "Work") to the public domain.
7  *
8  * Dedicator makes this dedication for the benefit of the
9  * public at large and to the detriment of Dedicator's heirs
10  * and successors. Dedicator intends this dedication to be an
11  * overt act of relinquishment in perpetuity of all present
12  * and future rights under copyright law, whether vested or
13  * contingent, in the Work. Dedicator understands that such
14  * relinquishment of all rights includes the relinquishment of
15  * all rights to enforce (by lawsuit or otherwise) those
16  * copyrights in the Work.
17  *
18  * Dedicator recognizes that, once placed in the public
19  * domain, the Work may be freely reproduced, distributed,
20  * transmitted, used, modified, built upon, or otherwise
21  * exploited by anyone for any purpose, commercial or non-
22  * commercial, and in any way, including by methods that have
23  * not yet been invented or conceived.
24  */

25
26 package net.killingar.forum.actions.planning;
27
28 import net.killingar.forum.internal.User;
29 import net.killingar.forum.internal.managers.OptionsManager;
30 import net.killingar.forum.internal.managers.PlanningManager;
31 import net.killingar.forum.internal.managers.TimeManager;
32
33 import java.sql.Timestamp JavaDoc;
34 import java.util.ArrayList JavaDoc;
35 import java.util.List JavaDoc;
36
37 public class View extends ActionPlanningSupport
38 {
39     // Private --------------------------------------------------------
40
long userHideThreshold = 182;
41     static final java.text.SimpleDateFormat JavaDoc dateFormatter = new java.text.SimpleDateFormat JavaDoc("yyyy-MM-dd");
42     long time = -1;
43
44     // Attributes -----------------------------------------------------
45
List JavaDoc events = new ArrayList JavaDoc();
46     List JavaDoc users = new ArrayList JavaDoc();
47
48     public List JavaDoc getEvents() { return events; }
49     public List JavaDoc getUsers() { return users; }
50
51   public void setTime(long inTime) { time = inTime; }
52
53
54     // Types ----------------------------------------------------------
55
private static class Event
56     {
57         net.killingar.forum.internal.Event event;
58         boolean unread;
59         String JavaDoc time;
60         User owner;
61
62         public net.killingar.forum.internal.Event getEvent() { return event; }
63         public boolean getUnread() { return unread; }
64         public String JavaDoc getTime() { return time; }
65         public User getOwner() { return owner; }
66
67         public Event(
68             net.killingar.forum.internal.Event event,
69             boolean unread,
70             String JavaDoc time,
71             User owner)
72         {
73             this.event = event;
74             this.unread = unread;
75             this.time = time;
76             this.owner = owner;
77         }
78     }
79
80     private static class EventData
81     {
82         private net.killingar.forum.internal.EventData eventData;
83         private boolean unread;
84
85         public net.killingar.forum.internal.EventData getEventData() { return eventData; }
86         public boolean getUnread() { return unread; }
87
88         public EventData(
89             net.killingar.forum.internal.EventData eventData,
90             boolean unread)
91         {
92             this.eventData = eventData;
93             this.unread = unread;
94         }
95     }
96
97     private static class UserData
98     {
99         private List JavaDoc eventData;
100     private User user;
101         private long daysSinceRead;
102
103         public List JavaDoc getEventData() { return eventData; }
104         public User getUser() { return user; }
105         public long getDaysSinceRead() { return daysSinceRead; }
106
107         public UserData(
108             List JavaDoc eventData,
109             User user,
110             long daysSinceRead)
111         {
112             this.eventData = eventData;
113             this.user = user;
114             this.daysSinceRead = daysSinceRead;
115         }
116     }
117
118     // Setters --------------------------------------------------------
119

120     // Getters --------------------------------------------------------
121

122     // Implementation -------------------------------------------------
123
protected String JavaDoc doExecute()
124     {
125         try
126         {
127             PlanningManager planningMgr = (PlanningManager)manager.getManager(PlanningManager.class.getName());
128             TimeManager timeMgr = (TimeManager)manager.getManager(TimeManager.class.getName());
129             OptionsManager optionMgr = (OptionsManager)manager.getManager(OptionsManager.class.getName());
130
131             {
132                 String JavaDoc tmp = optionMgr.get("user hide threshold");
133                 if (tmp != null)
134                     userHideThreshold = Long.parseLong(tmp);
135             }
136
137             net.killingar.forum.internal.Event events[] = planningMgr.getEvents();
138             for (int i = 0; i < events.length; i++)
139             {
140                 net.killingar.forum.internal.Event event = events[i];
141                 if (event.groupID != 0 && !manager.isUserInGroup(manager.getUserID(), event.groupID))
142                     events[i] = null;
143             }
144             User[] users = manager.getCommonGroupUsers(manager.getUserID());
145
146             java.util.Arrays.sort(users);
147
148             Timestamp JavaDoc timeOnPlanning = time != -1? new Timestamp JavaDoc(time): planningMgr.getTimeOnPlanning();
149
150             for (int i = 0; i < events.length; i++)
151             {
152                 if (events[i] != null)
153                 {
154                     this.events.add(
155                         new Event(
156                             events[i],
157                             events[i].created.after(timeOnPlanning),
158                             dateFormatter.format(events[i].time),
159                             manager.getUser(events[i].ownerID)));
160                 }
161             }
162
163             for (int i = 0; i < users.length; i++)
164             {
165                 long daysSinceRead = manager.daysSinceUserRead(users[i].ID);
166                 if (daysSinceRead > userHideThreshold)
167                     continue;
168
169                 List JavaDoc eventData = new ArrayList JavaDoc();
170
171                 for (int j = 0; j < events.length; j++)
172                 {
173                     if (events[j] == null)continue;
174
175                     net.killingar.forum.internal.EventData foo = planningMgr.getEventData(events[j].ID, users[i].ID);
176                     eventData.add(new EventData(foo, foo == null? false : foo.time.after(timeOnPlanning)));
177                 }
178
179                 this.users.add(new UserData(eventData, users[i], daysSinceRead));
180             }
181
182             planningMgr.setReadPlanning();
183             timeMgr.setUserTime(TimeManager.systemWelcome);
184         }
185         catch (Exception JavaDoc e)
186         {
187             e.printStackTrace();
188             addErrorMessage("executing "+getClass().toString()+" action failed, exception thrown: "+e.toString());
189             return ERROR;
190         }
191
192         return SUCCESS;
193     }
194 }
195
Popular Tags