Skip to content

Commit

Permalink
SPR-6419, manager implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Micha Kiener committed Jan 7, 2010
1 parent 38415e9 commit 8aac395
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,22 @@ public boolean mustBeRoot() {
}

/**
* Returns <code>true</code>, if the given, current conversation must be
* ended as a new one having this join mode was created. This is the case,
* if the current one is not a switched one and if the join mode is either
* new or switched.
*
* @param currentConversation the current conversation to check whether it
* should be ended implicitly according to this join mode
* @return <code>true</code>, if an already existing conversation must be
* ended before creating a new one
*/
public boolean mustEndCurrent() {
return (this == NEW);
public boolean mustEndCurrent(Conversation currentConversation) {
if (currentConversation != null && currentConversation.isSwitched()) {
return false;
}

return (this == NEW || this == SWITCHED);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,38 +216,39 @@ public Conversation beginConversation(boolean temporary, JoinMode joinMode) {
// set the temporary flag of the newly created conversation and also
// assign it a newly created, unique id
newConversation.setTemporary(temporary);
newConversation.setSwitched(joinMode == JoinMode.SWITCHED);
newConversation.setId(createNewConversationId());

store.registerConversation(newConversation);
}

// check, if there is a current conversation
if (currentConversation != null) {
// check, if nesting is not allowed and throw an exception if so
if (joinMode.mustBeRoot()) {
throw new IllegalStateException(
"Beginning a new conversation while one is still in progress and nesting is not allowed is not possible.");
}

if (joinMode.mustBeJoined()) {
currentConversation.joinConversation();
return currentConversation;
}

if (joinMode.mustBeSwitched()) {
if (joinMode.mustBeSwitched() && currentConversation.isSwitched()) {
currentConversation.deactivated(ConversationDeactivationType.NEW_SWITCHED, newConversation);
}

// check, if the current one must be ended before creating a new one
if (joinMode.mustEndCurrent()) {
if (joinMode.mustEndCurrent(currentConversation)) {
endConversation(currentConversation, ConversationEndingType.TRANSCRIBED);
}

// check, if nesting is not allowed and throw an exception if so
if (joinMode.mustBeRoot()) {
throw new IllegalStateException(
"Beginning a new conversation while one is still in progress and nesting is not allowed is not possible.");
}

// nest the new conversation to the current one, if available and
// set the current one as the parent of the new one
if (joinMode.mustBeNested()) {
newConversation.setParentConversation(currentConversation, joinMode.mustBeIsolated());
newConversation.deactivated(joinMode.mustBeIsolated() ? ConversationDeactivationType.NEW_ISOLATED
currentConversation.deactivated(joinMode.mustBeIsolated() ? ConversationDeactivationType.NEW_ISOLATED
: ConversationDeactivationType.NEW_NESTED, newConversation);
}
}
Expand Down

0 comments on commit 8aac395

Please sign in to comment.