Issue #427 exceptions are good

Change-Id: I67bb428804d025d20423b9e2320006c70e9b4c68

Former-commit-id: ec20a1f9d6076c2f72909f9fb9a6c88598201dcf
This commit is contained in:
Nate Jensen 2012-04-18 17:05:27 -05:00
parent a54660c377
commit 47639de899
6 changed files with 76 additions and 179 deletions

View file

@ -69,7 +69,6 @@ import com.raytheon.uf.viz.collaboration.ui.CollaborationUtils;
import com.raytheon.uf.viz.collaboration.ui.editor.CollaborationEditor; import com.raytheon.uf.viz.collaboration.ui.editor.CollaborationEditor;
import com.raytheon.uf.viz.collaboration.ui.login.LoginData; import com.raytheon.uf.viz.collaboration.ui.login.LoginData;
import com.raytheon.uf.viz.collaboration.ui.login.LoginDialog; import com.raytheon.uf.viz.collaboration.ui.login.LoginDialog;
import com.raytheon.uf.viz.collaboration.ui.role.ParticipantEventController;
import com.raytheon.uf.viz.collaboration.ui.session.CollaborationSessionView; import com.raytheon.uf.viz.collaboration.ui.session.CollaborationSessionView;
import com.raytheon.uf.viz.collaboration.ui.session.PeerToPeerView; import com.raytheon.uf.viz.collaboration.ui.session.PeerToPeerView;
import com.raytheon.uf.viz.collaboration.ui.session.SessionView; import com.raytheon.uf.viz.collaboration.ui.session.SessionView;
@ -774,31 +773,6 @@ public class CollaborationDataManager implements IRosterEventSubscriber {
}); });
} }
@Deprecated
public String joinCollaborationSession(String venueName, String sessionId) {
String result = sessionId;
if (sessionsMap.get(sessionId) == null) {
IVenueSession session = null;
try {
session = getSessionManager().joinCollaborationVenue(venueName);
result = session.getSessionId();
ISharedDisplaySession displaySession = (ISharedDisplaySession) session;
sessionsMap.put(result, session);
ParticipantEventController pec = new ParticipantEventController(
displaySession);
pec.startup();
// TODO this method is broken and should be removed
} catch (CollaborationException e) {
// TODO Auto-generated catch block. Please revise as
// appropriate.
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(),
e);
}
}
return result;
}
public void registerEventHandler(Object handler) { public void registerEventHandler(Object handler) {
eventBus.register(handler); eventBus.register(handler);
} }

View file

@ -683,35 +683,37 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
} }
} }
@Deprecated
private void createJoinCollaboration() { private void createJoinCollaboration() {
IStructuredSelection selection = (IStructuredSelection) usersTreeViewer // IStructuredSelection selection = (IStructuredSelection)
.getSelection(); // usersTreeViewer
Object[] nodes = selection.toArray(); // .getSelection();
for (Object node : nodes) { // Object[] nodes = selection.toArray();
if (node instanceof SessionGroup) { // for (Object node : nodes) {
SessionGroup sg = (SessionGroup) node; // if (node instanceof SessionGroup) {
// System.out.println("Join: " + sg.getId()); // SessionGroup sg = (SessionGroup) node;
CollaborationDataManager manager = CollaborationDataManager // // System.out.println("Join: " + sg.getId());
.getInstance(); // CollaborationDataManager manager = CollaborationDataManager
String sessionId = manager.joinCollaborationSession( // .getInstance();
sg.getText(), sg.getId()); // String sessionId = manager.joinCollaborationSession(
sg.setId(sessionId); // sg.getText(), sg.getId());
try { // sg.setId(sessionId);
IViewPart part = PlatformUI // try {
.getWorkbench() // IViewPart part = PlatformUI
.getActiveWorkbenchWindow() // .getWorkbench()
.getActivePage() // .getActiveWorkbenchWindow()
.showView(CollaborationSessionView.ID, sessionId, // .getActivePage()
IWorkbenchPage.VIEW_ACTIVATE); // .showView(CollaborationSessionView.ID, sessionId,
} catch (PartInitException e) { // IWorkbenchPage.VIEW_ACTIVATE);
statusHandler.handle(Priority.PROBLEM, // } catch (PartInitException e) {
"Unable to open collaboation sesson", e); // statusHandler.handle(Priority.PROBLEM,
} catch (Exception e) { // "Unable to open collaboation sesson", e);
statusHandler.handle(Priority.ERROR, "Unexpected excepton", // } catch (Exception e) {
e); // statusHandler.handle(Priority.ERROR, "Unexpected excepton",
} // e);
} // }
} // }
// }
} }
/** /**

View file

@ -69,7 +69,7 @@ public interface ISession extends IEventPublisher {
* Close and clean up this session. After a close, isConnected must return * Close and clean up this session. After a close, isConnected must return
* false. * false.
*/ */
void close(); public void close();
/** /**
* *
@ -82,12 +82,12 @@ public interface ISession extends IEventPublisher {
* *
* @return The connection status. * @return The connection status.
*/ */
boolean isConnected(); public boolean isConnected();
/** /**
* Get the session identifier. * Get the session identifier.
* *
* @return The session identifier. * @return The session identifier.
*/ */
String getSessionId(); public String getSessionId();
} }

View file

@ -130,11 +130,4 @@ public interface ISharedDisplaySession extends IVenueSession {
*/ */
public boolean isConnected(); public boolean isConnected();
/**
* Get the session identifier.
*
* @return The session identifier.
*/
public String getSessionId();
} }

View file

@ -68,7 +68,6 @@ import com.raytheon.uf.viz.collaboration.comm.identity.roster.IRosterManager;
import com.raytheon.uf.viz.collaboration.comm.identity.user.IChatID; import com.raytheon.uf.viz.collaboration.comm.identity.user.IChatID;
import com.raytheon.uf.viz.collaboration.comm.identity.user.IQualifiedID; import com.raytheon.uf.viz.collaboration.comm.identity.user.IQualifiedID;
import com.raytheon.uf.viz.collaboration.comm.identity.user.IVenueParticipant; import com.raytheon.uf.viz.collaboration.comm.identity.user.IVenueParticipant;
import com.raytheon.uf.viz.collaboration.comm.provider.Errors;
import com.raytheon.uf.viz.collaboration.comm.provider.Presence; import com.raytheon.uf.viz.collaboration.comm.provider.Presence;
import com.raytheon.uf.viz.collaboration.comm.provider.Tools; import com.raytheon.uf.viz.collaboration.comm.provider.Tools;
import com.raytheon.uf.viz.collaboration.comm.provider.event.RosterChangeEvent; import com.raytheon.uf.viz.collaboration.comm.provider.event.RosterChangeEvent;
@ -437,32 +436,8 @@ public class SessionManager implements IEventPublisher {
sessions.put(session.getSessionId(), session); sessions.put(session.getSessionId(), session);
} }
} catch (Exception e) { } catch (Exception e) {
// TODO fix throw new CollaborationException("Error joining venue "
e.printStackTrace(); + invitation.getRoomId().getName(), e);
}
return session;
}
/**
*
* @param venueName
* @return
* @throws CollaborationException
*/
@Deprecated
public IVenueSession joinCollaborationVenue(String venueName)
throws CollaborationException {
VenueSession session = null;
try {
session = new VenueSession(container, eventBus, this);
if (session != null) {
session.joinVenue(venueName);
sessions.put(session.getSessionId(), session);
}
} catch (Exception e) {
// TODO
e.printStackTrace();
} }
return session; return session;
} }
@ -476,12 +451,10 @@ public class SessionManager implements IEventPublisher {
public ISharedDisplaySession createCollaborationVenue(String venueName, public ISharedDisplaySession createCollaborationVenue(String venueName,
String subject) throws CollaborationException { String subject) throws CollaborationException {
SharedDisplaySession session = null; SharedDisplaySession session = null;
int errorStatus = -1;
try { try {
session = new SharedDisplaySession(container, eventBus, this); session = new SharedDisplaySession(container, eventBus, this);
if (session != null) {
errorStatus = session.createVenue(venueName, subject); session.createVenue(venueName, subject);
if (errorStatus == Errors.NO_ERROR) {
String name = Tools.parseName(account); String name = Tools.parseName(account);
String host = Tools.parseHost(account); String host = Tools.parseHost(account);
@ -492,31 +465,11 @@ public class SessionManager implements IEventPublisher {
session.setUserId(me); session.setUserId(me);
sessions.put(session.getSessionId(), session); sessions.put(session.getSessionId(), session);
}
}
} catch (Exception e) {
// TODO
e.printStackTrace();
} finally {
if (errorStatus != Errors.NO_ERROR) {
// TODO handle this in a more generic way
String message = null;
switch (errorStatus) {
case Errors.BAD_NAME:
message = "Badly formed session name.";
break;
case Errors.VENUE_EXISTS:
message = "Session name already in use.";
break;
case Errors.CANNOT_CONNECT:
message = "Unable to connect.";
default:
message = "Unknown problem creating session";
}
throw new CollaborationException(message);
}
}
return session; return session;
} catch (Exception e) {
throw new CollaborationException(
"Error creating collaboration venue " + venueName, e);
}
} }
/** /**
@ -567,7 +520,7 @@ public class SessionManager implements IEventPublisher {
* *
* @param session * @param session
*/ */
void removeSession(ISession session) { protected void removeSession(ISession session) {
sessions.remove(session); sessions.remove(session);
} }
@ -688,7 +641,7 @@ public class SessionManager implements IEventPublisher {
/** /**
* *
*/ */
ISession getSession(String sessionId) { protected ISession getSession(String sessionId) {
return sessions.get(sessionId); return sessions.get(sessionId);
} }

View file

@ -41,6 +41,8 @@ import org.eclipse.ecf.presence.chatroom.IChatRoomParticipantListener;
import org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID; import org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID;
import com.google.common.eventbus.EventBus; import com.google.common.eventbus.EventBus;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException; import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException;
import com.raytheon.uf.viz.collaboration.comm.identity.IMessage; import com.raytheon.uf.viz.collaboration.comm.identity.IMessage;
import com.raytheon.uf.viz.collaboration.comm.identity.IPresence; import com.raytheon.uf.viz.collaboration.comm.identity.IPresence;
@ -52,7 +54,6 @@ import com.raytheon.uf.viz.collaboration.comm.identity.invite.VenueInvite;
import com.raytheon.uf.viz.collaboration.comm.identity.user.IQualifiedID; import com.raytheon.uf.viz.collaboration.comm.identity.user.IQualifiedID;
import com.raytheon.uf.viz.collaboration.comm.identity.user.IVenueParticipant; import com.raytheon.uf.viz.collaboration.comm.identity.user.IVenueParticipant;
import com.raytheon.uf.viz.collaboration.comm.provider.CollaborationMessage; import com.raytheon.uf.viz.collaboration.comm.provider.CollaborationMessage;
import com.raytheon.uf.viz.collaboration.comm.provider.Errors;
import com.raytheon.uf.viz.collaboration.comm.provider.Presence; import com.raytheon.uf.viz.collaboration.comm.provider.Presence;
import com.raytheon.uf.viz.collaboration.comm.provider.TextMessage; import com.raytheon.uf.viz.collaboration.comm.provider.TextMessage;
import com.raytheon.uf.viz.collaboration.comm.provider.Tools; import com.raytheon.uf.viz.collaboration.comm.provider.Tools;
@ -96,6 +97,9 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.VenueParticipant;
public class VenueSession extends BaseSession implements IVenueSession { public class VenueSession extends BaseSession implements IVenueSession {
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(VenueSession.class);
private static final String SEND_CMD = "[[COMMAND"; private static final String SEND_CMD = "[[COMMAND";
private static final String SEND_TXT = "[[TEXT]]"; private static final String SEND_TXT = "[[TEXT]]";
@ -119,7 +123,7 @@ public class VenueSession extends BaseSession implements IVenueSession {
* @param container * @param container
* @param eventBus * @param eventBus
*/ */
VenueSession(IContainer container, EventBus externalBus, protected VenueSession(IContainer container, EventBus externalBus,
SessionManager manager, String sessionId) SessionManager manager, String sessionId)
throws CollaborationException { throws CollaborationException {
super(container, externalBus, manager, sessionId); super(container, externalBus, manager, sessionId);
@ -130,7 +134,7 @@ public class VenueSession extends BaseSession implements IVenueSession {
* @param container * @param container
* @param eventBus * @param eventBus
*/ */
VenueSession(IContainer container, EventBus externalBus, protected VenueSession(IContainer container, EventBus externalBus,
SessionManager manager) throws CollaborationException { SessionManager manager) throws CollaborationException {
super(container, externalBus, manager); super(container, externalBus, manager);
} }
@ -239,17 +243,14 @@ public class VenueSession extends BaseSession implements IVenueSession {
if (sender != null) { if (sender != null) {
VenueInvite invite = buildInvite(body); VenueInvite invite = buildInvite(body);
String msgBody = Tools.marshallData(invite); String msgBody = Tools.marshallData(invite);
ID roomId = venueInfo.getConnectedID(); ID roomId = venueInfo.getConnectedID();
ID userId = IDFactory.getDefault().createID( ID userId = IDFactory.getDefault().createID(
getConnectionNamespace(), id); getConnectionNamespace(), id);
try { try {
sender.sendInvitation(roomId, userId, subject, msgBody); sender.sendInvitation(roomId, userId, subject, msgBody);
} catch (ECFException e) { } catch (ECFException e) {
// TODO fix throw new CollaborationException("Error sending invitation", e);
e.printStackTrace();
} }
} }
} }
@ -278,15 +279,7 @@ public class VenueSession extends BaseSession implements IVenueSession {
} }
} }
/**
*
* @see com.raytheon.uf.viz.collaboration.comm.identity.ISession#getSessionId()
*/
@Override @Override
public String getSessionId() {
return sessionId;
}
public void sendChatMessage(String message) throws CollaborationException { public void sendChatMessage(String message) throws CollaborationException {
this.sendMessageToVenue(message); this.sendMessageToVenue(message);
} }
@ -304,7 +297,7 @@ public class VenueSession extends BaseSession implements IVenueSession {
sender.sendMessage(SEND_TXT + message); sender.sendMessage(SEND_TXT + message);
} }
} catch (ECFException e) { } catch (ECFException e) {
throw new CollaborationException("Error sending text messge", e); throw new CollaborationException("Error sending messge", e);
} }
} }
} }
@ -313,12 +306,7 @@ public class VenueSession extends BaseSession implements IVenueSession {
this.userID = id; this.userID = id;
} }
/** protected void joinVenue(String venueName) throws CollaborationException {
*
* @see com.raytheon.uf.viz.collaboration.comm.identity.IVenueSession#joinVenue(java.lang.String)
*/
int joinVenue(String venueName) {
int errorStatus = -1;
try { try {
// Create chat room container from manager // Create chat room container from manager
venueManager = getConnectionPresenceAdapter().getChatRoomManager(); venueManager = getConnectionPresenceAdapter().getChatRoomManager();
@ -326,30 +314,25 @@ public class VenueSession extends BaseSession implements IVenueSession {
venueInfo = venueManager.getChatRoomInfo(venueName); venueInfo = venueManager.getChatRoomInfo(venueName);
subject = venueInfo.getDescription(); subject = venueInfo.getDescription();
if (venueInfo != null) { if (venueInfo != null) {
errorStatus = completeVenueConnection(venueInfo); completeVenueConnection(venueInfo);
} else {
// Could not join venue.
} }
} else {
} }
} catch (Exception e) { } catch (Exception e) {
// TODO fix throw new CollaborationException(
System.out.println(String.format("joinVenue(%s)", venueName)); "Error joining venue " + venueName, e);
e.printStackTrace();
} }
return errorStatus;
} }
/** /**
* *
* @param venueName * @param venueName
* @throws CollaborationException
* @throws Exception * @throws Exception
* @see com.raytheon.uf.viz.collaboration.comm.identity.IVenueSession#createVenue(java.lang.String, * @see com.raytheon.uf.viz.collaboration.comm.identity.IVenueSession#createVenue(java.lang.String,
* java.lang.String) * java.lang.String)
*/ */
int createVenue(String venueName, String subject) { protected void createVenue(String venueName, String subject)
int errorStatus = -1; throws CollaborationException {
try { try {
this.subject = subject; this.subject = subject;
// Create chat room container from manager // Create chat room container from manager
@ -363,31 +346,22 @@ public class VenueSession extends BaseSession implements IVenueSession {
props.put(Tools.VENUE_SUBJECT_PROP, subject); props.put(Tools.VENUE_SUBJECT_PROP, subject);
} }
venueInfo = venueManager.createChatRoom(venueName, props); venueInfo = venueManager.createChatRoom(venueName, props);
errorStatus = completeVenueConnection(venueInfo); completeVenueConnection(venueInfo);
} else {
errorStatus = Errors.VENUE_EXISTS;
} }
} else {
errorStatus = Errors.CANNOT_CONNECT; // is this correct?
} }
} catch (Exception e) { } catch (Exception e) {
// TODO this is bad, we assume it's a bad venue name but it might throw new CollaborationException("Error creating venue "
// not be + venueName, e);
// and we'd give a poor error message
System.out.println(String.format("createVenue(%s)", venueName));
e.printStackTrace();
errorStatus = Errors.BAD_NAME;
} }
return errorStatus;
} }
/** /**
* *
* @return * @return
* @throws CollaborationException
*/ */
private int completeVenueConnection(IChatRoomInfo venueInfo) { private void completeVenueConnection(IChatRoomInfo venueInfo)
int errorStatus = Errors.NO_ERROR; throws CollaborationException {
if (venueInfo != null) { if (venueInfo != null) {
try { try {
venueContainer = venueInfo.createChatRoomContainer(); venueContainer = venueInfo.createChatRoomContainer();
@ -453,10 +427,10 @@ public class VenueSession extends BaseSession implements IVenueSession {
} }
} catch (Exception e) { } catch (Exception e) {
errorStatus = -1; throw new CollaborationException(
"Error completing connection to venue", e);
} }
} }
return errorStatus;
} }
/** /**
@ -513,8 +487,9 @@ public class VenueSession extends BaseSession implements IVenueSession {
getEventPublisher().post(o); getEventPublisher().post(o);
} }
} catch (CollaborationException ce) { } catch (CollaborationException ce) {
// TODO : more robust!! statusHandler.error(
ce.printStackTrace(); "Error deserializing received message on venue "
+ venueInfo.getName(), ce);
} }
} }
} }