// group assignment is not editable => perform source to destination automatically
mappingSet.add(new Entry(oldInvocation.getGroup()), new Entry(newInvocation.getGroup()));
// Create duplicated command entries according to the original execution order
CommandEntryManager commandEntryManager = new CommandEntryManager(locale,session);
SortedSet<CommandEntry> newCommandEntries = new TreeSet<CommandEntry>(new CommandEntryManager.CommandEntryComparator());
Set<CommandEntry> oldCommandEntries = oldInvocation.getCommandEntries();
SortedSet<CommandEntry> sortedOldCommandEntries = new TreeSet<CommandEntry>(new CommandEntryManager.CommandEntryComparator());
sortedOldCommandEntries.addAll(oldCommandEntries);
for (CommandEntry oldCommandEntry : sortedOldCommandEntries) {
CommandEntryExtender extender = commandEntryManager.createCommandEntryExtender(oldCommandEntry);
CommandEntry duplicatedCommandEntry = extender.duplicateCommandEntry(newInvocation.getGroup(),mappingSet);
Set<InteractionList> invocations = new TreeSet<InteractionList>();
invocations.add(newInvocation);
duplicatedCommandEntry.setInteractionLists(invocations);
commandEntryManager.create(duplicatedCommandEntry); // also sets the ID for sorting
newCommandEntries.add(duplicatedCommandEntry);
}
newInvocation.setCommandEntries(newCommandEntries);
SmsDbManager smsDbManager = new SmsDbManager(locale,session);
smsDbManager.createInvocation(newInvocation);