public void copySubscribers(AEntity from, AEntity to) { Subscription fromSubscription = subscriptionDao.getSubscriptionBySubject(from); if (fromSubscription == null || fromSubscription.isSubscribersEmailsEmpty()) return; Subscription toSubscription = subscriptionDao.getSubscriptionBySubject(to); if (toSubscription == null) toSubscription = subscriptionDao.postSubscription(to); toSubscription.addSubscribersEmails(fromSubscription.getSubscribersEmails()); }
public void subscribe(String email, AEntity subject) { if (!Str.isEmail(email)) throw new RuntimeException("Invalid email: " + email); email = email.toLowerCase(); Subscription subscription = subscriptionDao.getSubscriptionBySubject(subject); if (subscription == null) subscription = subscriptionDao.postSubscription(subject); subscription.addSubscribersEmail(email); log.info(email, "subscribed to", subject); }
private void unsubscribeAll(String email, String key) { email = email.toLowerCase(); Set<Subscription> subscriptions = subscriptionDao.getSubscriptionsBySubscribersEmail(email); if (subscriptions.isEmpty()) { log.debug(email, "is not subscribed to anything"); return; } for (Subscription subscription : subscriptions) { subscription.removeSubscribersEmail(email); } log.info(email, "unsubscribed from", subscriptions.size(), "entities"); }
public void unsubscribe(String email, AEntity subject, String key) throws InvalidKeyException { email = email.toLowerCase(); if (!createKey(email).equals(key)) throw new InvalidKeyException(email); if (subject == null) { unsubscribeAll(email, key); return; } Subscription subscription = subscriptionDao.getSubscriptionBySubject(subject); if (subscription == null || !subscription.containsSubscribersEmail(email)) { log.debug(email, "is not subscribed to", subject); return; } subscription.removeSubscribersEmail(email); log.info(email, "unsubscribed from", subject); }
@Override public void unsubscribe(Subscription subscription) { SilverTrace.info("subscribe", "SubscribeBmEJB.unsubscribe", "root.MSG_GEN_ENTER_METHOD"); Connection con = null; try { con = getConnection(); subscriptionDao.remove(con, subscription); } catch (SQLException e) { DBUtil.rollback(con); throw new SubscribeRuntimeException( "SubscribeBmEJB.removeSubscribe()", SilverpeasRuntimeException.ERROR, "subscribe.CANNOT_REMOVE_SUBSCRIBE", e); } finally { DBUtil.close(con); } }
/** * Method declaration * * @param node * @return * @see */ @Override public Collection<String> getSubscribers(WAPrimaryKey pk) { SilverTrace.info( "subscribe", "SubscribeBmEJB.getNodeSubscribersId", "root.MSG_GEN_ENTER_METHOD"); Connection con = null; try { con = getConnection(); return subscriptionDao.getSubscribers(con, pk); } catch (Exception e) { throw new SubscribeRuntimeException( "SubscribeBmEJB.getNodeSubscribersId()", SilverpeasRuntimeException.ERROR, "subscribe.CANNOT_GET_NODE_SUBSCRIBERS", e); } finally { DBUtil.close(con); } }
/** * Method declaration * * @param userId * @return * @see */ @Override public Collection<? extends Subscription> getUserSubscriptions(String userId) { SilverTrace.info( "subscribe", "SubscribeBmEJB.getUserSubscriptions", "root.MSG_GEN_ENTER_METHOD"); Connection con = null; try { con = getConnection(); return subscriptionDao.getSubscriptionsBySubscriber(con, userId); } catch (Exception e) { throw new SubscribeRuntimeException( "SubscribeBmEJB.getUserSubscriptions()", SilverpeasRuntimeException.ERROR, "subscribe.CANNOT_GET_USER_SUBSCRIBES", e); } finally { DBUtil.close(con); } }
/** * Method declaration * * @param node * @param path * @see */ @Override public void unsubscribeByPath(NodePK node, String path) { SilverTrace.info( "subscribe", "SubscribeBmEJB.removeSubscriptionsByPath", "root.MSG_GEN_ENTER_METHOD"); Connection con = null; try { con = getConnection(); subscriptionDao.removeByNodePath(con, node.getComponentName(), path); } catch (SQLException e) { DBUtil.rollback(con); throw new SubscribeRuntimeException( "SubscribeBmEJB.removeSubscriptionsByPath()", SilverpeasRuntimeException.ERROR, "subscribe.CANNOT_REMOVE_NODE_SUBSCRIBES", e); } finally { DBUtil.close(con); } }
/** * Method declaration * * @param userId * @param componentName * @return * @see */ @Override public Collection<? extends Subscription> getUserSubscriptionsByComponent( String userId, String componentName) { SilverTrace.info( "subscribe", "SubscribeBmEJB.getUserSubscriptionsByComponent", "root.MSG_GEN_ENTER_METHOD"); Connection con = null; try { con = getConnection(); return subscriptionDao.getSubscriptionsBySubscriberAndComponent(con, userId, componentName); } catch (Exception e) { throw new SubscribeRuntimeException( "SubscribeBmEJB.getUserSubscribesPKsByspaceAndcomponent()", SilverpeasRuntimeException.ERROR, "subscribe.CANNOT_GET_USER_SUBSCRIBES_SPACE_COMPONENT", e); } finally { DBUtil.close(con); } }
public void notifySubscribers( AEntity subject, String message, Project project, String exceptionEmail) { Subscription subscription = subscriptionDao.getSubscriptionBySubject(subject); if (subscription == null || subscription.isSubscribersEmailsEmpty()) { log.debug("No subscribers for", subject); return; } Set<String> subscribersEmails = subscription.getSubscribersEmails(); if (exceptionEmail != null) subscribersEmails.remove(exceptionEmail.toLowerCase()); if (subscribersEmails.isEmpty()) { log.debug("No subscribers for", subject); return; } synchronized (notifications) { for (Notification notification : notifications) { if (!notification.subject.equals(subject)) continue; notification.merge(message, subscribersEmails); return; } notifications.add(new Notification(subject, message, project, subscribersEmails)); } }