Added recipients sets for a number of predefined groups that will receive e-mails. Still needs some kind of split into different mails when list of recipients is to long.
This commit is contained in:
parent
1b487ae750
commit
cca16fda2f
src/main/java/se/su/dsv/scipro
admin/panels
data
@ -3,8 +3,9 @@
|
||||
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
|
||||
<body>
|
||||
<wicket:panel>
|
||||
<h5>Mail from administrator</h5>
|
||||
<h5 class="peer-title">Mail from administrator</h5>
|
||||
<div wicket:id="feedbackPanel"></div>
|
||||
<b>Recipients:</b>
|
||||
<div class="append-bottom" wicket:id="radioChoices">
|
||||
<input type="radio"/>
|
||||
</div>
|
||||
|
@ -25,7 +25,6 @@ import org.apache.wicket.validation.validator.StringValidator;
|
||||
|
||||
import se.su.dsv.scipro.data.dao.interfaces.GeneralSystemSettingsDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.MailEventDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.GeneralSystemSettings;
|
||||
import se.su.dsv.scipro.data.dataobjects.MailEvent;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
@ -33,8 +32,6 @@ import se.su.dsv.scipro.data.facade.MailFacade;
|
||||
|
||||
public class AdminMailPanel extends Panel {
|
||||
|
||||
@SpringBean
|
||||
private UserDao userDao;
|
||||
@SpringBean
|
||||
private MailEventDao mailEventDao;
|
||||
@SpringBean
|
||||
@ -45,17 +42,15 @@ public class AdminMailPanel extends Panel {
|
||||
private Set<User> userSet;
|
||||
private static final Logger logger = Logger.getLogger(AdminMailPanel.class);
|
||||
private final String AUTHORS_JUSTME = "Just me"; //Dev purposes
|
||||
private final String AUTHORS_ACTIVE_PROJECT = "Authors with active projects";
|
||||
private final String AUTHORS_ALL = "All authors";
|
||||
// private final String AUTHORS_CONFIRMED = "Authors with confirmed project ideas";
|
||||
// private final String AUTHORS_UNCONFIRMED = "Authors with unconfirmed project ideas";
|
||||
private final String AUTHORS_ACTIVE_PROJECT = "All authors with active projects";
|
||||
private final String AUTHORS_ACTIVE_BACHELOR = "Authors with active bachelor projects";
|
||||
private final String AUTHORS_ACTIVE_MASTER = "Authors with active master projects";
|
||||
private final String AUTHORS_CONFIRMED = "Authors with confirmed project ideas";
|
||||
private final String AUTHORS_REFUSED = "Authors with refused project ideas";
|
||||
private final String SUPERVISOR_ALL = "All supervisors";
|
||||
// private final String SUPERVISOR_CONFIRMED = "Supervisors with confirmed project ideas";
|
||||
private final String SUPERVISOR_UNCONFIRMED = "Supervisors with unconfirmed project ideas";
|
||||
// private final String AUTHORS = "authors";
|
||||
private final String THESISSUPPORT = "Thesis support";
|
||||
// private final String SUPERVISOR = "supervisor";
|
||||
private final String SUPERVISOR_CONFIRMED = "Supervisors with confirmed project ideas";
|
||||
private final String SUPERVISOR_UNCONFIRMED = "Supervisors with project ideas waiting to be confirmed";
|
||||
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ -94,6 +89,7 @@ public class AdminMailPanel extends Panel {
|
||||
add(disabledLabel);
|
||||
|
||||
Button submitButton = new Button("submitButton");
|
||||
//TODO Remove comments.
|
||||
//submitButton.setEnabled(gsettings.isMailNotifications()); <-- Commented out for testing purposes.
|
||||
submitButton.add(new SimpleAttributeModifier(
|
||||
"onclick",
|
||||
@ -115,9 +111,14 @@ public class AdminMailPanel extends Panel {
|
||||
protected void onSubmit() {
|
||||
|
||||
try {
|
||||
MailEvent me = new MailEvent(mailSubjectField.getInput(), mailBodyField.getInput(), userSet, fromName, fromEmail);
|
||||
me = mailEventDao.save(me);
|
||||
info("E-mail sent successfully to the following users: " + me.getRecipients());
|
||||
for (User u : userSet) {
|
||||
System.out.println(u.getEmailAddress());
|
||||
}
|
||||
System.out.println(userSet.size());
|
||||
|
||||
//MailEvent me = new MailEvent(mailSubjectField.getInput(), mailBodyField.getInput(), userSet, fromName, fromEmail);
|
||||
//me = mailEventDao.save(me);
|
||||
//info("E-mail sent successfully to the selected recipients!);
|
||||
} catch (Exception e) {
|
||||
logger.info("Failed to send e-mail");
|
||||
}
|
||||
@ -126,8 +127,8 @@ public class AdminMailPanel extends Panel {
|
||||
}
|
||||
|
||||
private void setUpRadioButtons() {
|
||||
List<String> options = Arrays.asList(new String[]{AUTHORS_JUSTME,AUTHORS_ALL,AUTHORS_ACTIVE_PROJECT,AUTHORS_REFUSED,THESISSUPPORT,SUPERVISOR_ALL, SUPERVISOR_UNCONFIRMED});
|
||||
final RadioChoice<String> choice = new RadioChoice<String>("radioChoices",Model.of(AUTHORS_ALL), options);
|
||||
List<String> options = Arrays.asList(new String[]{AUTHORS_JUSTME,AUTHORS_ACTIVE_PROJECT,AUTHORS_ACTIVE_BACHELOR,AUTHORS_ACTIVE_MASTER,AUTHORS_CONFIRMED,AUTHORS_REFUSED,SUPERVISOR_ALL,SUPERVISOR_CONFIRMED, SUPERVISOR_UNCONFIRMED});
|
||||
final RadioChoice<String> choice = new RadioChoice<String>("radioChoices",Model.of(AUTHORS_JUSTME), options);
|
||||
|
||||
//Default values, taken from RadioChoice constructor above (Model.of(your choice)).
|
||||
userSet = new HashSet<User>();
|
||||
@ -153,15 +154,28 @@ public class AdminMailPanel extends Panel {
|
||||
recipients = mailFacade.addJustMe();
|
||||
}
|
||||
else if(choiceInput.equals(AUTHORS_ACTIVE_PROJECT)) {
|
||||
recipients = mailFacade.addActiveAuthors();
|
||||
}
|
||||
else if(choiceInput.equals(AUTHORS_ACTIVE_BACHELOR)) {
|
||||
recipients = mailFacade.addActiveBachelorAuthors();
|
||||
}
|
||||
else if(choiceInput.equals(AUTHORS_ACTIVE_MASTER)) {
|
||||
recipients = mailFacade.addActiveMasterAuthors();
|
||||
}
|
||||
else if(choiceInput.equals(AUTHORS_CONFIRMED)) {
|
||||
recipients = mailFacade.addAuthorsWithConfirmedIdeas();
|
||||
}
|
||||
else if(choiceInput.equals(AUTHORS_REFUSED)) {
|
||||
recipients = mailFacade.addAuthorsWithRefusedIdeas();
|
||||
}
|
||||
else if(choiceInput.equals(THESISSUPPORT)) {
|
||||
|
||||
else if(choiceInput.equals(SUPERVISOR_ALL)) {
|
||||
recipients = mailFacade.addAllSupervisors();
|
||||
}
|
||||
else if(choiceInput.equals(SUPERVISOR_ALL)) {
|
||||
else if(choiceInput.equals(SUPERVISOR_CONFIRMED)) {
|
||||
recipients = mailFacade.addSupervisorsWithConfirmedIdeas();
|
||||
}
|
||||
else if(choiceInput.equals(SUPERVISOR_UNCONFIRMED)) {
|
||||
recipients = mailFacade.addSupervisorsWithUnconfirmedIdeas();
|
||||
}
|
||||
return recipients;
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.Log;
|
||||
import se.su.dsv.scipro.data.dataobjects.Project;
|
||||
import se.su.dsv.scipro.data.dataobjects.ProjectClass;
|
||||
import se.su.dsv.scipro.data.dataobjects.Student;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.data.enums.ProjectStatus;
|
||||
import se.su.dsv.scipro.data.enums.ProjectTeamMemberRoles;
|
||||
@ -522,6 +523,8 @@ public class ProjectDaoJPAImp extends AbstractDaoJPAImp<Project> implements Proj
|
||||
.projectStatuses(params.getProjectStatuses())
|
||||
.createdAfter(params.getCreatedAfter())
|
||||
.createdBefore(params.getCreatedBefore())
|
||||
.authors(params.getAuthors())
|
||||
// .creator(params.getCreator())
|
||||
.sortField(params.getSortField(), params.getDirection())
|
||||
.limit(params.getLimit())
|
||||
.offset(params.getOffset());
|
||||
@ -568,6 +571,29 @@ public class ProjectDaoJPAImp extends AbstractDaoJPAImp<Project> implements Proj
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public QuerySet authors(Collection<Student> authors) {
|
||||
if (authors != null && !authors.isEmpty()) {
|
||||
getQuery().combine(
|
||||
new Query()
|
||||
.join("_.projectParticipants a")
|
||||
.where("a IN (:authors)")
|
||||
.parameter("authors", authors)
|
||||
.distinct());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
// public QuerySet creator(User user) {
|
||||
// if (user != null) {
|
||||
// getQuery().combine(
|
||||
// new Query()
|
||||
// .where("_.creator = :user")
|
||||
// .parameter("user", user));
|
||||
// }
|
||||
// return this;
|
||||
// }
|
||||
|
||||
public QuerySet createdAfter(Date createdAfter) {
|
||||
if (createdAfter != null) {
|
||||
|
@ -1,14 +1,27 @@
|
||||
package se.su.dsv.scipro.data.facade;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectClassDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.Employee;
|
||||
import se.su.dsv.scipro.data.dataobjects.Project;
|
||||
import se.su.dsv.scipro.data.dataobjects.ProjectClass;
|
||||
import se.su.dsv.scipro.data.dataobjects.Student;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.data.enums.ProjectStatus;
|
||||
import se.su.dsv.scipro.match.dao.interfaces.ProjectIdeaDao;
|
||||
import se.su.dsv.scipro.match.dao.interfaces.SupervisorDao;
|
||||
import se.su.dsv.scipro.match.dataobject.Match;
|
||||
import se.su.dsv.scipro.match.dataobject.Match.Status;
|
||||
import se.su.dsv.scipro.match.dataobject.ProjectIdea;
|
||||
|
||||
@Service
|
||||
public class MailFacade {
|
||||
@ -17,6 +30,16 @@ public class MailFacade {
|
||||
private UserDao userDao;
|
||||
@Autowired
|
||||
private ProjectDao projectDao;
|
||||
@Autowired
|
||||
private SupervisorDao supervisorDao;
|
||||
@Autowired
|
||||
private ProjectClassDao projectClassDao;
|
||||
@Autowired
|
||||
private ProjectIdeaDao projectIdeaDao;
|
||||
|
||||
private ProjectDao.Params projectParams;
|
||||
private ProjectIdeaDao.Params projectIdeaParams;
|
||||
private Set<User> recipients;
|
||||
|
||||
public Set<User> addJustMe() {
|
||||
Set<User> recipients = new HashSet<User>();
|
||||
@ -25,4 +48,97 @@ public class MailFacade {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Set<User> addAllSupervisors() {
|
||||
recipients = new HashSet<User>();
|
||||
List<Employee> allSupervisors = supervisorDao.findAll();
|
||||
for (Employee e : allSupervisors) {
|
||||
recipients.add(e.getUser());
|
||||
}
|
||||
return recipients;
|
||||
}
|
||||
|
||||
public Set<User> addActiveAuthors() {
|
||||
setProjectParams(ProjectStatus.ACTIVE, null);
|
||||
return authorsFromProjects();
|
||||
}
|
||||
|
||||
public Set<User> addActiveBachelorAuthors() {
|
||||
setProjectParams(ProjectStatus.ACTIVE, ProjectClass.BACHELOR);
|
||||
return authorsFromProjects();
|
||||
}
|
||||
|
||||
public Set<User> addActiveMasterAuthors() {
|
||||
setProjectParams(ProjectStatus.ACTIVE, ProjectClass.MASTER);
|
||||
return authorsFromProjects();
|
||||
}
|
||||
|
||||
public Set<User> addAuthorsWithRefusedIdeas() {
|
||||
setProjectIdeaParams(Match.Status.REFUSED);
|
||||
return authorsFromProjectIdeas();
|
||||
}
|
||||
|
||||
public Set<User> addAuthorsWithConfirmedIdeas() {
|
||||
setProjectIdeaParams(Match.Status.CONFIRMED);
|
||||
return authorsFromProjectIdeas();
|
||||
}
|
||||
|
||||
public Set<User> addSupervisorsWithUnconfirmedIdeas() {
|
||||
setProjectIdeaParams(Match.Status.PUBLISHED);
|
||||
return supervisorsFromProjectIdeas();
|
||||
}
|
||||
|
||||
public Set<User> addSupervisorsWithConfirmedIdeas() {
|
||||
setProjectIdeaParams(Match.Status.CONFIRMED);
|
||||
return supervisorsFromProjectIdeas();
|
||||
}
|
||||
|
||||
private void setProjectIdeaParams(Status matchStatus) {
|
||||
projectIdeaParams = new ProjectIdeaDao.Params();
|
||||
if(matchStatus != null)
|
||||
projectIdeaParams.setStatuses(Arrays.asList(new Status[]{matchStatus}));
|
||||
|
||||
}
|
||||
|
||||
private void setProjectParams(ProjectStatus status, String projectClass) {
|
||||
projectParams = new ProjectDao.Params();
|
||||
if (status != null)
|
||||
projectParams.setProjectStatuses(Arrays.asList(new ProjectStatus[]{status}));
|
||||
if (projectClass != null)
|
||||
projectParams.setProjectClasses(Arrays.asList(new ProjectClass[]{projectClassDao.getProjectClass(projectClass)}));
|
||||
}
|
||||
|
||||
private Set<User> authorsFromProjectIdeas() {
|
||||
List<ProjectIdea> listOfIdeas = projectIdeaDao.findProjectIdeas(projectIdeaParams);
|
||||
recipients = new HashSet<User>();
|
||||
for (ProjectIdea idea : listOfIdeas) {
|
||||
for (Student s : idea.getAuthors())
|
||||
recipients.add(s.getUser());
|
||||
}
|
||||
return recipients;
|
||||
}
|
||||
|
||||
private Set<User> supervisorsFromProjectIdeas() {
|
||||
List<ProjectIdea> listOfIdeas = projectIdeaDao.findProjectIdeas(projectIdeaParams);
|
||||
recipients = new HashSet<User>();
|
||||
for (ProjectIdea idea : listOfIdeas) {
|
||||
recipients.add(idea.getMatch().getSupervisor().getUser());
|
||||
}
|
||||
return recipients;
|
||||
}
|
||||
|
||||
private Set<User> authorsFromProjects() {
|
||||
List<Project> listOfProjects = projectDao.findProjects(projectParams);
|
||||
recipients = new HashSet<User>();
|
||||
for (Project p : listOfProjects) {
|
||||
for (Student s : p.getProjectParticipants())
|
||||
recipients.add(s.getUser());
|
||||
}
|
||||
return recipients;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user