// group assignment is not editable => perform source to destination automatically
mappingSet.add(new Entry(oldFragment.getGroup()), new Entry(newFragment.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 = oldFragment.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(newFragment.getGroup(),mappingSet);
Set<InteractionList> fragments = new TreeSet<InteractionList>();
fragments.add(newFragment);
duplicatedCommandEntry.setInteractionLists(fragments);
commandEntryManager.create(duplicatedCommandEntry); // also sets the ID for sorting
newCommandEntries.add(duplicatedCommandEntry);
}
newFragment.setCommandEntries(newCommandEntries);
SmsDbManager smsDbManager = new SmsDbManager(locale,session);
smsDbManager.createFragment(newFragment);