Use top level project task for grouped sub tasks

Instead of using the group task as the project task need to pull the top level parent.
A grouped task will have as parent the group not the project.

Fixes #21
This commit is contained in:
lmann99 2017-02-05 11:28:51 -05:00
parent 89d81f8f5b
commit 64e095a841
6 changed files with 44 additions and 7 deletions

View file

@ -243,7 +243,8 @@ public abstract class TaskElement extends BaseEntity {
}
public String getProjectCode() {
return getOrderElement().getOrder().getCode();
//then get the top level project code
return getTopMost().getOrderElement().getOrder().getCode();
}
public void setName(String name) {

View file

@ -303,6 +303,42 @@ public class TaskElementDAOTest {
assertThat(child.getParent(), equalTo(reloaded));
}
@Test
@Transactional
public void theTopMostPropertyIsTheToplevelTask() {
TaskGroup taskGroup = createValidTaskGroup();
TaskElement taskElement = createValidTask();
taskGroup.addTaskElement(taskElement);
taskElementDAO.save(taskGroup);
TaskGroup taskGroup2 = createValidTaskGroup();
TaskElement taskElement2 = createValidTask();
taskGroup2.addTaskElement(taskElement2);
taskElementDAO.save(taskGroup2);
taskGroup.addTaskElement(taskGroup2);
taskElementDAO.save(taskGroup);
flushAndEvict(taskGroup);
flushAndEvict(taskGroup2);
TaskElement reloaded;
try {
reloaded = taskElementDAO.find(taskGroup.getId());
} catch (InstanceNotFoundException e) {
throw new RuntimeException(e);
}
List<TaskElement> children = reloaded.getChildren();
for (TaskElement child : children) {
if (child instanceof TaskGroup) {
TaskElement child2 = child.getChildren().get(0);
assertThat(child2.getTopMost(), equalTo(reloaded));
}
}
}
@Test
@Transactional
public void savingGroupSavesAssociatedTaskElements() {

View file

@ -113,8 +113,8 @@ public class SendEmailOnMilestoneReached implements IEmailNotificationJob {
private void sendEmailNotificationToManager(TaskElement item) {
String responsible = "";
if ( item.getParent().getOrderElement().getOrder().getResponsible() != null ) {
responsible = item.getParent().getOrderElement().getOrder().getResponsible();
if ( item.getTopMost().getOrderElement().getOrder().getResponsible() != null ) {
responsible = item.getTopMost().getOrderElement().getOrder().getResponsible();
}
User user = null;
@ -130,7 +130,7 @@ public class SendEmailOnMilestoneReached implements IEmailNotificationJob {
emailNotificationModel.setUpdated(new Date());
emailNotificationModel.setResource(user.getWorker());
emailNotificationModel.setTask(item);
emailNotificationModel.setProject(item.getParent());
emailNotificationModel.setProject(item.getTopMost());
emailNotificationModel.confirmSave();
}
} catch (InstanceNotFoundException e) {

View file

@ -145,7 +145,7 @@ public class SendEmailOnTaskShouldFinish implements IEmailNotificationJob {
emailNotificationModel.setUpdated(new Date());
emailNotificationModel.setResource(resourceItem);
emailNotificationModel.setTask(item);
emailNotificationModel.setProject(item.getParent());
emailNotificationModel.setProject(item.getTopMost());
emailNotificationModel.confirmSave();
}
}

View file

@ -147,7 +147,7 @@ public class SendEmailOnTaskShouldStart implements IEmailNotificationJob {
emailNotificationModel.setUpdated(new Date());
emailNotificationModel.setResource(resourceItem);
emailNotificationModel.setTask(item);
emailNotificationModel.setProject(item.getParent());
emailNotificationModel.setProject(item.getTopMost());
emailNotificationModel.confirmSave();
}
}

View file

@ -800,7 +800,7 @@ public class TaskPropertiesController extends GenericForwardComposer<Component>
emailNotificationModel.setTask(currentTaskElement.getTaskSource().getTask());
emailNotificationModel.setProject(currentTaskElement.getParent().getTaskSource().getTask());
emailNotificationModel.setProject(currentTaskElement.getTopMost().getTaskSource().getTask());
emailNotificationModel.confirmSave();
} catch (DataIntegrityViolationException e) {