001: /*
002: * Copyright (c) 2001 - 2005 ivata limited.
003: * All rights reserved.
004: * -----------------------------------------------------------------------------
005: * ivata groupware may be redistributed under the GNU General Public
006: * License as published by the Free Software Foundation;
007: * version 2 of the License.
008: *
009: * These programs are free software; you can redistribute them and/or
010: * modify them under the terms of the GNU General Public License
011: * as published by the Free Software Foundation; version 2 of the License.
012: *
013: * These programs are distributed in the hope that they will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: *
017: * See the GNU General Public License in the file LICENSE.txt for more
018: * details.
019: *
020: * If you would like a copy of the GNU General Public License write to
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place - Suite 330
024: * Boston, MA 02111-1307, USA.
025: *
026: *
027: * To arrange commercial support and licensing, contact ivata at
028: * http://www.ivata.com/contact.jsp
029: * -----------------------------------------------------------------------------
030: * $Log: UserRemoveBean.java,v $
031: * Revision 1.3 2005/04/10 20:31:59 colinmacleod
032: * Added new themes.
033: * Changed id type to String.
034: * Changed i tag to em and b tag to strong.
035: * Improved PicoContainerFactory with NanoContainer scripts.
036: *
037: * Revision 1.2 2005/04/09 17:19:45 colinmacleod
038: * Changed copyright text to GPL v2 explicitly.
039: *
040: * Revision 1.1.1.1 2005/03/10 17:51:59 colinmacleod
041: * Restructured ivata op around Hibernate/PicoContainer.
042: * Renamed ivata groupware.
043: *
044: * Revision 1.4 2004/07/13 19:47:29 colinmacleod
045: * Moved project to POJOs from EJBs.
046: * Applied PicoContainer to services layer (replacing session EJBs).
047: * Applied Hibernate to persistence layer (replacing entity EJBs).
048: *
049: * Revision 1.3 2004/03/21 21:16:29 colinmacleod
050: * Shortened name to ivata op.
051: *
052: * Revision 1.2 2004/02/01 22:07:31 colinmacleod
053: * Added full names to author tags
054: *
055: * Revision 1.1.1.1 2004/01/27 20:58:40 colinmacleod
056: * Moved ivata openportal to SourceForge..
057: *
058: * Revision 1.5 2003/11/13 16:11:08 jano
059: * commitng everything to CVS
060: * can deploy and application is ruuning, can login into
061: *
062: * Revision 1.4 2003/11/03 11:29:44 jano
063: * commiting library,
064: * tryinjg to fix deploying problem
065: *
066: * Revision 1.3 2003/10/28 13:16:14 jano
067: * commiting library,
068: * still fixing compile and building openGroupware project
069: *
070: * Revision 1.2 2003/10/15 14:16:53 colin
071: * fixing for XDoclet
072: * -----------------------------------------------------------------------------
073: */
074: package com.ivata.groupware.business.library.listener;
075:
076: import javax.ejb.EJBException;
077: import javax.ejb.MessageDrivenBean;
078: import javax.ejb.MessageDrivenContext;
079: import javax.jms.JMSException;
080: import javax.jms.Message;
081: import javax.jms.MessageListener;
082: import javax.jms.ObjectMessage;
083:
084: import com.ivata.groupware.admin.security.user.UserEvent;
085:
086: /**
087: * <p>This bean listens for events when a user is removed.</p>
088: *
089: * @since 2003-10-09
090: * @author Colin MacLeod
091: * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
092: * @version $Revision: 1.3 $
093: *
094: * @ejb.bean
095: * name = "UserRemoveLibrary"
096: * display-name = "UserRemoveLibrary"
097: * acknowledge-mode = "Auto-acknowledge"
098: * destination-type = "javax.jms.Topic"
099: *
100: * @jboss.destination-jndi-name
101: * name = "topic/topicUserRemove"
102: */
103: public class UserRemoveBean implements MessageDrivenBean,
104: MessageListener {
105: MessageDrivenContext messageDrivenContext;
106:
107: public void ejbCreate() {
108: }
109:
110: public void ejbRemove() {
111: }
112:
113: public void onMessage(final Message message) {
114: // check this is an object message
115: if (!ObjectMessage.class.isInstance(message)) {
116: throw new EJBException(
117: "ERROR in folder.UserRemoveBean: unknown messaage class ("
118: + message.getClass().getName() + ")");
119: }
120:
121: ObjectMessage objectMessage = (ObjectMessage) message;
122: UserEvent userEvent = null;
123:
124: try {
125: userEvent = (UserEvent) objectMessage.getObject();
126: } catch (JMSException e) {
127: throw new EJBException(e);
128: }
129:
130: String userName = userEvent.getUserName();
131:
132: /**
133: try {
134: boolean deleteUser = true;
135: // check if we can removeUser
136: // find library items
137: LibraryItemLocalHome libraryItemHome = (LibraryItemLocalHome)
138: ApplicationServer.findLocalHome("LibraryItemLocal",
139: LibraryItemLocalHome.class);
140: java.util.Collection items = libraryItemHome.findByCreatedBy(this.getName());
141:
142:
143: // if he has not LIN -> find comments
144: if (items.isEmpty()) {
145: CommentLocalHome commentHome = (CommentLocalHome)
146: ApplicationServer.findLocalHome("CommentLocal",
147: CommentLocalHome.class);
148: java.util.Collection comments = commentHome.findByUserName(this.getName());
149:
150: // if he has not comments -> find files
151: if (comments.isEmpty()) {
152: FileLocalHome fileHome = (FileLocalHome)
153: ApplicationServer.findLocalHome("FileLocal",
154: FileLocalHome.class);
155: java.util.Collection files = fileHome.findByUserName(this.getName());
156:
157: // if he has not files -> find events
158: // if he has events in futer he can have privet events
159: if (files.isEmpty()) {
160: EventLocalHome eventHome = (EventLocalHome)
161: ApplicationServer.findLocalHome("EventLocal",
162: EventLocalHome.class);
163: java.util.Collection events = eventHome.findByUserName(this.getName());
164:
165: //if he has not events -> find groups
166: if (events.isEmpty()) {
167:
168: java.util.Collection groups = groupHome.findByCreatedBy(this.getName());
169:
170: // if he has not groups -> find contacts
171: if (groups.isEmpty()) {
172: PersonLocalHome personHome = (PersonLocalHome)
173: ApplicationServer.findLocalHome("PersonLocal",
174: PersonLocalHome.class);
175: java.util.Collection persons = personHome.findByCreatedBy(this.getName());
176:
177: if (!persons.isEmpty()) {
178: deleteUser = false;
179: }
180:
181: } else {
182: deleteUser = false;
183: }
184:
185: } else {
186: deleteUser = false;
187: }
188: } else {
189: deleteUser = false;
190: }
191: } else {
192: deleteUser = false;
193: }
194: } else {
195: deleteUser = false;
196: }
197: } catch (FinderException e) {
198: throw new EJBException(e);
199: } catch (NamingException e) {
200: throw new EJBException(e);
201: } catch (RemoveException e) {
202: throw new EJBException(e);
203: }
204: */
205: }
206:
207: public final void setMessageDrivenContext(
208: final MessageDrivenContext messageDrivenContext) {
209: this.messageDrivenContext = messageDrivenContext;
210: }
211: }
|