1 19 20 package org.efs.openreports.actions.admin; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 25 import com.opensymphony.xwork.ActionContext; 26 import com.opensymphony.xwork.ActionSupport; 27 28 import org.efs.openreports.ORStatics; 29 import org.efs.openreports.objects.Report; 30 import org.efs.openreports.objects.ReportGroup; 31 import org.efs.openreports.objects.ReportUser; 32 import org.efs.openreports.providers.*; 33 34 public class EditGroupAction extends ActionSupport implements ReportProviderAware, GroupProviderAware, UserProviderAware 35 { 36 private String command; 37 private String submitType; 38 39 private int id; 40 private String name; 41 private String description; 42 43 private ReportGroup reportGroup; 44 private int[] reportIds; 45 46 private GroupProvider groupProvider; 47 private ReportProvider reportProvider; 48 private UserProvider userProvider; 49 50 public String execute() 51 { 52 try 53 { 54 if (command.equals("edit")) 55 { 56 reportGroup = groupProvider.getReportGroup(new Integer (id)); 57 } 58 else 59 { 60 reportGroup = new ReportGroup(); 61 } 62 63 if (command.equals("edit") && submitType == null) 64 { 65 name = reportGroup.getName(); 66 description = reportGroup.getDescription(); 67 reportIds = null; 68 } 69 70 if (submitType == null) 71 return INPUT; 72 73 reportGroup.setName(name); 74 reportGroup.setDescription(description); 75 reportGroup.setReports(convertIdsToReports(reportIds)); 76 77 if (command.equals("edit")) 78 { 79 groupProvider.updateReportGroup(reportGroup); 80 } 81 82 if (command.equals("add")) 83 { 84 groupProvider.insertReportGroup(reportGroup); 85 } 86 87 ReportUser user = (ReportUser) ActionContext.getContext().getSession().get(ORStatics.REPORT_USER); 89 if (user != null) 90 { 91 user = userProvider.getUser(user.getId()); 92 ActionContext.getContext().getSession().put(ORStatics.REPORT_USER, user); 93 } 94 95 return SUCCESS; 96 } 97 catch (Exception e) 98 { 99 addActionError(e.toString()); 100 return INPUT; 101 } 102 } 103 104 public String getCommand() 105 { 106 return command; 107 } 108 109 public String getDescription() 110 { 111 return description; 112 } 113 114 public String getName() 115 { 116 return name; 117 } 118 119 public String getSubmitType() 120 { 121 return submitType; 122 } 123 124 public void setCommand(String command) 125 { 126 this.command = command; 127 } 128 129 public void setDescription(String description) 130 { 131 this.description = description; 132 } 133 134 public void setName(String name) 135 { 136 this.name = name; 137 } 138 139 public void setSubmitType(String submitType) 140 { 141 this.submitType = submitType; 142 } 143 144 public List getReports() 145 { 146 try 147 { 148 return reportProvider.getReports(); 149 } 150 catch (Exception e) 151 { 152 addActionError(e.getMessage()); 153 return null; 154 } 155 } 156 157 public List getReportsInGroup() 158 { 159 return reportGroup.getReports(); 160 } 161 162 public int getId() 163 { 164 return id; 165 } 166 167 public void setId(int id) 168 { 169 this.id = id; 170 } 171 172 public int[] getReportIds() 173 { 174 return reportIds; 175 } 176 177 public void setReportIds(int[] reportIds) 178 { 179 this.reportIds = reportIds; 180 } 181 182 private List convertIdsToReports(int[] ids) 183 { 184 if (ids == null) 185 return null; 186 187 List reports = new ArrayList (); 188 189 try 190 { 191 for (int i = 0; i < ids.length; i++) 192 { 193 Report report = reportProvider.getReport(new Integer (ids[i])); 194 reports.add(report); 195 } 196 } 197 catch (Exception e) 198 { 199 addActionError(e.toString()); 200 } 201 202 return reports; 203 } 204 205 public void setGroupProvider(GroupProvider groupProvider) 206 { 207 this.groupProvider = groupProvider; 208 } 209 210 public void setReportProvider(ReportProvider reportProvider) 211 { 212 this.reportProvider = reportProvider; 213 } 214 215 public void setUserProvider(UserProvider userProvider) 216 { 217 this.userProvider = userProvider; 218 } 219 220 } | Popular Tags |