1 19 20 package org.efs.openreports.actions; 21 22 import java.util.Collections ; 23 import java.util.List ; 24 25 import com.opensymphony.xwork.ActionContext; 26 import com.opensymphony.xwork.ActionSupport; 27 28 import org.apache.log4j.Logger; 29 30 import org.efs.openreports.ORStatics; 31 import org.efs.openreports.objects.ReportGroup; 32 import org.efs.openreports.objects.ReportUser; 33 import org.efs.openreports.providers.GroupProvider; 34 import org.efs.openreports.providers.GroupProviderAware; 35 import org.efs.openreports.util.LocalStrings; 36 37 public class ReportListAction 38 extends ActionSupport 39 implements GroupProviderAware 40 { 41 protected static Logger log = Logger.getLogger(ReportListAction.class); 42 43 private int groupId = Integer.MIN_VALUE; 44 45 private List reports; 46 47 private GroupProvider groupProvider; 48 49 public List getReports() 50 { 51 return reports; 52 } 53 54 public String execute() 55 { 56 try 57 { 58 ReportGroup reportGroup = null; 59 60 if (groupId == Integer.MIN_VALUE) 61 { 62 reportGroup = 63 (ReportGroup) ActionContext.getContext().getSession().get( 64 ORStatics.REPORT_GROUP); 65 } 66 else 67 { 68 ReportUser reportUser = 69 (ReportUser) ActionContext.getContext().getSession().get( 70 ORStatics.REPORT_USER); 71 72 reportGroup = 73 groupProvider.getReportGroup(new Integer (groupId)); 74 75 if (reportUser.isValidGroup(reportGroup)) 76 { 77 ActionContext.getContext().getSession().put( 78 ORStatics.REPORT_GROUP, 79 reportGroup); 80 } 81 else 82 { 83 addActionError(LocalStrings.getString(LocalStrings.ERROR_REPORTGROUP_NOTAUTHORIZED)); 84 return ERROR; 85 } 86 } 87 88 if (reportGroup != null) 89 { 90 reports = reportGroup.getReportsForDisplay(); 91 Collections.sort(reports); 92 } 93 94 return SUCCESS; 95 } 96 catch (Exception e) 97 { 98 addActionError(e.toString()); 99 return ERROR; 100 } 101 } 102 103 public int getGroupId() 104 { 105 return groupId; 106 } 107 108 public void setGroupId(int groupId) 109 { 110 this.groupId = groupId; 111 } 112 113 public void setGroupProvider(GroupProvider groupProvider) 114 { 115 this.groupProvider = groupProvider; 116 } 117 } | Popular Tags |