From 0ff7fd2338437550cb14ca9a81719d0fa3cb4700 Mon Sep 17 00:00:00 2001 From: Yang Zhenhui Date: Fri, 21 Dec 2012 14:06:09 +0800 Subject: [PATCH] Move project and branch info to new base class NotificationEmail Class NotificationEmail holds data about project and branch, and let the class ChangeEmail only hold change and patchset info, then for emails that are not related to change and patchset, such as direct pushed email, they can use class NotificationEmail as base class. Change-Id: I57c71c8a10857f7c03c6ed476c79401018e6d343 --- .../gerrit/server/mail/ChangeEmail.java | 7 +--- .../gerrit/server/mail/NotificationEmail.java | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 gerrit-server/src/main/java/com/google/gerrit/server/mail/NotificationEmail.java diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/mail/ChangeEmail.java b/gerrit-server/src/main/java/com/google/gerrit/server/mail/ChangeEmail.java index f18154be4e..3175b9bf3b 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/mail/ChangeEmail.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/mail/ChangeEmail.java @@ -65,7 +65,7 @@ import java.util.Set; import java.util.TreeSet; /** Sends an email to one or more interested parties. */ -public abstract class ChangeEmail extends OutgoingEmail { +public abstract class ChangeEmail extends NotificationEmail { private static final Logger log = LoggerFactory.getLogger(ChangeEmail.class); protected final Change change; @@ -80,7 +80,7 @@ public abstract class ChangeEmail extends OutgoingEmail { protected ChangeEmail(EmailArguments ea, final String anonymousCowardName, final Change c, final String mc) { - super(ea, anonymousCowardName, mc); + super(ea, anonymousCowardName, mc, c.getProject(), c.getDest()); change = c; changeData = new ChangeData(change); emailOnlyAuthors = false; @@ -571,10 +571,7 @@ public abstract class ChangeEmail extends OutgoingEmail { velocityContext.put("change", change); velocityContext.put("changeId", change.getKey()); velocityContext.put("coverLetter", getCoverLetter()); - velocityContext.put("branch", change.getDest()); velocityContext.put("fromName", getNameFor(fromId)); - velocityContext.put("projectName", // - projectState != null ? projectState.getProject().getName() : null); velocityContext.put("patchSet", patchSet); velocityContext.put("patchSetInfo", patchSetInfo); } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/mail/NotificationEmail.java b/gerrit-server/src/main/java/com/google/gerrit/server/mail/NotificationEmail.java new file mode 100644 index 0000000000..b0d5862027 --- /dev/null +++ b/gerrit-server/src/main/java/com/google/gerrit/server/mail/NotificationEmail.java @@ -0,0 +1,41 @@ +// Copyright (C) 2012 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.server.mail; + +import com.google.gerrit.reviewdb.client.Branch; +import com.google.gerrit.reviewdb.client.Project; + +/** + * Common class for notifications that are related to a project and branch + */ +public abstract class NotificationEmail extends OutgoingEmail { + protected Project.NameKey project; + protected Branch.NameKey branch; + + protected NotificationEmail(EmailArguments ea, String anonymousCowardName, + String mc, Project.NameKey project, Branch.NameKey branch) { + super(ea, anonymousCowardName, mc); + + this.project = project; + this.branch = branch; + } + + @Override + protected void setupVelocityContext() { + super.setupVelocityContext(); + velocityContext.put("projectName", project.get()); + velocityContext.put("branch", branch); + } +} \ No newline at end of file