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.testimonials.TestimonialManager; 22 import com.blandware.atleap.webapp.action.core.BaseAction; 23 import com.blandware.atleap.webapp.form.TestimonialForm; 24 import com.blandware.atleap.webapp.util.core.CacheUtil; 25 import com.blandware.atleap.webapp.util.core.WebappConstants; 26 import com.blandware.atleap.webapp.util.core.WebappUtil; 27 import org.apache.struts.action.ActionForm; 28 import org.apache.struts.action.ActionForward; 29 import org.apache.struts.action.ActionMapping; 30 import org.apache.struts.action.ActionMessage; 31 import org.apache.struts.action.ActionMessages; 32 33 import javax.servlet.http.HttpServletRequest ; 34 import javax.servlet.http.HttpServletResponse ; 35 36 55 public final class DeleteTestimonialAction extends BaseAction { 56 65 public ActionForward execute(ActionMapping mapping, ActionForm form, 66 HttpServletRequest request, HttpServletResponse response) throws Exception { 67 68 TestimonialForm testimonialForm = (TestimonialForm) form; 69 Long testimonialId = null; 70 if ( testimonialForm.getId() != null ) { 71 testimonialId = Long.valueOf(testimonialForm.getId()); 72 } else { 73 if ( log.isWarnEnabled() ) { 74 log.warn("Missing testimonial item ID. Returning to list..."); 75 } 76 return mapping.findForward("listTestimonials"); 77 } 78 79 TestimonialManager testimonialManager = (TestimonialManager) getBean(TestimonialModuleConstants.TESTIMONIAL_MANAGER_BEAN); 80 Testimonial testimonial = testimonialManager.retrieveTestimonial(testimonialId); 81 82 if ( testimonial == null ) { 83 ActionMessages errors = new ActionMessages(); 85 errors.add("testimonialNotFound", new ActionMessage("testimonials.errors.notFound")); 86 saveErrors(request, errors); 87 return mapping.findForward("listTestimonials"); 88 } 89 90 if ( !"true".equalsIgnoreCase(request.getParameter("force")) && testimonial.isInUse() ) { 91 String action = mapping.findForward("listTestimonials").getPath(); 93 String redirectUrl = WebappUtil.getActionMappingURL(action, null, request, WebappConstants.URL_TYPE_DOMAIN_RELATIVE); 94 request.getSession().setAttribute(WebappConstants.LINKED_OBJECTS_REDIRECT_URL_KEY, redirectUrl); 95 ActionMessages messages = new ActionMessages(); 96 messages.add("deleteWarning", new ActionMessage("testimonials.messages.deleteWarning")); 97 saveMessages(request, messages); 98 request.getSession().removeAttribute(WebappConstants.LINKED_OBJECTS_UPDATE_ACTION_KEY); 99 request.getSession().setAttribute(WebappConstants.LINKED_OBJECTS_DELETE_ACTION_KEY, "testimonials/deleteTestimonial"); 100 request.setAttribute(WebappConstants.LINKED_OBJECT_ID_KEY, testimonial.getId()); 101 request.setAttribute(WebappConstants.LINKED_OBJECT_TYPE_KEY, "page"); 102 return mapping.findForward("viewLinkedObjects"); 103 } 104 105 String uri = testimonial.getUri(); 106 testimonialManager.deleteTestimonial(testimonialId); 107 108 SearchManager searchManager = SearchManager.getInstance(request.getSession().getServletContext()); 110 searchManager.unIndexPage(uri, request); 111 112 CacheUtil cacheUtil = CacheUtil.getInstance(request); 113 cacheUtil.flushLocalizableFieldValueCache(testimonialId); 114 115 return mapping.findForward("listTestimonials"); 116 } 117 } | Popular Tags |