diff --git a/libreplan-business/src/main/resources/org/libreplan/business/orders/entities/Orders.hbm.xml b/libreplan-business/src/main/resources/org/libreplan/business/orders/entities/Orders.hbm.xml
index e5cd1fd06..3415245de 100644
--- a/libreplan-business/src/main/resources/org/libreplan/business/orders/entities/Orders.hbm.xml
+++ b/libreplan-business/src/main/resources/org/libreplan/business/orders/entities/Orders.hbm.xml
@@ -249,7 +249,7 @@
-
+
@@ -264,8 +264,7 @@
-
+
diff --git a/libreplan-business/src/main/resources/org/libreplan/business/planner/entities/Tasks.hbm.xml b/libreplan-business/src/main/resources/org/libreplan/business/planner/entities/Tasks.hbm.xml
index 93d70032b..547e11f8c 100644
--- a/libreplan-business/src/main/resources/org/libreplan/business/planner/entities/Tasks.hbm.xml
+++ b/libreplan-business/src/main/resources/org/libreplan/business/planner/entities/Tasks.hbm.xml
@@ -41,7 +41,7 @@
+ index="idx_task_element_on_task_group" />
@@ -100,7 +100,7 @@
class="org.libreplan.business.planner.entities.consolidations.Consolidation" cascade="all"/>
-
+
@@ -126,7 +126,7 @@
-
+
diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/notifications/realization/SendEmailOnMilestoneReached.java b/libreplan-webapp/src/main/java/org/libreplan/importers/notifications/realization/SendEmailOnMilestoneReached.java
index 51185efc6..0d7fbc976 100644
--- a/libreplan-webapp/src/main/java/org/libreplan/importers/notifications/realization/SendEmailOnMilestoneReached.java
+++ b/libreplan-webapp/src/main/java/org/libreplan/importers/notifications/realization/SendEmailOnMilestoneReached.java
@@ -38,6 +38,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
@@ -72,7 +73,15 @@ public class SendEmailOnMilestoneReached implements IEmailNotificationJob {
@Autowired
EmailConnectionValidator emailConnectionValidator;
+ /**
+ * Transactional here is needed because without this annotation we are getting
+ * "LazyInitializationException: could not initialize proxy - no Session" error,
+ * when "item.getParent().getOrderElement().getOrder().getResponsible()" method was called.
+ * Earlier this trouble was not present because in Tasks.hbm.xml for "TaskElement" class field
+ * named "parent", which has relation "many-to-one" to "TaskGroup", lazy was set to "false".
+ */
@Override
+ @Transactional
public void sendEmail() {
// Gathering data
checkMilestoneDate();
@@ -108,11 +117,13 @@ public class SendEmailOnMilestoneReached implements IEmailNotificationJob {
emailNotificationModel.setUpdated(new Date());
String responsible = "";
- if ( item.getParent().getOrderElement().getOrder().getResponsible() != null )
+ if ( item.getParent().getOrderElement().getOrder().getResponsible() != null ) {
responsible = item.getParent().getOrderElement().getOrder().getResponsible();
+ }
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();
diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/notifications/realization/SendEmailOnTaskShouldFinish.java b/libreplan-webapp/src/main/java/org/libreplan/importers/notifications/realization/SendEmailOnTaskShouldFinish.java
index c371f14b2..6d6b20ea7 100644
--- a/libreplan-webapp/src/main/java/org/libreplan/importers/notifications/realization/SendEmailOnTaskShouldFinish.java
+++ b/libreplan-webapp/src/main/java/org/libreplan/importers/notifications/realization/SendEmailOnTaskShouldFinish.java
@@ -20,6 +20,8 @@
package org.libreplan.importers.notifications.realization;
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeComparator;
import org.libreplan.business.common.Configuration;
import org.libreplan.business.email.entities.EmailNotification;
import org.libreplan.business.email.entities.EmailTemplateEnum;
@@ -66,7 +68,15 @@ public class SendEmailOnTaskShouldFinish implements IEmailNotificationJob {
@Autowired
private EmailConnectionValidator emailConnectionValidator;
+ /**
+ * Transactional here is needed because without this annotation we are getting
+ * "LazyInitializationException: could not initialize proxy - no Session" error,
+ * when "item.getAllResourceAllocations()" method was called.
+ * Earlier this trouble was not present because in Tasks.hbm.xml for joined subclass "Task" field
+ * named "resourceAllocations", which has relation "one-to-many" to "ResourceAllocation", lazy was set to "false".
+ */
@Override
+ @Transactional
public void sendEmail() {
// Gather data for email sending
taskShouldFinish();
@@ -95,23 +105,15 @@ public class SendEmailOnTaskShouldFinish implements IEmailNotificationJob {
@Transactional
public void taskShouldFinish() {
- // TODO resolve deprecated
// Check if current date equals with item date
- Date date = new Date();
- int currentYear = date.getYear();
- int currentMonth = date.getMonth();
- int currentDay = date.getDay();
+ DateTime currentDate = new DateTime();
+ DateTimeComparator dateTimeComparator = DateTimeComparator.getDateOnlyInstance();
List tasks = taskElementDAO.getTaskElementsWithParentsWithoutMilestones();
for (TaskElement item : tasks){
- Date endDate = item.getEndDate();
- int endYear = endDate.getYear();
- int endMonth = endDate.getMonth();
- int endDay = endDate.getDay();
+ DateTime endDate = new DateTime(item.getEndDate());
- if ( currentYear == endYear &&
- currentMonth == endMonth &&
- currentDay == endDay ) {
+ if ( dateTimeComparator.compare(currentDate, endDate) == 0 ) {
// Get all resources for current task and send them email notification
sendEmailNotificationAboutTaskShouldFinish(item);
}
diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/notifications/realization/SendEmailOnTaskShouldStart.java b/libreplan-webapp/src/main/java/org/libreplan/importers/notifications/realization/SendEmailOnTaskShouldStart.java
index 2cde7ac07..45a231d21 100644
--- a/libreplan-webapp/src/main/java/org/libreplan/importers/notifications/realization/SendEmailOnTaskShouldStart.java
+++ b/libreplan-webapp/src/main/java/org/libreplan/importers/notifications/realization/SendEmailOnTaskShouldStart.java
@@ -19,6 +19,8 @@
package org.libreplan.importers.notifications.realization;
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeComparator;
import org.libreplan.business.common.Configuration;
import org.libreplan.business.email.entities.EmailNotification;
@@ -66,7 +68,15 @@ public class SendEmailOnTaskShouldStart implements IEmailNotificationJob {
@Autowired
private EmailConnectionValidator emailConnectionValidator;
+ /**
+ * Transactional here is needed because without this annotation we are getting
+ * "LazyInitializationException: could not initialize proxy - no Session" error,
+ * when "item.getAllResourceAllocations()" method was called.
+ * Earlier this trouble was not present because in Tasks.hbm.xml for joined subclass "Task" field
+ * named "resourceAllocations", which has relation "one-to-many" to "ResourceAllocation", lazy was set to "false".
+ */
@Override
+ @Transactional
public void sendEmail() {
// Gather data
taskShouldStart();
@@ -97,20 +107,14 @@ public class SendEmailOnTaskShouldStart implements IEmailNotificationJob {
@Transactional
public void taskShouldStart() {
// Check if current date equals with item date
- Date date = new Date();
- // TODO resolve deprecated
- int currentYear = date.getYear();
- int currentMonth = date.getMonth();
- int currentDay = date.getDay();
+ DateTime currentDate = new DateTime();
+ DateTimeComparator dateTimeComparator = DateTimeComparator.getDateOnlyInstance();
List tasks = taskElementDAO.getTaskElementsWithParentsWithoutMilestones();
for (TaskElement item : tasks) {
- Date startDate = item.getStartDate();
- int startYear = startDate.getYear();
- int startMonth = startDate.getMonth();
- int startDay = startDate.getDay();
+ DateTime startDate = new DateTime(item.getStartDate());
- if ( currentYear == startYear && currentMonth == startMonth && currentDay == startDay ) {
+ if ( dateTimeComparator.compare(currentDate, startDate) == 0) {
// Get all resources for current task and send them email notification
sendEmailNotificationAboutTaskShouldStart(item);
}