1 16 package com.blandware.atleap.webapp.action.testimonials; 17 18 import com.blandware.atleap.common.TestimonialModuleConstants; 19 import com.blandware.atleap.model.testimonials.Testimonial; 20 import com.blandware.atleap.search.SearchManager; 21 import com.blandware.atleap.service.exception.BeanAlreadyExistsException; 22 import com.blandware.atleap.service.testimonials.TestimonialManager; 23 import com.blandware.atleap.webapp.action.core.BaseAction; 24 import com.blandware.atleap.webapp.form.TestimonialForm; 25 import com.blandware.atleap.webapp.util.core.CacheUtil; 26 import org.apache.commons.validator.GenericValidator; 27 import org.apache.struts.action.*; 28 import org.springframework.orm.ObjectOptimisticLockingFailureException; 29 30 import javax.servlet.http.HttpServletRequest ; 31 import javax.servlet.http.HttpServletResponse ; 32 33 52 public final class ChangeTestimonialActivityAction extends BaseAction { 53 62 public ActionForward execute(ActionMapping mapping, ActionForm form, 63 HttpServletRequest request, HttpServletResponse response) throws Exception { 64 65 TestimonialForm testimonialForm = (TestimonialForm) form; 66 67 Long testimonialId = null; 68 if ( !GenericValidator.isBlankOrNull(testimonialForm.getId()) ) { 69 testimonialId = Long.valueOf(testimonialForm.getId()); 70 } else { 71 if ( log.isWarnEnabled() ) { 72 log.warn("Missing content page ID. Returning to list."); 73 } 74 return mapping.findForward("listTestimonials"); 75 } 76 77 TestimonialManager testimonialManager = (TestimonialManager) getBean(TestimonialModuleConstants.TESTIMONIAL_MANAGER_BEAN); 78 Testimonial testimonial = testimonialManager.retrieveTestimonial(testimonialId); 79 80 if ( testimonial == null ) { 81 ActionMessages errors = new ActionMessages(); 83 errors.add("testimonialNotFound", new ActionMessage("testimonials.errors.notFound")); 84 saveErrors(request, errors); 85 return mapping.findForward("listTestimonials"); 86 } 87 88 String mode = request.getParameter("mode"); 89 boolean alreadyActive = testimonial.getActive() != null ? testimonial.getActive().booleanValue() : false; 90 boolean active = true; 91 if ( !"active".equalsIgnoreCase(mode) ) { 92 active = false; 93 } 94 95 try { 96 97 if ( (alreadyActive && !active) || (!alreadyActive && active) ) { 98 testimonial.setActive(Boolean.valueOf(active)); 99 testimonialManager.updateTestimonial(testimonial); 100 101 SearchManager searchManager = SearchManager.getInstance(request.getSession().getServletContext()); 102 searchManager.unIndexPage(testimonial.getUri(), request); 103 104 if ( active ) { 105 searchManager.indexPage(testimonial, request); 106 } 107 108 CacheUtil cacheUtil = CacheUtil.getInstance(request); 109 cacheUtil.flushLocalizableFieldValueCache(testimonialId); 110 } 111 } catch ( BeanAlreadyExistsException e ) { 112 ActionMessages errors = new ActionMessages(); 114 errors.add("testimonialAlreadyExists", new ActionMessage("errors.testimonialAlreadyExists")); 115 saveErrors(request, errors); 116 return mapping.findForward("listTestimonials"); 117 } catch ( ObjectOptimisticLockingFailureException e ) { 118 ActionMessages errors = new ActionMessages(); 120 errors.add("updateFailed", new ActionMessage("testimonials.errors.updateFailed")); 121 saveErrors(request, errors); 122 return mapping.findForward("listTestimonials"); 123 } 124 return mapping.findForward("listTestimonials"); 125 } 126 } | Popular Tags |