001/*
002 * (C) Copyright 2007-2008 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nuxeo - initial API and implementation
018 *
019 * $Id$
020 */
021
022package org.nuxeo.ecm.platform.ec.notification;
023
024import java.util.Arrays;
025
026import org.nuxeo.ecm.core.api.CoreSession;
027import org.nuxeo.ecm.core.api.DocumentModel;
028import org.nuxeo.ecm.platform.notification.api.Notification;
029
030/**
031 * A notification that a user can subscribe to.
032 * <p>
033 * It has:
034 * <ul>
035 * <li>a name
036 * <li>a channel - for now only email is supported
037 * <li>a subject - as a fixed string or a template to customize subject notifications
038 * <li>a template - so the notifications that the user will receive can be customized
039 * </ul>
040 *
041 * @author <a href="mailto:npaslaru@nuxeo.com">Narcis Paslaru</a>
042 * @author <a href="mailto:tmartins@nuxeo.com">Thierry Martins</a>
043 */
044public class NotificationImpl implements Notification {
045
046    private static final long serialVersionUID = 6550698875484943882L;
047
048    private final String name;
049
050    private final String template;
051
052    private final String subjectTemplate;
053
054    private final String subject;
055
056    private final String channel;
057
058    private final boolean autoSubscribed;
059
060    private final String availableIn;
061
062    private final String label;
063
064    private boolean enabled;
065
066    private String templateExpr;
067
068    public NotificationImpl(String name, String template, String channel, String subjectTemplate,
069            boolean autoSubscribed, String subject, String availableIn, String label) {
070        this.name = name;
071        this.template = template;
072        this.channel = channel;
073        this.subjectTemplate = subjectTemplate;
074        this.autoSubscribed = autoSubscribed;
075        this.subject = subject;
076        this.availableIn = availableIn;
077        this.label = label;
078    }
079
080    /**
081     * @since 5.6
082     */
083    public void setTemplateExpr(String templateExpr) {
084        this.templateExpr = templateExpr;
085    }
086
087    @Override
088    public String getName() {
089        return name;
090    }
091
092    @Override
093    public String getChannel() {
094        return channel;
095    }
096
097    @Override
098    public String getTemplate() {
099        return template;
100    }
101
102    @Override
103    public boolean getAutoSubscribed() {
104        return autoSubscribed;
105    }
106
107    @Override
108    public String getSubject() {
109        return subject;
110    }
111
112    @Override
113    public String getSubjectTemplate() {
114        return subjectTemplate;
115    }
116
117    @Override
118    public String getAvailableIn() {
119        return availableIn;
120    }
121
122    @Override
123    public String getLabel() {
124        return label;
125    }
126
127    @Override
128    public boolean equals(Object obj) {
129        if (obj == this) {
130            return true;
131        }
132        if (obj instanceof NotificationImpl) {
133            NotificationImpl other = (NotificationImpl) obj;
134            return name.equals(other.name);
135        }
136        return false;
137    }
138
139    @Override
140    public int hashCode() {
141        return name.hashCode();
142    }
143
144    @Override
145    public boolean getEnabled() {
146        return enabled;
147    }
148
149    public void setEnabled(boolean enabled) {
150        this.enabled = enabled;
151    }
152
153    @Override
154    public String getTemplateExpr() {
155        return templateExpr;
156    }
157
158}