diff --git a/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/entities/DeadlineCommunicationComparator.java b/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/entities/DeadlineCommunicationComparator.java
new file mode 100644
index 000000000..5557ed297
--- /dev/null
+++ b/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/entities/DeadlineCommunicationComparator.java
@@ -0,0 +1,49 @@
+/*
+ * This file is part of LibrePlan
+ *
+ * Copyright (C) 2011 WirelessGalicia, S.L.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package org.libreplan.business.externalcompanies.entities;
+
+import java.util.Comparator;
+
+import org.libreplan.business.externalcompanies.entities.DeadlineCommunication;
+
+/**
+* Comparator to {@link DeadlineCommunication}
+*
+* @author Susana Montes Pedreira
+*/
+public class DeadlineCommunicationComparator implements Comparator {
+
+ public DeadlineCommunicationComparator(){
+ }
+
+ @Override
+ public int compare(DeadlineCommunication arg0, DeadlineCommunication arg1) {
+ if (arg0.getSaveDate() == arg1.getSaveDate()) {
+ return 0;
+ }
+ if (arg0.getSaveDate() == null) {
+ return -1;
+ }
+ if (arg1.getSaveDate() == null) {
+ return 1;
+ }
+ return arg1.getSaveDate().compareTo(arg0.getSaveDate());
+ }
+ }
diff --git a/libreplan-business/src/main/java/org/libreplan/business/orders/entities/Order.java b/libreplan-business/src/main/java/org/libreplan/business/orders/entities/Order.java
index c355d5f41..dcbeb9912 100644
--- a/libreplan-business/src/main/java/org/libreplan/business/orders/entities/Order.java
+++ b/libreplan-business/src/main/java/org/libreplan/business/orders/entities/Order.java
@@ -29,12 +29,17 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.hibernate.validator.AssertTrue;
import org.hibernate.validator.NotNull;
+import org.hibernate.validator.Valid;
import org.libreplan.business.advance.bootstrap.PredefinedAdvancedTypes;
+import org.libreplan.business.advance.entities.AdvanceMeasurement;
+import org.libreplan.business.advance.entities.AdvanceMeasurementComparator;
import org.libreplan.business.advance.entities.AdvanceType;
import org.libreplan.business.advance.entities.DirectAdvanceAssignment;
import org.libreplan.business.calendars.entities.BaseCalendar;
@@ -42,6 +47,8 @@ import org.libreplan.business.common.Registry;
import org.libreplan.business.common.entities.EntitySequence;
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
import org.libreplan.business.externalcompanies.entities.CustomerCommunication;
+import org.libreplan.business.externalcompanies.entities.DeadlineCommunication;
+import org.libreplan.business.externalcompanies.entities.DeadlineCommunicationComparator;
import org.libreplan.business.externalcompanies.entities.ExternalCompany;
import org.libreplan.business.orders.daos.IOrderDAO;
import org.libreplan.business.planner.entities.DayAssignment;
@@ -107,6 +114,10 @@ public class Order extends OrderLineGroup implements Comparable {
private Set customerCommunications = new HashSet();
+ @Valid
+ private SortedSet deliveringDates = new TreeSet(
+ new DeadlineCommunicationComparator());
+
public enum SchedulingMode {
FORWARD, BACKWARDS;
}
@@ -576,4 +587,12 @@ public class Order extends OrderLineGroup implements Comparable {
return customerCommunications;
}
+ public void setDeliveringDates(SortedSet deliveringDates) {
+ this.deliveringDates = deliveringDates;
+ }
+
+ public SortedSet getDeliveringDates() {
+ return deliveringDates;
+ }
+
}
diff --git a/libreplan-business/src/main/resources/db.changelog-1.2.xml b/libreplan-business/src/main/resources/db.changelog-1.2.xml
index fa2c2d2b2..3587c4c81 100644
--- a/libreplan-business/src/main/resources/db.changelog-1.2.xml
+++ b/libreplan-business/src/main/resources/db.changelog-1.2.xml
@@ -103,4 +103,11 @@
+
+ Add new delivering date column to order
+
+
+
+
+
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 9a64422d8..49bb65994 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
@@ -150,6 +150,14 @@
+
+
+
+
+
+
diff --git a/libreplan-business/src/test/java/org/libreplan/business/test/orders/daos/OrderDAOTest.java b/libreplan-business/src/test/java/org/libreplan/business/test/orders/daos/OrderDAOTest.java
index 347dea5c7..44118161a 100644
--- a/libreplan-business/src/test/java/org/libreplan/business/test/orders/daos/OrderDAOTest.java
+++ b/libreplan-business/src/test/java/org/libreplan/business/test/orders/daos/OrderDAOTest.java
@@ -20,12 +20,17 @@
package org.libreplan.business.test.orders.daos;
import static junit.framework.Assert.assertNotNull;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
import static org.libreplan.business.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_FILE;
import static org.libreplan.business.test.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_TEST_FILE;
import java.util.Date;
import java.util.UUID;
+import org.joda.time.LocalDate;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -34,6 +39,7 @@ import org.libreplan.business.calendars.entities.BaseCalendar;
import org.libreplan.business.common.IAdHocTransactionService;
import org.libreplan.business.common.IOnTransaction;
import org.libreplan.business.common.exceptions.ValidationException;
+import org.libreplan.business.externalcompanies.entities.DeadlineCommunication;
import org.libreplan.business.orders.daos.IOrderDAO;
import org.libreplan.business.orders.entities.Order;
import org.libreplan.business.scenarios.IScenarioManager;
@@ -102,6 +108,56 @@ public class OrderDAOTest {
return order;
}
+ private Order createValidOrderWithDeadlineCommunications(String name) {
+ Order order = createValidOrder(name);
+
+ //create two deadline communications
+ Date date1 = (new Date());
+ Date date2 = (new LocalDate(date1).plusDays(3)).toDateTimeAtStartOfDay().toDate();
+
+ DeadlineCommunication deadlineCommunication1 = DeadlineCommunication.create(date1, null);
+ DeadlineCommunication deadlineCommunication2 = DeadlineCommunication.create(date2, null);
+
+ order.getDeliveringDates().add(deadlineCommunication1);
+ order.getDeliveringDates().add(deadlineCommunication2);
+
+ return order;
+ }
+
+ @Test
+ public void testSaveOrdersWithDeliveringDates() {
+ Order order = createValidOrderWithDeadlineCommunications("test");
+ orderDAO.save(order);
+ orderDAO.flush();
+
+ assertThat(order.getDeliveringDates().size(), equalTo(2));
+
+ DeadlineCommunication dcFirst = order.getDeliveringDates().first();
+ DeadlineCommunication dcLast = order.getDeliveringDates().last();
+
+ assertTrue(dcFirst.getSaveDate().after(dcLast.getSaveDate()));
+
+
+ //A new DeadlineCommunication is placed between the existing communications.
+ Date date = (new LocalDate(dcLast.getSaveDate()).plusDays(2)).toDateTimeAtStartOfDay().toDate();
+ DeadlineCommunication deadlineCommunication = DeadlineCommunication.create(date, null);
+ order.getDeliveringDates().add(deadlineCommunication);
+
+ orderDAO.save(order);
+ orderDAO.flush();
+
+ assertThat(order.getDeliveringDates().size(), equalTo(3));
+
+ dcFirst = order.getDeliveringDates().first();
+ dcLast = order.getDeliveringDates().last();
+ DeadlineCommunication new_dc = (DeadlineCommunication) order.getDeliveringDates().toArray()[1];
+
+ assertTrue(dcFirst.getSaveDate().after(dcLast.getSaveDate()));
+ assertTrue(dcFirst.getSaveDate().after(new_dc.getSaveDate()));
+ assertFalse(dcLast.equals(new_dc));
+ assertTrue(dcLast.getSaveDate().before(new_dc.getSaveDate()));
+ }
+
@Test
public void testSaveTwoOrdersWithDifferentNames() {
transactionService.runOnAnotherTransaction(new IOnTransaction() {