My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package in.partake.controller.api.event;

import in.partake.base.PartakeException;
import in.partake.controller.api.PartakeAPIActionSupport;
import in.partake.model.EventEx;
import in.partake.model.UserEx;
import in.partake.model.dao.DAOException;
import in.partake.model.dto.auxiliary.AttendanceStatus;
import in.partake.model.dto.auxiliary.ParticipationStatus;
import in.partake.model.dto.auxiliary.UserPermission;
import in.partake.resource.Constants;
import in.partake.resource.UserErrorCode;
import in.partake.service.EventService;
import in.partake.service.MessageService;
import in.partake.util.Util;
import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;

public class EventAction extends PartakeAPIActionSupport {
private static final long serialVersionUID = 1L;

public String get() throws DAOException {
String eventId = getParameter("eventId");
if (StringUtils.isBlank(eventId))
return renderInvalid(UserErrorCode.MISSING_EVENT_ID);
if (!Util.isUUID(eventId))
return renderInvalid(UserErrorCode.INVALID_EVENT_ID);

EventEx event = EventService.get().getEventExById(eventId);
if (event == null) { return renderInvalid(UserErrorCode.INVALID_EVENT_ID); }

if (event.isPrivate()) {
// TODO: EventsController とコードが同じなので共通化するべき 

// owner および manager は見ることが出来る。
// TOOD: Use PartakeSession instead of session.
String passcode = (String) session.get("event:" + eventId);
if (passcode == null) { passcode = getParameter("passcode"); }

UserEx loginUser = getLoginUser();
if (loginUser != null && event.hasPermission(loginUser, UserPermission.EVENT_PRIVATE_EVENT)) {
// OK. You have the right to show this event.
} else if (StringUtils.equals(event.getPasscode(), passcode)) {
// OK. The same passcode.
} else {
// public でなければ、passcode を入れなければ見ることが出来ない
return renderForbidden();
}
}

JSONObject obj = new JSONObject();
obj.put("event", event.toSafeJSON());
return renderOK(obj);
}

public String create() throws DAOException {
throw new RuntimeException("Not implemented yet");
}

public String modify() throws DAOException {
throw new RuntimeException("Not implemented yet");
}

public String remove() throws DAOException {
UserEx user = getLoginUser();
if (user == null)
return renderLoginRequired();

String eventId = getParameter("eventId");
if (eventId == null)
return renderInvalid(UserErrorCode.MISSING_EVENT_ID);
if (!Util.isUUID(eventId))
return renderInvalid(UserErrorCode.INVALID_EVENT_ID);

EventEx event = EventService.get().getEventExById(eventId);
if (event == null)
return renderNotFound();

if (!event.hasPermission(user, UserPermission.EVENT_REMOVE))
return renderForbidden();

EventService.get().remove(eventId);
return renderOK();
}

public String enroll() throws DAOException {
UserEx user = getLoginUser();
if (user == null)
return renderLoginRequired();

String eventId = getParameter("eventId");
if (eventId == null)
return renderInvalid(UserErrorCode.MISSING_EVENT_ID);
if (!Util.isUUID(eventId))
return renderInvalid(UserErrorCode.INVALID_EVENT_ID);

// If the comment does not exist, we use empty string instead.
String comment = getParameter("comment");
if (comment == null) { comment = ""; }
if (comment.length() > 1024)
return renderInvalid(UserErrorCode.INVALID_COMMENT_TOOLONG);

ParticipationStatus status = ParticipationStatus.safeValueOf(getParameter("status"));
if (status == null || status == ParticipationStatus.NOT_ENROLLED)
return renderInvalid(UserErrorCode.INVALID_ENROLL_STATUS);

throw new RuntimeException("Not implemented yet.");
// try {
// EventService.get().enrollForAPI(user, eventId, status, comment);
// return renderOK();
//
// } catch (PartakeException e) {
// return renderException(e);
// }
}

public String sendMessage() throws DAOException {
UserEx user = getLoginUser();
if (user == null)
return renderLoginRequired();

String eventId = getParameter("eventId");
if (eventId == null)
return renderInvalid(UserErrorCode.MISSING_EVENT_ID);
if (!Util.isUUID(eventId))
return renderInvalid(UserErrorCode.INVALID_EVENT_ID);

String message = getParameter("message");
if (StringUtils.isBlank(message))
return renderInvalid(UserErrorCode.MISSING_MESSAGE);

try {
MessageService.get().sendMessage(user, eventId, message);
return renderOK();
} catch (PartakeException e) {
return renderException(e);
}
}

public String attend() throws DAOException {
UserEx user = getLoginUser();
if (user == null)
return renderLoginRequired();

assert getPartakeSession() != null;
assert getPartakeSession().getCSRFPrevention() != null;
String token = getParameter(Constants.ATTR_PARTAKE_API_SESSION_TOKEN);
if (!getPartakeSession().getCSRFPrevention().isValidSessionToken(token))
return renderInvalid(UserErrorCode.INVALID_SESSION);

String userId = getParameter("userId");
if (userId == null)
return renderInvalid(UserErrorCode.MISSING_USER_ID);

String eventId = getParameter("eventId");
if (eventId == null)
return renderInvalid(UserErrorCode.MISSING_EVENT_ID);

String status = getParameter("status");
if (status == null || !AttendanceStatus.isValueOf(status))
return renderInvalid(UserErrorCode.MISSING_ATTENDANCE_STATUS);

// TODO: This should be transactional.
EventEx event = EventService.get().getEventExById(eventId);
if (event == null)
return renderInvalid(UserErrorCode.INVALID_EVENT_ID);

if (!event.hasPermission(user, UserPermission.EVENT_EDIT_PARTICIPANTS))
return renderForbidden();

if (EventService.get().updateAttendanceStatus(userId, eventId, AttendanceStatus.safeValueOf(status)))
return renderOK();
else
return renderInvalid(UserErrorCode.UNKNOWN_USER_ERROR);
}

}

Change log

r691 by ma...@mayah.jp on Feb 11, 2012   Diff
API: sendMessage implemented.
Go to: 
Project members, sign in to write a code review

Older revisions

r690 by ma...@mayah.jp on Feb 11, 2012   Diff
New resource messages.
r685 by ma...@mayah.jp on Feb 7, 2012   Diff
Reorganizing API.
r678 by ma...@mayah.jp on Jan 25, 2012   Diff
Postgres9 passes all tests!
All revisions of this file

File info

Size: 6910 bytes, 178 lines
Powered by Google Project Hosting