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.criterion.Restrictions;
|
||||
import org.libreplan.business.common.Registry;
|
||||
import org.libreplan.business.common.daos.GenericDAOHibernate;
|
||||
import org.libreplan.business.orders.entities.Order;
|
||||
import org.libreplan.business.users.entities.OrderAuthorization;
|
||||
|
|
@ -68,6 +69,7 @@ public class OrderAuthorizationDAO extends GenericDAOHibernate<OrderAuthorizatio
|
|||
public List<OrderAuthorization> listByUserAndItsProfiles(User user) {
|
||||
List<OrderAuthorization> list = new ArrayList<OrderAuthorization>();
|
||||
list.addAll(listByUser(user));
|
||||
Registry.getUserDAO().reattach(user);
|
||||
for(Profile profile : user.getProfiles()) {
|
||||
list.addAll(listByProfile(profile));
|
||||
}
|
||||
|
|
@ -79,6 +81,7 @@ public class OrderAuthorizationDAO extends GenericDAOHibernate<OrderAuthorizatio
|
|||
if (!listByUser(user).isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
Registry.getUserDAO().reattach(user);
|
||||
for (Profile profile : user.getProfiles()) {
|
||||
if (!listByProfile(profile).isEmpty()) {
|
||||
return true;
|
||||
|
|
@ -108,6 +111,7 @@ public class OrderAuthorizationDAO extends GenericDAOHibernate<OrderAuthorizatio
|
|||
public List<OrderAuthorization> listByOrderUserAndItsProfiles(Order order, User user) {
|
||||
List<OrderAuthorization> list = new ArrayList<OrderAuthorization>();
|
||||
list.addAll(listByOrderAndUser(order,user));
|
||||
Registry.getUserDAO().reattach(user);
|
||||
for(Profile profile : user.getProfiles()) {
|
||||
list.addAll(listByOrderAndProfile(order, profile));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ public class SchedulerManager implements ISchedulerManager {
|
|||
String triggerName = jobSchedulerConfiguration.getJobName() + TRIGGER_SUFFIX;
|
||||
String triggerGroup = jobSchedulerConfiguration.getJobGroup() + TRIGGER_SUFFIX;
|
||||
|
||||
CronTriggerFactoryBean trigger = getTriggerBean(triggerName, triggerGroup);
|
||||
CronTrigger trigger = getTriggerBean(triggerName, triggerGroup);
|
||||
if ( trigger == null ) {
|
||||
LOG.warn("Trigger not found");
|
||||
|
||||
|
|
@ -164,7 +164,7 @@ public class SchedulerManager implements ISchedulerManager {
|
|||
}
|
||||
|
||||
// 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
|
||||
*/
|
||||
private CronTriggerFactoryBean createCronTriggerBean(JobSchedulerConfiguration jobSchedulerConfiguration) {
|
||||
CronTriggerFactoryBean cronTriggerBean = new CronTriggerFactoryBean();
|
||||
final CronTriggerFactoryBean cronTriggerBean = new CronTriggerFactoryBean();
|
||||
cronTriggerBean.setName(jobSchedulerConfiguration.getJobName() + TRIGGER_SUFFIX);
|
||||
cronTriggerBean.setGroup(jobSchedulerConfiguration.getJobGroup() + TRIGGER_SUFFIX);
|
||||
|
||||
|
|
@ -238,9 +238,8 @@ public class SchedulerManager implements ISchedulerManager {
|
|||
cronTriggerBean.setCronExpression(
|
||||
String.valueOf(new CronExpression(jobSchedulerConfiguration.getCronExpression())));
|
||||
|
||||
cronTriggerBean.setName(jobSchedulerConfiguration.getJobName());
|
||||
cronTriggerBean.setGroup(jobSchedulerConfiguration.getJobGroup());
|
||||
|
||||
cronTriggerBean.afterPropertiesSet();
|
||||
|
||||
return cronTriggerBean;
|
||||
|
||||
} catch (ParseException e) {
|
||||
|
|
@ -259,7 +258,7 @@ public class SchedulerManager implements ISchedulerManager {
|
|||
* @return the created <code>JobDetailFactoryBean</code> or null if unable to it
|
||||
*/
|
||||
private JobDetailFactoryBean createJobDetailBean(JobSchedulerConfiguration jobSchedulerConfiguration) {
|
||||
JobDetailFactoryBean jobDetailBean = new JobDetailFactoryBean();
|
||||
final JobDetailFactoryBean jobDetailBean = new JobDetailFactoryBean();
|
||||
|
||||
Class<?> jobClass = getJobClass(jobSchedulerConfiguration.getJobClassName());
|
||||
if ( jobClass == null ) {
|
||||
|
|
@ -274,6 +273,8 @@ public class SchedulerManager implements ISchedulerManager {
|
|||
jobDataAsMap.put("applicationContext", applicationContext);
|
||||
jobDetailBean.setJobDataAsMap(jobDataAsMap);
|
||||
|
||||
jobDetailBean.afterPropertiesSet();
|
||||
|
||||
return jobDetailBean;
|
||||
}
|
||||
|
||||
|
|
@ -322,9 +323,9 @@ public class SchedulerManager implements ISchedulerManager {
|
|||
* the trigger group
|
||||
* @return CronTriggerFactoryBean if found, otherwise null
|
||||
*/
|
||||
private CronTriggerFactoryBean getTriggerBean(String triggerName, String triggerGroup) {
|
||||
private CronTrigger getTriggerBean(String triggerName, String triggerGroup) {
|
||||
try {
|
||||
return (CronTriggerFactoryBean) this.scheduler.getTrigger(TriggerKey.triggerKey(triggerName, triggerGroup));
|
||||
return (CronTrigger) this.scheduler.getTrigger(TriggerKey.triggerKey(triggerName, triggerGroup));
|
||||
} catch (SchedulerException 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");
|
||||
|
||||
IEmailNotificationJob milestoneReached =
|
||||
(SendEmailOnMilestoneReached) applicationContext.getBean("SendEmailOnMilestoneReached");
|
||||
(IEmailNotificationJob) applicationContext.getBean("sendEmailOnMilestoneReached");
|
||||
|
||||
milestoneReached.sendEmail();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class SendEmailOnResourceRemovedFromTaskJob extends QuartzJobBean {
|
|||
(ApplicationContext) context.getJobDetail().getJobDataMap().get("applicationContext");
|
||||
|
||||
IEmailNotificationJob resourceRemovedFromTask =
|
||||
(IEmailNotificationJob) applicationContext.getBean("SendEmailOnResourceRemovedFromTask");
|
||||
(IEmailNotificationJob) applicationContext.getBean("sendEmailOnResourceRemovedFromTask");
|
||||
|
||||
resourceRemovedFromTask.sendEmail();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public class SendEmailOnTaskAssignedToResourceJob extends QuartzJobBean {
|
|||
(ApplicationContext) context.getJobDetail().getJobDataMap().get("applicationContext");
|
||||
|
||||
IEmailNotificationJob taskAssignedToResource =
|
||||
(IEmailNotificationJob) applicationContext.getBean("SendEmailOnTaskAssignedToResource");
|
||||
(IEmailNotificationJob) applicationContext.getBean("sendEmailOnTaskAssignedToResource");
|
||||
|
||||
taskAssignedToResource.sendEmail();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public class SendEmailOnTaskShouldFinishJob extends QuartzJobBean {
|
|||
(ApplicationContext) context.getJobDetail().getJobDataMap().get("applicationContext");
|
||||
|
||||
IEmailNotificationJob taskShouldFinish =
|
||||
(IEmailNotificationJob) applicationContext.getBean("SendEmailOnTaskShouldFinish");
|
||||
(IEmailNotificationJob) applicationContext.getBean("sendEmailOnTaskShouldFinish");
|
||||
|
||||
taskShouldFinish.sendEmail();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public class SendEmailOnTaskShouldStartJob extends QuartzJobBean {
|
|||
context.getJobDetail().getJobDataMap().get("applicationContext");
|
||||
|
||||
IEmailNotificationJob taskShouldStart =
|
||||
(IEmailNotificationJob) applicationContext.getBean("SendEmailOnTaskShouldStart");
|
||||
(IEmailNotificationJob) applicationContext.getBean("sendEmailOnTaskShouldStart");
|
||||
|
||||
taskShouldStart.sendEmail();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class SendEmailOnTimesheetDataMissingJob extends QuartzJobBean {
|
|||
(ApplicationContext) context.getJobDetail().getJobDataMap().get("applicationContext");
|
||||
|
||||
IEmailNotificationJob timesheetMissing =
|
||||
(IEmailNotificationJob) applicationContext.getBean("SendEmailOnTimesheetDataMissing");
|
||||
(IEmailNotificationJob) applicationContext.getBean("sendEmailOnTimesheetDataMissing");
|
||||
|
||||
timesheetMissing.sendEmail();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,21 +123,20 @@ public class SendEmailOnMilestoneReached implements IEmailNotificationJob {
|
|||
|
||||
User user = null;
|
||||
try {
|
||||
// FIXME: Code below can produce NullPointerException if "Responsible" field is not set in Project Details -> General data
|
||||
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);
|
||||
|
||||
if ( user.getWorker() != null && userHasNeededRoles ) {
|
||||
emailNotificationModel.setResource(user.getWorker());
|
||||
emailNotificationModel.setTask(item);
|
||||
emailNotificationModel.setProject(item.getParent());
|
||||
emailNotificationModel.confirmSave();
|
||||
}
|
||||
if ( user.getWorker() != null && userHasNeededRoles ) {
|
||||
emailNotificationModel.setResource(user.getWorker());
|
||||
emailNotificationModel.setTask(item);
|
||||
emailNotificationModel.setProject(item.getParent());
|
||||
emailNotificationModel.confirmSave();
|
||||
}
|
||||
} catch (InstanceNotFoundException e) {
|
||||
// do nothing, responsible user is either blank or free text in order
|
||||
}
|
||||
}
|
||||
|
||||
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.resources.entities.Resource;
|
||||
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.workreports.entities.HoursManagementEnum;
|
||||
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.valueobjects.DescriptionField;
|
||||
import org.libreplan.business.workreports.valueobjects.DescriptionValue;
|
||||
import org.libreplan.web.UserUtil;
|
||||
import org.libreplan.web.common.ConstraintChecker;
|
||||
import org.libreplan.web.common.IMessagesForUser;
|
||||
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.bandboxsearch.BandboxSearch;
|
||||
import org.libreplan.web.common.entrypoints.IURLHandlerRegistry;
|
||||
import org.libreplan.web.security.SecurityUtils;
|
||||
import org.libreplan.web.users.dashboard.IPersonalTimesheetController;
|
||||
import org.zkoss.ganttz.IPredicate;
|
||||
import org.zkoss.ganttz.util.ComponentsFinder;
|
||||
|
|
@ -689,16 +693,29 @@ public class WorkReportCRUDController
|
|||
|
||||
@Override
|
||||
public void goToEditForm(WorkReport workReport) {
|
||||
if ( workReportModel.isPersonalTimesheet(workReport) ) {
|
||||
goToEditPersonalTimeSheet(workReport);
|
||||
} else {
|
||||
if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_TIMESHEETS)) {
|
||||
workReportModel.initEdit(workReport);
|
||||
createWindow.setTitle(_("Edit Timesheet"));
|
||||
loadComponents(createWindow);
|
||||
prepareWorkReportList();
|
||||
getVisibility().showOnly(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) {
|
||||
|
|
@ -989,7 +1006,8 @@ public class WorkReportCRUDController
|
|||
|
||||
NewDataSortableGrid grid = (NewDataSortableGrid) row.getParent().getParent();
|
||||
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)) {
|
||||
appendHoursStartAndFinish(row);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue