1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package net.smartlab.web.registry;
25
26 import java.util.Collection;
27 import java.util.Iterator;
28
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
31
32 import org.apache.struts.action.ActionForm;
33 import org.apache.struts.action.ActionMapping;
34 import org.apache.struts.action.DynaActionForm;
35
36 import net.smartlab.web.AbstractArchiveAction;
37 import net.smartlab.web.ActionException;
38 import net.smartlab.web.BusinessException;
39
40
41
42
43
44
45 public class EntryAction extends AbstractArchiveAction {
46
47
48
49
50 private Domain domain = Domain.getInstance();
51
52
53
54
55
56
57
58 public String search(ActionForm form, HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) throws ActionException {
59 try {
60 Collection entries = domain.listEntries(super.getSearchInfo(request));
61 request.setAttribute("entries", entries);
62 return "success";
63 } catch (BusinessException be) {
64 throw new ActionException(be.getMessage(), be.getCause());
65 }
66
67 }
68
69
70
71
72
73
74
75 public String select(ActionForm form, HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) throws ActionException {
76 try {
77 Entry entry = domain.findEntry(request.getParameter("id"));
78 request.setAttribute("entry", entry);
79 if (form != null && !super.hasErrors(request)) {
80 super.reset(form, request, mapping);
81 super.populate(form, entry, request.getLocale());
82 }
83 return "success";
84 } catch (BusinessException be) {
85 throw new ActionException(be.getMessage(), be.getCause());
86 }
87 }
88
89
90
91
92
93
94
95 public String update(ActionForm form, HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) throws ActionException {
96 try {
97 Entry entry = null;
98 if (super.isChecked("group", request)) {
99 entry = new List();
100 String[] entries = super.getSelection(form, "user-selection");
101 if (entries != null) {
102 for (int i = 0; i < entries.length; i++) {
103 ((List)entry).add(domain.findEntry(entries[i]));
104 }
105 }
106 } else {
107
108 entry = null;
109 }
110 super.valorize(form, entry, request.getLocale());
111 domain.updateEntry(entry);
112 } catch (BusinessException be) {
113 throw new ActionException(be.getMessage(), be.getCause());
114 }
115 return "success";
116 }
117
118
119
120
121
122
123
124 public String remove(ActionForm form, HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) throws ActionException {
125 try {
126 domain.removeEntry(request.getParameter("id"));
127 } catch (BusinessException be) {
128 throw new ActionException(be.getMessage(), be.getCause());
129 }
130 return "success";
131 }
132
133
134
135
136
137
138
139 public String removeAll(ActionForm form, HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) throws ActionException {
140 try {
141 String[] ids = super.getListSelection(request);
142 for (int i = 0; i < ids.length; i++) {
143 domain.removeEntry(ids[i]);
144 }
145 } catch (BusinessException be) {
146 throw new ActionException(be.getMessage(), be.getCause());
147 }
148 return "success";
149 }
150
151
152
153
154
155
156
157
158
159
160
161 public String entries(ActionForm form, HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) throws ActionException {
162 try {
163 Entry entry = domain.findEntry(request.getParameter("id"));
164 request.setAttribute("entry", entry);
165 List list = (List)entry;
166 Collection entries = list.getEntries();
167 String[] selection = new String[entries.size()];
168 Iterator selected = entries.iterator();
169 for (int i = 0; selected.hasNext(); i++) {
170 Entry member = (Entry)selected.next();
171 selection[i] = Long.toString(member.getId());
172 }
173 ((DynaActionForm)form).set("entry-selection", selection);
174 request.setAttribute("entries", domain.listEntries(super.getSearchInfo(request)));
175 return "success";
176 } catch (BusinessException be) {
177 throw new ActionException(be.getMessage(), be.getCause());
178 }
179 }
180 }