package com.javaeye.jert.action.user.report;
import com.javaeye.jert.action.user.BaseUserAction;
import com.javaeye.jert.domain.ReportDefinition;
import com.javaeye.jert.domain.query.QueryParameter;
import com.javaeye.jert.service.DatabaseService;
import com.javaeye.jert.service.ReportDefinitionService;
import com.javaeye.jert.service.SecurityService;
import com.javaeye.user.util.RemoteUser;
/**
* @author Quake Wang
* @since 2004-12-27
* @version $Revision: 1.5 $
*/
public class BaseReportAction extends BaseUserAction {
private DatabaseService databaseService;
private SecurityService securityService;
private Long reportDefinitionId;
protected ReportDefinitionService reportDefinitionService;
protected ReportDefinition reportDefinition;
protected QueryParameter[] parameters;
private String queryString;
public boolean hasPermission() {
if(reportDefinition == null) return true;
return securityService.hasReportPermission(RemoteUser.get(), reportDefinition);
}
public String getQueryString() {
if (queryString == null) {
queryString = generateQueryString();
}
return queryString;
}
private String generateQueryString() {
StringBuffer result = new StringBuffer();
result.append("reportDefinitionId=").append(reportDefinitionId);
for (int i = 0; i < parameters.length; i++) {
QueryParameter p = parameters[i];
result.append("¶meters[").append(i).append("].value=").append(p.getValue());
}
return result.toString();
}
public void setReportDefinitionId(Long reportDefinitionId) {
this.reportDefinitionId = reportDefinitionId;
this.reportDefinition = reportDefinitionService.getReportDefinition(reportDefinitionId);
this.parameters = reportDefinition.getDefaultQueryParameters();
}
public Long getReportDefinitionId() {
return reportDefinitionId;
}
public ReportDefinitionService getReportDefinitionService() {
return reportDefinitionService;
}
public void setReportDefinitionService(ReportDefinitionService reportDefinitionService) {
this.reportDefinitionService = reportDefinitionService;
}
public ReportDefinition getReportDefinition() {
return reportDefinition;
}
public void setReportDefinition(ReportDefinition reportDefinition) {
this.reportDefinition = reportDefinition;
}
public QueryParameter[] getParameters() {
return parameters;
}
public void setParameters(QueryParameter[] parameters) {
this.parameters = parameters;
}
public DatabaseService getDatabaseService() {
return databaseService;
}
public void setDatabaseService(DatabaseService databaseService) {
this.databaseService = databaseService;
}
public void setSecurityService(SecurityService securityService) {
this.securityService = securityService;
}
}