KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > efs > openreports > actions > admin > EditReportGroupsAction


1 /*
2  * Copyright (C) 2006 Erik Swenson - erik@oreports.com
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the Free
6  * Software Foundation; either version 2 of the License, or (at your option)
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16  * Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */

19
20 package org.efs.openreports.actions.admin;
21
22 import java.util.*;
23
24 import com.opensymphony.xwork.ActionContext;
25 import com.opensymphony.xwork.ActionSupport;
26
27 import org.apache.log4j.Logger;
28 import org.efs.openreports.ORStatics;
29 import org.efs.openreports.objects.*;
30 import org.efs.openreports.providers.*;
31
32 public class EditReportGroupsAction
33     extends ActionSupport
34     implements ReportProviderAware, GroupProviderAware, UserProviderAware
35 {
36     protected static Logger log =
37         Logger.getLogger(EditReportGroupsAction.class);
38
39     private int id;
40     private int[] groupIds = new int[0];
41
42     private String JavaDoc submitType;
43
44     private Report report;
45     
46     private List groups;
47     private List groupsForReport;
48
49     private ReportProvider reportProvider;
50     private GroupProvider groupProvider;
51     private UserProvider userProvider;
52
53     public String JavaDoc execute()
54     {
55         try
56         {
57             report = reportProvider.getReport(new Integer JavaDoc(id));
58             groupsForReport = groupProvider.getGroupsForReport(report);
59             groups = groupProvider.getReportGroups();
60
61             if (submitType == null) return INPUT;
62             
63             Iterator iterator = groups.iterator();
64             while(iterator.hasNext())
65             {
66                 ReportGroup group = (ReportGroup) iterator.next();
67
68                 boolean reportInGroup = false;
69                 
70                 for (int i = 0; i < groupIds.length; i++)
71                 {
72                     if (group.getId().equals(new Integer JavaDoc(groupIds[i])))
73                     {
74                         reportInGroup = true;
75                         
76                         if (!group.isValidReport(report))
77                         {
78                             group.getReports().add(report);
79                             groupProvider.updateReportGroup(group);
80                         }
81                     }
82                 }
83                 
84                 if (!reportInGroup)
85                 {
86                     for (int i=0; i < group.getReports().size(); i++)
87                     {
88                         Report groupReport = (Report) group.getReports().get(i);
89                         if (groupReport.getId().equals(report.getId()))
90                         {
91                             group.getReports().remove(groupReport);
92                             groupProvider.updateReportGroup(group);
93                             
94                             i=0;
95                         }
96                     }
97                 }
98             }
99             
100             //refresh current user
101
ReportUser user = (ReportUser) ActionContext.getContext().getSession().get(ORStatics.REPORT_USER);
102             if (user != null)
103             {
104                 user = userProvider.getUser(user.getId());
105                 ActionContext.getContext().getSession().put(ORStatics.REPORT_USER, user);
106             }
107
108             return SUCCESS;
109         }
110         catch (Exception JavaDoc e)
111         {
112             e.printStackTrace();
113             addActionError(e.toString());
114             return INPUT;
115         }
116     }
117
118     public int getId()
119     {
120         return id;
121     }
122
123     public void setId(int id)
124     {
125         this.id = id;
126     }
127
128     public List getGroupsForReport()
129     {
130         return groupsForReport;
131     }
132
133     public List getGroups()
134     {
135         return groups;
136     }
137
138     public void setReportProvider(ReportProvider reportProvider)
139     {
140         this.reportProvider = reportProvider;
141     }
142
143     public Report getReport()
144     {
145         return report;
146     }
147
148     public void setReport(Report report)
149     {
150         this.report = report;
151     }
152     
153     public void setGroupProvider(GroupProvider groupProvider)
154     {
155         this.groupProvider = groupProvider;
156     }
157
158     public void setUserProvider(UserProvider userProvider)
159     {
160         this.userProvider = userProvider;
161     }
162
163     public int[] getGroupIds()
164     {
165         return groupIds;
166     }
167
168     public void setGroupIds(int[] groupIds)
169     {
170         this.groupIds = groupIds;
171     }
172
173     public String JavaDoc getSubmitType()
174     {
175         return submitType;
176     }
177
178     public void setSubmitType(String JavaDoc submitType)
179     {
180         this.submitType = submitType;
181     }
182     
183 }
Popular Tags