Set<CommandEntry> oldCommandEntries = oldTimerEvent.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(newTimerEvent.getGroup(),mappingSet);
Set<TimerEvent> timerEvents = new TreeSet<TimerEvent>();
timerEvents.add(newTimerEvent);
duplicatedCommandEntry.setTimerEvents(timerEvents);
commandEntryManager.create(duplicatedCommandEntry); // also sets the ID for sorting
newCommandEntries.add(duplicatedCommandEntry);
}
newTimerEvent.setCommandEntries(newCommandEntries);
new SmsServiceDbManager(locale,session).createTimerEvent(newTimerEvent);