return;
}
//create a Person object for current user
Person person = PersonFactory.findPerson(authorMbox);
if (person == null) {
person = PersonFactory.createPerson(authorMbox, null, false);
}
// show root posts of given resource
if (request.getParameter("getRootPosts") != null && "true".equals(request.getParameter("getRootPosts"))) {
//get the evaluation of the resource
float currentRating = Float.isNaN(resource.getEvaluation()) ? 0 : resource.getEvaluation();
float currentUserRating = Float.isNaN(resource.getEvaluation(person)) ? 0 : resource.getEvaluation(person);
//System.out.println("__eval " + resource.getEvaluation(person) + " .. " + resource.getEvaluationsNo());
//sets the attributes used after redirection
request.setAttribute("resourceUri", resourceUri);
request.setAttribute("authorMbox", authorMbox);
request.setAttribute("currentRating", Float.valueOf(currentRating));
request.setAttribute("currentUserRating", Float.valueOf(currentUserRating));
request.setAttribute("isUserAllowedToRate", Float.isNaN(resource.getEvaluation(person)) ? true : false );
request.setAttribute("currentRatingsNo", resource.getEvaluationsNo());
/*System.out.println(request.getAttribute("currentRating") + " " + request.getAttribute("currentUserRating") + " "
+ request.getAttribute("currentRatingsNo"));*/
request.getRequestDispatcher(JSP_PAGE_PATH).forward(request,response);
return;
}
// add the post
if (request.getParameter("addPost") != null && "true".equals(request.getParameter("addPost"))) {
// get the post information from the request
String postTitle = request.getParameter("postTitle");
String parentPostUri = request.getParameter("parentPostUri");
String postBody = request.getParameter("postBody");
String postKeywords = request.getParameter("postKeywords");
//String isRootPost = request.getParameter("isRootPost");
if (postBody == null || "".equals(postBody)) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, String.format(MISSING_PARAM_ADDED_POST));
return;
}
Set<String> hasKeywords = new TreeSet<String>();
if (postKeywords != null && !"".equals(postKeywords)) {
processKeywords(postKeywords, hasKeywords);
}
String strMilis = Long.toString(System.currentTimeMillis());
//create a post with attributes set to given values
SiocPostBean post = new SiocPostBean();
post.setUri(request.getRequestURL()+"/"+Sha1sum.getInstance().calc(person.getMbox().toString()+strMilis));
post.setPostedBy(person);
post.setPostedResource(resourceUri);
post.setPostBody(postBody);
post.setPostedWhen(strMilis);
post.setPostTitle(postTitle);