⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 executereportaction.java

📁 The ability to create groups of reports, and grant users access to reports by group. The ability to
💻 JAVA
字号:
/*
 * Copyright (C) 2004 Erik Swenson - eswenson@opensourcesoft.net
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place - Suite 330, Boston, MA 02111-1307, USA.
 *  
 */

package org.efs.openreports.actions;

import java.util.*;

import com.opensymphony.xwork.ActionContext;
import com.opensymphony.xwork.ActionSupport;

import org.efs.openreports.ORStatics;
import org.efs.openreports.objects.*;
import org.efs.openreports.providers.*;
import org.efs.openreports.util.LocalStrings;

import net.sf.hibernate.HibernateException;

public class ExecuteReportAction extends ActionSupport
		implements
			ReportProviderAware,
			ParameterProviderAware,
			UserProviderAware
{
	private int reportId;
	private String exportType;
	private String userName;
	private String password;

	private ParameterProvider parameterProvider;
	private ReportProvider reportProvider;
	private UserProvider userProvider;

	public String execute()
	{
		try
		{
			// get user, validate, and put in session
			ReportUser user = userProvider.getUser(userName);

			if (user == null || !user.getPassword().equals(password))
			{
				addActionError(LocalStrings.getString(LocalStrings.ERROR_LOGIN_INVALID));
				return ERROR;
			}

			ActionContext.getContext().getSession().put(ORStatics.REPORT_USER, user);
						
			Report report = reportProvider.getReport(new Integer(reportId));

			if (report == null)
			{
				addActionError(LocalStrings.getString(LocalStrings.ERROR_REPORT_INVALID));
				return ERROR;
			}

			// validate user authorized to view report
			
			List groups = user.getGroups();
			boolean validReport = false;
			
			Iterator iterator = groups.iterator();
			while(iterator.hasNext())
			{
				ReportGroup reportGroup = (ReportGroup) iterator.next();
				if (reportGroup.isValidReport(report))
				{
					validReport = true;
				}				
			}
			
			if (!validReport)
			{
				addActionError(LocalStrings.getString(LocalStrings.ERROR_REPORT_NOTAUTHORIZED));
				return ERROR;
			}

			ActionContext.getContext().getSession().put(ORStatics.REPORT, report);
			
			// check for queryReport
			boolean queryReport = false;
			if (report.getQuery() != null && report.getQuery().length() > 0)
			{
				queryReport = true;
			}			

			// get exportType, validate, and put in session

			if (exportType == null || exportType.length() < 1)
			{
				if (!queryReport)
				{
					addActionError(LocalStrings.getString(LocalStrings.ERROR_EXPORTTYPE_REQUIRED));
					return ERROR;
				}
			}

			ActionContext.getContext().getSession().put(ORStatics.EXPORT_TYPE, exportType);

			// vaidate parameters, create map of parameters, and put in session			

			List reportParameters = report.getParameters();

			parameterProvider.validateParameters(reportParameters, ActionContext.getContext()
					.getParameters());

			Map map = parameterProvider.getReportParametersMap(reportParameters, ActionContext
					.getContext().getParameters());
			map.put(ORStatics.USER_ID, user.getId());
			map.put(ORStatics.EXTERNAL_ID, user.getExternalId());
			map.put(ORStatics.USER_NAME, user.getName());

			ActionContext.getContext().getSession().remove(ORStatics.REPORT_PARAMETERS);
			ActionContext.getContext().getSession().put(ORStatics.REPORT_PARAMETERS, map);
			
			if (queryReport) return ORStatics.QUERY_REPORT_ACTION;
						
			return SUCCESS;
		}
		catch (ProviderException e)
		{
			if (e.getException() instanceof HibernateException)
			{
				addActionError(LocalStrings.getString(LocalStrings.ERROR_REPORT_INVALID));
				return ERROR;
			}
			
			addActionError(e.getMessage());
			return ERROR;
		}
	}

	public int getReportId()
	{
		return reportId;
	}

	public void setReportId(int reportId)
	{
		this.reportId = reportId;
	}

	public String getExportType()
	{
		return exportType;
	}

	public void setExportType(String exportType)
	{
		this.exportType = exportType;
	}

	public String getPassword()
	{
		return password;
	}

	public void setPassword(String password)
	{
		this.password = password;
	}

	public String getUserName()
	{
		return userName;
	}

	public void setUserName(String userName)
	{
		this.userName = userName;
	}

	public void setParameterProvider(ParameterProvider parameterProvider)
	{
		this.parameterProvider = parameterProvider;
	}

	public void setReportProvider(ReportProvider reportProvider)
	{
		this.reportProvider = reportProvider;
	}

	public void setUserProvider(UserProvider userProvider)
	{
		this.userProvider = userProvider;
	}
}

⌨️ 快捷键说明

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