Model model, HttpServletRequest request, HttpSession session){
if(!ajaxUtil.isAjaxRequest(request)){
throw new ResourceNotFoundException();
}
if(result.hasErrors()){
return new AjaxResult(AjaxResultCode.INVALID,
BindingErrors.from(result));
}
Activity activity = activityRepository.findOne(bean.getActId());
if(activity==null){
throw new RuntimeException("Invalid activity id:" + bean.getActId());
}
if(activity.getTargetSpot() == null ||
(ActivityType.SPOT != activity.getType() &&
ActivityType.FORWARD != activity.getType())){
throw new RuntimeException("Invalid activity type:" + activity.getType());
}
Spot target = spotRepository.findOne(activity.getTargetSpot());
// save forward as comment
Forward fwd = Forward.from(bean, signInUser);
fwd.setAct(activity);
fwd = forwardRepository.save(fwd);
// incr forwarded count of original activity
activityRepository.inc(activity.getId(), "forwardedCount", 1);
// save forward activity
activity = new Activity();
activity.setOwner(signInUser.getId());
activity.setCreatedAt(new Date());
activity.setTargetSpot(target.getId());
activity.setContent(bean.getContent());
activity.setType(ActivityType.FORWARD);
activity.setBasedOn(bean.getActId());
activity.setBy(sessionUtil.getBy(session));
activityRepository.save(activity);
// incr forwarded count of target spot
spotRepository.inc(target.getId(), "forwardedCount", 1);
// incr forward count of sign in user
userRepository.inc(signInUser.getId(), "forwardCount", 1);
return new AjaxResult(AjaxResultCode.SUCCESS, fwd);
}