Merge pull request #118 from PaulLuchyn/master

Resolved InvalidDataAccessApiUsageException
This commit is contained in:
Jeroen Baten 2016-11-09 16:04:44 +01:00 committed by GitHub
commit 2dbd1eb5b7
5 changed files with 45 additions and 29 deletions

View file

@ -249,7 +249,7 @@
</type> </type>
</property> </property>
<many-to-one name="orderElement" column="order_element_id" lazy="false"/> <many-to-one name="orderElement" column="order_element_id" />
<one-to-one name="taskSource" class="TaskSource" cascade="delete" access="field" <one-to-one name="taskSource" class="TaskSource" cascade="delete" access="field"
property-ref="schedulingData" /> property-ref="schedulingData" />
@ -264,8 +264,7 @@
<version name="version" access="property" type="long" /> <version name="version" access="property" type="long" />
<many-to-one name="schedulingData" class="SchedulingDataForVersion" cascade="none" unique="true" access="field" <many-to-one name="schedulingData" class="SchedulingDataForVersion" cascade="none" unique="true" access="field" />
lazy="false" />
<one-to-one name="task" class="org.libreplan.business.planner.entities.TaskElement" constrained="true" <one-to-one name="task" class="org.libreplan.business.planner.entities.TaskElement" constrained="true"
cascade="delete" access="field" lazy="false"/> cascade="delete" access="field" lazy="false"/>

View file

@ -41,7 +41,7 @@
<!-- Indexed --> <!-- Indexed -->
<many-to-one name="parent" class="TaskGroup" cascade="none" column="parent" <many-to-one name="parent" class="TaskGroup" cascade="none" column="parent"
index="idx_task_element_on_task_group" lazy="false" /> index="idx_task_element_on_task_group" />
<one-to-one name="taskSource" cascade="delete" /> <one-to-one name="taskSource" cascade="delete" />
@ -100,7 +100,7 @@
class="org.libreplan.business.planner.entities.consolidations.Consolidation" cascade="all"/> class="org.libreplan.business.planner.entities.consolidations.Consolidation" cascade="all"/>
<!-- Indexed on the other side --> <!-- Indexed on the other side -->
<set name="resourceAllocations" cascade="all-delete-orphan" lazy="false"> <set name="resourceAllocations" cascade="all-delete-orphan" >
<key column="task" /> <key column="task" />
<one-to-many class="ResourceAllocation" /> <one-to-many class="ResourceAllocation" />
</set> </set>
@ -126,7 +126,7 @@
</list> </list>
</joined-subclass> </joined-subclass>
<joined-subclass name="TaskMilestone" table="task_milestone"> <joined-subclass name="TaskMilestone" table="task_milestone" >
<key column="task_element_id"/> <key column="task_element_id"/>
<component name="startConstraint"> <component name="startConstraint">

View file

@ -38,6 +38,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -72,7 +73,15 @@ public class SendEmailOnMilestoneReached implements IEmailNotificationJob {
@Autowired @Autowired
EmailConnectionValidator emailConnectionValidator; 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 @Override
@Transactional
public void sendEmail() { public void sendEmail() {
// Gathering data // Gathering data
checkMilestoneDate(); checkMilestoneDate();
@ -108,11 +117,13 @@ public class SendEmailOnMilestoneReached implements IEmailNotificationJob {
emailNotificationModel.setUpdated(new Date()); emailNotificationModel.setUpdated(new Date());
String responsible = ""; String responsible = "";
if ( item.getParent().getOrderElement().getOrder().getResponsible() != null ) if ( item.getParent().getOrderElement().getOrder().getResponsible() != null ) {
responsible = item.getParent().getOrderElement().getOrder().getResponsible(); responsible = item.getParent().getOrderElement().getOrder().getResponsible();
}
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) { } catch (InstanceNotFoundException e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -20,6 +20,8 @@
package org.libreplan.importers.notifications.realization; 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.common.Configuration;
import org.libreplan.business.email.entities.EmailNotification; import org.libreplan.business.email.entities.EmailNotification;
import org.libreplan.business.email.entities.EmailTemplateEnum; import org.libreplan.business.email.entities.EmailTemplateEnum;
@ -66,7 +68,15 @@ public class SendEmailOnTaskShouldFinish implements IEmailNotificationJob {
@Autowired @Autowired
private EmailConnectionValidator emailConnectionValidator; 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 @Override
@Transactional
public void sendEmail() { public void sendEmail() {
// Gather data for email sending // Gather data for email sending
taskShouldFinish(); taskShouldFinish();
@ -97,23 +107,15 @@ public class SendEmailOnTaskShouldFinish implements IEmailNotificationJob {
@Transactional @Transactional
public void taskShouldFinish() { public void taskShouldFinish() {
// TODO resolve deprecated
// Check if current date equals with item date // Check if current date equals with item date
Date date = new Date(); DateTime currentDate = new DateTime();
int currentYear = date.getYear(); DateTimeComparator dateTimeComparator = DateTimeComparator.getDateOnlyInstance();
int currentMonth = date.getMonth();
int currentDay = date.getDay();
List<TaskElement> tasks = taskElementDAO.getTaskElementsWithParentsWithoutMilestones(); List<TaskElement> tasks = taskElementDAO.getTaskElementsWithParentsWithoutMilestones();
for (TaskElement item : tasks){ for (TaskElement item : tasks){
Date endDate = item.getEndDate(); DateTime endDate = new DateTime(item.getEndDate());
int endYear = endDate.getYear();
int endMonth = endDate.getMonth();
int endDay = endDate.getDay();
if ( currentYear == endYear && if ( dateTimeComparator.compare(currentDate, endDate) == 0 ) {
currentMonth == endMonth &&
currentDay == endDay ) {
// Get all resources for current task and send them email notification // Get all resources for current task and send them email notification
sendEmailNotificationAboutTaskShouldFinish(item); sendEmailNotificationAboutTaskShouldFinish(item);
} }

View file

@ -19,6 +19,8 @@
package org.libreplan.importers.notifications.realization; 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.common.Configuration;
import org.libreplan.business.email.entities.EmailNotification; import org.libreplan.business.email.entities.EmailNotification;
@ -66,7 +68,15 @@ public class SendEmailOnTaskShouldStart implements IEmailNotificationJob {
@Autowired @Autowired
private EmailConnectionValidator emailConnectionValidator; 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 @Override
@Transactional
public void sendEmail() { public void sendEmail() {
// Gather data // Gather data
taskShouldStart(); taskShouldStart();
@ -98,20 +108,14 @@ public class SendEmailOnTaskShouldStart implements IEmailNotificationJob {
@Transactional @Transactional
public void taskShouldStart() { public void taskShouldStart() {
// Check if current date equals with item date // Check if current date equals with item date
Date date = new Date(); DateTime currentDate = new DateTime();
// TODO resolve deprecated DateTimeComparator dateTimeComparator = DateTimeComparator.getDateOnlyInstance();
int currentYear = date.getYear();
int currentMonth = date.getMonth();
int currentDay = date.getDay();
List<TaskElement> tasks = taskElementDAO.getTaskElementsWithParentsWithoutMilestones(); List<TaskElement> tasks = taskElementDAO.getTaskElementsWithParentsWithoutMilestones();
for (TaskElement item : tasks) { for (TaskElement item : tasks) {
Date startDate = item.getStartDate(); DateTime startDate = new DateTime(item.getStartDate());
int startYear = startDate.getYear();
int startMonth = startDate.getMonth();
int startDay = startDate.getDay();
if ( currentYear == startYear && currentMonth == startMonth && currentDay == startDay ) { if ( dateTimeComparator.compare(currentDate, startDate) == 0) {
// Get all resources for current task and send them email notification // Get all resources for current task and send them email notification
sendEmailNotificationAboutTaskShouldStart(item); sendEmailNotificationAboutTaskShouldStart(item);
} }