public static Result edit(Long id) {
Logger.info("EDIT");
try {
Logger.info("Community Edit for id:" + id);
User user = new User();
user = user.getUserFromSession(session());
//specify which fields are allowed to be set, to prevent against mass-assignment
Form<Community> filledForm = form(Community.class).bindFromRequest("name", "copyrightText", "introductoryText", "shortDescription", "sidebarText");
if(filledForm.hasErrors()){
return badRequest(views.html.community.edit.render(user, filledForm, "Edit Comm", "", ""));
}
Community editCommunity = filledForm.get();
//Determine if the edited community is changed from original. i.e. don't update unless necessary
RestResponse originalCommunityResponse = Community.findByID(id);
Community originalCommunity = null;
if(originalCommunityResponse.modelObject instanceof Community) {
originalCommunity = (Community) originalCommunityResponse.modelObject;
}
if(editCommunity.equals(originalCommunity)) {
Logger.info("Communities are equal, nothing to do");
flash("success", "No changes to community detected");
return redirect(routes.Communities.show(id));
} else {
editCommunity.id = originalCommunity.id;
RestResponse restResponse = editCommunity.update(user.token());
HttpResponse httpResponse = restResponse.httpResponse;
if(httpResponse.getStatusLine().getStatusCode() == 200) {
Logger.info("ok");
flash("success", "Community has been updated.");
return redirect(routes.Communities.show(id));