public void run() {
JobDataMap data = context.getJobDetail().getJobDataMap();
String inode = data.getString("inode");
List<Campaign> campaigns;
RelationshipAPI relationshipAPI = APILocator.getRelationshipAPI();
/**
* if inode is set on Job Context, there's a recurrent campaign, otherwise
* pulls a list of all waiting recipients, iterates through that list and
* calls the sendNewsletter method for each one. After sending, the
* recipient sent property is updated to the current time
*
*/
if (InodeUtils.isSet(inode)) {
Campaign c = CampaignFactory.getCampaign(inode);
campaigns = new ArrayList<Campaign>();
if (c.isActive() &&
!(UtilMethods.isSet(c.getExpirationDate()) && c.getExpirationDate().before(new Date()))) {
// create new child campaign and added to campaign array
try {
Campaign childCampaign = new Campaign();
BeanUtils.copyProperties(childCampaign, c);
childCampaign.setParentCampaign(c.getInode());
childCampaign.setInode(null);
childCampaign.setIsRecurrent(false);
childCampaign.setLocked(true);
HibernateUtil.saveOrUpdate(childCampaign);
MailingList ml = (MailingList) InodeFactory.getChildOfClass(c, MailingList.class);
HTMLPage page = (HTMLPage) InodeFactory.getChildOfClass(c, HTMLPage.class);
Communication comm = (Communication) InodeFactory.getChildOfClass(c, Communication.class);
UserFilter userfilter = (UserFilter) InodeFactory.getChildOfClass(c, UserFilter.class);
if(InodeUtils.isSet(ml.getInode())){
relationshipAPI.addRelationship(childCampaign.getInode(), ml.getInode(), "child");
}
if(InodeUtils.isSet(page.getInode())){
relationshipAPI.addRelationship(childCampaign.getInode(), page.getInode(), "child");
}
if (InodeUtils.isSet(comm.getInode())) {
relationshipAPI.addRelationship(childCampaign.getInode(), comm.getInode(), "child");
}
if (InodeUtils.isSet(userfilter.getInode())) {
relationshipAPI.addRelationship(childCampaign.getInode(), userfilter.getInode(), "child");
}
HibernateUtil.saveOrUpdate(childCampaign);
campaigns.add(childCampaign);