diff --git a/src/main/java/se/su/dsv/scipro/data/dataobjects/Event.java b/src/main/java/se/su/dsv/scipro/data/dataobjects/Event.java index de3d93992e..413633c472 100644 --- a/src/main/java/se/su/dsv/scipro/data/dataobjects/Event.java +++ b/src/main/java/se/su/dsv/scipro/data/dataobjects/Event.java @@ -154,11 +154,7 @@ public abstract class Event extends LazyDeletableDomainObject @Override public int compareTo(Event other) { - int dcomp = dueDate.compareTo(other.dueDate); - if(dcomp == 0) - return id.compareTo(other.id); - else - return dcomp; + return (int) (dueDate.getTime() - other.dueDate.getTime()); } public Panel getDisplayPanel(String id){ diff --git a/src/main/java/se/su/dsv/scipro/data/dataobjects/ProjectEventTemplate.java b/src/main/java/se/su/dsv/scipro/data/dataobjects/ProjectEventTemplate.java index 38811fcf5b..9e5f128247 100644 --- a/src/main/java/se/su/dsv/scipro/data/dataobjects/ProjectEventTemplate.java +++ b/src/main/java/se/su/dsv/scipro/data/dataobjects/ProjectEventTemplate.java @@ -38,6 +38,9 @@ public class ProjectEventTemplate extends DomainObject implements Comparable<Pro @Column(nullable=false) private long estimatedTimeConsumption = 0; + @Column(nullable=false) + private int daysOffset; + @Column(nullable=false) private boolean requireHandIn = false; @@ -46,6 +49,10 @@ public class ProjectEventTemplate extends DomainObject implements Comparable<Pro public ProjectEventTemplate(){} + public ProjectEventTemplate(int daysOffset){ + this.daysOffset = daysOffset; + } + public Long getId() { return id; } @@ -53,6 +60,14 @@ public class ProjectEventTemplate extends DomainObject implements Comparable<Pro public void setId(Long id) { this.id = id; } + + public void setdaysOffset(int daysOffset){ + this.daysOffset = daysOffset; + } + + public int getDaysOffset(){ + return daysOffset; + } public String getTitle() { return title; diff --git a/src/main/java/se/su/dsv/scipro/util/ScheduleGenerator.java b/src/main/java/se/su/dsv/scipro/util/ScheduleGenerator.java index 527ba60e47..29252357f4 100644 --- a/src/main/java/se/su/dsv/scipro/util/ScheduleGenerator.java +++ b/src/main/java/se/su/dsv/scipro/util/ScheduleGenerator.java @@ -11,7 +11,10 @@ import org.joda.time.DateMidnight; import org.joda.time.DateTimeConstants; import org.joda.time.Days; +import se.su.dsv.scipro.SciProSession; +import se.su.dsv.scipro.data.dao.interfaces.EventDao; import se.su.dsv.scipro.data.dao.interfaces.ProjectDao; +import se.su.dsv.scipro.data.dao.interfaces.ProjectEventDao; import se.su.dsv.scipro.data.dao.interfaces.ScheduleTemplateDao; import se.su.dsv.scipro.data.dataobjects.Project; import se.su.dsv.scipro.data.dataobjects.ProjectEvent; @@ -27,6 +30,9 @@ public class ScheduleGenerator { @SpringBean private ProjectDao projectDao; + @SpringBean + private ProjectEventDao projectEventDao; + private Project project; private ScheduleTemplate template; private List<ProjectEventTemplate> eventTemplates; @@ -72,14 +78,17 @@ public class ScheduleGenerator { List<ProjectEvent> events = new ArrayList<ProjectEvent>(); DateMidnight datePointer = new DateMidnight(startDate); + DateMidnight tempPointer; int totalDuration = 0; for(ProjectEventTemplate e : eventTemplates){ + tempPointer = new DateMidnight(datePointer); ProjectEvent event = e.createEventFromTemplate(); - event.setParticipants(project.getProjectParticipants()); + event.setParticipants(project.getProjectParticipants());//might have to remove this + if(e.getEstimatedTimeConsumption() <= 1){ + datePointer = new DateMidnight(startDate).plusDays(e.getDaysOffset()); + } double duration = (double) e.getEstimatedTimeConsumption() * ratio; - if(duration < 1.0) - duration = 1.0; datePointer = datePointer.plusDays((int) duration); totalDuration += (int)duration; @@ -94,6 +103,9 @@ public class ScheduleGenerator { } event.setDueDate(datePointer.toDate()); events.add(event); + if(e.getEstimatedTimeConsumption() <= 1){ + datePointer = tempPointer; + } } return new ScheduleGeneratorResult(template, events, totalDuration, templateEstimatedDays, startDate.toDate(), endDate.toDate()); } diff --git a/src/main/java/se/su/dsv/scipro/util/TemplateGenerator.java b/src/main/java/se/su/dsv/scipro/util/TemplateGenerator.java index 5ef62a4209..b493c4068d 100644 --- a/src/main/java/se/su/dsv/scipro/util/TemplateGenerator.java +++ b/src/main/java/se/su/dsv/scipro/util/TemplateGenerator.java @@ -38,6 +38,7 @@ public class TemplateGenerator { //based on ScheduleGenerator private int templateEstimatedDays = 0; private int durationInDays = 0; + private int daysOffset; private DateMidnight startDate; @@ -56,12 +57,9 @@ public class TemplateGenerator { //based on ScheduleGenerator if(schedule.getStartDate() != null){ this.startDate = new DateMidnight(schedule.getStartDate()); }else{ - this.startDate = new DateMidnight(projectEvents.first().getDueDate()); + int days = (new DateMidnight(projectEvents.first().getDueDate()).getDayOfYear() - new DateMidnight(schedule.getStartDate()).getDayOfYear()); + this.startDate = new DateMidnight(projectEvents.first().getDueDate()).minusDays(days); } - - - - } public ScheduleTemplate generate(){ @@ -94,9 +92,12 @@ public class TemplateGenerator { //based on ScheduleGenerator pet.setRequireHandIn(pe.isRequireHandIn()); pet.setScheduleTemplate(template); + int daysOffset = (new DateMidnight(pe.getDueDate()).getDayOfYear() - startDate.getDayOfYear()); + + pet.setdaysOffset(daysOffset); datePointer = datePointer.plusDays(durationInDays); - templateEstimatedDays += durationInDays; + setTemplateEstimatedDays(getTemplateEstimatedDays() + durationInDays); projectEventTemplate.add(pet); } @@ -158,5 +159,21 @@ public class TemplateGenerator { //based on ScheduleGenerator this.startDate = new DateMidnight(startDate); } + public int getTemplateEstimatedDays() { + return templateEstimatedDays; + } + + public void setTemplateEstimatedDays(int templateEstimatedDays) { + this.templateEstimatedDays = templateEstimatedDays; + } + + public int getDaysOffset() { + return daysOffset; + } + + public void setDaysOffset(int daysOffset) { + this.daysOffset = daysOffset; + } + }