001/* 002 * (C) Copyright 2007-2008 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Nuxeo - initial API and implementation 016 * 017 * $Id$ 018 */ 019 020package org.nuxeo.ecm.platform.ec.notification; 021 022import java.util.Arrays; 023 024import org.nuxeo.ecm.core.api.CoreSession; 025import org.nuxeo.ecm.core.api.DocumentModel; 026import org.nuxeo.ecm.platform.notification.api.Notification; 027 028/** 029 * A notification that a user can subscribe to. 030 * <p> 031 * It has: 032 * <ul> 033 * <li>a name 034 * <li>a channel - for now only email is supported 035 * <li>a subject - as a fixed string or a template to customize subject notifications 036 * <li>a template - so the notifications that the user will receive can be customized 037 * </ul> 038 * 039 * @author <a href="mailto:npaslaru@nuxeo.com">Narcis Paslaru</a> 040 * @author <a href="mailto:tmartins@nuxeo.com">Thierry Martins</a> 041 */ 042public class NotificationImpl implements Notification { 043 044 private static final long serialVersionUID = 6550698875484943882L; 045 046 private final String name; 047 048 private final String template; 049 050 private final String subjectTemplate; 051 052 private final String subject; 053 054 private final String channel; 055 056 private final boolean autoSubscribed; 057 058 private final String availableIn; 059 060 private final String label; 061 062 private boolean enabled; 063 064 private String templateExpr; 065 066 public NotificationImpl(String name, String template, String channel, String subjectTemplate, 067 boolean autoSubscribed, String subject, String availableIn, String label) { 068 this.name = name; 069 this.template = template; 070 this.channel = channel; 071 this.subjectTemplate = subjectTemplate; 072 this.autoSubscribed = autoSubscribed; 073 this.subject = subject; 074 this.availableIn = availableIn; 075 this.label = label; 076 } 077 078 /** 079 * @since 5.6 080 */ 081 public void setTemplateExpr(String templateExpr) { 082 this.templateExpr = templateExpr; 083 } 084 085 @Override 086 public String getName() { 087 return name; 088 } 089 090 @Override 091 public String getChannel() { 092 return channel; 093 } 094 095 @Override 096 public String getTemplate() { 097 return template; 098 } 099 100 @Override 101 public boolean getAutoSubscribed() { 102 return autoSubscribed; 103 } 104 105 @Override 106 public String getSubject() { 107 return subject; 108 } 109 110 @Override 111 public String getSubjectTemplate() { 112 return subjectTemplate; 113 } 114 115 @Override 116 public String getAvailableIn() { 117 return availableIn; 118 } 119 120 @Override 121 public String getLabel() { 122 return label; 123 } 124 125 @Override 126 public boolean equals(Object obj) { 127 if (obj == this) { 128 return true; 129 } 130 if (obj instanceof NotificationImpl) { 131 NotificationImpl other = (NotificationImpl) obj; 132 return name.equals(other.name); 133 } 134 return false; 135 } 136 137 @Override 138 public int hashCode() { 139 return name.hashCode(); 140 } 141 142 @Override 143 public boolean getEnabled() { 144 return enabled; 145 } 146 147 public void setEnabled(boolean enabled) { 148 this.enabled = enabled; 149 } 150 151 @Override 152 public String getTemplateExpr() { 153 return templateExpr; 154 } 155 156}