throws Exception {
boolean result = true;
HibernateUtil.startTransaction();
Campaign c = (Campaign) req.getAttribute(WebKeys.CAMPAIGN_EDIT);
String updateCampaignPermissionsOnly = req.getParameter(com.dotmarketing.util.Constants.UPDATE_CAMPAIGN_PERMISSIONS_ONLY);
boolean updateAll = false;
if ((updateCampaignPermissionsOnly == null) || (updateCampaignPermissionsOnly.equalsIgnoreCase("false")))
updateAll = true;
if ((updateCampaignPermissionsOnly != null) && (!updateAll)) {
try {
int temp = Integer.parseInt(updateCampaignPermissionsOnly);
if (temp < 1)
updateAll = true;
} catch (Exception e) {
}
}
if (updateAll) {
CampaignForm cfform = (CampaignForm) form;
boolean isWasRecurrent = c.getIsRecurrent();
BeanUtils.copyProperties(req.getAttribute(WebKeys.CAMPAIGN_EDIT), cfform);
HibernateUtil.saveOrUpdate(c);
// wipe the old mailing list that was the child
MailingList ml = (MailingList) InodeFactory.getChildOfClass(c, MailingList.class);
c.deleteChild(ml);
//try to get the campaign's new mailing list
ml = (MailingList) InodeFactory.getInode(String.valueOf(cfform.getMailingList()), MailingList.class);
if (InodeUtils.isSet(ml.getInode())) {
c.addChild(ml);
}
// wipe the old communication that was the child
Communication comm = (Communication) InodeFactory.getChildOfClass(c, Communication.class);
c.deleteChild(comm);
//try to get the campaign's new communication
comm = (Communication) InodeFactory.getInode(String.valueOf(cfform.getCommunicationInode()), Communication.class);
if (InodeUtils.isSet(comm.getInode())) {
c.addChild(comm);
}
// wipe the old user filter that was the child
UserFilter userfilter = (UserFilter) InodeFactory.getChildOfClass(c, UserFilter.class);
c.deleteChild(userfilter);
//try to get the campaign's new communication
userfilter = (UserFilter) InodeFactory.getInode(String.valueOf(cfform.getUserFilterInode()), UserFilter.class);
if (InodeUtils.isSet(userfilter.getInode())) {
c.addChild(userfilter);
}
c.setUserId(user.getUserId());
if (c.getIsRecurrent()) {
SchedulerForm schedulerForm = new SchedulerForm();
BeanUtils.copyProperties(schedulerForm, cfform);
schedulerForm.setJavaClass("com.dotmarketing.quartz.job.DeliverCampaignThread");
//schedulerForm.setJobName(c.getTitle());
schedulerForm.setJobName(String.valueOf(c.getInode()));
HashMap hashMap = new HashMap<String, String>();
hashMap.put("inode", c.getInode());
schedulerForm.setMap(hashMap);
schedulerForm.setJobDescription(c.getTitle());
//schedulerForm.setJobGroup(String.valueOf(c.getInode()));
schedulerForm.setJobGroup("Recurrent Campaign");
// create/edit quartz job
result = EditSchedulerAction._saveScheduler(req, res, config, schedulerForm, user);
}
else if (isWasRecurrent) {
// ending quartz job
QuartzUtils.removeJob(c.getInode(), "Recurrent Campaign");
}
if (result)
HibernateUtil.saveOrUpdate(c);