deletealertusercontroller.java

来自「Java的框架」· Java 代码 · 共 73 行

JAVA
73
字号
package mcaps.core.alert.webapp.controller;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import mcap.core.alert.model.Alert;
import mcap.core.alert.model.AlertUser;
import mcap.core.alert.service.AlertManager;
import mcap.core.alert.util.NameConstants;
import mcap.core.base.webapp.controller.BaseController;

import org.apache.commons.lang.StringUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.view.RedirectView;


/**
 * @author Tan Beng Suang
 * @date 09-Sep-2005
 * @version 1.0.1.0
 */
public class DeleteAlertUserController extends BaseController {

	private AlertManager alertManager;
	
	/**
	 * Sets the alertManager.
	 * @param alertManager The alertManager to set.
	 */
	public void setAlertManager (AlertManager alertManager) {
		this.alertManager = alertManager;
	}


//	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		String id = request.getParameter ("id");
		
		if (StringUtils.isBlank (id))
			throw new Exception ("Alert user id not specified.");
		
		AlertUser user = this.alertManager.getAlertUser(id);
		
		if (user == null)
			throw new Exception ("Alert user not found.");
		
		Alert alert = this.alertManager.getAlert(user.getAlertId());
		
		if (alert == null)
			throw new Exception ("Alert not found.");
		
		if (!request.isUserInRole(NameConstants.ALERT_ADMIN_ROLE) && 
				!alert.getCreator ().equals(request.getRemoteUser())){
			response.sendError (HttpServletResponse.SC_FORBIDDEN);
			return null;
		}
		
		this.alertManager.removeAlertUser (user.getId());
		Locale locale = request.getLocale ();
		saveMessage (request, getText("alertuserinfo.deleted", user.getUsername(),
				locale));
		
		return new ModelAndView (new RedirectView ("viewAlert.action?id=" + alert.getId()));

	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?