1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.imixs.workflow.jee.ejb;
29
30 import java.util.Collection;
31 import java.util.Iterator;
32 import java.util.Map;
33
34 import javax.annotation.security.DeclareRoles;
35 import javax.annotation.security.RolesAllowed;
36 import javax.ejb.EJB;
37 import javax.ejb.LocalBean;
38 import javax.ejb.Stateless;
39
40 import org.imixs.workflow.ItemCollection;
41 import org.imixs.workflow.exceptions.AccessDeniedException;
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 @DeclareRoles({ "org.imixs.ACCESSLEVEL.NOACCESS",
61 "org.imixs.ACCESSLEVEL.READERACCESS",
62 "org.imixs.ACCESSLEVEL.AUTHORACCESS",
63 "org.imixs.ACCESSLEVEL.EDITORACCESS",
64 "org.imixs.ACCESSLEVEL.MANAGERACCESS" })
65 @RolesAllowed({ "org.imixs.ACCESSLEVEL.NOACCESS",
66 "org.imixs.ACCESSLEVEL.READERACCESS",
67 "org.imixs.ACCESSLEVEL.AUTHORACCESS",
68 "org.imixs.ACCESSLEVEL.EDITORACCESS",
69 "org.imixs.ACCESSLEVEL.MANAGERACCESS" })
70 @Stateless
71 @LocalBean
72 public class ReportService {
73
74 @EJB
75 EntityService entityService;
76
77
78
79
80
81
82
83
84
85 public ItemCollection getReport(String aReportName) {
86
87 ItemCollection itemCol = findReport(aReportName);
88 return itemCol;
89 }
90
91
92
93
94
95
96
97
98
99 public Collection<ItemCollection> getReportList(int startpos, int count) {
100 String sQuery = null;
101 sQuery = "SELECT";
102 sQuery += " wi FROM Entity as wi " + "WHERE wi.type = 'ReportEntity'";
103
104 Collection<ItemCollection> col = entityService.findAllEntities(sQuery,
105 startpos, count);
106
107 return col;
108 }
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126 public void updateReport(ItemCollection aReport)
127 throws AccessDeniedException {
128
129 aReport.replaceItemValue("type", "ReportEntity");
130
131
132 String sUniqueID = aReport.getItemValueString("$uniqueID");
133
134 if ("".equals(sUniqueID)) {
135 String sReportName = aReport.getItemValueString("txtName");
136
137 ItemCollection oldReport = findReport(sReportName);
138 if (oldReport != null) {
139
140 aReport = updateReport(aReport, oldReport);
141 }
142 }
143
144 entityService.save(aReport);
145 }
146
147
148
149
150
151
152
153
154
155
156
157 public Collection<ItemCollection> processReport(String aReportName) {
158
159 ItemCollection itemCol = findReport(aReportName);
160 String sQuery = itemCol.getItemValueString("txtQuery");
161 int istartPos = itemCol.getItemValueInteger("numStartPos");
162 int imaxcount = itemCol.getItemValueInteger("numMaxCount");
163 if (imaxcount == 0)
164 imaxcount = -1;
165
166 Collection<ItemCollection> col = entityService.findAllEntities(sQuery,
167 istartPos, imaxcount);
168 return col;
169 }
170
171
172
173
174
175
176
177 private ItemCollection findReport(String aid) {
178 String sQuery = null;
179 sQuery = "SELECT";
180 sQuery += " wi FROM Entity as wi " + "JOIN wi.textItems as i "
181 + "WHERE (wi.id='" + aid + "') OR "
182 + "(i.itemName = 'txtname' " + "AND i.itemValue = '" + aid
183 + "') " + " AND wi.type = 'ReportEntity'";
184
185 Collection<ItemCollection> col = entityService.findAllEntities(sQuery,
186 0, 1);
187 if (col.size() > 0)
188 return col.iterator().next();
189 else
190 return null;
191 }
192
193
194
195
196
197
198
199
200 private ItemCollection updateReport(ItemCollection newReport,
201 ItemCollection oldReport) {
202 Iterator iter = newReport.getAllItems().entrySet().iterator();
203 while (iter.hasNext()) {
204 Map.Entry mapEntry = (Map.Entry) iter.next();
205 String sName = mapEntry.getKey().toString();
206 Object o = mapEntry.getValue();
207 if (isValidAttributeName(sName)) {
208 oldReport.replaceItemValue(sName, o);
209 }
210 }
211 return oldReport;
212 }
213
214
215
216
217
218
219
220
221 private boolean isValidAttributeName(String aName) {
222 if ("namcreator".equalsIgnoreCase(aName))
223 return false;
224 if ("$created".equalsIgnoreCase(aName))
225 return false;
226 if ("$modified".equalsIgnoreCase(aName))
227 return false;
228 if ("$uniqueID".equalsIgnoreCase(aName))
229 return false;
230 if ("$isAuthor".equalsIgnoreCase(aName))
231 return false;
232
233 return true;
234
235 }
236 }