Object oldTimerEventId = req.getSession().getAttribute("oldInteractionListId");
if (oldTimerEventId == null || !(oldTimerEventId instanceof Long)){
throw new InputException(getResources(req).getMessage(locale, "admin.entryNotAvailable"),"old timer event entry not found in session",null,null);
}
TimerEvent oldTimerEvent = new SmsServiceDbManager(locale,session).getTimerEvent((Long)oldTimerEventId);
if (oldTimerEvent == null){
throw new InputException(getResources(req).getMessage(locale, "admin.entryNotAvailable"),"old timer event entry #" + oldTimerEventId + " not found",null,null);
}
checkAccessRights(req,oldTimerEvent.getGroup(),null);
Object newEntry = req.getSession().getAttribute("newTimerEvent");
if (newEntry == null || !(newEntry instanceof TimerEvent)){
throw new InputException(getResources(req).getMessage(locale, "admin.entryNotAvailable"),"new timer event entry not found in session",null,null);
}
// reload references in current session
TimerEvent newTimerEvent = (TimerEvent)newEntry;
f.initialize(newTimerEvent,locale,session,getResources(req));
newTimerEvent = new TimerEvent();
f.toEntry(newTimerEvent, locale, session, getResources(req));
checkAccessRights(req, newTimerEvent.getGroup(),null);
// group assignment is not editable => perform source to destination automatically
mappingSet.add(new Entry(oldTimerEvent.getGroup()), new Entry(newTimerEvent.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 = 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);
return mapping.findForward("duplicated");
}