1 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 ; 34 import java.util.ArrayList ; 35 import java.util.List ; 36 37 public class View extends ActionPlanningSupport 38 { 39 long userHideThreshold = 182; 41 static final java.text.SimpleDateFormat dateFormatter = new java.text.SimpleDateFormat ("yyyy-MM-dd"); 42 long time = -1; 43 44 List events = new ArrayList (); 46 List users = new ArrayList (); 47 48 public List getEvents() { return events; } 49 public List getUsers() { return users; } 50 51 public void setTime(long inTime) { time = inTime; } 52 53 54 private static class Event 56 { 57 net.killingar.forum.internal.Event event; 58 boolean unread; 59 String time; 60 User owner; 61 62 public net.killingar.forum.internal.Event getEvent() { return event; } 63 public boolean getUnread() { return unread; } 64 public String 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 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 eventData; 100 private User user; 101 private long daysSinceRead; 102 103 public List getEventData() { return eventData; } 104 public User getUser() { return user; } 105 public long getDaysSinceRead() { return daysSinceRead; } 106 107 public UserData( 108 List eventData, 109 User user, 110 long daysSinceRead) 111 { 112 this.eventData = eventData; 113 this.user = user; 114 this.daysSinceRead = daysSinceRead; 115 } 116 } 117 118 120 122 protected String 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 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 timeOnPlanning = time != -1? new Timestamp (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 eventData = new ArrayList (); 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 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 |