Updates to email notification routines
This commit is contained in:
parent
aade5c1743
commit
02800f97db
10 changed files with 53 additions and 30 deletions
|
|
@ -26,6 +26,7 @@ import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.Criteria;
|
import org.hibernate.Criteria;
|
||||||
import org.hibernate.criterion.Restrictions;
|
import org.hibernate.criterion.Restrictions;
|
||||||
|
import org.libreplan.business.common.Registry;
|
||||||
import org.libreplan.business.common.daos.GenericDAOHibernate;
|
import org.libreplan.business.common.daos.GenericDAOHibernate;
|
||||||
import org.libreplan.business.orders.entities.Order;
|
import org.libreplan.business.orders.entities.Order;
|
||||||
import org.libreplan.business.users.entities.OrderAuthorization;
|
import org.libreplan.business.users.entities.OrderAuthorization;
|
||||||
|
|
@ -68,6 +69,7 @@ public class OrderAuthorizationDAO extends GenericDAOHibernate<OrderAuthorizatio
|
||||||
public List<OrderAuthorization> listByUserAndItsProfiles(User user) {
|
public List<OrderAuthorization> listByUserAndItsProfiles(User user) {
|
||||||
List<OrderAuthorization> list = new ArrayList<OrderAuthorization>();
|
List<OrderAuthorization> list = new ArrayList<OrderAuthorization>();
|
||||||
list.addAll(listByUser(user));
|
list.addAll(listByUser(user));
|
||||||
|
Registry.getUserDAO().reattach(user);
|
||||||
for(Profile profile : user.getProfiles()) {
|
for(Profile profile : user.getProfiles()) {
|
||||||
list.addAll(listByProfile(profile));
|
list.addAll(listByProfile(profile));
|
||||||
}
|
}
|
||||||
|
|
@ -79,6 +81,7 @@ public class OrderAuthorizationDAO extends GenericDAOHibernate<OrderAuthorizatio
|
||||||
if (!listByUser(user).isEmpty()) {
|
if (!listByUser(user).isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Registry.getUserDAO().reattach(user);
|
||||||
for (Profile profile : user.getProfiles()) {
|
for (Profile profile : user.getProfiles()) {
|
||||||
if (!listByProfile(profile).isEmpty()) {
|
if (!listByProfile(profile).isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -108,6 +111,7 @@ public class OrderAuthorizationDAO extends GenericDAOHibernate<OrderAuthorizatio
|
||||||
public List<OrderAuthorization> listByOrderUserAndItsProfiles(Order order, User user) {
|
public List<OrderAuthorization> listByOrderUserAndItsProfiles(Order order, User user) {
|
||||||
List<OrderAuthorization> list = new ArrayList<OrderAuthorization>();
|
List<OrderAuthorization> list = new ArrayList<OrderAuthorization>();
|
||||||
list.addAll(listByOrderAndUser(order,user));
|
list.addAll(listByOrderAndUser(order,user));
|
||||||
|
Registry.getUserDAO().reattach(user);
|
||||||
for(Profile profile : user.getProfiles()) {
|
for(Profile profile : user.getProfiles()) {
|
||||||
list.addAll(listByOrderAndProfile(order, profile));
|
list.addAll(listByOrderAndProfile(order, profile));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -150,7 +150,7 @@ public class SchedulerManager implements ISchedulerManager {
|
||||||
String triggerName = jobSchedulerConfiguration.getJobName() + TRIGGER_SUFFIX;
|
String triggerName = jobSchedulerConfiguration.getJobName() + TRIGGER_SUFFIX;
|
||||||
String triggerGroup = jobSchedulerConfiguration.getJobGroup() + TRIGGER_SUFFIX;
|
String triggerGroup = jobSchedulerConfiguration.getJobGroup() + TRIGGER_SUFFIX;
|
||||||
|
|
||||||
CronTriggerFactoryBean trigger = getTriggerBean(triggerName, triggerGroup);
|
CronTrigger trigger = getTriggerBean(triggerName, triggerGroup);
|
||||||
if ( trigger == null ) {
|
if ( trigger == null ) {
|
||||||
LOG.warn("Trigger not found");
|
LOG.warn("Trigger not found");
|
||||||
|
|
||||||
|
|
@ -164,7 +164,7 @@ public class SchedulerManager implements ISchedulerManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
// deleteJob doesn't work using unscheduleJob
|
// deleteJob doesn't work using unscheduleJob
|
||||||
this.scheduler.unscheduleJob(trigger.getObject().getKey());
|
this.scheduler.unscheduleJob(trigger.getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -230,7 +230,7 @@ public class SchedulerManager implements ISchedulerManager {
|
||||||
* create it
|
* create it
|
||||||
*/
|
*/
|
||||||
private CronTriggerFactoryBean createCronTriggerBean(JobSchedulerConfiguration jobSchedulerConfiguration) {
|
private CronTriggerFactoryBean createCronTriggerBean(JobSchedulerConfiguration jobSchedulerConfiguration) {
|
||||||
CronTriggerFactoryBean cronTriggerBean = new CronTriggerFactoryBean();
|
final CronTriggerFactoryBean cronTriggerBean = new CronTriggerFactoryBean();
|
||||||
cronTriggerBean.setName(jobSchedulerConfiguration.getJobName() + TRIGGER_SUFFIX);
|
cronTriggerBean.setName(jobSchedulerConfiguration.getJobName() + TRIGGER_SUFFIX);
|
||||||
cronTriggerBean.setGroup(jobSchedulerConfiguration.getJobGroup() + TRIGGER_SUFFIX);
|
cronTriggerBean.setGroup(jobSchedulerConfiguration.getJobGroup() + TRIGGER_SUFFIX);
|
||||||
|
|
||||||
|
|
@ -238,8 +238,7 @@ public class SchedulerManager implements ISchedulerManager {
|
||||||
cronTriggerBean.setCronExpression(
|
cronTriggerBean.setCronExpression(
|
||||||
String.valueOf(new CronExpression(jobSchedulerConfiguration.getCronExpression())));
|
String.valueOf(new CronExpression(jobSchedulerConfiguration.getCronExpression())));
|
||||||
|
|
||||||
cronTriggerBean.setName(jobSchedulerConfiguration.getJobName());
|
cronTriggerBean.afterPropertiesSet();
|
||||||
cronTriggerBean.setGroup(jobSchedulerConfiguration.getJobGroup());
|
|
||||||
|
|
||||||
return cronTriggerBean;
|
return cronTriggerBean;
|
||||||
|
|
||||||
|
|
@ -259,7 +258,7 @@ public class SchedulerManager implements ISchedulerManager {
|
||||||
* @return the created <code>JobDetailFactoryBean</code> or null if unable to it
|
* @return the created <code>JobDetailFactoryBean</code> or null if unable to it
|
||||||
*/
|
*/
|
||||||
private JobDetailFactoryBean createJobDetailBean(JobSchedulerConfiguration jobSchedulerConfiguration) {
|
private JobDetailFactoryBean createJobDetailBean(JobSchedulerConfiguration jobSchedulerConfiguration) {
|
||||||
JobDetailFactoryBean jobDetailBean = new JobDetailFactoryBean();
|
final JobDetailFactoryBean jobDetailBean = new JobDetailFactoryBean();
|
||||||
|
|
||||||
Class<?> jobClass = getJobClass(jobSchedulerConfiguration.getJobClassName());
|
Class<?> jobClass = getJobClass(jobSchedulerConfiguration.getJobClassName());
|
||||||
if ( jobClass == null ) {
|
if ( jobClass == null ) {
|
||||||
|
|
@ -274,6 +273,8 @@ public class SchedulerManager implements ISchedulerManager {
|
||||||
jobDataAsMap.put("applicationContext", applicationContext);
|
jobDataAsMap.put("applicationContext", applicationContext);
|
||||||
jobDetailBean.setJobDataAsMap(jobDataAsMap);
|
jobDetailBean.setJobDataAsMap(jobDataAsMap);
|
||||||
|
|
||||||
|
jobDetailBean.afterPropertiesSet();
|
||||||
|
|
||||||
return jobDetailBean;
|
return jobDetailBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -322,9 +323,9 @@ public class SchedulerManager implements ISchedulerManager {
|
||||||
* the trigger group
|
* the trigger group
|
||||||
* @return CronTriggerFactoryBean if found, otherwise null
|
* @return CronTriggerFactoryBean if found, otherwise null
|
||||||
*/
|
*/
|
||||||
private CronTriggerFactoryBean getTriggerBean(String triggerName, String triggerGroup) {
|
private CronTrigger getTriggerBean(String triggerName, String triggerGroup) {
|
||||||
try {
|
try {
|
||||||
return (CronTriggerFactoryBean) this.scheduler.getTrigger(TriggerKey.triggerKey(triggerName, triggerGroup));
|
return (CronTrigger) this.scheduler.getTrigger(TriggerKey.triggerKey(triggerName, triggerGroup));
|
||||||
} catch (SchedulerException e) {
|
} catch (SchedulerException e) {
|
||||||
LOG.error("Unable to get job trigger", e);
|
LOG.error("Unable to get job trigger", e);
|
||||||
}
|
}
|
||||||
|
|
@ -333,3 +334,4 @@ public class SchedulerManager implements ISchedulerManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ public class SendEmailOnMilestoneReachedJob extends QuartzJobBean {
|
||||||
(ApplicationContext) context.getJobDetail().getJobDataMap().get("applicationContext");
|
(ApplicationContext) context.getJobDetail().getJobDataMap().get("applicationContext");
|
||||||
|
|
||||||
IEmailNotificationJob milestoneReached =
|
IEmailNotificationJob milestoneReached =
|
||||||
(SendEmailOnMilestoneReached) applicationContext.getBean("SendEmailOnMilestoneReached");
|
(IEmailNotificationJob) applicationContext.getBean("sendEmailOnMilestoneReached");
|
||||||
|
|
||||||
milestoneReached.sendEmail();
|
milestoneReached.sendEmail();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ public class SendEmailOnResourceRemovedFromTaskJob extends QuartzJobBean {
|
||||||
(ApplicationContext) context.getJobDetail().getJobDataMap().get("applicationContext");
|
(ApplicationContext) context.getJobDetail().getJobDataMap().get("applicationContext");
|
||||||
|
|
||||||
IEmailNotificationJob resourceRemovedFromTask =
|
IEmailNotificationJob resourceRemovedFromTask =
|
||||||
(IEmailNotificationJob) applicationContext.getBean("SendEmailOnResourceRemovedFromTask");
|
(IEmailNotificationJob) applicationContext.getBean("sendEmailOnResourceRemovedFromTask");
|
||||||
|
|
||||||
resourceRemovedFromTask.sendEmail();
|
resourceRemovedFromTask.sendEmail();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ public class SendEmailOnTaskAssignedToResourceJob extends QuartzJobBean {
|
||||||
(ApplicationContext) context.getJobDetail().getJobDataMap().get("applicationContext");
|
(ApplicationContext) context.getJobDetail().getJobDataMap().get("applicationContext");
|
||||||
|
|
||||||
IEmailNotificationJob taskAssignedToResource =
|
IEmailNotificationJob taskAssignedToResource =
|
||||||
(IEmailNotificationJob) applicationContext.getBean("SendEmailOnTaskAssignedToResource");
|
(IEmailNotificationJob) applicationContext.getBean("sendEmailOnTaskAssignedToResource");
|
||||||
|
|
||||||
taskAssignedToResource.sendEmail();
|
taskAssignedToResource.sendEmail();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ public class SendEmailOnTaskShouldFinishJob extends QuartzJobBean {
|
||||||
(ApplicationContext) context.getJobDetail().getJobDataMap().get("applicationContext");
|
(ApplicationContext) context.getJobDetail().getJobDataMap().get("applicationContext");
|
||||||
|
|
||||||
IEmailNotificationJob taskShouldFinish =
|
IEmailNotificationJob taskShouldFinish =
|
||||||
(IEmailNotificationJob) applicationContext.getBean("SendEmailOnTaskShouldFinish");
|
(IEmailNotificationJob) applicationContext.getBean("sendEmailOnTaskShouldFinish");
|
||||||
|
|
||||||
taskShouldFinish.sendEmail();
|
taskShouldFinish.sendEmail();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ public class SendEmailOnTaskShouldStartJob extends QuartzJobBean {
|
||||||
context.getJobDetail().getJobDataMap().get("applicationContext");
|
context.getJobDetail().getJobDataMap().get("applicationContext");
|
||||||
|
|
||||||
IEmailNotificationJob taskShouldStart =
|
IEmailNotificationJob taskShouldStart =
|
||||||
(IEmailNotificationJob) applicationContext.getBean("SendEmailOnTaskShouldStart");
|
(IEmailNotificationJob) applicationContext.getBean("sendEmailOnTaskShouldStart");
|
||||||
|
|
||||||
taskShouldStart.sendEmail();
|
taskShouldStart.sendEmail();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ public class SendEmailOnTimesheetDataMissingJob extends QuartzJobBean {
|
||||||
(ApplicationContext) context.getJobDetail().getJobDataMap().get("applicationContext");
|
(ApplicationContext) context.getJobDetail().getJobDataMap().get("applicationContext");
|
||||||
|
|
||||||
IEmailNotificationJob timesheetMissing =
|
IEmailNotificationJob timesheetMissing =
|
||||||
(IEmailNotificationJob) applicationContext.getBean("SendEmailOnTimesheetDataMissing");
|
(IEmailNotificationJob) applicationContext.getBean("sendEmailOnTimesheetDataMissing");
|
||||||
|
|
||||||
timesheetMissing.sendEmail();
|
timesheetMissing.sendEmail();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -123,21 +123,20 @@ public class SendEmailOnMilestoneReached implements IEmailNotificationJob {
|
||||||
|
|
||||||
User user = null;
|
User user = null;
|
||||||
try {
|
try {
|
||||||
// FIXME: Code below can produce NullPointerException if "Responsible" field is not set in Project Details -> General data
|
|
||||||
user = userDAO.findByLoginName(responsible);
|
user = userDAO.findByLoginName(responsible);
|
||||||
} catch (InstanceNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean userHasNeededRoles =
|
boolean userHasNeededRoles =
|
||||||
user.isInRole(UserRole.ROLE_SUPERUSER) || user.isInRole(UserRole.ROLE_EMAIL_MILESTONE_REACHED);
|
user.isInRole(UserRole.ROLE_SUPERUSER) || user.isInRole(UserRole.ROLE_EMAIL_MILESTONE_REACHED);
|
||||||
|
|
||||||
if ( user.getWorker() != null && userHasNeededRoles ) {
|
if ( user.getWorker() != null && userHasNeededRoles ) {
|
||||||
emailNotificationModel.setResource(user.getWorker());
|
emailNotificationModel.setResource(user.getWorker());
|
||||||
emailNotificationModel.setTask(item);
|
emailNotificationModel.setTask(item);
|
||||||
emailNotificationModel.setProject(item.getParent());
|
emailNotificationModel.setProject(item.getParent());
|
||||||
emailNotificationModel.confirmSave();
|
emailNotificationModel.confirmSave();
|
||||||
}
|
}
|
||||||
|
} catch (InstanceNotFoundException e) {
|
||||||
|
// do nothing, responsible user is either blank or free text in order
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkMilestoneDate() {
|
public void checkMilestoneDate() {
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,8 @@ import org.libreplan.business.labels.entities.LabelType;
|
||||||
import org.libreplan.business.orders.entities.OrderElement;
|
import org.libreplan.business.orders.entities.OrderElement;
|
||||||
import org.libreplan.business.resources.entities.Resource;
|
import org.libreplan.business.resources.entities.Resource;
|
||||||
import org.libreplan.business.resources.entities.Worker;
|
import org.libreplan.business.resources.entities.Worker;
|
||||||
|
import org.libreplan.business.users.entities.User;
|
||||||
|
import org.libreplan.business.users.entities.UserRole;
|
||||||
import org.libreplan.business.workingday.EffortDuration;
|
import org.libreplan.business.workingday.EffortDuration;
|
||||||
import org.libreplan.business.workreports.entities.HoursManagementEnum;
|
import org.libreplan.business.workreports.entities.HoursManagementEnum;
|
||||||
import org.libreplan.business.workreports.entities.WorkReport;
|
import org.libreplan.business.workreports.entities.WorkReport;
|
||||||
|
|
@ -48,6 +50,7 @@ import org.libreplan.business.workreports.entities.WorkReportLine;
|
||||||
import org.libreplan.business.workreports.entities.WorkReportType;
|
import org.libreplan.business.workreports.entities.WorkReportType;
|
||||||
import org.libreplan.business.workreports.valueobjects.DescriptionField;
|
import org.libreplan.business.workreports.valueobjects.DescriptionField;
|
||||||
import org.libreplan.business.workreports.valueobjects.DescriptionValue;
|
import org.libreplan.business.workreports.valueobjects.DescriptionValue;
|
||||||
|
import org.libreplan.web.UserUtil;
|
||||||
import org.libreplan.web.common.ConstraintChecker;
|
import org.libreplan.web.common.ConstraintChecker;
|
||||||
import org.libreplan.web.common.IMessagesForUser;
|
import org.libreplan.web.common.IMessagesForUser;
|
||||||
import org.libreplan.web.common.Level;
|
import org.libreplan.web.common.Level;
|
||||||
|
|
@ -59,6 +62,7 @@ import org.libreplan.web.common.components.NewDataSortableColumn;
|
||||||
import org.libreplan.web.common.components.NewDataSortableGrid;
|
import org.libreplan.web.common.components.NewDataSortableGrid;
|
||||||
import org.libreplan.web.common.components.bandboxsearch.BandboxSearch;
|
import org.libreplan.web.common.components.bandboxsearch.BandboxSearch;
|
||||||
import org.libreplan.web.common.entrypoints.IURLHandlerRegistry;
|
import org.libreplan.web.common.entrypoints.IURLHandlerRegistry;
|
||||||
|
import org.libreplan.web.security.SecurityUtils;
|
||||||
import org.libreplan.web.users.dashboard.IPersonalTimesheetController;
|
import org.libreplan.web.users.dashboard.IPersonalTimesheetController;
|
||||||
import org.zkoss.ganttz.IPredicate;
|
import org.zkoss.ganttz.IPredicate;
|
||||||
import org.zkoss.ganttz.util.ComponentsFinder;
|
import org.zkoss.ganttz.util.ComponentsFinder;
|
||||||
|
|
@ -689,18 +693,31 @@ public class WorkReportCRUDController
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void goToEditForm(WorkReport workReport) {
|
public void goToEditForm(WorkReport workReport) {
|
||||||
if ( workReportModel.isPersonalTimesheet(workReport) ) {
|
if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_TIMESHEETS)) {
|
||||||
goToEditPersonalTimeSheet(workReport);
|
|
||||||
} else {
|
|
||||||
workReportModel.initEdit(workReport);
|
workReportModel.initEdit(workReport);
|
||||||
createWindow.setTitle(_("Edit Timesheet"));
|
createWindow.setTitle(_("Edit Timesheet"));
|
||||||
loadComponents(createWindow);
|
loadComponents(createWindow);
|
||||||
prepareWorkReportList();
|
prepareWorkReportList();
|
||||||
getVisibility().showOnly(createWindow);
|
getVisibility().showOnly(createWindow);
|
||||||
Util.reloadBindings(createWindow);
|
Util.reloadBindings(createWindow);
|
||||||
|
|
||||||
|
} else if (SecurityUtils.isUserInRole(UserRole.ROLE_BOUND_USER) &&
|
||||||
|
workReportModel.isPersonalTimesheet(workReport) &&
|
||||||
|
belongsToCurrentUser(workReport)) {
|
||||||
|
|
||||||
|
goToEditPersonalTimeSheet(workReport);
|
||||||
|
} else {
|
||||||
|
messagesForUser.showMessage(Level.WARNING, _("You do not have permissions to edit this timesheet"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean belongsToCurrentUser(WorkReport workReport) {
|
||||||
|
User user = UserUtil.getUserFromSession();
|
||||||
|
assert user != null;
|
||||||
|
|
||||||
|
return workReport.getResource().getId().equals(user.getWorker().getId());
|
||||||
|
}
|
||||||
|
|
||||||
private void goToEditPersonalTimeSheet(WorkReport workReport) {
|
private void goToEditPersonalTimeSheet(WorkReport workReport) {
|
||||||
workReportModel.initEdit(workReport);
|
workReportModel.initEdit(workReport);
|
||||||
Date date = workReportModel.getFirstWorkReportLine().getDate();
|
Date date = workReportModel.getFirstWorkReportLine().getDate();
|
||||||
|
|
@ -989,7 +1006,8 @@ public class WorkReportCRUDController
|
||||||
|
|
||||||
NewDataSortableGrid grid = (NewDataSortableGrid) row.getParent().getParent();
|
NewDataSortableGrid grid = (NewDataSortableGrid) row.getParent().getParent();
|
||||||
NewDataSortableColumn priorityColumn = (NewDataSortableColumn) grid.getChildren().get(1).getChildren().get(2);
|
NewDataSortableColumn priorityColumn = (NewDataSortableColumn) grid.getChildren().get(1).getChildren().get(2);
|
||||||
priorityColumn.setWidth("110px");
|
// DISCUSS: Are there any implications to not setting a width on this column??
|
||||||
|
//priorityColumn.setWidth("110px");
|
||||||
|
|
||||||
if (!getWorkReport().getWorkReportType().getHoursManagement().equals(HoursManagementEnum.NUMBER_OF_HOURS)) {
|
if (!getWorkReport().getWorkReportType().getHoursManagement().equals(HoursManagementEnum.NUMBER_OF_HOURS)) {
|
||||||
appendHoursStartAndFinish(row);
|
appendHoursStartAndFinish(row);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue