//logger.finer("\n***elements = " + sb.toString());
//createUser(request, htUpload);
// just for now comment out the above line
// need to check if fileupload is complete
Person newEditPerson = null;
boolean isEditable = Boolean.parseBoolean(request.getParameter("isEditable"));
if (isEditable) {
newEditPerson = getPerson(request);
} else {
newEditPerson = createUser(request, htUpload, fuh);
}
logger.log(Level.FINER, "A new Person has been added and persisted");
request.setAttribute("displayPerson", newEditPerson);
String id = String.valueOf(newEditPerson.getUserID());
htUpload = fuh.handleFileUpload(id, request, response);
updateUser(newEditPerson, htUpload);
}
return "/site.jsp?page=personContent.jsp";
} else if (path.equals("/person/fileuploadPersonFinal")) {
// file upload status request
FileUploadHandler.handleFileUploadFinal(request, response);
return null;
} else if (path.equals("/person/fileuploadStatusPerson")) {
// file upload status request
FileUploadHandler.handleFileStatus(request, response);
return null;
} else {
if (method.equals("GET")) // default to a read action
{
actionType = AT_READ_PARAMVALUE;
}
}
} else {
ModelFacade modelFacade = (ModelFacade) context.getAttribute(MF_KEY);
UserBean userBean = (UserBean) request.getSession().getAttribute("userBean");
Person loggedInPerson = userBean.getLoggedInPerson();
if (loggedInPerson == null) {
userBean.setDisplayMessage("Log in to manage invitations");
return null;
}
String requestorUsername = request.getParameter(USER_NAME_PARAM);
String friendUsername = request.getParameter(FRIEND_PARAM);
if (actionType.equals(GET_FRIENDS)) {
Person p = getPerson(request);
if (p != null) {
out.write(p.getFriendsAsJson());
}
out.close();
return null;
} else if (actionType.equals(GET_POSTED_EVENTS)) {
Person p = getPerson(request);
if (p != null) {
out.write(modelFacade.getPostedEventsAsJson(p));
}
out.close();
return null;
} else if (actionType.equals(GET_ATTEND_EVENTS)) {
Person p = getPerson(request);
if (p != null) {
out.write(p.getAttendEventsAsJson());
}
out.close();
return null;
} else if (actionType.equals(REVOKE_INVITE)) {
//Person p = getPerson(request);
//Person friend = getFriend(request);
//String requestorUsername = request.getParameter(USER_NAME_PARAM);
//String friendUsername = request.getParameter(FRIEND_PARAM);
Invitation inv = modelFacade.findInvitation(loggedInPerson.getUserName(), friendUsername);
if (inv != null) {
modelFacade.deleteInvitation(loggedInPerson, inv);
}
//update outgoing invitation list
//out.write(loggedInPerson.getOutgoingInvitationsAsJson());
response.setContentType("application/json;charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write(this.OutgoingInvitationsAsJson(loggedInPerson, "revokeInvite"));
response.flushBuffer();
out.close();
} else if (actionType.equals(APPROVE_FRIEND)) {
Invitation acceptedInv = modelFacade.findInvitation(friendUsername, loggedInPerson.getUserName());
modelFacade.addFriend(loggedInPerson.getUserName(), friendUsername);
modelFacade.deleteInvitation(loggedInPerson, acceptedInv);
} else if (actionType.equals(REJECT_INVITE)) {
//this is an incoming friendship request so the friend is the requestor
//Invitation revokedInv = modelFacade.findInvitation(friendUsername, loggedInPerson.getUserName());
//let do this in memory
// Invitation foundInv = null;
Collection<Invitation> invs = loggedInPerson.getIncomingInvitations();
Iterator<Invitation> invsIter = invs.iterator();
Invitation revokedInv = null;
while (invsIter.hasNext()) {
revokedInv = invsIter.next();
//incoming
if ((revokedInv.getRequestor().getUserName().equalsIgnoreCase(friendUsername)) && (revokedInv.getCandidate().getUserName().equalsIgnoreCase(requestorUsername))) {
break;
}
}
modelFacade.deleteInvitation(loggedInPerson, revokedInv);
}
}
response.setContentType("application/json;charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
Person p = null;
if (AT_CREATE_PARAMVALUE.equals(actionType)) {
// this shouldn't be hit anymore because the person will be created by a fileupload
p = createUser(request);
} else if (AT_READ_PARAMVALUE.equals(actionType)) {
p = getPerson(request);
} else if (AT_UPDATE_PARAMVALUE.equals(actionType)) {
p = updateUser(request);
} else if (AT_DELETE_PARAMVALUE.equals(actionType)) {
deleteUser(request);
} else if (AT_ADD_FRIEND.equals(actionType)) {
p = addFriend(request);
}
if (p != null) {
out.write(p.toJson());
}
out.close();
return null;
}