This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
/
ContactLanguageTeamMembersAction.java
145 lines (121 loc) · 4.77 KB
/
ContactLanguageTeamMembersAction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* Copyright 2016, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/
package org.zanata.action;
import com.google.common.collect.Lists;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.zanata.ApplicationConfiguration;
import org.zanata.common.LocaleId;
import org.zanata.dao.LocaleMemberDAO;
import org.zanata.email.ContactLanguageTeamMembersEmailStrategy;
import org.zanata.email.EmailStrategy;
import org.zanata.i18n.Messages;
import org.zanata.model.HAccount;
import org.zanata.model.HLocale;
import org.zanata.model.HLocaleMember;
import org.zanata.security.annotations.Authenticated;
import org.zanata.security.annotations.CheckLoggedIn;
import org.zanata.service.EmailService;
import org.zanata.service.LocaleService;
import org.zanata.ui.faces.FacesMessages;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
import java.util.List;
/**
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*/
@Named("contactLanguageTeamMembersAction")
@javax.faces.bean.ViewScoped
@Slf4j
public class ContactLanguageTeamMembersAction implements Serializable {
@Inject
@Authenticated
private HAccount authenticatedAccount;
@Inject
private FacesMessages facesMessages;
@Inject
private EmailService emailServiceImpl;
@Inject
private LocaleService localeServiceImpl;
@Inject
private Messages msgs;
@Inject
private ApplicationConfiguration applicationConfiguration;
@Inject
private LocaleMemberDAO localeMemberDAO;
@Getter
@Setter
private String message;
@Getter
@Setter
private String subject;
@Getter
@Setter
private String localeId;
private HLocale locale;
private List<HLocaleMember> getMembers() {
return localeMemberDAO.findActiveMembers(new LocaleId(localeId));
}
@CheckLoggedIn
public void send() {
List<HLocaleMember> members = getMembers();
if(!members.isEmpty()) {
String fromName = authenticatedAccount.getPerson().getName();
String fromLoginName = authenticatedAccount.getUsername();
String replyEmail = authenticatedAccount.getPerson().getEmail();
String contactCoordinatorLink =
applicationConfiguration.getServerPath() +
"/language/view/" + localeId;
String localeNativeName = getLocale().retrieveNativeName();
EmailStrategy strategy =
new ContactLanguageTeamMembersEmailStrategy(
fromLoginName, fromName, replyEmail,
getSubject(),
getLocale().getLocaleId().getId(),
localeNativeName, message, contactCoordinatorLink);
try {
String msg = emailServiceImpl.sendToLanguageTeamMembers(
getLocale().getLocaleId(), strategy, members);
facesMessages.addGlobal(msg);
} catch (Exception e) {
String subject = strategy.getSubject(msgs);
StringBuilder sb =
new StringBuilder()
.append("Failed to send email with subject '")
.append(strategy.getSubject(msgs))
.append("' , message '").append(message)
.append("'");
log.error(
"Failed to send email: fromName '{}', fromLoginName '{}', replyEmail '{}', subject '{}', message '{}'. {}",
fromName, fromLoginName, replyEmail, subject, message, e);
facesMessages.addGlobal(sb.toString());
}
}
}
public HLocale getLocale() {
if (locale == null) {
locale = localeServiceImpl.getByLocaleId(new LocaleId(localeId));
}
return locale;
}
}