1 package com.dotmarketing.portlets.campaigns.factories; 2 3 4 import com.dotmarketing.db.DotHibernate; 5 import com.dotmarketing.factories.InodeFactory; 6 import com.dotmarketing.portlets.campaigns.model.Campaign; 7 import com.dotmarketing.portlets.campaigns.model.Click; 8 import com.dotmarketing.portlets.campaigns.model.Recipient; 9 import com.liferay.portal.model.User; 10 11 15 public class RecipientFactory { 16 17 public static Recipient getRecipientByCampaignAndSubscriber(Campaign c, User s) { 18 return (Recipient) InodeFactory.getChildOfClassbyCondition(c, Recipient.class, "email='" + s.getEmailAddress() + "'"); 19 } 20 21 22 23 24 25 26 27 28 29 30 31 private static final String SELECT_RECIPIENTS_WITH_LINK = " SELECT parent from tree, click where child = inode and link like ?"; 32 33 public static final Recipient getRecipient(String id) { 34 try { 35 return getRecipient(Long.parseLong(id)); 36 } 37 catch (Exception e) { 38 return new Recipient(); 39 } 40 } 41 42 public static final Recipient getRecipient(long id) { 43 DotHibernate dh = new DotHibernate(Recipient.class); 44 return (Recipient) dh.load(id); 45 } 46 47 public static final java.util.List getOpenedRecipientsByCampaign(Campaign c) { 48 49 50 return InodeFactory.getChildrenClassByCondition(c, Recipient.class, "opened is not null"); 51 52 53 54 } 55 56 public static final java.util.List getUnopenedRecipientsByCampaign(Campaign c) { 57 58 return InodeFactory.getChildrenClassByCondition(c, Recipient.class, "opened is null"); 59 60 } 61 62 public static final java.util.List getAllRecipientsByCampaign(Campaign c) { 63 64 return InodeFactory.getChildrenClassByOrder(c, Recipient.class, "sent"); 65 66 67 } 68 69 public static final java.util.List getWaitingRecipientsByCampaign(Campaign c) { 70 71 return InodeFactory.getChildrenClassByCondition(c, Recipient.class, "sent is null"); 72 73 74 } 75 76 public static final java.util.List getRecipientsByCampaignAndClick(Campaign q, Click c) { 77 com.dotmarketing.db.DotConnect dbo = new com.dotmarketing.db.DotConnect(); 78 dbo.setSQL(SELECT_RECIPIENTS_WITH_LINK); 79 dbo.addParam(c.getLink()); 80 java.util.Iterator results = dbo.getResults().iterator(); 81 StringBuffer nasty = new StringBuffer ("0"); 82 while (results.hasNext()) { 83 java.util.HashMap hm = (java.util.HashMap ) results.next(); 84 nasty.append("," + hm.get("parent")); 85 } 86 87 DotHibernate dh = new DotHibernate(Recipient.class); 88 dh.setQuery("from inode in class com.dotmarketing.portlets.campaigns.model.Recipient where ? in inode.parents.elements and inode in ( " + nasty + ")"); 89 90 dh.setParam(q.getInode()); 91 java.util.List al = dh.list(); 92 return al; 93 94 } 95 } 96 | Popular Tags |