KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cowsultants > itracker > ejb > beans > session > IssueHandlerBean


1 /*
2  * This software was designed and created by Jason Carroll.
3  * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4  * The author can be reached at jcarroll@cowsultants.com
5  * ITracker website: http://www.cowsultants.com
6  * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it only under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  */

18
19 package cowsultants.itracker.ejb.beans.session;
20
21 import java.io.*;
22 import java.util.*;
23 import java.rmi.*;
24 import java.sql.Timestamp JavaDoc;
25 import javax.ejb.*;
26 import javax.jms.*;
27 import javax.naming.*;
28 import javax.rmi.*;
29
30 import cowsultants.itracker.ejb.beans.entity.*;
31 import cowsultants.itracker.ejb.beans.message.*;
32 import cowsultants.itracker.ejb.client.exceptions.*;
33 import cowsultants.itracker.ejb.client.interfaces.*;
34 import cowsultants.itracker.ejb.client.resources.*;
35 import cowsultants.itracker.ejb.client.models.*;
36 import cowsultants.itracker.ejb.client.util.*;
37
38
39 public class IssueHandlerBean implements SessionBean {
40     protected InitialContext ic = null;
41     protected IDGeneratorHome idHome = null;
42     protected UserHandlerHome uhHome = null;
43     protected SystemConfigurationHome scHome = null;
44
45     protected ComponentLocalHome cHome = null;
46     protected CustomFieldLocalHome cfHome = null;
47     protected IssueLocalHome iHome = null;
48     protected IssueActivityLocalHome iaHome = null;
49     protected IssueAttachmentLocalHome iattHome = null;
50     protected IssueFieldLocalHome ifHome = null;
51     protected IssueHistoryLocalHome ihHome = null;
52     protected NotificationLocalHome nHome = null;
53     protected ProjectLocalHome pHome = null;
54     protected UserLocalHome uHome = null;
55     protected VersionLocalHome vHome = null;
56
57     private static String JavaDoc notificationFactoryName = NotificationMessageBean.DEFAULT_CONNECTION_FACTORY;
58     private static String JavaDoc notificationQueueName = NotificationMessageBean.DEFAULT_QUEUE_NAME;
59     private static String JavaDoc systemBaseURL = "";
60
61     public IssueModel getIssue(Integer JavaDoc issueId) {
62         try {
63             IssueLocal issue = iHome.findByPrimaryKey(issueId);
64             return issue.getModel();
65         } catch(FinderException fe) {
66         }
67         return null;
68     }
69
70     public IssueModel[] getAllIssues() {
71         int i = 0;
72         IssueModel[] issueArray = new IssueModel[0];
73
74         try {
75             Collection issues = iHome.findAll();
76             issueArray = new IssueModel[issues.size()];
77             for(Iterator iterator = issues.iterator(); iterator.hasNext(); i++) {
78                 issueArray[i] = ((IssueLocal) iterator.next()).getModel();
79             }
80         } catch(FinderException fe) {
81         }
82         return issueArray;
83     }
84
85     public int getNumberIssues() {
86         try {
87             Collection issues = iHome.findAll();
88             return issues.size();
89         } catch(FinderException fe) {
90         }
91         return 0;
92     }
93
94
95     public IssueModel[] getIssuesCreatedByUser(Integer JavaDoc userId) {
96         return getIssuesCreatedByUser(userId, true);
97     }
98
99     public IssueModel[] getIssuesCreatedByUser(Integer JavaDoc userId, boolean availableProjectsOnly) {
100         int i = 0;
101         IssueModel[] issueArray = new IssueModel[0];
102
103         try {
104             Collection issues = (availableProjectsOnly ? iHome.findByCreatorInAvailableProjects(userId, IssueUtilities.STATUS_CLOSED) :
105                                                          iHome.findByCreator(userId, IssueUtilities.STATUS_CLOSED));
106             issueArray = new IssueModel[issues.size()];
107             for(Iterator iterator = issues.iterator(); iterator.hasNext(); i++) {
108                 issueArray[i] = ((IssueLocal) iterator.next()).getModel();
109             }
110         } catch(FinderException fe) {
111         }
112         return issueArray;
113     }
114
115     public IssueModel[] getIssuesOwnedByUser(Integer JavaDoc userId) {
116         return getIssuesOwnedByUser(userId, true);
117     }
118
119     public IssueModel[] getIssuesOwnedByUser(Integer JavaDoc userId, boolean availableProjectsOnly) {
120         int i = 0;
121         IssueModel[] issueArray = new IssueModel[0];
122
123         try {
124             Collection issues = (availableProjectsOnly ? iHome.findByOwnerInAvailableProjects(userId, IssueUtilities.STATUS_RESOLVED) :
125                                                          iHome.findByOwner(userId, IssueUtilities.STATUS_RESOLVED));
126             issueArray = new IssueModel[issues.size()];
127             for(Iterator iterator = issues.iterator(); iterator.hasNext(); i++) {
128                 issueArray[i] = ((IssueLocal) iterator.next()).getModel();
129             }
130         } catch(FinderException fe) {
131         }
132         return issueArray;
133     }
134
135     public IssueModel[] getIssuesWatchedByUser(Integer JavaDoc userId) {
136         return getIssuesWatchedByUser(userId, true);
137     }
138
139     public IssueModel[] getIssuesWatchedByUser(Integer JavaDoc userId, boolean availableProjectsOnly) {
140         int i = 0;
141         IssueModel[] issueArray = new IssueModel[0];
142
143         try {
144             Collection issues = (availableProjectsOnly ? iHome.findByNotificationInAvailableProjects(userId, IssueUtilities.STATUS_CLOSED) :
145                                                          iHome.findByNotification(userId, IssueUtilities.STATUS_CLOSED));
146             issueArray = new IssueModel[issues.size()];
147             for(Iterator iterator = issues.iterator(); iterator.hasNext(); i++) {
148                 issueArray[i] = ((IssueLocal) iterator.next()).getModel();
149             }
150         } catch(FinderException fe) {
151         }
152         return issueArray;
153     }
154
155     public IssueModel[] getUnassignedIssues() {
156         return getUnassignedIssues(true);
157     }
158
159     public IssueModel[] getUnassignedIssues(boolean availableProjectsOnly) {
160         int i = 0;
161         IssueModel[] issueArray = new IssueModel[0];
162
163         try {
164 // This query doesn't work correctly in JBoss...need to examine why
165
// Collection issues = iHome.findByNullOwner(IssueUtilities.STATUS_ASSIGNED);
166
Collection issues = (availableProjectsOnly ? iHome.findByStatusLessThanEqualToInAvailableProjects(IssueUtilities.STATUS_UNASSIGNED) :
167                                                          iHome.findByStatusLessThanEqualTo(IssueUtilities.STATUS_UNASSIGNED));
168             issueArray = new IssueModel[issues.size()];
169             for(Iterator iterator = issues.iterator(); iterator.hasNext(); i++) {
170                 issueArray[i] = ((IssueLocal) iterator.next()).getModel();
171             }
172         } catch(FinderException fe) {
173         }
174         return issueArray;
175     }
176
177     /**
178       * Returns all issues with a status equal to the given status number
179       * @param status the status to compare
180       * @return an array of IssueModels that match the criteria
181       */

182     public IssueModel[] getIssuesWithStatus(int status) {
183         int i = 0;
184         IssueModel[] issueArray = new IssueModel[0];
185
186         try {
187             Collection issues = iHome.findByStatus(status);
188             issueArray = new IssueModel[issues.size()];
189             for(Iterator iterator = issues.iterator(); iterator.hasNext(); i++) {
190                 issueArray[i] = ((IssueLocal) iterator.next()).getModel();
191             }
192         } catch(FinderException fe) {
193         }
194         return issueArray;
195     }
196
197     /**
198       * Returns all issues with a status less than the given status number
199       * @param status the status to compare
200       * @return an array of IssueModels that match the criteria
201       */

202     public IssueModel[] getIssuesWithStatusLessThan(int status) {
203         int i = 0;
204         IssueModel[] issueArray = new IssueModel[0];
205
206         try {
207             Collection issues = iHome.findByStatusLessThan(status);
208             issueArray = new IssueModel[issues.size()];
209             for(Iterator iterator = issues.iterator(); iterator.hasNext(); i++) {
210                 issueArray[i] = ((IssueLocal) iterator.next()).getModel();
211             }
212         } catch(FinderException fe) {
213         }
214         return issueArray;
215     }
216
217     /**
218       * Returns all issues with a severity equal to the given severity number
219       * @param severity the severity to compare
220       * @return an array of IssueModels that match the criteria
221       */

222     public IssueModel[] getIssuesWithSeverity(int severity) {
223         int i = 0;
224         IssueModel[] issueArray = new IssueModel[0];
225
226         try {
227             Collection issues = iHome.findBySeverity(severity);
228             issueArray = new IssueModel[issues.size()];
229             for(Iterator iterator = issues.iterator(); iterator.hasNext(); i++) {
230                 issueArray[i] = ((IssueLocal) iterator.next()).getModel();
231             }
232         } catch(FinderException fe) {
233         }
234         return issueArray;
235     }
236
237     public IssueModel[] getIssuesByProjectId(Integer JavaDoc projectId) {
238         return getIssuesByProjectId(projectId, IssueUtilities.STATUS_END);
239     }
240
241     public IssueModel[] getIssuesByProjectId(Integer JavaDoc projectId, int status) {
242         int i = 0;
243         IssueModel[] issueArray = new IssueModel[0];
244
245         try {
246             Collection issues = iHome.findByProjectIdAndLowerStatus(projectId, status);
247             issueArray = new IssueModel[issues.size()];
248             for(Iterator iterator = issues.iterator(); iterator.hasNext(); i++) {
249                 issueArray[i] = ((IssueLocal) iterator.next()).getModel();
250             }
251         } catch(FinderException fe) {
252         }
253         return issueArray;
254     }
255
256     public UserModel getIssueCreator(Integer JavaDoc issueId) {
257         try {
258             IssueLocal issue = iHome.findByPrimaryKey(issueId);
259             UserLocal user = issue.getCreator();
260             return (user != null ? user.getModel() : null);
261         } catch(FinderException fe) {
262         }
263         return null;
264     }
265
266     public UserModel getIssueOwner(Integer JavaDoc issueId) {
267         try {
268             IssueLocal issue = iHome.findByPrimaryKey(issueId);
269             UserLocal user = issue.getOwner();
270             return (user != null ? user.getModel() : null);
271         } catch(FinderException fe) {
272         }
273         return null;
274     }
275
276     public ComponentModel[] getIssueComponents(Integer JavaDoc issueId) {
277         int i = 0;
278         ComponentModel[] componentArray = new ComponentModel[0];
279
280         try {
281             IssueLocal issue = iHome.findByPrimaryKey(issueId);
282             Collection components = issue.getComponents();
283             componentArray = new ComponentModel[components.size()];
284             for(Iterator iterator = components.iterator(); iterator.hasNext(); i++) {
285                 componentArray[i] = ((ComponentLocal) iterator.next()).getModel();
286             }
287         } catch(FinderException fe) {
288         }
289         return componentArray;
290     }
291
292     public VersionModel[] getIssueVersions(Integer JavaDoc issueId) {
293         int i = 0;
294         VersionModel[] versionArray = new VersionModel[0];
295
296         try {
297             IssueLocal issue = iHome.findByPrimaryKey(issueId);
298             Collection versions = issue.getVersions();
299             versionArray = new VersionModel[versions.size()];
300             for(Iterator iterator = versions.iterator(); iterator.hasNext(); i++) {
301                 versionArray[i] = ((VersionLocal) iterator.next()).getModel();
302             }
303         } catch(FinderException fe) {
304         }
305         return versionArray;
306     }
307
308     public IssueAttachmentModel[] getIssueAttachments(Integer JavaDoc issueId) {
309         int i = 0;
310         IssueAttachmentModel[] attachmentsArray = new IssueAttachmentModel[0];
311
312         try {
313             IssueLocal issue = iHome.findByPrimaryKey(issueId);
314             Collection attachments = issue.getAttachments();
315             attachmentsArray = new IssueAttachmentModel[attachments.size()];
316             for(Iterator iterator = attachments.iterator(); iterator.hasNext(); i++) {
317                 attachmentsArray[i] = ((IssueAttachmentLocal) iterator.next()).getModel();
318             }
319         } catch(FinderException fe) {
320         }
321         return attachmentsArray;
322     }
323
324     public IssueHistoryModel[] getIssueHistory(Integer JavaDoc issueId) {
325         int i = 0;
326         IssueHistoryModel[] historyArray = new IssueHistoryModel[0];
327         Vector results = new Vector();
328
329         try {
330             Collection history = ihHome.findByIssueId(issueId);
331             historyArray = new IssueHistoryModel[history.size()];
332             for(Iterator iterator = history.iterator(); iterator.hasNext(); i++) {
333                 IssueHistoryLocal entry = (IssueHistoryLocal) iterator.next();
334                 if(entry.getStatus() == IssueUtilities.HISTORY_STATUS_AVAILABLE) {
335                     results.addElement(entry.getModel());
336                 }
337             }
338             historyArray = new IssueHistoryModel[results.size()];
339             results.copyInto(historyArray);
340         } catch(FinderException fe) {
341         }
342         return historyArray;
343     }
344
345     public IssueModel createIssue(IssueModel model, Integer JavaDoc projectId, Integer JavaDoc userId, Integer JavaDoc createdById) {
346         try {
347             IDGenerator idGen = idHome.create();
348             ProjectLocal project = pHome.findByPrimaryKey(projectId);
349             UserLocal creator = uHome.findByPrimaryKey(userId);
350
351             if(project.getStatus() != ProjectUtilities.STATUS_ACTIVE) {
352                 throw new IssueException("Project is not active.");
353             }
354             IssueLocal issue = iHome.create(idGen.getId(IssueLocal.ID_NAME));
355             if(issue != null) {
356                 if(createdById == null || createdById.equals(userId)) {
357                     IssueActivityModel activity = new IssueActivityModel(IssueUtilities.ACTIVITY_ISSUE_CREATED,
358                         "", issue.getId(), userId);
359                     addIssueActivity(activity, issue, creator);
360                 } else {
361                     UserLocal createdBy = uHome.findByPrimaryKey(createdById);
362                     IssueActivityModel activity = new IssueActivityModel(IssueUtilities.ACTIVITY_ISSUE_CREATED,
363                         ITrackerResources.getString("itracker.activity.system.createdfor") + " " +
364                         creator.getFirstName() + " " + creator.getLastName(), issue.getId(), createdById);
365                     addIssueActivity(activity, issue, createdBy);
366                 }
367
368                 issue.setModel(model);
369                 issue.setProject(project);
370                 issue.setCreator(creator);
371                 return issue.getModel();
372             }
373         } catch(CreateException ce) {
374             Logger.logError("Error while creating new issue.", ce);
375         } catch(FinderException fe) {
376             Logger.logError("Error while creating new issue.", fe);
377         } catch(IssueException ie) {
378             Logger.logInfo("Error while creating new issue: " + ie.getMessage());
379         }
380         return null;
381     }
382
383     public IssueModel updateIssue(IssueModel model, Integer JavaDoc userId) {
384         try {
385             String JavaDoc existingTargetVersion = null;
386             IssueLocal issue = iHome.findByPrimaryKey(model.getId());
387             UserLocal user = uHome.findByPrimaryKey(userId);
388
389             if(issue.getProject().getStatus() != ProjectUtilities.STATUS_ACTIVE) {
390                 throw new IssueException("Project is not active.");
391             }
392
393             if(issue.getDescription() != null && model.getDescription() != null && ! issue.getDescription().equalsIgnoreCase(model.getDescription())) {
394                 IssueActivityModel activity = new IssueActivityModel(IssueUtilities.ACTIVITY_DESCRIPTION_CHANGE,
395                     ITrackerResources.getString("itracker.web.generic.from") + ": " + issue.getDescription(), model.getId(), userId);
396                 addIssueActivity(activity, issue, user);
397             }
398
399             if(issue.getResolution() != null && model.getResolution() != null && ! issue.getResolution().equalsIgnoreCase(model.getResolution())) {
400                 IssueActivityModel activity = new IssueActivityModel(IssueUtilities.ACTIVITY_RESOLUTION_CHANGE,
401                     ITrackerResources.getString("itracker.web.generic.from") + ": " + issue.getResolution(), model.getId(), userId);
402                 addIssueActivity(activity, issue, user);
403             }
404
405             if(issue.getStatus() != model.getStatus() && model.getStatus() != -1) {
406                 IssueActivityModel activity = new IssueActivityModel(IssueUtilities.ACTIVITY_STATUS_CHANGE,
407                     IssueUtilities.getStatusName(issue.getStatus()) + " " + ITrackerResources.getString("itracker.web.generic.to") + " " +
408                     IssueUtilities.getStatusName(model.getStatus()), model.getId(), userId);
409                 addIssueActivity(activity, issue, user);
410             }
411
412             if(issue.getSeverity() != model.getSeverity() && model.getSeverity() != -1) {
413                 IssueActivityModel activity = new IssueActivityModel(IssueUtilities.ACTIVITY_SEVERITY_CHANGE,
414                     IssueUtilities.getSeverityName(issue.getSeverity()) + " " + ITrackerResources.getString("itracker.web.generic.to") + " " +
415                     IssueUtilities.getSeverityName(model.getSeverity()), model.getId(), userId);
416                 addIssueActivity(activity, issue, user);
417             }
418
419             if(issue.getTargetVersion() != null && model.getTargetVersion() != null && ! issue.getTargetVersion().getId().equals(model.getTargetVersionId())) {
420                 existingTargetVersion = issue.getTargetVersion().getNumber();
421             }
422
423             issue.setModel(model);
424             if(model.getTargetVersionId() != null) {
425                 try {
426                     VersionLocal version = vHome.findByPrimaryKey(model.getTargetVersionId());
427                     issue.setTargetVersion(version);
428
429                     IssueActivityModel activity = new IssueActivityModel(IssueUtilities.ACTIVITY_TARGETVERSION_CHANGE,
430                         existingTargetVersion + " " + ITrackerResources.getString("itracker.web.generic.to") + " " + version.getNumber(),
431                         model.getId(), userId);
432                     addIssueActivity(activity, issue, user);
433                 } catch(FinderException fe2) {
434                     issue.setTargetVersion(null);
435                 }
436             } else {
437                 issue.setTargetVersion(null);
438             }
439             return issue.getModel();
440         } catch(FinderException fe) {
441         } catch(IssueException ie) {
442             Logger.logInfo("Error while updating new issue: " + ie.getMessage());
443         }
444         return null;
445     }
446
447     /**
448       * Moves an issues from its current project to a new project.
449       * @param issue an IssueModel of the issue to move
450       * @param projectId the id of the target project
451       * @param userId the id of the user that is moving the issue
452       * @return an IssueModel of the issue after it has been moved
453       */

454     public IssueModel moveIssue(IssueModel model, Integer JavaDoc projectId, Integer JavaDoc userId) {
455         if(model == null) {
456             return null;
457         }
458
459         try {
460             IssueLocal issue = iHome.findByPrimaryKey(model.getId());
461             ProjectLocal project = pHome.findByPrimaryKey(projectId);
462             UserLocal user = uHome.findByPrimaryKey(userId);
463
464             IssueActivityModel activity = new IssueActivityModel(IssueUtilities.ACTIVITY_ISSUE_MOVE, model.getProjectName() + " " + ITrackerResources.getString("itracker.web.generic.to") + " " + project.getName(), issue.getId(), userId);
465             addIssueActivity(activity, issue, user);
466
467             issue.setProject(project);
468
469             // The versions and components are per project so we need to delete these
470
setIssueComponents(issue.getId(), new HashSet(), userId);
471             setIssueVersions(issue.getId(), new HashSet(), userId);
472
473             return issue.getModel();
474         } catch(FinderException fe) {
475         }
476         return null;
477     }
478
479     public boolean deleteIssue(IssueModel model) {
480         if(model != null) {
481             try {
482                 IssueLocal issue = iHome.findByPrimaryKey(model.getId());
483                 issue.remove();
484                 return true;
485             } catch(FinderException fe) {
486                 Logger.logError("Error while removing issue " + model.getId() + ".", fe);
487             } catch(RemoveException re) {
488                 Logger.logError("Error while removing issue " + model.getId() + ".", re);
489             }
490         }
491         return false;
492     }
493
494     public boolean addIssueHistory(IssueHistoryModel model) {
495         try {
496             IDGenerator idGen = idHome.create();
497             IssueLocal issue = iHome.findByPrimaryKey(model.getIssueId());
498             UserLocal user = uHome.findByPrimaryKey(model.getUserId());
499
500             IssueHistoryLocal history = ihHome.create(idGen.getId(IssueHistoryLocal.ID_NAME));
501             history.setModel(model);
502             history.setIssue(issue);
503             history.setUser(user);
504             return true;
505         } catch(CreateException ce) {
506         } catch(FinderException fe) {
507         }
508         return false;
509     }
510
511     public boolean setIssueFields(Integer JavaDoc issueId, IssueFieldModel[] fields) {
512         try {
513             IssueLocal issue = iHome.findByPrimaryKey(issueId);
514
515             Collection issueFields = issue.getFields();
516             for(Iterator iter = issueFields.iterator(); iter.hasNext(); ) {
517                 try {
518                     IssueFieldLocal field = (IssueFieldLocal) iter.next();
519                     iter.remove();
520                     field.remove();
521                 } catch(RemoveException re) {
522                     Logger.logInfo("Unable to remove issue field value. Manual database cleanup may be necessary.");
523                 }
524             }
525             if(fields.length > 0) {
526                 IDGenerator idGen = idHome.create();
527                 for(int i = 0; i < fields.length; i++) {
528                     IssueFieldLocal field = ifHome.create(idGen.getId(IssueFieldLocal.ID_NAME));
529                     CustomFieldLocal customField = cfHome.findByPrimaryKey(fields[i].getCustomFieldId());
530                     field.setModel(fields[i]);
531                     field.setCustomField(customField);
532                     field.setIssue(issue);
533                     issueFields.add(field);
534                 }
535             }
536             return true;
537         } catch(CreateException ce) {
538         } catch(FinderException fe) {
539         }
540
541         return false;
542     }
543
544     public boolean setIssueComponents(Integer JavaDoc issueId, HashSet componentIds, Integer JavaDoc userId) {
545         boolean wasChanged = false;
546         StringBuffer JavaDoc changesBuf = new StringBuffer JavaDoc();
547
548         try {
549             IssueLocal issue = iHome.findByPrimaryKey(issueId);
550
551             Collection components = issue.getComponents();
552
553             if(componentIds.isEmpty() && components != null && ! components.isEmpty()) {
554                 wasChanged = true;
555                 changesBuf.append(ITrackerResources.getString("itracker.web.generic.all") + " " + ITrackerResources.getString("itracker.web.generic.removed"));
556                 components.clear();
557             } else {
558                 for(Iterator iterator = components.iterator(); iterator.hasNext(); ) {
559                     ComponentLocal component = (ComponentLocal) iterator.next();
560                     if(componentIds.contains(component.getId())) {
561                         componentIds.remove(component.getId());
562                     } else {
563                         wasChanged = true;
564                         changesBuf.append(ITrackerResources.getString("itracker.web.generic.removed") + ": " + component.getName() + "; ");
565                         iterator.remove();
566                     }
567                 }
568                 for(Iterator iterator = componentIds.iterator(); iterator.hasNext(); ) {
569                     Integer JavaDoc componentId = (Integer JavaDoc) iterator.next();
570                     try {
571                         ComponentLocal component = cHome.findByPrimaryKey(componentId);
572                         wasChanged = true;
573                         changesBuf.append(ITrackerResources.getString("itracker.web.generic.added") + ": " + component.getName() + "; ");
574
575                         components.add(component);
576                     } catch(FinderException afe) {
577                     }
578                 }
579             }
580             if(wasChanged) {
581                 IssueActivityModel activity = new IssueActivityModel(IssueUtilities.ACTIVITY_COMPONENTS_MODIFIED,
582                     changesBuf.toString(), issue.getId(), userId);
583                 addIssueActivity(activity);
584             }
585
586             return true;
587         } catch(FinderException fe) {
588         }
589         return false;
590     }
591
592     public boolean setIssueVersions(Integer JavaDoc issueId, HashSet versionIds, Integer JavaDoc userId) {
593         boolean wasChanged = false;
594         StringBuffer JavaDoc changesBuf = new StringBuffer JavaDoc();
595
596         try {
597             IssueLocal issue = iHome.findByPrimaryKey(issueId);
598
599             Collection versions = issue.getVersions();
600
601             if(versionIds.isEmpty() && versions != null && ! versions.isEmpty()) {
602                 wasChanged = true;
603                 changesBuf.append(ITrackerResources.getString("itracker.web.generic.all") + " " + ITrackerResources.getString("itracker.web.generic.removed"));
604                 versions.clear();
605             } else {
606                 for(Iterator iterator = versions.iterator(); iterator.hasNext(); ) {
607                     VersionLocal version = (VersionLocal) iterator.next();
608                     if(versionIds.contains(version.getId())) {
609                         versionIds.remove(version.getId());
610                     } else {
611                         wasChanged = true;
612                         changesBuf.append(ITrackerResources.getString("itracker.web.generic.removed") + ": " + version.getNumber() + "; ");
613                         iterator.remove();
614                     }
615                 }
616                 for(Iterator iterator = versionIds.iterator(); iterator.hasNext(); ) {
617                     Integer JavaDoc versionId = (Integer JavaDoc) iterator.next();
618                     try {
619                         VersionLocal version = vHome.findByPrimaryKey(versionId);
620                         wasChanged = true;
621                         changesBuf.append(ITrackerResources.getString("itracker.web.generic.added") + ": " + version.getNumber() + "; ");
622
623                         versions.add(version);
624                     } catch(FinderException afe) {
625                     }
626                 }
627             }
628             if(wasChanged) {
629                 IssueActivityModel activity = new IssueActivityModel(IssueUtilities.ACTIVITY_VERSIONS_MODIFIED,
630                     changesBuf.toString(), issue.getId(), userId);
631                 addIssueActivity(activity);
632             }
633             return true;
634         } catch(FinderException fe) {
635         }
636         return false;
637     }
638
639     public boolean assignIssue(Integer JavaDoc issueId, Integer JavaDoc userId) {
640         return assignIssue(issueId, userId, userId);
641     }
642
643     public boolean assignIssue(Integer JavaDoc issueId, Integer JavaDoc userId, Integer JavaDoc assignedByUserId) {
644         if(userId.intValue() == -1) {
645             return unassignIssue(issueId, assignedByUserId);
646         }
647
648         try {
649             UserLocal assignedByUser;
650             IssueLocal issue = iHome.findByPrimaryKey(issueId);
651             UserLocal user = uHome.findByPrimaryKey(userId);
652
653             if(assignedByUserId.equals(userId)) {
654                 assignedByUser = user;
655             } else {
656                 assignedByUser = uHome.findByPrimaryKey(assignedByUserId);
657             }
658
659             UserLocal currOwner = issue.getOwner();
660
661             if(currOwner == null || ! currOwner.getId().equals(user.getId())) {
662                 if(currOwner != null && ! hasIssueNotification(issueId, currOwner.getId(), NotificationUtilities.ROLE_CONTRIBUTER)) {
663                     try {
664                         IDGenerator idGen = idHome.create();
665                         NotificationLocal notification = nHome.create(idGen.getId(NotificationLocal.ID_NAME));
666                         NotificationModel model = new NotificationModel(NotificationUtilities.ROLE_CONTRIBUTER);
667                         notification.setModel(model);
668                         notification.setIssue(issue);
669                         notification.setUser(currOwner);
670                     } catch(CreateException ce) {
671                     }
672                 }
673
674                 IssueActivityModel activity = new IssueActivityModel(IssueUtilities.ACTIVITY_OWNER_CHANGE,
675                     (currOwner == null ? "[" + ITrackerResources.getString("itracker.web.generic.unassigned") + "]" : currOwner.getLogin())
676                     + " " + ITrackerResources.getString("itracker.web.generic.to") + " " + user.getLogin(), issueId, assignedByUserId);
677                 addIssueActivity(activity, issue, assignedByUser);
678
679                 issue.setOwner(user);
680                 if(issue.getStatus() < IssueUtilities.STATUS_ASSIGNED) {
681                     issue.setStatus(IssueUtilities.STATUS_ASSIGNED);
682                 }
683             }
684             return true;
685         } catch(FinderException fe) {
686         }
687         return false;
688     }
689
690     public boolean unassignIssue(Integer JavaDoc issueId, Integer JavaDoc assignedByUserId) {
691         try {
692             UserLocal assignedByUser = uHome.findByPrimaryKey(assignedByUserId);
693             IssueLocal issue = iHome.findByPrimaryKey(issueId);
694
695             if(issue.getOwner() != null) {
696                 if(! hasIssueNotification(issueId, issue.getOwner().getId(), NotificationUtilities.ROLE_CONTRIBUTER)) {
697                     try {
698                         IDGenerator idGen = idHome.create();
699                         NotificationLocal notification = nHome.create(idGen.getId(NotificationLocal.ID_NAME));
700                         NotificationModel model = new NotificationModel(NotificationUtilities.ROLE_CONTRIBUTER);
701                         notification.setModel(model);
702                         notification.setIssue(issue);
703                         notification.setUser(issue.getOwner());
704                     } catch(CreateException ce) {
705                     }
706                 }
707
708                 IssueActivityModel activity = new IssueActivityModel(IssueUtilities.ACTIVITY_OWNER_CHANGE,
709                     (issue.getOwner() == null ? "[" + ITrackerResources.getString("itracker.web.generic.unassigned") + "]" : issue.getOwner().getLogin())
710                     + " " + ITrackerResources.getString("itracker.web.generic.to") + " [" + ITrackerResources.getString("itracker.web.generic.unassigned") + "]", issueId, assignedByUserId);
711                 addIssueActivity(activity, issue, assignedByUser);
712
713                 issue.setOwner(null);
714                 if(issue.getStatus() >= IssueUtilities.STATUS_ASSIGNED) {
715                     issue.setStatus(IssueUtilities.STATUS_UNASSIGNED);
716                 }
717             }
718             return true;
719         } catch(FinderException fe) {
720         }
721         return false;
722     }
723
724     public boolean addIssueActivity(IssueActivityModel model) {
725         try {
726             IssueLocal issue = iHome.findByPrimaryKey(model.getIssueId());
727             UserLocal user = uHome.findByPrimaryKey(model.getUserId());
728             return addIssueActivity(model, issue, user);
729         } catch(FinderException fe) {
730         }
731         return false;
732     }
733
734     public boolean addIssueActivity(IssueActivityModel model, IssueLocal issue) {
735         try {
736             UserLocal user = uHome.findByPrimaryKey(model.getUserId());
737             return addIssueActivity(model, issue, user);
738         } catch(FinderException fe) {
739         }
740         return false;
741     }
742
743     public boolean addIssueActivity(IssueActivityModel model, IssueLocal issue, UserLocal user) {
744         try {
745             IDGenerator idGen = idHome.create();
746             IssueActivityLocal activity = iaHome.create(idGen.getId(IssueActivityLocal.ID_NAME));
747             activity.setModel(model);
748             activity.setIssue(issue);
749             activity.setUser(user);
750             return true;
751         } catch(CreateException ce) {
752         }
753         return false;
754     }
755
756     public void updateIssueActivityNotification(Integer JavaDoc issueId, boolean notificationSent) {
757         if(issueId == null) {
758             return;
759         }
760
761         try {
762             Collection activity = iaHome.findByIssueId(issueId);
763             for(Iterator iter = activity.iterator(); iter.hasNext(); ) {
764                 ((IssueActivityLocal) iter.next()).setNotificationSent((notificationSent ? 1 : 0));
765             }
766         } catch(FinderException fe) {
767         }
768     }
769
770     public boolean addIssueAttachment(IssueAttachmentModel model, byte[] data) {
771         try {
772             IssueLocal issue = iHome.findByPrimaryKey(model.getIssueId());
773             UserLocal user = uHome.findByPrimaryKey(model.getUserId());
774
775             IDGenerator idGen = idHome.create();
776             IssueAttachmentLocal attachment = iattHome.create(idGen.getId(IssueAttachmentLocal.ID_NAME));
777             model.setFileName("attachment" + attachment.getId());
778             attachment.setModel(model);
779             attachment.setFileData((data == null ? new byte[0] : data));
780             attachment.setIssue(issue);
781             attachment.setUser(user);
782             return true;
783         } catch(CreateException ce) {
784         } catch(FinderException fe) {
785         }
786         return false;
787     }
788
789     public boolean setIssueAttachmentData(Integer JavaDoc attachmentId, byte[] data) {
790         if(attachmentId != null && data != null) {
791             try {
792                 IssueAttachmentLocal attachment = iattHome.findByPrimaryKey(attachmentId);
793                 attachment.setFileData(data);
794                 return true;
795             } catch(FinderException fe) {
796             }
797         }
798         return false;
799     }
800
801     public boolean setIssueAttachmentData(String JavaDoc fileName, byte[] data) {
802         if(fileName != null && data != null) {
803             try {
804                 IssueAttachmentLocal attachment = iattHome.findByFileName(fileName);
805                 attachment.setFileData(data);
806                 return true;
807             } catch(FinderException fe) {
808             }
809         }
810         return false;
811     }
812
813     public boolean removeIssueAttachment(Integer JavaDoc attachmentId) {
814         try {
815             iattHome.remove(attachmentId);
816             return true;
817         } catch(RemoveException re) {
818         }
819         return false;
820     }
821
822     public Integer JavaDoc removeIssueHistoryEntry(Integer JavaDoc entryId, Integer JavaDoc userId) {
823         try {
824             IssueHistoryLocal history = ihHome.findByPrimaryKey(entryId);
825             if(history != null) {
826                 history.setStatus(IssueUtilities.HISTORY_STATUS_REMOVED);
827                 history.setLastModifiedDate(new Timestamp JavaDoc(new Date().getTime()));
828
829                 IssueActivityModel activity = new IssueActivityModel(IssueUtilities.ACTIVITY_REMOVE_HISTORY,
830                     ITrackerResources.getString("itracker.web.generic.entry") + " " + entryId + " " + ITrackerResources.getString("itracker.web.generic.removed") + ".", history.getIssue().getId(), userId);
831                 addIssueActivity(activity);
832                 return history.getIssue().getId();
833             }
834         } catch(FinderException fe) {
835         }
836         return new Integer JavaDoc(-1);
837     }
838
839     public ProjectModel getIssueProject(Integer JavaDoc issueId) {
840         try {
841             IssueLocal issue = iHome.findByPrimaryKey(issueId);
842             ProjectLocal project = issue.getProject();
843             return (project != null ? project.getModel() : null);
844         } catch(FinderException fe) {
845         }
846         return null;
847     }
848
849
850     public HashSet getIssueComponentIds(Integer JavaDoc issueId) {
851         HashSet componentIds = new HashSet();
852
853         try {
854             IssueLocal issue = iHome.findByPrimaryKey(issueId);
855             Collection components = issue.getComponents();
856             for(Iterator iterator = components.iterator(); iterator.hasNext(); ) {
857                 componentIds.add(((ComponentLocal) iterator.next()).getId());
858             }
859         } catch(FinderException fe) {
860         }
861         return componentIds;
862     }
863
864     public HashSet getIssueVersionIds(Integer JavaDoc issueId) {
865         HashSet versionIds = new HashSet();
866
867         try {
868             IssueLocal issue = iHome.findByPrimaryKey(issueId);
869             Collection versions = issue.getVersions();
870             for(Iterator iterator = versions.iterator(); iterator.hasNext(); ) {
871                 versionIds.add(((VersionLocal) iterator.next()).getId());
872             }
873         } catch(FinderException fe) {
874         }
875         return versionIds;
876     }
877
878     public IssueActivityModel[] getIssueActivity(Integer JavaDoc issueId) {
879         int i = 0;
880         IssueActivityModel[] activityArray = new IssueActivityModel[0];
881
882         try {
883             Collection activity = iaHome.findByIssueId(issueId);
884             activityArray = new IssueActivityModel[activity.size()];
885             for(Iterator iterator = activity.iterator(); iterator.hasNext(); i++) {
886                 activityArray[i] = ((IssueActivityLocal) iterator.next()).getModel();
887             }
888         } catch(FinderException fe) {
889         }
890         return activityArray;
891     }
892
893     public IssueActivityModel[] getIssueActivity(Integer JavaDoc issueId, boolean notificationSent) {
894         int i = 0;
895         IssueActivityModel[] activityArray = new IssueActivityModel[0];
896
897         try {
898             Collection activity = iaHome.findByIssueIdAndNotification(issueId, (notificationSent ? 1 : 0));
899             activityArray = new IssueActivityModel[activity.size()];
900             for(Iterator iterator = activity.iterator(); iterator.hasNext(); i++) {
901                 activityArray[i] = ((IssueActivityLocal) iterator.next()).getModel();
902             }
903         } catch(FinderException fe) {
904         }
905         return activityArray;
906     }
907
908     public IssueAttachmentModel[] getAllIssueAttachments() {
909         int i = 0;
910         IssueAttachmentModel[] attachmentArray = new IssueAttachmentModel[0];
911
912         try {
913             Collection attachments = iattHome.findAll();
914             attachmentArray = new IssueAttachmentModel[attachments.size()];
915             for(Iterator iterator = attachments.iterator(); iterator.hasNext(); i++) {
916                 attachmentArray[i] = ((IssueAttachmentLocal) iterator.next()).getModel();
917             }
918         } catch(FinderException fe) {
919         }
920         return attachmentArray;
921     }
922
923     public long[] getAllIssueAttachmentsSizeAndCount() {
924         long[] sizeAndCount = new long[2];
925
926         int i = 0;
927         try {
928             Collection attachments = iattHome.findAll();
929             sizeAndCount[1] = attachments.size();
930             for(Iterator iterator = attachments.iterator(); iterator.hasNext(); i++) {
931                 sizeAndCount[0] += ((IssueAttachmentLocal) iterator.next()).getSize();
932             }
933         } catch(FinderException fe) {
934         }
935         return sizeAndCount;
936     }
937
938     public IssueAttachmentModel getIssueAttachment(Integer JavaDoc attachmentId) {
939         IssueAttachmentModel attachmentModel = null;
940
941         try {
942             IssueAttachmentLocal attachment = iattHome.findByPrimaryKey(attachmentId);
943             attachmentModel = attachment.getModel();
944         } catch(FinderException fe) {
945         }
946         return attachmentModel;
947     }
948
949     public byte[] getIssueAttachmentData(Integer JavaDoc attachmentId) {
950         byte[] data = new byte[0];
951
952         try {
953             IssueAttachmentLocal attachment = iattHome.findByPrimaryKey(attachmentId);
954             data = attachment.getFileData();
955         } catch(FinderException fe) {
956         }
957         return data;
958     }
959
960     public int getIssueAttachmentCount(Integer JavaDoc issueId) {
961         int i = 0;
962         try {
963             IssueLocal issue = iHome.findByPrimaryKey(issueId);
964             Collection attachments = issue.getAttachments();
965             i = attachments.size();
966         } catch(FinderException fe) {
967         }
968         return i;
969     }
970
971     /**
972       * Returns the latest issue history entry for a particular issue.
973       * @param issueId the id of the issue to return the history entry for.
974       * @return the latest IssueHistoryModel, or null if no entries could be found
975       */

976     public IssueHistoryModel getLastIssueHistory(Integer JavaDoc issueId) {
977         IssueHistoryModel model = null;
978
979         try {
980             IssueHistoryLocal lastEntry = null;
981             Collection history = ihHome.findByIssueId(issueId);
982             Iterator iterator = history.iterator();
983             while(iterator.hasNext()) {
984                 IssueHistoryLocal nextEntry = (IssueHistoryLocal) iterator.next();
985                 if(nextEntry != null) {
986                     if(lastEntry == null && nextEntry.getLastModifiedDate() != null) {
987                         lastEntry = nextEntry;
988                     } else if(nextEntry.getLastModifiedDate() != null &&
989                               nextEntry.getLastModifiedDate().equals(lastEntry.getLastModifiedDate()) &&
990                               nextEntry.getId().compareTo(lastEntry.getId()) > 0) {
991                         lastEntry = nextEntry;
992                     } else if(nextEntry.getLastModifiedDate() != null &&
993                               nextEntry.getLastModifiedDate().after(lastEntry.getLastModifiedDate())) {
994                         lastEntry = nextEntry;
995                     }
996                 }
997             }
998             if(lastEntry != null) {
999                 model = lastEntry.getModel();
1000            }
1001        } catch(FinderException fe) {
1002        }
1003
1004        return model;
1005    }
1006
1007    /**
1008      * Retrieves the primary issue notifications. Primary notifications
1009      * are defined as the issue owner (or creator if not assigned), and any project owners.
1010      * This should encompass the list of people that should be notified so that action
1011      * can be taken on an issue that needs immediate attention.
1012      * @param issueId the id of the issue to find notifications for
1013      * @returns an array of NotificationModels
1014      */

1015    public NotificationModel[] getPrimaryIssueNotifications(Integer JavaDoc issueId) {
1016        return getIssueNotifications(issueId, true, false);
1017    }
1018
1019    /**
1020      * Retrieves all notifications for an issue where the notification's user is also active.
1021      * @param issueId the id of the issue to find notifications for
1022      * @returns an array of NotificationModels
1023      */

1024    public NotificationModel[] getIssueNotifications(Integer JavaDoc issueId) {
1025        return getIssueNotifications(issueId, false, true);
1026    }
1027
1028    /**
1029      * Retrieves an array of issue notifications. The notifications by default
1030      * is the creator and owner of the issue, all project admins for the issue's project,
1031      * and anyone else that has a notfication on file.
1032      * @param issueId the id of the issue to find notifications for
1033      * @param pimaryOnly only include the primary notifications
1034      * @param activeOnly only include the notification if the user is currently active (not locked or deleted)
1035      * @returns an array of NotificationModels
1036      * @see IssueHandlerBean#getPrimaryIssueNotifications
1037      */

1038    public NotificationModel[] getIssueNotifications(Integer JavaDoc issueId, boolean primaryOnly, boolean activeOnly) {
1039        NotificationModel[] notificationArray = new NotificationModel[0];
1040        Vector notificationVector = new Vector();
1041        IssueLocal issue = null;
1042
1043        if(! primaryOnly) {
1044            try {
1045                Collection notifications = nHome.findByIssueId(issueId);
1046                for(Iterator iterator = notifications.iterator(); iterator.hasNext(); ) {
1047                    NotificationLocal notification = (NotificationLocal) iterator.next();
1048                    UserLocal notificationUser = notification.getUser();
1049                    if(! activeOnly || notificationUser.getStatus() == UserUtilities.STATUS_ACTIVE) {
1050                        notificationVector.add(notification.getModel());
1051                    }
1052                }
1053            } catch(FinderException fe) {
1054            }
1055        }
1056
1057        // Now add in other notifications like owner, creator, project owners, etc...
1058
try {
1059            boolean hasOwner = false;
1060            issue = iHome.findByPrimaryKey(issueId);
1061            if(issue.getOwner() != null) {
1062                UserModel ownerModel = issue.getOwner().getModel();
1063                if(ownerModel != null && (! activeOnly || ownerModel.getStatus() == UserUtilities.STATUS_ACTIVE)) {
1064                    notificationVector.add(new NotificationModel(ownerModel, issueId, NotificationUtilities.ROLE_OWNER));
1065                    hasOwner = true;
1066                }
1067            }
1068            if(! primaryOnly || ! hasOwner) {
1069                UserModel creatorModel = issue.getCreator().getModel();
1070                if(creatorModel != null && (! activeOnly || creatorModel.getStatus() == UserUtilities.STATUS_ACTIVE)) {
1071                    notificationVector.add(new NotificationModel(creatorModel, issueId, NotificationUtilities.ROLE_CREATOR));
1072                }
1073            }
1074        } catch(FinderException fe) {
1075        }
1076
1077        try {
1078            if(issue != null) {
1079                ProjectLocal project = pHome.findByPrimaryKey(issue.getProject().getId());
1080                Collection projectOwners = project.getOwners();
1081                for(Iterator iterator = projectOwners.iterator(); iterator.hasNext(); ) {
1082                    UserLocal projectOwner = (UserLocal) iterator.next();
1083                    if(projectOwner != null && (! activeOnly || projectOwner.getStatus() == UserUtilities.STATUS_ACTIVE)) {
1084                        notificationVector.add(new NotificationModel(projectOwner.getModel(), issueId, NotificationUtilities.ROLE_PO));
1085                    }
1086                }
1087            }
1088        } catch(FinderException fe) {
1089        }
1090
1091        notificationArray = new NotificationModel[notificationVector.size()];
1092        notificationVector.copyInto(notificationArray);
1093        return notificationArray;
1094    }
1095
1096    public boolean addIssueNotification(NotificationModel model) {
1097        if(model != null) {
1098            try {
1099                UserLocal user = uHome.findByPrimaryKey(model.getUserId());
1100                IssueLocal issue = iHome.findByPrimaryKey(model.getIssueId());
1101
1102                IDGenerator idGen = idHome.create();
1103                NotificationLocal notification = nHome.create(idGen.getId(NotificationLocal.ID_NAME));
1104                notification.setModel(model);
1105                notification.setIssue(issue);
1106                notification.setUser(user);
1107
1108                return true;
1109            } catch(CreateException ce) {
1110            } catch(FinderException ce) {
1111            }
1112        }
1113        return false;
1114    }
1115
1116    public boolean hasIssueNotification(Integer JavaDoc issueId, Integer JavaDoc userId) {
1117        return hasIssueNotification(issueId, userId, NotificationUtilities.ROLE_ANY);
1118    }
1119
1120    public boolean hasIssueNotification(Integer JavaDoc issueId, Integer JavaDoc userId, int role) {
1121        if(issueId != null && userId != null) {
1122            NotificationModel[] notifications = getIssueNotifications(issueId, false, false);
1123
1124            for(int i = 0; i < notifications.length; i++) {
1125                if(role == NotificationUtilities.ROLE_ANY || notifications[i].getNotificationRole() == role) {
1126                    if(notifications[i].getUserId().equals(userId)) {
1127                        return true;
1128                    }
1129                }
1130            }
1131        }
1132        return false;
1133    }
1134
1135    public int getOpenIssueCountByProjectId(Integer JavaDoc projectId) {
1136        try {
1137            Collection issues = iHome.findByProjectIdAndLowerStatus(projectId, IssueUtilities.STATUS_RESOLVED);
1138            return issues.size();
1139        } catch(FinderException fe) {
1140        }
1141
1142        return 0;
1143    }
1144
1145    public int getResolvedIssueCountByProjectId(Integer JavaDoc projectId) {
1146        try {
1147            Collection issues = iHome.findByProjectIdAndHigherStatus(projectId, IssueUtilities.STATUS_RESOLVED);
1148            return issues.size();
1149        } catch(FinderException fe) {
1150        }
1151
1152        return 0;
1153    }
1154
1155    public int getTotalIssueCountByProjectId(Integer JavaDoc projectId) {
1156        try {
1157            Collection issues = iHome.findByProjectId(projectId);
1158            return issues.size();
1159        } catch(FinderException fe) {
1160        }
1161
1162        return 0;
1163    }
1164
1165    public Date getLatestIssueDateByProjectId(Integer JavaDoc projectId) {
1166        return iHome.latestModificationDate(projectId);
1167    }
1168
1169    public void sendNotification(Integer JavaDoc issueId, int type, String JavaDoc baseURL) {
1170        sendNotification(issueId, type, baseURL, null, null);
1171    }
1172
1173    public void sendNotification(Integer JavaDoc issueId, int type, String JavaDoc baseURL, HashSet addresses, Integer JavaDoc lastModifiedDays) {
1174        try {
1175            QueueConnectionFactory factory = (QueueConnectionFactory) ic.lookup("java:comp/env/" + notificationFactoryName);
1176            Queue notificationQueue = (Queue) ic.lookup("java:comp/env/" + notificationQueueName);
1177            QueueConnection connect = factory.createQueueConnection();
1178            QueueSession session = connect.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
1179
1180            QueueSender sender = session.createSender(notificationQueue);
1181
1182            MapMessage message = session.createMapMessage();
1183            message.setInt("issueId", issueId.intValue());
1184            message.setInt("type", type);
1185            message.setObject("lastModifiedDays", (lastModifiedDays == null ? new Integer JavaDoc(-1) : lastModifiedDays));
1186
1187
1188            if(systemBaseURL != null && ! systemBaseURL.equals("")) {
1189                message.setString("baseURL", systemBaseURL);
1190            } else if(baseURL != null) {
1191                message.setString("baseURL", baseURL);
1192            }
1193            if(addresses != null) {
1194                try {
1195                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
1196                    ObjectOutputStream oos = new ObjectOutputStream(baos);
1197                    oos.writeObject(addresses);
1198                    message.setObject("addresses", baos.toByteArray());
1199                } catch(Exception JavaDoc e) {
1200                    Logger.logDebug("Unable to write address list for notification: " + e.getMessage());
1201                }
1202            }
1203
1204            sender.send(message);
1205        } catch(NamingException ne) {
1206            Logger.logError("Error looking up ConnectionFactory/Queue " + notificationFactoryName + "/" + notificationQueueName + ".", ne);
1207        } catch(JMSException jmse) {
1208            Logger.logWarn("Error sending notification message", jmse);
1209        }
1210    }
1211
1212    public boolean canViewIssue(Integer JavaDoc issueId, UserModel user) {
1213        try {
1214            IssueModel issue = getIssue(issueId);
1215            UserHandler uh = uhHome.create();
1216            HashMap permissions = uh.getUserPermissions(user, AuthenticationConstants.REQ_SOURCE_WEB);
1217            return IssueUtilities.canViewIssue(issue, user.getId(), permissions);
1218        } catch(CreateException ce) {
1219            Logger.logError("Error while checking user access to permission.", ce);
1220        }
1221        return false;
1222    }
1223
1224    public boolean canViewIssue(IssueModel issue, UserModel user) {
1225        try {
1226            UserHandler uh = uhHome.create();
1227            HashMap permissions = uh.getUserPermissions(user, AuthenticationConstants.REQ_SOURCE_WEB);
1228            return IssueUtilities.canViewIssue(issue, user.getId(), permissions);
1229        } catch(CreateException ce) {
1230            Logger.logError("Error while checking user access to permission.", ce);
1231        }
1232        return false;
1233    }
1234
1235    public void ejbCreate() {
1236        try {
1237            ic = new InitialContext();
1238            Object JavaDoc idRef = ic.lookup("java:comp/env/" + IDGenerator.JNDI_NAME);
1239            idHome = (IDGeneratorHome) PortableRemoteObject.narrow(idRef, IDGeneratorHome.class);
1240
1241            Object JavaDoc uhRef = ic.lookup("java:comp/env/" + UserHandler.JNDI_NAME);
1242            uhHome = (UserHandlerHome) PortableRemoteObject.narrow(uhRef, UserHandlerHome.class);
1243
1244            cHome = (ComponentLocalHome) ic.lookup("java:comp/env/" + ComponentLocal.JNDI_NAME);
1245            cfHome = (CustomFieldLocalHome) ic.lookup("java:comp/env/" + CustomFieldLocal.JNDI_NAME);
1246            iHome = (IssueLocalHome) ic.lookup("java:comp/env/" + IssueLocal.JNDI_NAME);
1247            iaHome = (IssueActivityLocalHome) ic.lookup("java:comp/env/" + IssueActivityLocal.JNDI_NAME);
1248            iattHome = (IssueAttachmentLocalHome) ic.lookup("java:comp/env/" + IssueAttachmentLocal.JNDI_NAME);
1249            ifHome = (IssueFieldLocalHome) ic.lookup("java:comp/env/" + IssueFieldLocal.JNDI_NAME);
1250            ihHome = (IssueHistoryLocalHome) ic.lookup("java:comp/env/" + IssueHistoryLocal.JNDI_NAME);
1251            nHome = (NotificationLocalHome) ic.lookup("java:comp/env/" + NotificationLocal.JNDI_NAME);
1252            pHome = (ProjectLocalHome) ic.lookup("java:comp/env/" + ProjectLocal.JNDI_NAME);
1253            uHome = (UserLocalHome) ic.lookup("java:comp/env/" + UserLocal.JNDI_NAME);
1254            vHome = (VersionLocalHome) ic.lookup("java:comp/env/" + VersionLocal.JNDI_NAME);
1255
1256            Object JavaDoc scRef = ic.lookup("java:comp/env/" + SystemConfiguration.JNDI_NAME);
1257            scHome = (SystemConfigurationHome) PortableRemoteObject.narrow(scRef, SystemConfigurationHome.class);
1258            SystemConfiguration sc = scHome.create();
1259            systemBaseURL = sc.getProperty("system_base_url", "");
1260        } catch(CreateException ce) {
1261            Logger.logError("Exception while accessing application properties.", ce);
1262        } catch(NamingException ne) {
1263            Logger.logError("Exception while looking up home interfaces.", ne);
1264        }
1265    }
1266
1267    public void setSessionContext(SessionContext value) {}
1268    public void ejbActivate() {}
1269    public void ejbPassivate() {}
1270    public void ejbRemove() {}
1271}
1272  
Popular Tags